Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed references to the boost library in remaining source and header files.
[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         EditorMode = FALSE;
28         sliPriority->Disable();
30         cmbType->Append(wxT(""));
31         cmbType->Append(_("Home"));
32         cmbType->Append(_("Work"));     
33 }
35 void frmContactEditorCategory::EnablePriority( wxCommandEvent& event )
36 {
37         if (chkUsePref->IsChecked()){
38                 sliPriority->Enable();
39         } else {
40                 sliPriority->Disable();
41         }
42 }
44 void frmContactEditorCategory::ProcessAction( wxCommandEvent& event )
45 {
47         long ListCtrlIndex;
48         
49         if (EditorMode == FALSE){
51                 wxString strValue;
52         
53                 // Setup Organisation Name.
54                 
55                 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
57                 strValue.Clear();
59                 strValue = cmbType->GetString(cmbType->GetSelection());
61                 // Setup Category Type.
63                 if (strValue == _("Home")) {
64                 
65                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
66                 
67                 } else if (strValue == _("Work")) {
68                 
69                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
70                 
71                 } else {
72                 
73                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("")));
74                 
75                 }
76                 
77                 // Setup Category Priority.
78                 
79                 if (chkUsePref->IsChecked()){
80                 
81                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
82                 
83                 } else {
84                 
85                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
86                 
87                 }
88                 
89                 // Add to form.
90                 
91                 wxListItem coldata;
92                 
93                 coldata.SetId(CategoryListIndex);
94                 coldata.SetData(CategoryListIndex);
95                 coldata.SetText(txtCategory->GetValue());
96                 ListCtrlIndex = CategoryListCtrlPtr->InsertItem(coldata);
97                 
98                 if (chkUsePref->IsChecked()){
99                 
100                         CategoryListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
101                 
102                 }
103                 
104                 this->Close();
105                 
106         } else if (EditorMode == TRUE) {
107         
108                 long longSelected = -1;
109                 wxString strValue;      
110         
111                 // Update Category Name.
112                 
113                 CategoryListPtr->erase(CategoryListIndex);
114                 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
115                 
116                 // Update Category Type.
117                 
118                 CategoryListTypePtr->erase(CategoryListIndex);
119         
120                 strValue = cmbType->GetString(cmbType->GetSelection());
121                 
122                 if (strValue == _("Home")) {
123                 
124                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
125                 
126                 } else if (strValue == _("Work")) {
127                 
128                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
129                 
130                 }               
131                 
132                 // Update Category Priority.
133                 
134                 CategoryListPrefPtr->erase(CategoryListIndex);
135                 
136                 if (chkUsePref->IsChecked()){
137                 
138                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
139                 
140                 } else {
141                 
142                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
143                 
144                 }
145                 
146                 // Update form.
147                 
148                 longSelected = CategoryListCtrlPtr->GetNextItem(longSelected, 
149                         wxLIST_NEXT_ALL,
150                         wxLIST_STATE_SELECTED);
151                         
152                 if (longSelected == -1){
153                         return;
154                 }               
155                 
156                 CategoryListCtrlPtr->SetItem(longSelected, 0, txtCategory->GetValue());
157                 
158                 if (chkUsePref->IsChecked()){
159                 
160                         CategoryListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
161                 
162                 } else {
163                 
164                         CategoryListCtrlPtr->SetItem(longSelected, 1, wxT(""));
165                 
166                 }
167                 
168                 this->Close();  
169         
170         }
174 void frmContactEditorCategory::SetEditorMode(bool EditMode)
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                 
218                         strValue = striter->second;
219                 
220                 }
221                 
222                 if (strValue == wxT("home")){
223                 
224                         cmbType->SetSelection(1);
225                 
226                 } else if (strValue == wxT("work")){
227                 
228                         cmbType->SetSelection(2);       
229                 
230                 } else {
231                 
232                         cmbType->SetSelection(0);
233                 
234                 }
235                 
236                 // Get the organisation priority.
237                 
238                 intiter = CategoryListPrefPtr->find(CategoryListIndex);
239                 
240                 if (intiter->first == CategoryListIndex && intiter->second > 0){
241                 
242                         sliPriority->SetValue(intiter->second);
243                         sliPriority->Enable();
244                         chkUsePref->SetValue(TRUE);
245                 
246                 }
247                 
248         }
249                 
252 void frmContactEditorCategory::CloseWindow( wxCommandEvent& event )
254         this->Close();
257 void frmContactEditorCategory::SetupPointers(std::map<int, wxString> *CategoryList,
258         std::map<int, wxString> *CategoryListAltID,
259         std::map<int, wxString> *CategoryListPID,
260         std::map<int, wxString> *CategoryListType,
261         std::map<int, wxString> *CategoryListTokens,
262         std::map<int, int> *CategoryListPref,
263         wxListCtrl *CategoryListCtrl,
264         int CategoryIndex )
267         CategoryListPtr = CategoryList;
268         //CategoryListSortAsPtr = CategoryListSortAs;
269         CategoryListAltIDPtr = CategoryListAltID;
270         CategoryListPIDPtr = CategoryListPID;
271         CategoryListTypePtr = CategoryListType;
272         CategoryListTokensPtr = CategoryListTokens;
273         CategoryListPrefPtr = CategoryListPref;
274         CategoryListCtrlPtr = CategoryListCtrl;
275         CategoryListIndex = CategoryIndex;
276         
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