Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / contacteditor / frmContactEditorAddress.cpp
1 #include "frmContactEditorAddress.h"
2 #include <map>
3 #include <wx/tokenzr.h>
5 #include "../common/textprocessing.h"
7 frmContactEditorAddress::frmContactEditorAddress( wxWindow* parent )
8 :
9 frmContactEditorAddressADT( parent )
10 {
11         EditorMode = FALSE;
12         sliPriority->Disable();
13 }
15 void frmContactEditorAddress::InitAddressEditor( wxInitDialogEvent& event )
16 {
17         // Do nothing with this subroutine at this time.
18 }
20 void frmContactEditorAddress::EnablePriority( wxCommandEvent& event )
21 {
22         if (chkUsePref->IsChecked()){
23                 sliPriority->Enable();
24         } else {
25                 sliPriority->Disable();
26         }
27 }
29 void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
30 {
32         // Check what edit mode we are in and go from there.
33         
34         long ListCtrlIndex;
35         
36         if (EditorMode == FALSE){
37         
38                 // Add the address to the list (maps).
39                 
40                 AddressListPtr->erase(AddressListIndex);                
41                 AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
43                 AddressListTownPtr->erase(AddressListIndex);
44                 AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue()));
46                 AddressListCountyPtr->erase(AddressListIndex);
47                 AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue()));
49                 AddressListPostCodePtr->erase(AddressListIndex);
50                 AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue()));
52                 AddressListCountryPtr->erase(AddressListIndex);
53                 AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
54                 
55                 // Add the label to the list (maps).
56                 
57                 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, txtLabel->GetValue()));
58                 
59                 // Add the language to the list (maps).
60                 
61                 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
62                 
63                 // No AltIDs at present.
64                 
65                 // No PIDs at present.
66                 
67                 // There are no tokens for a new address to add so this can be
68                 // ignored for the time being.
69                 
70                 // Add the Geopositioning to the list (maps).
71                 
72                 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
73                 
74                 // Add the Timezone to the list (maps).
76                 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
77                 
78                 if (EditSectionType == CE_GENERAL){
79                 
80                         AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("")));
81                 
82                 } else if (EditSectionType == CE_HOME) {
83                 
84                         AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("home")));
85                 
86                 } else if (EditSectionType == CE_WORK) {
87                 
88                         AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("work")));
89                 
90                 }
91                 
92                 //AddressListTypePtr = &AddressListType;
93                 
94                 // Add the mediatype to the list (maps).
95                 
96                 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
97                 
98                 //AddressListMediatypePtr = &AddressListMediatype;
99                 //AddressListPrefPtr = &AddressListPref;
100                 
101                 if (chkUsePref->IsChecked()){
102                 
103                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
104                 
105                 } else {
106                 
107                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));                
108                 
109                 }
110                 
111                 // Add to the form.
112                 
113                 wxListItem coldata;
114                 
115                 coldata.SetId(AddressListIndex);
116                 coldata.SetData(AddressListIndex);              
117                 coldata.SetText(txtAddress->GetValue());
118                 ListCtrlIndex = AddressListCtrlPtr->InsertItem(coldata);
119                 
120                 AddressListCtrlPtr->SetItem(ListCtrlIndex, 1, txtTownCity->GetValue());
121                 AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue());
122                 AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue());
123                 
124                 if (chkUsePref->IsChecked()){
125                 
126                         AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
127                 
128                 }
129                 
130                 this->Close();
131         
132         } else if (EditorMode == TRUE){
133         
134                 // Edit the address in the list.
135                 
136                 wxString strAddress;
137                 wxString strValue;
138                 long longSelected = -1;
139                 
140                 /*
141                 strAddress.Append(wxT(";;"));
143                 strAddress.Append(txtAddress->GetValue());
144                 strAddress.Append(wxT(";"));
145                 
146                 strAddress.Append(txtTownCity->GetValue());
147                 strAddress.Append(wxT(";"));
148                 
149                 strAddress.Append(txtCounty->GetValue());
150                 strAddress.Append(wxT(";"));
151                 
152                 strAddress.Append(txtPostCode->GetValue());
153                 strAddress.Append(wxT(";"));
155                 strAddress.Append(txtCountry->GetValue());
156                 */
157                 
158                 AddressListPtr->erase(AddressListIndex);                
159                 AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
161                 AddressListTownPtr->erase(AddressListIndex);
162                 AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue()));
164                 AddressListCountyPtr->erase(AddressListIndex);
165                 AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue()));
167                 AddressListPostCodePtr->erase(AddressListIndex);
168                 AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue()));
170                 AddressListCountryPtr->erase(AddressListIndex);
171                 AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
172                 
173                 //AddressListLabelPtr = &AddressListLabel;
174                 
175                 // Add the label to the list (maps).
176                 
177                 AddressListLabelPtr->erase(AddressListIndex);
178                 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, txtLabel->GetValue()));
179                 
180                 // Add the language to the list (maps).
181                 
182                 //AddressListLangPtr = &AddressListLang;
183                 
184                 AddressListLangPtr->erase(AddressListIndex);
185                 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
186                 
187                 //AddressListAltIDPtr = &AddressListAltID;
188                 
189                 // No AltIDs at present.
190                 
191                 // No PIDs at present.
192                 
193                 // There are no tokens for a new address to add so this can be
194                 // ignored for the time being.
195                 
196                 // Add the Geopositioning to the list (maps).
197                 
198                 AddressListGeoPtr->erase(AddressListIndex);
199                 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
200                 
201                 // Add the Timezone to the list (maps).
202                 
203                 AddressListTimezonePtr->erase(AddressListIndex);
204                 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
206                 // No need to update type since it will not have changed.
207                 
208                 //AddressListTypePtr = &AddressListType;
209                 
210                 // Add the mediatype to the list (maps).
211                 
212                 AddressListMediatypePtr->erase(AddressListIndex);
213                 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
214                 
215                 //AddressListMediatypePtr = &AddressListMediatype;
216                 //AddressListPrefPtr = &AddressListPref;
217                 
218                 AddressListPrefPtr->erase(AddressListIndex);
219                 
220                 if (chkUsePref->IsChecked()){
221                 
222                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
223                 
224                 } else {
225                 
226                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));                
227                 
228                 }
229                 
230                 // Update the form with the new details.
231                 
232                 longSelected = AddressListCtrlPtr->GetNextItem(longSelected, 
233                         wxLIST_NEXT_ALL,
234                         wxLIST_STATE_SELECTED);
235     
236                 if (longSelected == -1){
237                         return;
238                 }
240                 AddressListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());           
241                 AddressListCtrlPtr->SetItem(longSelected, 1, txtTownCity->GetValue());
242                 AddressListCtrlPtr->SetItem(longSelected, 2, txtCounty->GetValue());
243                 AddressListCtrlPtr->SetItem(longSelected, 3, txtPostCode->GetValue());
244                 
245                 if (chkUsePref->IsChecked()){
246                 
247                         AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
248                 
249                 } else {
250                 
251                         AddressListCtrlPtr->SetItem(longSelected, 4, wxT(""));
252                 
253                 }
254                 
255                 this->Close();
256         
257         }
261 void frmContactEditorAddress::CloseWindow( wxCommandEvent& event )
263         this->Close();
266 void frmContactEditorAddress::CopyAddress( wxCommandEvent& event )
269         wxString MailingLabel;
270         bool AddComma = FALSE;
271         
272         if (!txtAddress->IsEmpty()){
273         
274                 MailingLabel.Append(txtAddress->GetValue());
275                 AddComma = TRUE;
276         
277         }
278         
279         if (!txtTownCity->IsEmpty()){
280         
281                 if(AddComma == TRUE){
282                 
283                         MailingLabel.Append(wxT(",\n"));
284                         AddComma = FALSE;
285                 
286                 }
287                 
288                 MailingLabel.Append(txtTownCity->GetValue());
289                 AddComma = TRUE;
290         
291         }
292         
293         if (!txtCounty->IsEmpty()){
294         
295                 if(AddComma == TRUE){
296                 
297                         MailingLabel.Append(wxT(",\n"));
298                         AddComma = FALSE;
299                 
300                 }
301                 
302                 MailingLabel.Append(txtCounty->GetValue());
303                 AddComma = TRUE;
304         
305         }
306         
307         if (!txtPostCode->IsEmpty()){
308         
309                 if(AddComma == TRUE){
310                 
311                         MailingLabel.Append(wxT(",\n"));
312                         AddComma = FALSE;
313                 
314                 }
315                 
316                 MailingLabel.Append(txtPostCode->GetValue());
317                 AddComma = TRUE;
318         
319         }
320         
321         if (!txtCountry->IsEmpty()){
322         
323                 if(AddComma == TRUE){
324                 
325                         MailingLabel.Append(wxT(",\n"));
326                         AddComma = FALSE;
327                 
328                 }
329                 
330                 MailingLabel.Append(txtCountry->GetValue());
331                 AddComma = TRUE;
332         
333         }       
334         
335         txtLabel->SetValue(MailingLabel);
339 void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType )
341         // Set if the editor is adding or editing an address.
342         // FALSE = Add
343         // TRUE = Edit
344         
345         if (EditMode == FALSE){
346         
347                 EditorMode = FALSE;
348                 btnAction->SetLabel(_("Add"));
349                 this->SetTitle(_("Add Address"));
350         
351         } else if (EditMode == TRUE){
352         
353                 EditorMode = TRUE;
354                 btnAction->SetLabel(_("Modify"));
355                 this->SetTitle(_("Modify Address"));
356                 
357                 wxString strValue;
358                 
359                 std::map<int,int>::iterator intiter;
360                 std::map<int,wxString>::iterator striter;               
361                 
362                 // Load the data into the form.
363                 
364                 striter = AddressListPtr->find(AddressListIndex);
365                  
366                 if (striter->first == AddressListIndex){
367                 
368                         txtAddress->SetValue(striter->second);
369                 
370                 }
371                 
372                 striter = AddressListTownPtr->find(AddressListIndex);
374                 if (striter->first == AddressListIndex){
375                 
376                         txtTownCity->SetValue(striter->second);
377                 
378                 }
379                 
380                 striter = AddressListCountyPtr->find(AddressListIndex);
382                 if (striter->first == AddressListIndex){
383                 
384                         txtCounty->SetValue(striter->second);
385                 
386                 }
388                 striter = AddressListPostCodePtr->find(AddressListIndex);
390                 if (striter->first == AddressListIndex){
391                 
392                         txtPostCode->SetValue(striter->second);
393                 
394                 }
396                 striter = AddressListCountryPtr->find(AddressListIndex);
398                 if (striter->first == AddressListIndex){
399                 
400                         txtCountry->SetValue(striter->second);
401                 
402                 }
403                 
404                 //CaptureString(&strValue, TRUE);
405                 //->Replace(wxT("\;"), wxT("\;;"), TRUE);
406                 
407                 // Setup the Slider.
408                 
409                 intiter = AddressListPrefPtr->find(AddressListIndex);
410                 
411                 if (intiter->first == AddressListIndex && intiter->second > 0){
412                 
413                         sliPriority->SetValue(intiter->second);
414                         sliPriority->Enable();
415                         chkUsePref->SetValue(TRUE);
416                 
417                 }
418                 
419                 // Setup the Label.
420                 
421                 striter = AddressListLabelPtr->find(AddressListIndex);
422                  
423                 if (striter->first == AddressListIndex){
424                 
425                         strValue = striter->second;
426                 
427                 }
429                 txtLabel->SetValue(strValue);
430                 
431                 // Setup the Language, Geographic position and timezone.
432                 
433                 striter = AddressListLangPtr->find(AddressListIndex);
434                  
435                 if (striter->first == AddressListIndex){
436                 
437                         strValue = striter->second;
438                 
439                 }       
440                 
441                 cmbLanguage->SetValue(strValue);
442                 
443                 striter = AddressListGeoPtr->find(AddressListIndex);
444                  
445                 if (striter->first == AddressListIndex){
446                 
447                         strValue = striter->second;
448                 
449                 }
450                 
451                 txtGeo->SetValue(strValue);
452                 
453                 striter = AddressListTimezonePtr->find(AddressListIndex);
454                  
455                 if (striter->first == AddressListIndex){
456                 
457                         strValue = striter->second;
458                 
459                 }
460                 
461                 txtTimezone->SetValue(strValue);        
462         
463         }
464         
465         EditSectionType = SectType;
468 void frmContactEditorAddress::SetupPointers( std::map<int, wxString> *AddressList,
469         std::map<int, wxString> *AddressListTown,
470         std::map<int, wxString> *AddressListCounty,
471         std::map<int, wxString> *AddressListPostCode,
472         std::map<int, wxString> *AddressListCountry,
473         std::map<int, wxString> *AddressListLabel,
474         std::map<int, wxString> *AddressListLang,               
475         std::map<int, wxString> *AddressListAltID,
476         std::map<int, wxString> *AddressListPID,
477         std::map<int, wxString> *AddressListTokens,
478         std::map<int, wxString> *AddressListGeo,
479         std::map<int, wxString> *AddressListTimezone,
480         std::map<int, wxString> *AddressListType,
481         std::map<int, wxString> *AddressListMediatype,
482         std::map<int, int> *AddressListPref,
483         wxListCtrl *AddressListCtrl, 
484         int AddressIndex )
487         AddressListPtr = AddressList;
488         AddressListTownPtr = AddressListTown;
489         AddressListCountyPtr = AddressListCounty;
490         AddressListPostCodePtr = AddressListPostCode;
491         AddressListCountryPtr = AddressListCountry;
492         AddressListLabelPtr = AddressListLabel;
493         AddressListLangPtr = AddressListLang;
494         AddressListAltIDPtr = AddressListAltID;
495         AddressListPIDPtr = AddressListPID;
496         AddressListTokensPtr = AddressListTokens;
497         AddressListGeoPtr = AddressListGeo;
498         AddressListTimezonePtr = AddressListTimezone;
499         AddressListTypePtr = AddressListType;
500         AddressListMediatypePtr = AddressListMediatype;
501         AddressListPrefPtr = AddressListPref;
502         AddressListCtrlPtr = AddressListCtrl;
503         AddressListIndex = AddressIndex;
504         
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