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 // Add the mediatype to the list (maps).
125 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
127 if (chkUsePref->IsChecked()){
129 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
133 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
141 coldata.SetId(AddressListIndex);
142 coldata.SetData(AddressListIndex);
143 coldata.SetText(txtAddress->GetValue());
144 ListCtrlIndex = AddressListCtrlPtr->InsertItem(coldata);
146 AddressListCtrlPtr->SetItem(ListCtrlIndex, 1, txtTownCity->GetValue());
147 AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue());
148 AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue());
150 if (chkUsePref->IsChecked()){
152 AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
158 } else if (EditorMode == TRUE){
160 // Edit the address in the list.
164 long longSelected = -1;
166 AddressListPtr->erase(AddressListIndex);
167 AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
169 AddressListTownPtr->erase(AddressListIndex);
170 AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue()));
172 AddressListCountyPtr->erase(AddressListIndex);
173 AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue()));
175 AddressListPostCodePtr->erase(AddressListIndex);
176 AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue()));
178 AddressListCountryPtr->erase(AddressListIndex);
179 AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
181 // Add the label to the list (maps).
183 AddressListLabelPtr->erase(AddressListIndex);
185 wxString LabelData = txtLabel->GetValue();
186 LabelData.Prepend("\"");
187 LabelData.Append("\"");
188 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
190 // Add the language to the list (maps).
192 AddressListLangPtr->erase(AddressListIndex);
193 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
195 //AddressListAltIDPtr = &AddressListAltID;
197 // No AltIDs at present.
199 // No PIDs at present.
201 // There are no tokens for a new address to add so this can be
202 // ignored for the time being.
204 // Add the Geopositioning to the list (maps).
206 AddressListGeoPtr->erase(AddressListIndex);
207 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
209 // Add the Timezone to the list (maps).
211 AddressListTimezonePtr->erase(AddressListIndex);
212 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
214 // Add the mediatype to the list (maps).
216 AddressListMediatypePtr->erase(AddressListIndex);
217 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
219 AddressListPrefPtr->erase(AddressListIndex);
221 if (chkUsePref->IsChecked()){
223 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
227 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
231 // Update the form with the new details.
233 longSelected = AddressListCtrlPtr->GetNextItem(longSelected,
235 wxLIST_STATE_SELECTED);
237 if (longSelected == -1){
241 AddressListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
242 AddressListCtrlPtr->SetItem(longSelected, 1, txtTownCity->GetValue());
243 AddressListCtrlPtr->SetItem(longSelected, 2, txtCounty->GetValue());
244 AddressListCtrlPtr->SetItem(longSelected, 3, txtPostCode->GetValue());
246 if (chkUsePref->IsChecked()){
248 AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
252 AddressListCtrlPtr->SetItem(longSelected, 4, wxT(""));
262 void frmContactEditorAddress::CloseWindow( wxCommandEvent& event )
271 void frmContactEditorAddress::CopyAddress( wxCommandEvent& event )
276 wxString MailingLabel;
277 bool AddComma = FALSE;
279 if (!txtAddress->IsEmpty()){
281 MailingLabel.Append(txtAddress->GetValue());
286 if (!txtTownCity->IsEmpty()){
288 if(AddComma == TRUE){
290 MailingLabel.Append(wxT(",\n"));
295 MailingLabel.Append(txtTownCity->GetValue());
300 if (!txtCounty->IsEmpty()){
302 if(AddComma == TRUE){
304 MailingLabel.Append(wxT(",\n"));
309 MailingLabel.Append(txtCounty->GetValue());
314 if (!txtPostCode->IsEmpty()){
316 if(AddComma == TRUE){
318 MailingLabel.Append(wxT(",\n"));
323 MailingLabel.Append(txtPostCode->GetValue());
328 if (!txtCountry->IsEmpty()){
330 if(AddComma == TRUE){
332 MailingLabel.Append(wxT(",\n"));
337 MailingLabel.Append(txtCountry->GetValue());
342 txtLabel->SetValue(MailingLabel);
346 void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType )
349 // Set the editor mode.
351 // Set if the editor is adding or editing an address.
355 if (EditMode == FALSE){
358 btnAction->SetLabel(_("Add"));
359 this->SetTitle(_("Add Address"));
361 } else if (EditMode == TRUE){
364 btnAction->SetLabel(_("Modify"));
365 this->SetTitle(_("Modify Address"));
369 std::map<int,int>::iterator intiter;
370 std::map<int,wxString>::iterator striter;
372 // Load the data into the form.
374 striter = AddressListPtr->find(AddressListIndex);
376 if (striter->first == AddressListIndex &&
377 striter != AddressListPtr->end()){
379 txtAddress->SetValue(striter->second);
383 striter = AddressListTownPtr->find(AddressListIndex);
385 if (striter->first == AddressListIndex &&
386 striter != AddressListTownPtr->end()){
388 txtTownCity->SetValue(striter->second);
392 striter = AddressListCountyPtr->find(AddressListIndex);
394 if (striter->first == AddressListIndex &&
395 striter != AddressListCountyPtr->end()){
397 txtCounty->SetValue(striter->second);
401 striter = AddressListPostCodePtr->find(AddressListIndex);
403 if (striter->first == AddressListIndex &&
404 striter != AddressListPostCodePtr->end()){
406 txtPostCode->SetValue(striter->second);
410 striter = AddressListCountryPtr->find(AddressListIndex);
412 if (striter->first == AddressListIndex &&
413 striter != AddressListCountryPtr->end()){
415 txtCountry->SetValue(striter->second);
421 intiter = AddressListPrefPtr->find(AddressListIndex);
423 if (intiter->first == AddressListIndex && intiter->second > 0 && intiter != AddressListPrefPtr->end() &&
424 intiter != AddressListPrefPtr->end()){
426 sliPriority->SetValue(intiter->second);
427 sliPriority->Enable();
428 chkUsePref->SetValue(TRUE);
434 striter = AddressListLabelPtr->find(AddressListIndex);
436 if (striter->first == AddressListIndex && striter != AddressListLabelPtr->end() &&
437 striter != AddressListLabelPtr->end()){
439 strValue = striter->second;
440 if (strValue.Left(1) == "\"" && strValue.Right(1) == "\""){
441 strValue.erase(0, 1);
442 strValue.RemoveLast();
447 txtLabel->SetValue(strValue);
449 // Setup the Language, Geographic position and timezone.
451 striter = AddressListLangPtr->find(AddressListIndex);
453 if (striter->first == AddressListIndex && striter != AddressListLangPtr->end()){
455 strValue = striter->second;
459 cmbLanguage->SetValue(strValue);
461 striter = AddressListGeoPtr->find(AddressListIndex);
463 if (striter->first == AddressListIndex && striter != AddressListGeoPtr->end()){
465 strValue = striter->second;
469 txtGeo->SetValue(strValue);
471 striter = AddressListTimezonePtr->find(AddressListIndex);
473 if (striter->first == AddressListIndex && striter != AddressListTimezonePtr->end()){
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 // Setup the pointers.
507 AddressListPtr = AddressList;
508 AddressListTownPtr = AddressListTown;
509 AddressListCountyPtr = AddressListCounty;
510 AddressListPostCodePtr = AddressListPostCode;
511 AddressListCountryPtr = AddressListCountry;
512 AddressListLabelPtr = AddressListLabel;
513 AddressListLangPtr = AddressListLang;
514 AddressListAltIDPtr = AddressListAltID;
515 AddressListPIDPtr = AddressListPID;
516 AddressListTokensPtr = AddressListTokens;
517 AddressListGeoPtr = AddressListGeo;
518 AddressListTimezonePtr = AddressListTimezone;
519 AddressListTypePtr = AddressListType;
520 AddressListMediatypePtr = AddressListMediatype;
521 AddressListPrefPtr = AddressListPref;
522 AddressListCtrlPtr = AddressListCtrl;
523 AddressListIndex = AddressIndex;