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 )
30 sliPriority->Disable();
33 void frmContactEditorAddress::InitAddressEditor( wxInitDialogEvent& event )
35 // Do nothing with this subroutine at this time.
38 void frmContactEditorAddress::EnablePriority( wxCommandEvent& event )
40 if (chkUsePref->IsChecked()){
41 sliPriority->Enable();
43 sliPriority->Disable();
47 void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
50 // Check what edit mode we are in and go from there.
54 if (EditorMode == FALSE){
56 // Add the address to the list (maps).
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()));
73 // Add the label to the list (maps).
75 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, txtLabel->GetValue()));
77 // Add the language to the list (maps).
79 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
81 // No AltIDs at present.
83 // No PIDs at present.
85 // There are no tokens for a new address to add so this can be
86 // ignored for the time being.
88 // Add the Geopositioning to the list (maps).
90 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
92 // Add the Timezone to the list (maps).
94 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
96 if (EditSectionType == CE_GENERAL){
98 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("")));
100 } else if (EditSectionType == CE_HOME) {
102 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("home")));
104 } else if (EditSectionType == CE_WORK) {
106 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("work")));
110 //AddressListTypePtr = &AddressListType;
112 // Add the mediatype to the list (maps).
114 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
116 //AddressListMediatypePtr = &AddressListMediatype;
117 //AddressListPrefPtr = &AddressListPref;
119 if (chkUsePref->IsChecked()){
121 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
125 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
133 coldata.SetId(AddressListIndex);
134 coldata.SetData(AddressListIndex);
135 coldata.SetText(txtAddress->GetValue());
136 ListCtrlIndex = AddressListCtrlPtr->InsertItem(coldata);
138 AddressListCtrlPtr->SetItem(ListCtrlIndex, 1, txtTownCity->GetValue());
139 AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue());
140 AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue());
142 if (chkUsePref->IsChecked()){
144 AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
150 } else if (EditorMode == TRUE){
152 // Edit the address in the list.
156 long longSelected = -1;
159 strAddress.Append(wxT(";;"));
161 strAddress.Append(txtAddress->GetValue());
162 strAddress.Append(wxT(";"));
164 strAddress.Append(txtTownCity->GetValue());
165 strAddress.Append(wxT(";"));
167 strAddress.Append(txtCounty->GetValue());
168 strAddress.Append(wxT(";"));
170 strAddress.Append(txtPostCode->GetValue());
171 strAddress.Append(wxT(";"));
173 strAddress.Append(txtCountry->GetValue());
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()));
191 //AddressListLabelPtr = &AddressListLabel;
193 // Add the label to the list (maps).
195 AddressListLabelPtr->erase(AddressListIndex);
196 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, txtLabel->GetValue()));
198 // Add the language to the list (maps).
200 //AddressListLangPtr = &AddressListLang;
202 AddressListLangPtr->erase(AddressListIndex);
203 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
205 //AddressListAltIDPtr = &AddressListAltID;
207 // No AltIDs at present.
209 // No PIDs at present.
211 // There are no tokens for a new address to add so this can be
212 // ignored for the time being.
214 // Add the Geopositioning to the list (maps).
216 AddressListGeoPtr->erase(AddressListIndex);
217 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
219 // Add the Timezone to the list (maps).
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.
226 //AddressListTypePtr = &AddressListType;
228 // Add the mediatype to the list (maps).
230 AddressListMediatypePtr->erase(AddressListIndex);
231 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
233 //AddressListMediatypePtr = &AddressListMediatype;
234 //AddressListPrefPtr = &AddressListPref;
236 AddressListPrefPtr->erase(AddressListIndex);
238 if (chkUsePref->IsChecked()){
240 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
244 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
248 // Update the form with the new details.
250 longSelected = AddressListCtrlPtr->GetNextItem(longSelected,
252 wxLIST_STATE_SELECTED);
254 if (longSelected == -1){
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());
263 if (chkUsePref->IsChecked()){
265 AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
269 AddressListCtrlPtr->SetItem(longSelected, 4, wxT(""));
279 void frmContactEditorAddress::CloseWindow( wxCommandEvent& event )
284 void frmContactEditorAddress::CopyAddress( wxCommandEvent& event )
287 wxString MailingLabel;
288 bool AddComma = FALSE;
290 if (!txtAddress->IsEmpty()){
292 MailingLabel.Append(txtAddress->GetValue());
297 if (!txtTownCity->IsEmpty()){
299 if(AddComma == TRUE){
301 MailingLabel.Append(wxT(",\n"));
306 MailingLabel.Append(txtTownCity->GetValue());
311 if (!txtCounty->IsEmpty()){
313 if(AddComma == TRUE){
315 MailingLabel.Append(wxT(",\n"));
320 MailingLabel.Append(txtCounty->GetValue());
325 if (!txtPostCode->IsEmpty()){
327 if(AddComma == TRUE){
329 MailingLabel.Append(wxT(",\n"));
334 MailingLabel.Append(txtPostCode->GetValue());
339 if (!txtCountry->IsEmpty()){
341 if(AddComma == TRUE){
343 MailingLabel.Append(wxT(",\n"));
348 MailingLabel.Append(txtCountry->GetValue());
353 txtLabel->SetValue(MailingLabel);
357 void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType )
359 // Set if the editor is adding or editing an address.
363 if (EditMode == FALSE){
366 btnAction->SetLabel(_("Add"));
367 this->SetTitle(_("Add Address"));
369 } else if (EditMode == TRUE){
372 btnAction->SetLabel(_("Modify"));
373 this->SetTitle(_("Modify Address"));
377 std::map<int,int>::iterator intiter;
378 std::map<int,wxString>::iterator striter;
380 // Load the data into the form.
382 striter = AddressListPtr->find(AddressListIndex);
384 if (striter->first == AddressListIndex){
386 txtAddress->SetValue(striter->second);
390 striter = AddressListTownPtr->find(AddressListIndex);
392 if (striter->first == AddressListIndex){
394 txtTownCity->SetValue(striter->second);
398 striter = AddressListCountyPtr->find(AddressListIndex);
400 if (striter->first == AddressListIndex){
402 txtCounty->SetValue(striter->second);
406 striter = AddressListPostCodePtr->find(AddressListIndex);
408 if (striter->first == AddressListIndex){
410 txtPostCode->SetValue(striter->second);
414 striter = AddressListCountryPtr->find(AddressListIndex);
416 if (striter->first == AddressListIndex){
418 txtCountry->SetValue(striter->second);
422 //CaptureString(&strValue, TRUE);
423 //->Replace(wxT("\;"), wxT("\;;"), TRUE);
427 intiter = AddressListPrefPtr->find(AddressListIndex);
429 if (intiter->first == AddressListIndex && intiter->second > 0){
431 sliPriority->SetValue(intiter->second);
432 sliPriority->Enable();
433 chkUsePref->SetValue(TRUE);
439 striter = AddressListLabelPtr->find(AddressListIndex);
441 if (striter->first == AddressListIndex){
443 strValue = striter->second;
447 txtLabel->SetValue(strValue);
449 // Setup the Language, Geographic position and timezone.
451 striter = AddressListLangPtr->find(AddressListIndex);
453 if (striter->first == AddressListIndex){
455 strValue = striter->second;
459 cmbLanguage->SetValue(strValue);
461 striter = AddressListGeoPtr->find(AddressListIndex);
463 if (striter->first == AddressListIndex){
465 strValue = striter->second;
469 txtGeo->SetValue(strValue);
471 striter = AddressListTimezonePtr->find(AddressListIndex);
473 if (striter->first == AddressListIndex){
475 strValue = striter->second;
479 txtTimezone->SetValue(strValue);
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,
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;