Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditorCategory: Implemented priority control
[xestiaab/.git] / source / contacteditor / frmContactEditorCategory.cpp
1 // frmContactEditorCategory.cpp - frmContactEditorCategory form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmContactEditorCategory.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
23 frmContactEditorCategory::frmContactEditorCategory( wxWindow* parent )
24 :
25 frmContactEditorCategoryADT( parent )
26 {
27         
28         // Setup the window.
29         
30         EditorMode = FALSE;
31         priorityCtrl = new XABPriorityCtrl(tabGeneral);
32         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
34         cmbType->Append(wxT(""));
35         cmbType->Append(_("Home"));
36         cmbType->Append(_("Work"));     
37 }
39 void frmContactEditorCategory::ProcessAction( wxCommandEvent& event )
40 {
42         // Process action.
43         
44         long ListCtrlIndex;
45         
46         if (EditorMode == FALSE){
48                 wxString strValue;
49         
50                 // Setup Organisation Name.
51                 
52                 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
54                 strValue.Clear();
56                 strValue = cmbType->GetString(cmbType->GetSelection());
58                 // Setup Category Type.
60                 if (strValue == _("Home")) {
61                 
62                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
63                 
64                 } else if (strValue == _("Work")) {
65                 
66                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
67                 
68                 } else {
69                 
70                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("")));
71                 
72                 }
73                 
74                 // Setup Category Priority.
75                 
76                 if (priorityCtrl->IsPriorityChecked()){
77                 
78                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, priorityCtrl->GetValue()));
79                 
80                 } else {
81                 
82                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
83                 
84                 }
85                 
86                 // Add to form.
87                 
88                 wxListItem coldata;
89                 
90                 coldata.SetId(CategoryListIndex);
91                 coldata.SetData(CategoryListIndex);
92                 coldata.SetText(txtCategory->GetValue());
93                 ListCtrlIndex = CategoryListCtrlPtr->InsertItem(coldata);
94                 
95                 if (priorityCtrl->IsPriorityChecked()){
96                 
97                         CategoryListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
98                 
99                 }
100                 
101                 this->Close();
102                 
103         } else if (EditorMode == TRUE) {
104         
105                 long longSelected = -1;
106                 wxString strValue;      
107         
108                 // Update Category Name.
109                 
110                 CategoryListPtr->erase(CategoryListIndex);
111                 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
112                 
113                 // Update Category Type.
114                 
115                 CategoryListTypePtr->erase(CategoryListIndex);
116         
117                 strValue = cmbType->GetString(cmbType->GetSelection());
118                 
119                 if (strValue == _("Home")) {
120                 
121                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
122                 
123                 } else if (strValue == _("Work")) {
124                 
125                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
126                 
127                 }               
128                 
129                 // Update Category Priority.
130                 
131                 CategoryListPrefPtr->erase(CategoryListIndex);
132                 
133                 if (priorityCtrl->IsPriorityChecked()){
134                 
135                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, priorityCtrl->GetValue()));
136                 
137                 } else {
138                 
139                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
140                 
141                 }
142                 
143                 // Update form.
144                 
145                 longSelected = CategoryListCtrlPtr->GetNextItem(longSelected, 
146                         wxLIST_NEXT_ALL,
147                         wxLIST_STATE_SELECTED);
148                         
149                 if (longSelected == -1){
150                         return;
151                 }               
152                 
153                 CategoryListCtrlPtr->SetItem(longSelected, 0, txtCategory->GetValue());
154                 
155                 if (priorityCtrl->IsPriorityChecked()){
156                 
157                         CategoryListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
158                 
159                 } else {
160                 
161                         CategoryListCtrlPtr->SetItem(longSelected, 1, wxT(""));
162                 
163                 }
164                 
165                 this->Close();  
166         
167         }
171 void frmContactEditorCategory::SetEditorMode(bool EditMode)
173         
174         // Set the editor mode.
175         
176         // Set if the editor is adding or editing an address.
177         // FALSE = Add
178         // TRUE = Edit
179         
180         if (EditMode == FALSE){
181         
182                 EditorMode = FALSE;
183                 btnAction->SetLabel(_("Add"));
184                 this->SetTitle(_("Add Category"));
185         
186         } else if (EditMode == TRUE){
187         
188                 EditorMode = TRUE;
189                 btnAction->SetLabel(_("Modify"));
190                 this->SetTitle(_("Modify Category"));           
191                 
192                 // Load the data into the form.
193                 
194                 std::map<int,int>::iterator intiter;
195                 std::map<int,wxString>::iterator striter;               
196                 wxString strValue;              
197                         
198                 // Get the organisation name.
199                 
200                 striter = CategoryListPtr->find(CategoryListIndex);
201                  
202                 if (striter->first == CategoryListIndex){
203                 
204                         strValue = striter->second;
205                 
206                 }
207                 
208                 txtCategory->SetValue(strValue);
209                 
210                 strValue.Clear();
211                 
212                 // Get the type.
213                 
214                 striter = CategoryListTypePtr->find(CategoryListIndex); 
215                 
216                 if (striter->first == CategoryListIndex &&
217                         striter != CategoryListTypePtr->end()){
218                 
219                         strValue = striter->second;
220                 
221                 }
222                 
223                 if (strValue == wxT("home")){
224                 
225                         cmbType->SetSelection(1);
226                 
227                 } else if (strValue == wxT("work")){
228                 
229                         cmbType->SetSelection(2);       
230                 
231                 } else {
232                 
233                         cmbType->SetSelection(0);
234                 
235                 }
236                 
237                 // Get the organisation priority.
238                 
239                 intiter = CategoryListPrefPtr->find(CategoryListIndex);
240                 
241                 if (intiter->first == CategoryListIndex && intiter->second > 0 &&
242                         intiter != CategoryListPrefPtr->end()){
243                 
244                         priorityCtrl->SetValue(intiter->second);
245                         priorityCtrl->EnablePriority(true);
246                 
247                 }
248                 
249         }
250                 
253 void frmContactEditorCategory::CloseWindow( wxCommandEvent& event )
255         
256         // Close this window.
257         
258         this->Close();
259         
262 void frmContactEditorCategory::SetupPointers(std::map<int, wxString> *CategoryList,
263         std::map<int, wxString> *CategoryListAltID,
264         std::map<int, wxString> *CategoryListPID,
265         std::map<int, wxString> *CategoryListType,
266         std::map<int, wxString> *CategoryListTokens,
267         std::map<int, int> *CategoryListPref,
268         wxListCtrl *CategoryListCtrl,
269         int CategoryIndex )
272         // Setup the pointers.
273         
274         CategoryListPtr = CategoryList;
275         CategoryListAltIDPtr = CategoryListAltID;
276         CategoryListPIDPtr = CategoryListPID;
277         CategoryListTypePtr = CategoryListType;
278         CategoryListTokensPtr = CategoryListTokens;
279         CategoryListPrefPtr = CategoryListPref;
280         CategoryListCtrlPtr = CategoryListCtrl;
281         CategoryListIndex = CategoryIndex;
282         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy