Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Fixed source code formatting in CALURI for ConvertToV3
[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                 wxString LabelData = txtLabel->GetValue();
76                 LabelData.Prepend("\"");
77                 LabelData.Append("\"");
78                 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
79                 
80                 // Add the language to the list (maps).
81                 
82                 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
83                 
84                 // No AltIDs at present.
85                 
86                 // No PIDs at present.
87                 
88                 // There are no tokens for a new address to add so this can be
89                 // ignored for the time being.
90                 
91                 // Add the Geopositioning to the list (maps).
92                 
93                 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
94                 
95                 // Add the Timezone to the list (maps).
97                 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
98                 
99                 if (EditSectionType == CE_GENERAL){
100                 
101                         AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("")));
102                 
103                 } else if (EditSectionType == CE_HOME) {
104                 
105                         AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("home")));
106                 
107                 } else if (EditSectionType == CE_WORK) {
108                 
109                         AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("work")));
110                 
111                 }
112                 
113                 //AddressListTypePtr = &AddressListType;
114                 
115                 // Add the mediatype to the list (maps).
116                 
117                 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
118                 
119                 //AddressListMediatypePtr = &AddressListMediatype;
120                 //AddressListPrefPtr = &AddressListPref;
121                 
122                 if (chkUsePref->IsChecked()){
123                 
124                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
125                 
126                 } else {
127                 
128                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));                
129                 
130                 }
131                 
132                 // Add to the form.
133                 
134                 wxListItem coldata;
135                 
136                 coldata.SetId(AddressListIndex);
137                 coldata.SetData(AddressListIndex);              
138                 coldata.SetText(txtAddress->GetValue());
139                 ListCtrlIndex = AddressListCtrlPtr->InsertItem(coldata);
140                 
141                 AddressListCtrlPtr->SetItem(ListCtrlIndex, 1, txtTownCity->GetValue());
142                 AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue());
143                 AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue());
144                 
145                 if (chkUsePref->IsChecked()){
146                 
147                         AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
148                 
149                 }
150                 
151                 this->Close();
152         
153         } else if (EditorMode == TRUE){
154         
155                 // Edit the address in the list.
156                 
157                 wxString strAddress;
158                 wxString strValue;
159                 long longSelected = -1;
160                 
161                 /*
162                 strAddress.Append(wxT(";;"));
164                 strAddress.Append(txtAddress->GetValue());
165                 strAddress.Append(wxT(";"));
166                 
167                 strAddress.Append(txtTownCity->GetValue());
168                 strAddress.Append(wxT(";"));
169                 
170                 strAddress.Append(txtCounty->GetValue());
171                 strAddress.Append(wxT(";"));
172                 
173                 strAddress.Append(txtPostCode->GetValue());
174                 strAddress.Append(wxT(";"));
176                 strAddress.Append(txtCountry->GetValue());
177                 */
178                 
179                 AddressListPtr->erase(AddressListIndex);                
180                 AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
182                 AddressListTownPtr->erase(AddressListIndex);
183                 AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue()));
185                 AddressListCountyPtr->erase(AddressListIndex);
186                 AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue()));
188                 AddressListPostCodePtr->erase(AddressListIndex);
189                 AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue()));
191                 AddressListCountryPtr->erase(AddressListIndex);
192                 AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
193                 
194                 //AddressListLabelPtr = &AddressListLabel;
195                 
196                 // Add the label to the list (maps).
197                 
198                 AddressListLabelPtr->erase(AddressListIndex);
199                 
200                 wxString LabelData = txtLabel->GetValue();
201                 LabelData.Prepend("\"");
202                 LabelData.Append("\"");
203                 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
204                 
205                 // Add the language to the list (maps).
206                 
207                 //AddressListLangPtr = &AddressListLang;
208                 
209                 AddressListLangPtr->erase(AddressListIndex);
210                 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
211                 
212                 //AddressListAltIDPtr = &AddressListAltID;
213                 
214                 // No AltIDs at present.
215                 
216                 // No PIDs at present.
217                 
218                 // There are no tokens for a new address to add so this can be
219                 // ignored for the time being.
220                 
221                 // Add the Geopositioning to the list (maps).
222                 
223                 AddressListGeoPtr->erase(AddressListIndex);
224                 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
225                 
226                 // Add the Timezone to the list (maps).
227                 
228                 AddressListTimezonePtr->erase(AddressListIndex);
229                 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
231                 // No need to update type since it will not have changed.
232                 
233                 //AddressListTypePtr = &AddressListType;
234                 
235                 // Add the mediatype to the list (maps).
236                 
237                 AddressListMediatypePtr->erase(AddressListIndex);
238                 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
239                 
240                 //AddressListMediatypePtr = &AddressListMediatype;
241                 //AddressListPrefPtr = &AddressListPref;
242                 
243                 AddressListPrefPtr->erase(AddressListIndex);
244                 
245                 if (chkUsePref->IsChecked()){
246                 
247                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
248                 
249                 } else {
250                 
251                         AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));                
252                 
253                 }
254                 
255                 // Update the form with the new details.
256                 
257                 longSelected = AddressListCtrlPtr->GetNextItem(longSelected, 
258                         wxLIST_NEXT_ALL,
259                         wxLIST_STATE_SELECTED);
260     
261                 if (longSelected == -1){
262                         return;
263                 }
265                 AddressListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());           
266                 AddressListCtrlPtr->SetItem(longSelected, 1, txtTownCity->GetValue());
267                 AddressListCtrlPtr->SetItem(longSelected, 2, txtCounty->GetValue());
268                 AddressListCtrlPtr->SetItem(longSelected, 3, txtPostCode->GetValue());
269                 
270                 if (chkUsePref->IsChecked()){
271                 
272                         AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
273                 
274                 } else {
275                 
276                         AddressListCtrlPtr->SetItem(longSelected, 4, wxT(""));
277                 
278                 }
279                 
280                 this->Close();
281         
282         }
286 void frmContactEditorAddress::CloseWindow( wxCommandEvent& event )
288         this->Close();
291 void frmContactEditorAddress::CopyAddress( wxCommandEvent& event )
294         wxString MailingLabel;
295         bool AddComma = FALSE;
296         
297         if (!txtAddress->IsEmpty()){
298         
299                 MailingLabel.Append(txtAddress->GetValue());
300                 AddComma = TRUE;
301         
302         }
303         
304         if (!txtTownCity->IsEmpty()){
305         
306                 if(AddComma == TRUE){
307                 
308                         MailingLabel.Append(wxT(",\n"));
309                         AddComma = FALSE;
310                 
311                 }
312                 
313                 MailingLabel.Append(txtTownCity->GetValue());
314                 AddComma = TRUE;
315         
316         }
317         
318         if (!txtCounty->IsEmpty()){
319         
320                 if(AddComma == TRUE){
321                 
322                         MailingLabel.Append(wxT(",\n"));
323                         AddComma = FALSE;
324                 
325                 }
326                 
327                 MailingLabel.Append(txtCounty->GetValue());
328                 AddComma = TRUE;
329         
330         }
331         
332         if (!txtPostCode->IsEmpty()){
333         
334                 if(AddComma == TRUE){
335                 
336                         MailingLabel.Append(wxT(",\n"));
337                         AddComma = FALSE;
338                 
339                 }
340                 
341                 MailingLabel.Append(txtPostCode->GetValue());
342                 AddComma = TRUE;
343         
344         }
345         
346         if (!txtCountry->IsEmpty()){
347         
348                 if(AddComma == TRUE){
349                 
350                         MailingLabel.Append(wxT(",\n"));
351                         AddComma = FALSE;
352                 
353                 }
354                 
355                 MailingLabel.Append(txtCountry->GetValue());
356                 AddComma = TRUE;
357         
358         }       
359         
360         txtLabel->SetValue(MailingLabel);
364 void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType )
366         // Set if the editor is adding or editing an address.
367         // FALSE = Add
368         // TRUE = Edit
369         
370         if (EditMode == FALSE){
371         
372                 EditorMode = FALSE;
373                 btnAction->SetLabel(_("Add"));
374                 this->SetTitle(_("Add Address"));
375         
376         } else if (EditMode == TRUE){
377         
378                 EditorMode = TRUE;
379                 btnAction->SetLabel(_("Modify"));
380                 this->SetTitle(_("Modify Address"));
381                 
382                 wxString strValue;
383                 
384                 std::map<int,int>::iterator intiter;
385                 std::map<int,wxString>::iterator striter;               
386                 
387                 // Load the data into the form.
388                 
389                 striter = AddressListPtr->find(AddressListIndex);
390                  
391                 if (striter->first == AddressListIndex){
392                 
393                         txtAddress->SetValue(striter->second);
394                 
395                 }
396                 
397                 striter = AddressListTownPtr->find(AddressListIndex);
399                 if (striter->first == AddressListIndex){
400                 
401                         txtTownCity->SetValue(striter->second);
402                 
403                 }
404                 
405                 striter = AddressListCountyPtr->find(AddressListIndex);
407                 if (striter->first == AddressListIndex){
408                 
409                         txtCounty->SetValue(striter->second);
410                 
411                 }
413                 striter = AddressListPostCodePtr->find(AddressListIndex);
415                 if (striter->first == AddressListIndex){
416                 
417                         txtPostCode->SetValue(striter->second);
418                 
419                 }
421                 striter = AddressListCountryPtr->find(AddressListIndex);
423                 if (striter->first == AddressListIndex){
424                 
425                         txtCountry->SetValue(striter->second);
426                 
427                 }
428                 
429                 //CaptureString(&strValue, TRUE);
430                 //->Replace(wxT("\;"), wxT("\;;"), TRUE);
431                 
432                 // Setup the Slider.
433                 
434                 intiter = AddressListPrefPtr->find(AddressListIndex);
435                 
436                 if (intiter->first == AddressListIndex && intiter->second > 0 && intiter != AddressListPrefPtr->end()){
437                 
438                         sliPriority->SetValue(intiter->second);
439                         sliPriority->Enable();
440                         chkUsePref->SetValue(TRUE);
441                 
442                 }
443                 
444                 // Setup the Label.
445                 
446                 striter = AddressListLabelPtr->find(AddressListIndex);
447                  
448                 if (striter->first == AddressListIndex && striter != AddressListLabelPtr->end()){
449                 
450                         strValue = striter->second;
451                         if (strValue.Left(1) == "\"" && strValue.Right(1) == "\""){
452                                 strValue.erase(0, 1);
453                                 strValue.RemoveLast();
454                         }
455                 
456                 }
458                 txtLabel->SetValue(strValue);
459                 
460                 // Setup the Language, Geographic position and timezone.
461                 
462                 striter = AddressListLangPtr->find(AddressListIndex);
463                  
464                 if (striter->first == AddressListIndex && striter != AddressListLangPtr->end()){
465                 
466                         strValue = striter->second;
468                 }       
469                 
470                 cmbLanguage->SetValue(strValue);
471                 
472                 striter = AddressListGeoPtr->find(AddressListIndex);
473                  
474                 if (striter->first == AddressListIndex && striter != AddressListGeoPtr->end()){
475                 
476                         strValue = striter->second;
477                 
478                 }
479                 
480                 txtGeo->SetValue(strValue);
481                 
482                 striter = AddressListTimezonePtr->find(AddressListIndex);
483                  
484                 if (striter->first == AddressListIndex && striter != AddressListTimezonePtr->end()){
485                 
486                         strValue = striter->second;
487                 
488                 }
489                 
490                 txtTimezone->SetValue(strValue);        
491         
492         }
493         
494         EditSectionType = SectType;
497 void frmContactEditorAddress::SetupPointers( std::map<int, wxString> *AddressList,
498         std::map<int, wxString> *AddressListTown,
499         std::map<int, wxString> *AddressListCounty,
500         std::map<int, wxString> *AddressListPostCode,
501         std::map<int, wxString> *AddressListCountry,
502         std::map<int, wxString> *AddressListLabel,
503         std::map<int, wxString> *AddressListLang,               
504         std::map<int, wxString> *AddressListAltID,
505         std::map<int, wxString> *AddressListPID,
506         std::map<int, wxString> *AddressListTokens,
507         std::map<int, wxString> *AddressListGeo,
508         std::map<int, wxString> *AddressListTimezone,
509         std::map<int, wxString> *AddressListType,
510         std::map<int, wxString> *AddressListMediatype,
511         std::map<int, int> *AddressListPref,
512         wxListCtrl *AddressListCtrl, 
513         int AddressIndex )
516         AddressListPtr = AddressList;
517         AddressListTownPtr = AddressListTown;
518         AddressListCountyPtr = AddressListCounty;
519         AddressListPostCodePtr = AddressListPostCode;
520         AddressListCountryPtr = AddressListCountry;
521         AddressListLabelPtr = AddressListLabel;
522         AddressListLangPtr = AddressListLang;
523         AddressListAltIDPtr = AddressListAltID;
524         AddressListPIDPtr = AddressListPID;
525         AddressListTokensPtr = AddressListTokens;
526         AddressListGeoPtr = AddressListGeo;
527         AddressListTimezonePtr = AddressListTimezone;
528         AddressListTypePtr = AddressListType;
529         AddressListMediatypePtr = AddressListMediatype;
530         AddressListPrefPtr = AddressListPref;
531         AddressListCtrlPtr = AddressListCtrl;
532         AddressListIndex = AddressIndex;
533         
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