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