Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Replaced PREF code in IMPP for ProcessIntegerValue.
[xestiaab/.git] / source / contacteditor / frmContactEditorCalAdr.cpp
1 // frmContactEditorCalAdr.cpp - frmContactEditorCalAdr 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 "frmContactEditorCalAdr.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
23 frmContactEditorCalAdr::frmContactEditorCalAdr( wxWindow* parent )
24 :
25 frmContactEditorCalAdrADT( parent )
26 {
27         EditorMode = FALSE;
28         sliPriority->Disable();
29         
30         cmbType->Append(wxT(""));
31         cmbType->Append(_("Home"));
32         cmbType->Append(_("Work"));     
33 }
35 void frmContactEditorCalAdr::EnablePriority( wxCommandEvent& event )
36 {
37         if (chkUsePref->IsChecked()){
38                 sliPriority->Enable();
39         } else {
40                 sliPriority->Disable();
41         }
42 }
44 void frmContactEditorCalAdr::ProcessAction( wxCommandEvent& event )
45 {
46         long ListCtrlIndex;
47         
48         if (EditorMode == FALSE){
50                 wxString strValue;
51         
52                 // Setup Calendar Address.
53                 
54                 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
56                 strValue.Clear();
57                 
58                 strValue = cmbType->GetString(cmbType->GetSelection());
60                 // Setup Calendar Type.
62                 if (strValue == _("Home")) {
63                 
64                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
65                 
66                 } else if (strValue == _("Work")) {
67                 
68                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
69                 
70                 } else {
71                 
72                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("")));
73                 
74                 }
75                 
76                 // Setup Calendar Priority.
77                 
78                 if (chkUsePref->IsChecked()){
79                 
80                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
81                 
82                 } else {
83                 
84                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
85                 
86                 }
87                 
88                 // Add to form.
89                 
90                 wxListItem coldata;
91                 
92                 coldata.SetId(CalAdrListIndex);
93                 coldata.SetData(CalAdrListIndex);
94                 coldata.SetText(txtAddress->GetValue());
95                 ListCtrlIndex = CalAdrListCtrlPtr->InsertItem(coldata);
96                 
97                 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);
98                 
99                 if (chkUsePref->IsChecked()){
100                 
101                         CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
102                 
103                 }
104                 
105                 this->Close();
106                 
107         } else if (EditorMode == TRUE) {
108         
109                 long longSelected = -1;
110                 wxString strValue;      
111         
112                 // Update Category Name.
113                 
114                 CalAdrListPtr->erase(CalAdrListIndex);
115                 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
116                 
117                 // Update Category Type.
118                 
119                 CalAdrListTypePtr->erase(CalAdrListIndex);
120                 
121                 strValue.Clear();
122                 strValue = cmbType->GetString(cmbType->GetSelection());
123                 
124                 if (strValue == _("Home")) {
125                 
126                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
127                 
128                 } else if (strValue == _("Work")) {
129                 
130                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
131                 
132                 }               
133                 
134                 // Update Category Priority.
135                 
136                 CalAdrListPrefPtr->erase(CalAdrListIndex);
137                 
138                 if (chkUsePref->IsChecked()){
139                 
140                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
141                 
142                 } else {
143                 
144                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
145                 
146                 }
147                 
148                 // Update form.
149                 
150                 longSelected = CalAdrListCtrlPtr->GetNextItem(longSelected, 
151                         wxLIST_NEXT_ALL,
152                         wxLIST_STATE_SELECTED);
153                         
154                 if (longSelected == -1){
155                         return;
156                 }               
157                 
158                 CalAdrListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
159                 CalAdrListCtrlPtr->SetItem(longSelected, 1, strValue);          
160                 
161                 if (chkUsePref->IsChecked()){
162                 
163                         CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
164                 
165                 } else {
166                 
167                         CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT(""));
168                 
169                 }
170                 
171                 this->Close();  
172         
173         }
176 void frmContactEditorCalAdr::SetEditorMode(bool EditMode)
178         // Set if the editor is adding or editing an address.
179         // FALSE = Add
180         // TRUE = Edit
181         
182         if (EditMode == FALSE){
183         
184                 EditorMode = FALSE;
185                 btnAction->SetLabel(_("Add"));
186                 this->SetTitle(_("Add Calendar Address"));
187         
188         } else if (EditMode == TRUE){
189         
190                 EditorMode = TRUE;
191                 btnAction->SetLabel(_("Modify"));
192                 this->SetTitle(_("Modify Calendar Address"));
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 = CalAdrListPtr->find(CalAdrListIndex);
201                  
202                 if (striter->first == CalAdrListIndex){
203                 
204                         strValue = striter->second;
205                 
206                 }
207                 
208                 txtAddress->SetValue(strValue);
209                 
210                 strValue.Clear();
211                 
212                 // Get the type.
213                 
214                 striter = CalAdrListTypePtr->find(CalAdrListIndex);     
215                 
216                 if (striter->first == CalAdrListIndex){
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 = CalAdrListPrefPtr->find(CalAdrListIndex);
239                 
240                 if (intiter->first == CalAdrListIndex && intiter->second > 0){
241                 
242                         sliPriority->SetValue(intiter->second);
243                         sliPriority->Enable();
244                         chkUsePref->SetValue(TRUE);
245                 
246                 }
247                 
248         }
249                 
252 void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event )
254         this->Close();
257 void frmContactEditorCalAdr::SetupPointers(std::map<int, wxString> *CalAdrList,
258         std::map<int, wxString> *CalAdrListAltID,
259         std::map<int, wxString> *CalAdrListPID,
260         std::map<int, wxString> *CalAdrListType,
261         std::map<int, wxString> *CalAdrListTokens,
262         std::map<int, int> *CalAdrListPref,
263         wxListCtrl *CalAdrListCtrl,
264         int CalAdrIndex )
267         CalAdrListPtr = CalAdrList;
268         CalAdrListAltIDPtr = CalAdrListAltID;
269         CalAdrListPIDPtr = CalAdrListPID;
270         CalAdrListTypePtr = CalAdrListType;
271         CalAdrListTokensPtr = CalAdrListTokens;
272         CalAdrListPrefPtr = CalAdrListPref;
273         CalAdrListCtrlPtr = CalAdrListCtrl;
274         CalAdrListIndex = CalAdrIndex;
275         
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