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