Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed stray carddav.h from frmActivityMgr.h
[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         sliPriority->Disable();
33         cmbType->Append(wxT(""));
34         cmbType->Append(_("Home"));
35         cmbType->Append(_("Work"));     
36 }
38 void frmContactEditorCategory::EnablePriority( wxCommandEvent& event )
39 {
40         
41         // Enable/disable the priority setting.
42         
43         if (chkUsePref->IsChecked()){
44                 sliPriority->Enable();
45         } else {
46                 sliPriority->Disable();
47         }
48         
49 }
51 void frmContactEditorCategory::ProcessAction( wxCommandEvent& event )
52 {
54         // Process action.
55         
56         long ListCtrlIndex;
57         
58         if (EditorMode == FALSE){
60                 wxString strValue;
61         
62                 // Setup Organisation Name.
63                 
64                 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
66                 strValue.Clear();
68                 strValue = cmbType->GetString(cmbType->GetSelection());
70                 // Setup Category Type.
72                 if (strValue == _("Home")) {
73                 
74                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
75                 
76                 } else if (strValue == _("Work")) {
77                 
78                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
79                 
80                 } else {
81                 
82                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("")));
83                 
84                 }
85                 
86                 // Setup Category Priority.
87                 
88                 if (chkUsePref->IsChecked()){
89                 
90                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
91                 
92                 } else {
93                 
94                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
95                 
96                 }
97                 
98                 // Add to form.
99                 
100                 wxListItem coldata;
101                 
102                 coldata.SetId(CategoryListIndex);
103                 coldata.SetData(CategoryListIndex);
104                 coldata.SetText(txtCategory->GetValue());
105                 ListCtrlIndex = CategoryListCtrlPtr->InsertItem(coldata);
106                 
107                 if (chkUsePref->IsChecked()){
108                 
109                         CategoryListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
110                 
111                 }
112                 
113                 this->Close();
114                 
115         } else if (EditorMode == TRUE) {
116         
117                 long longSelected = -1;
118                 wxString strValue;      
119         
120                 // Update Category Name.
121                 
122                 CategoryListPtr->erase(CategoryListIndex);
123                 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
124                 
125                 // Update Category Type.
126                 
127                 CategoryListTypePtr->erase(CategoryListIndex);
128         
129                 strValue = cmbType->GetString(cmbType->GetSelection());
130                 
131                 if (strValue == _("Home")) {
132                 
133                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
134                 
135                 } else if (strValue == _("Work")) {
136                 
137                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
138                 
139                 }               
140                 
141                 // Update Category Priority.
142                 
143                 CategoryListPrefPtr->erase(CategoryListIndex);
144                 
145                 if (chkUsePref->IsChecked()){
146                 
147                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
148                 
149                 } else {
150                 
151                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
152                 
153                 }
154                 
155                 // Update form.
156                 
157                 longSelected = CategoryListCtrlPtr->GetNextItem(longSelected, 
158                         wxLIST_NEXT_ALL,
159                         wxLIST_STATE_SELECTED);
160                         
161                 if (longSelected == -1){
162                         return;
163                 }               
164                 
165                 CategoryListCtrlPtr->SetItem(longSelected, 0, txtCategory->GetValue());
166                 
167                 if (chkUsePref->IsChecked()){
168                 
169                         CategoryListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
170                 
171                 } else {
172                 
173                         CategoryListCtrlPtr->SetItem(longSelected, 1, wxT(""));
174                 
175                 }
176                 
177                 this->Close();  
178         
179         }
183 void frmContactEditorCategory::SetEditorMode(bool EditMode)
185         
186         // Set the editor mode.
187         
188         // Set if the editor is adding or editing an address.
189         // FALSE = Add
190         // TRUE = Edit
191         
192         if (EditMode == FALSE){
193         
194                 EditorMode = FALSE;
195                 btnAction->SetLabel(_("Add"));
196                 this->SetTitle(_("Add Category"));
197         
198         } else if (EditMode == TRUE){
199         
200                 EditorMode = TRUE;
201                 btnAction->SetLabel(_("Modify"));
202                 this->SetTitle(_("Modify Category"));           
203                 
204                 // Load the data into the form.
205                 
206                 std::map<int,int>::iterator intiter;
207                 std::map<int,wxString>::iterator striter;               
208                 wxString strValue;              
209                         
210                 // Get the organisation name.
211                 
212                 striter = CategoryListPtr->find(CategoryListIndex);
213                  
214                 if (striter->first == CategoryListIndex){
215                 
216                         strValue = striter->second;
217                 
218                 }
219                 
220                 txtCategory->SetValue(strValue);
221                 
222                 strValue.Clear();
223                 
224                 // Get the type.
225                 
226                 striter = CategoryListTypePtr->find(CategoryListIndex); 
227                 
228                 if (striter->first == CategoryListIndex &&
229                         striter != CategoryListTypePtr->end()){
230                 
231                         strValue = striter->second;
232                 
233                 }
234                 
235                 if (strValue == wxT("home")){
236                 
237                         cmbType->SetSelection(1);
238                 
239                 } else if (strValue == wxT("work")){
240                 
241                         cmbType->SetSelection(2);       
242                 
243                 } else {
244                 
245                         cmbType->SetSelection(0);
246                 
247                 }
248                 
249                 // Get the organisation priority.
250                 
251                 intiter = CategoryListPrefPtr->find(CategoryListIndex);
252                 
253                 if (intiter->first == CategoryListIndex && intiter->second > 0 &&
254                         intiter != CategoryListPrefPtr->end()){
255                 
256                         sliPriority->SetValue(intiter->second);
257                         sliPriority->Enable();
258                         chkUsePref->SetValue(TRUE);
259                 
260                 }
261                 
262         }
263                 
266 void frmContactEditorCategory::CloseWindow( wxCommandEvent& event )
268         
269         // Close this window.
270         
271         this->Close();
272         
275 void frmContactEditorCategory::SetupPointers(std::map<int, wxString> *CategoryList,
276         std::map<int, wxString> *CategoryListAltID,
277         std::map<int, wxString> *CategoryListPID,
278         std::map<int, wxString> *CategoryListType,
279         std::map<int, wxString> *CategoryListTokens,
280         std::map<int, int> *CategoryListPref,
281         wxListCtrl *CategoryListCtrl,
282         int CategoryIndex )
285         // Setup the pointers.
286         
287         CategoryListPtr = CategoryList;
288         CategoryListAltIDPtr = CategoryListAltID;
289         CategoryListPIDPtr = CategoryListPID;
290         CategoryListTypePtr = CategoryListType;
291         CategoryListTokensPtr = CategoryListTokens;
292         CategoryListPrefPtr = CategoryListPref;
293         CategoryListCtrlPtr = CategoryListCtrl;
294         CategoryListIndex = CategoryIndex;
295         
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