1 // frmContactEditorAddress.cpp - frmContactEditorAddress form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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"
21 #include <wx/tokenzr.h>
23 #include "../common/textprocessing.h"
25 frmContactEditorAddress::frmContactEditorAddress( wxWindow* parent )
27 frmContactEditorAddressADT( parent )
33 sliPriority->Disable();
37 void frmContactEditorAddress::InitAddressEditor( wxInitDialogEvent& event )
39 // Do nothing with this subroutine at this time.
42 void frmContactEditorAddress::EnablePriority( wxCommandEvent& event )
45 // Enable/disable the priority setting.
47 if (chkUsePref->IsChecked()){
48 sliPriority->Enable();
50 sliPriority->Disable();
55 void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
60 // Check what edit mode we are in and go from there.
64 if (EditorMode == FALSE){
66 // Add the address to the list (maps).
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()));
83 // Add the label to the list (maps).
85 wxString LabelData = txtLabel->GetValue();
86 LabelData.Prepend("\"");
87 LabelData.Append("\"");
88 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
90 // Add the language to the list (maps).
92 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
94 // No AltIDs at present.
96 // No PIDs at present.
98 // There are no tokens for a new address to add so this can be
99 // ignored for the time being.
101 // Add the Geopositioning to the list (maps).
103 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
105 // Add the Timezone to the list (maps).
107 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
109 if (EditSectionType == CE_GENERAL){
111 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("")));
113 } else if (EditSectionType == CE_HOME) {
115 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("home")));
117 } else if (EditSectionType == CE_WORK) {
119 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("work")));
123 //AddressListTypePtr = &AddressListType;
125 // Add the mediatype to the list (maps).
127 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
129 //AddressListMediatypePtr = &AddressListMediatype;
130 //AddressListPrefPtr = &AddressListPref;
132 if (chkUsePref->IsChecked()){
134 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
138 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
146 coldata.SetId(AddressListIndex);
147 coldata.SetData(AddressListIndex);
148 coldata.SetText(txtAddress->GetValue());
149 ListCtrlIndex = AddressListCtrlPtr->InsertItem(coldata);
151 AddressListCtrlPtr->SetItem(ListCtrlIndex, 1, txtTownCity->GetValue());
152 AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue());
153 AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue());
155 if (chkUsePref->IsChecked()){
157 AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
163 } else if (EditorMode == TRUE){
165 // Edit the address in the list.
169 long longSelected = -1;
172 strAddress.Append(wxT(";;"));
174 strAddress.Append(txtAddress->GetValue());
175 strAddress.Append(wxT(";"));
177 strAddress.Append(txtTownCity->GetValue());
178 strAddress.Append(wxT(";"));
180 strAddress.Append(txtCounty->GetValue());
181 strAddress.Append(wxT(";"));
183 strAddress.Append(txtPostCode->GetValue());
184 strAddress.Append(wxT(";"));
186 strAddress.Append(txtCountry->GetValue());
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()));
204 //AddressListLabelPtr = &AddressListLabel;
206 // Add the label to the list (maps).
208 AddressListLabelPtr->erase(AddressListIndex);
210 wxString LabelData = txtLabel->GetValue();
211 LabelData.Prepend("\"");
212 LabelData.Append("\"");
213 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
215 // Add the language to the list (maps).
217 //AddressListLangPtr = &AddressListLang;
219 AddressListLangPtr->erase(AddressListIndex);
220 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
222 //AddressListAltIDPtr = &AddressListAltID;
224 // No AltIDs at present.
226 // No PIDs at present.
228 // There are no tokens for a new address to add so this can be
229 // ignored for the time being.
231 // Add the Geopositioning to the list (maps).
233 AddressListGeoPtr->erase(AddressListIndex);
234 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
236 // Add the Timezone to the list (maps).
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.
243 //AddressListTypePtr = &AddressListType;
245 // Add the mediatype to the list (maps).
247 AddressListMediatypePtr->erase(AddressListIndex);
248 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
250 //AddressListMediatypePtr = &AddressListMediatype;
251 //AddressListPrefPtr = &AddressListPref;
253 AddressListPrefPtr->erase(AddressListIndex);
255 if (chkUsePref->IsChecked()){
257 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
261 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
265 // Update the form with the new details.
267 longSelected = AddressListCtrlPtr->GetNextItem(longSelected,
269 wxLIST_STATE_SELECTED);
271 if (longSelected == -1){
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());
280 if (chkUsePref->IsChecked()){
282 AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
286 AddressListCtrlPtr->SetItem(longSelected, 4, wxT(""));
296 void frmContactEditorAddress::CloseWindow( wxCommandEvent& event )
305 void frmContactEditorAddress::CopyAddress( wxCommandEvent& event )
310 wxString MailingLabel;
311 bool AddComma = FALSE;
313 if (!txtAddress->IsEmpty()){
315 MailingLabel.Append(txtAddress->GetValue());
320 if (!txtTownCity->IsEmpty()){
322 if(AddComma == TRUE){
324 MailingLabel.Append(wxT(",\n"));
329 MailingLabel.Append(txtTownCity->GetValue());
334 if (!txtCounty->IsEmpty()){
336 if(AddComma == TRUE){
338 MailingLabel.Append(wxT(",\n"));
343 MailingLabel.Append(txtCounty->GetValue());
348 if (!txtPostCode->IsEmpty()){
350 if(AddComma == TRUE){
352 MailingLabel.Append(wxT(",\n"));
357 MailingLabel.Append(txtPostCode->GetValue());
362 if (!txtCountry->IsEmpty()){
364 if(AddComma == TRUE){
366 MailingLabel.Append(wxT(",\n"));
371 MailingLabel.Append(txtCountry->GetValue());
376 txtLabel->SetValue(MailingLabel);
380 void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType )
383 // Set the editor mode.
385 // Set if the editor is adding or editing an address.
389 if (EditMode == FALSE){
392 btnAction->SetLabel(_("Add"));
393 this->SetTitle(_("Add Address"));
395 } else if (EditMode == TRUE){
398 btnAction->SetLabel(_("Modify"));
399 this->SetTitle(_("Modify Address"));
403 std::map<int,int>::iterator intiter;
404 std::map<int,wxString>::iterator striter;
406 // Load the data into the form.
408 striter = AddressListPtr->find(AddressListIndex);
410 if (striter->first == AddressListIndex &&
411 striter != AddressListPtr->end()){
413 txtAddress->SetValue(striter->second);
417 striter = AddressListTownPtr->find(AddressListIndex);
419 if (striter->first == AddressListIndex &&
420 striter != AddressListTownPtr->end()){
422 txtTownCity->SetValue(striter->second);
426 striter = AddressListCountyPtr->find(AddressListIndex);
428 if (striter->first == AddressListIndex &&
429 striter != AddressListCountyPtr->end()){
431 txtCounty->SetValue(striter->second);
435 striter = AddressListPostCodePtr->find(AddressListIndex);
437 if (striter->first == AddressListIndex &&
438 striter != AddressListPostCodePtr->end()){
440 txtPostCode->SetValue(striter->second);
444 striter = AddressListCountryPtr->find(AddressListIndex);
446 if (striter->first == AddressListIndex &&
447 striter != AddressListCountryPtr->end()){
449 txtCountry->SetValue(striter->second);
453 //CaptureString(&strValue, TRUE);
454 //->Replace(wxT("\;"), wxT("\;;"), TRUE);
458 intiter = AddressListPrefPtr->find(AddressListIndex);
460 if (intiter->first == AddressListIndex && intiter->second > 0 && intiter != AddressListPrefPtr->end() &&
461 intiter != AddressListPrefPtr->end()){
463 sliPriority->SetValue(intiter->second);
464 sliPriority->Enable();
465 chkUsePref->SetValue(TRUE);
471 striter = AddressListLabelPtr->find(AddressListIndex);
473 if (striter->first == AddressListIndex && striter != AddressListLabelPtr->end() &&
474 striter != AddressListLabelPtr->end()){
476 strValue = striter->second;
477 if (strValue.Left(1) == "\"" && strValue.Right(1) == "\""){
478 strValue.erase(0, 1);
479 strValue.RemoveLast();
484 txtLabel->SetValue(strValue);
486 // Setup the Language, Geographic position and timezone.
488 striter = AddressListLangPtr->find(AddressListIndex);
490 if (striter->first == AddressListIndex && striter != AddressListLangPtr->end()){
492 strValue = striter->second;
496 cmbLanguage->SetValue(strValue);
498 striter = AddressListGeoPtr->find(AddressListIndex);
500 if (striter->first == AddressListIndex && striter != AddressListGeoPtr->end()){
502 strValue = striter->second;
506 txtGeo->SetValue(strValue);
508 striter = AddressListTimezonePtr->find(AddressListIndex);
510 if (striter->first == AddressListIndex && striter != AddressListTimezonePtr->end()){
512 strValue = striter->second;
516 txtTimezone->SetValue(strValue);
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,
542 // Setup the pointers.
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;