Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor: Stop XAB crashing when pressing Modify/Delete
[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         
28         // Setup the window.
29         
30         EditorMode = FALSE;
31         priorityCtrl = new XABPriorityCtrl(tabGeneral);
32         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
33         
34         cmbType->Append(wxT(""));
35         cmbType->Append(_("Home"));
36         cmbType->Append(_("Work"));
37         
38 }
40 void frmContactEditorCalAdr::ProcessAction( wxCommandEvent& event )
41 {
42         
43         // Process action.
44         
45         long ListCtrlIndex;
46         
47         if (EditorMode == FALSE){
49                 wxString strValue;
50         
51                 // Setup Calendar Address.
52                 
53                 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
55                 strValue.Clear();
56                 
57                 strValue = cmbType->GetString(cmbType->GetSelection());
59                 // Setup Calendar Type.
61                 if (strValue == _("Home")) {
62                 
63                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
64                 
65                 } else if (strValue == _("Work")) {
66                 
67                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
68                 
69                 } else {
70                 
71                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("")));
72                 
73                 }
74                 
75                 // Setup Calendar Priority.
76                 
77                 if (priorityCtrl->IsPriorityChecked()){
78                 
79                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, priorityCtrl->GetValue()));
80                 
81                 } else {
82                 
83                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
84                 
85                 }
86                 
87                 // Add to form.
88                 
89                 wxListItem coldata;
90                 
91                 coldata.SetId(CalAdrListIndex);
92                 coldata.SetData(CalAdrListIndex);
93                 coldata.SetText(txtAddress->GetValue());
94                 ListCtrlIndex = CalAdrListCtrlPtr->InsertItem(coldata);
95                 
96                 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);
97                 
98                 if (priorityCtrl->IsPriorityChecked()){
99                 
100                         CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->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                 CalAdrListPtr->erase(CalAdrListIndex);
114                 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
115                 
116                 // Update Category Type.
117                 
118                 CalAdrListTypePtr->erase(CalAdrListIndex);
119                 
120                 strValue.Clear();
121                 strValue = cmbType->GetString(cmbType->GetSelection());
122                 
123                 if (strValue == _("Home")) {
124                 
125                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
126                 
127                 } else if (strValue == _("Work")) {
128                 
129                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
130                 
131                 }               
132                 
133                 // Update Category Priority.
134                 
135                 CalAdrListPrefPtr->erase(CalAdrListIndex);
136                 
137                 if (priorityCtrl->IsPriorityChecked()){
138                 
139                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, priorityCtrl->GetValue()));
140                 
141                 } else {
142                 
143                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
144                 
145                 }
146                 
147                 // Update form.
148                 
149                 longSelected = CalAdrListCtrlPtr->GetNextItem(longSelected, 
150                         wxLIST_NEXT_ALL,
151                         wxLIST_STATE_SELECTED);
152                         
153                 if (longSelected == -1){
154                         return;
155                 }               
156                 
157                 CalAdrListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
158                 CalAdrListCtrlPtr->SetItem(longSelected, 1, strValue);          
159                 
160                 if (priorityCtrl->IsPriorityChecked()){
161                 
162                         CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
163                 
164                 } else {
165                 
166                         CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT(""));
167                 
168                 }
169                 
170                 this->Close();  
171         
172         }
173         
176 void frmContactEditorCalAdr::SetEditorMode(bool EditMode)
178         
179         // Set the editor mode.
180         
181         // Set if the editor is adding or editing an address.
182         // FALSE = Add
183         // TRUE = Edit
184         
185         if (EditMode == FALSE){
186         
187                 EditorMode = FALSE;
188                 btnAction->SetLabel(_("Add"));
189                 this->SetTitle(_("Add Calendar Address"));
190         
191         } else if (EditMode == TRUE){
192         
193                 EditorMode = TRUE;
194                 btnAction->SetLabel(_("Modify"));
195                 this->SetTitle(_("Modify Calendar Address"));
196                 
197                 std::map<int,int>::iterator intiter;
198                 std::map<int,wxString>::iterator striter;               
199                 wxString strValue;              
200                         
201                 // Get the organisation name.
202                 
203                 striter = CalAdrListPtr->find(CalAdrListIndex);
204                  
205                 if (striter->first == CalAdrListIndex){
206                 
207                         strValue = striter->second;
208                 
209                 }
210                 
211                 txtAddress->SetValue(strValue);
212                 
213                 strValue.Clear();
214                 
215                 // Get the type.
216                 
217                 striter = CalAdrListTypePtr->find(CalAdrListIndex);     
218                 
219                 if (striter->first == CalAdrListIndex && 
220                         striter != CalAdrListTypePtr->end()){
221                 
222                         strValue = striter->second;
223                 
224                 }
225                 
226                 if (strValue == wxT("home")){
227                 
228                         cmbType->SetSelection(1);
229                 
230                 } else if (strValue == wxT("work")){
231                 
232                         cmbType->SetSelection(2);       
233                 
234                 } else {
235                 
236                         cmbType->SetSelection(0);
237                 
238                 }
239                 
240                 // Get the organisation priority.
241                 
242                 intiter = CalAdrListPrefPtr->find(CalAdrListIndex);
243                 
244                 if (intiter->first == CalAdrListIndex && intiter->second > 0 &&
245                         intiter != CalAdrListPrefPtr->end()){
246                 
247                         priorityCtrl->SetValue(intiter->second);
248                         priorityCtrl->EnablePriority(true);
249                 
250                 }
251                 
252         }
253                 
256 void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event )
258         
259         // Close the window.
260         
261         this->Close();
262         
265 void frmContactEditorCalAdr::SetupPointers(std::map<int, wxString> *CalAdrList,
266         std::map<int, wxString> *CalAdrListAltID,
267         std::map<int, wxString> *CalAdrListPID,
268         std::map<int, wxString> *CalAdrListType,
269         std::map<int, wxString> *CalAdrListTokens,
270         std::map<int, int> *CalAdrListPref,
271         wxListCtrl *CalAdrListCtrl,
272         int CalAdrIndex )
275         // Setup the pointers.
276         
277         CalAdrListPtr = CalAdrList;
278         CalAdrListAltIDPtr = CalAdrListAltID;
279         CalAdrListPIDPtr = CalAdrListPID;
280         CalAdrListTypePtr = CalAdrListType;
281         CalAdrListTokensPtr = CalAdrListTokens;
282         CalAdrListPrefPtr = CalAdrListPref;
283         CalAdrListCtrlPtr = CalAdrListCtrl;
284         CalAdrListIndex = CalAdrIndex;
285         
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