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 priorityCtrl = new XABPriorityCtrl(tabGeneral);
34 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
39 void frmContactEditorAddress::InitAddressEditor( wxInitDialogEvent& event )
41 // Do nothing with this subroutine at this time.
44 void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
49 // Check what edit mode we are in and go from there.
53 if (EditorMode == FALSE){
55 // Add the address to the list (maps).
57 AddressListPtr->erase(AddressListIndex);
58 AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
60 AddressListTownPtr->erase(AddressListIndex);
61 AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue()));
63 AddressListCountyPtr->erase(AddressListIndex);
64 AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue()));
66 AddressListPostCodePtr->erase(AddressListIndex);
67 AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue()));
69 AddressListCountryPtr->erase(AddressListIndex);
70 AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
72 // Add the label to the list (maps).
74 wxString LabelData = txtLabel->GetValue();
75 LabelData.Prepend("\"");
76 LabelData.Append("\"");
77 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
79 // Add the language to the list (maps).
81 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
83 // No AltIDs at present.
85 // No PIDs at present.
87 // There are no tokens for a new address to add so this can be
88 // ignored for the time being.
90 // Add the Geopositioning to the list (maps).
92 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
94 // Add the Timezone to the list (maps).
96 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
98 if (EditSectionType == CE_GENERAL){
100 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("")));
102 } else if (EditSectionType == CE_HOME) {
104 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("home")));
106 } else if (EditSectionType == CE_WORK) {
108 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("work")));
112 // Add the mediatype to the list (maps).
114 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
116 if (priorityCtrl->IsPriorityChecked()){
118 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, priorityCtrl->GetValue()));
122 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
130 coldata.SetId(AddressListIndex);
131 coldata.SetData(AddressListIndex);
132 coldata.SetText(txtAddress->GetValue());
133 ListCtrlIndex = AddressListCtrlPtr->InsertItem(coldata);
135 AddressListCtrlPtr->SetItem(ListCtrlIndex, 1, txtTownCity->GetValue());
136 AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue());
137 AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue());
139 if (priorityCtrl->IsPriorityChecked()){
141 AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
147 } else if (EditorMode == TRUE){
149 // Edit the address in the list.
153 long longSelected = -1;
155 AddressListPtr->erase(AddressListIndex);
156 AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
158 AddressListTownPtr->erase(AddressListIndex);
159 AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue()));
161 AddressListCountyPtr->erase(AddressListIndex);
162 AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue()));
164 AddressListPostCodePtr->erase(AddressListIndex);
165 AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue()));
167 AddressListCountryPtr->erase(AddressListIndex);
168 AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
170 // Add the label to the list (maps).
172 AddressListLabelPtr->erase(AddressListIndex);
174 wxString LabelData = txtLabel->GetValue();
175 LabelData.Prepend("\"");
176 LabelData.Append("\"");
177 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
179 // Add the language to the list (maps).
181 AddressListLangPtr->erase(AddressListIndex);
182 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
184 //AddressListAltIDPtr = &AddressListAltID;
186 // No AltIDs at present.
188 // No PIDs at present.
190 // There are no tokens for a new address to add so this can be
191 // ignored for the time being.
193 // Add the Geopositioning to the list (maps).
195 AddressListGeoPtr->erase(AddressListIndex);
196 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
198 // Add the Timezone to the list (maps).
200 AddressListTimezonePtr->erase(AddressListIndex);
201 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
203 // Add the mediatype to the list (maps).
205 AddressListMediatypePtr->erase(AddressListIndex);
206 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
208 AddressListPrefPtr->erase(AddressListIndex);
210 if (priorityCtrl->IsPriorityChecked()){
212 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, priorityCtrl->GetValue()));
216 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
220 // Update the form with the new details.
222 longSelected = AddressListCtrlPtr->GetNextItem(longSelected,
224 wxLIST_STATE_SELECTED);
226 if (longSelected == -1){
230 AddressListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
231 AddressListCtrlPtr->SetItem(longSelected, 1, txtTownCity->GetValue());
232 AddressListCtrlPtr->SetItem(longSelected, 2, txtCounty->GetValue());
233 AddressListCtrlPtr->SetItem(longSelected, 3, txtPostCode->GetValue());
235 if (priorityCtrl->IsPriorityChecked()){
237 AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
241 AddressListCtrlPtr->SetItem(longSelected, 4, wxT(""));
251 void frmContactEditorAddress::CloseWindow( wxCommandEvent& event )
260 void frmContactEditorAddress::CopyAddress( wxCommandEvent& event )
265 wxString MailingLabel;
266 bool AddComma = FALSE;
268 if (!txtAddress->IsEmpty()){
270 MailingLabel.Append(txtAddress->GetValue());
275 if (!txtTownCity->IsEmpty()){
277 if(AddComma == TRUE){
279 MailingLabel.Append(wxT(",\n"));
284 MailingLabel.Append(txtTownCity->GetValue());
289 if (!txtCounty->IsEmpty()){
291 if(AddComma == TRUE){
293 MailingLabel.Append(wxT(",\n"));
298 MailingLabel.Append(txtCounty->GetValue());
303 if (!txtPostCode->IsEmpty()){
305 if(AddComma == TRUE){
307 MailingLabel.Append(wxT(",\n"));
312 MailingLabel.Append(txtPostCode->GetValue());
317 if (!txtCountry->IsEmpty()){
319 if(AddComma == TRUE){
321 MailingLabel.Append(wxT(",\n"));
326 MailingLabel.Append(txtCountry->GetValue());
331 txtLabel->SetValue(MailingLabel);
335 void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType )
338 // Set the editor mode.
340 // Set if the editor is adding or editing an address.
344 if (EditMode == FALSE){
347 btnAction->SetLabel(_("Add"));
348 this->SetTitle(_("Add Address"));
350 } else if (EditMode == TRUE){
353 btnAction->SetLabel(_("Modify"));
354 this->SetTitle(_("Modify Address"));
358 std::map<int,int>::iterator intiter;
359 std::map<int,wxString>::iterator striter;
361 // Load the data into the form.
363 striter = AddressListPtr->find(AddressListIndex);
365 if (striter->first == AddressListIndex &&
366 striter != AddressListPtr->end()){
368 txtAddress->SetValue(striter->second);
372 striter = AddressListTownPtr->find(AddressListIndex);
374 if (striter->first == AddressListIndex &&
375 striter != AddressListTownPtr->end()){
377 txtTownCity->SetValue(striter->second);
381 striter = AddressListCountyPtr->find(AddressListIndex);
383 if (striter->first == AddressListIndex &&
384 striter != AddressListCountyPtr->end()){
386 txtCounty->SetValue(striter->second);
390 striter = AddressListPostCodePtr->find(AddressListIndex);
392 if (striter->first == AddressListIndex &&
393 striter != AddressListPostCodePtr->end()){
395 txtPostCode->SetValue(striter->second);
399 striter = AddressListCountryPtr->find(AddressListIndex);
401 if (striter->first == AddressListIndex &&
402 striter != AddressListCountryPtr->end()){
404 txtCountry->SetValue(striter->second);
410 intiter = AddressListPrefPtr->find(AddressListIndex);
412 if (intiter->first == AddressListIndex && intiter->second > 0 && intiter != AddressListPrefPtr->end() &&
413 intiter != AddressListPrefPtr->end()){
415 priorityCtrl->SetValue(intiter->second);
416 priorityCtrl->EnablePriority(true);
422 striter = AddressListLabelPtr->find(AddressListIndex);
424 if (striter->first == AddressListIndex && striter != AddressListLabelPtr->end() &&
425 striter != AddressListLabelPtr->end()){
427 strValue = striter->second;
428 if (strValue.Left(1) == "\"" && strValue.Right(1) == "\""){
429 strValue.erase(0, 1);
430 strValue.RemoveLast();
435 txtLabel->SetValue(strValue);
437 // Setup the Language, Geographic position and timezone.
439 striter = AddressListLangPtr->find(AddressListIndex);
441 if (striter->first == AddressListIndex && striter != AddressListLangPtr->end()){
443 strValue = striter->second;
447 cmbLanguage->SetValue(strValue);
449 striter = AddressListGeoPtr->find(AddressListIndex);
451 if (striter->first == AddressListIndex && striter != AddressListGeoPtr->end()){
453 strValue = striter->second;
457 txtGeo->SetValue(strValue);
459 striter = AddressListTimezonePtr->find(AddressListIndex);
461 if (striter->first == AddressListIndex && striter != AddressListTimezonePtr->end()){
463 strValue = striter->second;
467 txtTimezone->SetValue(strValue);
471 EditSectionType = SectType;
474 void frmContactEditorAddress::SetupPointers( std::map<int, wxString> *AddressList,
475 std::map<int, wxString> *AddressListTown,
476 std::map<int, wxString> *AddressListCounty,
477 std::map<int, wxString> *AddressListPostCode,
478 std::map<int, wxString> *AddressListCountry,
479 std::map<int, wxString> *AddressListLabel,
480 std::map<int, wxString> *AddressListLang,
481 std::map<int, wxString> *AddressListAltID,
482 std::map<int, wxString> *AddressListPID,
483 std::map<int, wxString> *AddressListTokens,
484 std::map<int, wxString> *AddressListGeo,
485 std::map<int, wxString> *AddressListTimezone,
486 std::map<int, wxString> *AddressListType,
487 std::map<int, wxString> *AddressListMediatype,
488 std::map<int, int> *AddressListPref,
489 wxListCtrl *AddressListCtrl,
493 // Setup the pointers.
495 AddressListPtr = AddressList;
496 AddressListTownPtr = AddressListTown;
497 AddressListCountyPtr = AddressListCounty;
498 AddressListPostCodePtr = AddressListPostCode;
499 AddressListCountryPtr = AddressListCountry;
500 AddressListLabelPtr = AddressListLabel;
501 AddressListLangPtr = AddressListLang;
502 AddressListAltIDPtr = AddressListAltID;
503 AddressListPIDPtr = AddressListPID;
504 AddressListTokensPtr = AddressListTokens;
505 AddressListGeoPtr = AddressListGeo;
506 AddressListTimezonePtr = AddressListTimezone;
507 AddressListTypePtr = AddressListType;
508 AddressListMediatypePtr = AddressListMediatype;
509 AddressListPrefPtr = AddressListPref;
510 AddressListCtrlPtr = AddressListCtrl;
511 AddressListIndex = AddressIndex;