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 wxString LabelData = txtLabel->GetValue();
76 LabelData.Prepend("\"");
77 LabelData.Append("\"");
78 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
80 // Add the language to the list (maps).
82 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
84 // No AltIDs at present.
86 // No PIDs at present.
88 // There are no tokens for a new address to add so this can be
89 // ignored for the time being.
91 // Add the Geopositioning to the list (maps).
93 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
95 // Add the Timezone to the list (maps).
97 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
99 if (EditSectionType == CE_GENERAL){
101 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("")));
103 } else if (EditSectionType == CE_HOME) {
105 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("home")));
107 } else if (EditSectionType == CE_WORK) {
109 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("work")));
113 //AddressListTypePtr = &AddressListType;
115 // Add the mediatype to the list (maps).
117 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
119 //AddressListMediatypePtr = &AddressListMediatype;
120 //AddressListPrefPtr = &AddressListPref;
122 if (chkUsePref->IsChecked()){
124 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
128 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
136 coldata.SetId(AddressListIndex);
137 coldata.SetData(AddressListIndex);
138 coldata.SetText(txtAddress->GetValue());
139 ListCtrlIndex = AddressListCtrlPtr->InsertItem(coldata);
141 AddressListCtrlPtr->SetItem(ListCtrlIndex, 1, txtTownCity->GetValue());
142 AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue());
143 AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue());
145 if (chkUsePref->IsChecked()){
147 AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
153 } else if (EditorMode == TRUE){
155 // Edit the address in the list.
159 long longSelected = -1;
162 strAddress.Append(wxT(";;"));
164 strAddress.Append(txtAddress->GetValue());
165 strAddress.Append(wxT(";"));
167 strAddress.Append(txtTownCity->GetValue());
168 strAddress.Append(wxT(";"));
170 strAddress.Append(txtCounty->GetValue());
171 strAddress.Append(wxT(";"));
173 strAddress.Append(txtPostCode->GetValue());
174 strAddress.Append(wxT(";"));
176 strAddress.Append(txtCountry->GetValue());
179 AddressListPtr->erase(AddressListIndex);
180 AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
182 AddressListTownPtr->erase(AddressListIndex);
183 AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue()));
185 AddressListCountyPtr->erase(AddressListIndex);
186 AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue()));
188 AddressListPostCodePtr->erase(AddressListIndex);
189 AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue()));
191 AddressListCountryPtr->erase(AddressListIndex);
192 AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
194 //AddressListLabelPtr = &AddressListLabel;
196 // Add the label to the list (maps).
198 AddressListLabelPtr->erase(AddressListIndex);
200 wxString LabelData = txtLabel->GetValue();
201 LabelData.Prepend("\"");
202 LabelData.Append("\"");
203 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData));
205 // Add the language to the list (maps).
207 //AddressListLangPtr = &AddressListLang;
209 AddressListLangPtr->erase(AddressListIndex);
210 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
212 //AddressListAltIDPtr = &AddressListAltID;
214 // No AltIDs at present.
216 // No PIDs at present.
218 // There are no tokens for a new address to add so this can be
219 // ignored for the time being.
221 // Add the Geopositioning to the list (maps).
223 AddressListGeoPtr->erase(AddressListIndex);
224 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
226 // Add the Timezone to the list (maps).
228 AddressListTimezonePtr->erase(AddressListIndex);
229 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
231 // No need to update type since it will not have changed.
233 //AddressListTypePtr = &AddressListType;
235 // Add the mediatype to the list (maps).
237 AddressListMediatypePtr->erase(AddressListIndex);
238 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
240 //AddressListMediatypePtr = &AddressListMediatype;
241 //AddressListPrefPtr = &AddressListPref;
243 AddressListPrefPtr->erase(AddressListIndex);
245 if (chkUsePref->IsChecked()){
247 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
251 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
255 // Update the form with the new details.
257 longSelected = AddressListCtrlPtr->GetNextItem(longSelected,
259 wxLIST_STATE_SELECTED);
261 if (longSelected == -1){
265 AddressListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
266 AddressListCtrlPtr->SetItem(longSelected, 1, txtTownCity->GetValue());
267 AddressListCtrlPtr->SetItem(longSelected, 2, txtCounty->GetValue());
268 AddressListCtrlPtr->SetItem(longSelected, 3, txtPostCode->GetValue());
270 if (chkUsePref->IsChecked()){
272 AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
276 AddressListCtrlPtr->SetItem(longSelected, 4, wxT(""));
286 void frmContactEditorAddress::CloseWindow( wxCommandEvent& event )
291 void frmContactEditorAddress::CopyAddress( wxCommandEvent& event )
294 wxString MailingLabel;
295 bool AddComma = FALSE;
297 if (!txtAddress->IsEmpty()){
299 MailingLabel.Append(txtAddress->GetValue());
304 if (!txtTownCity->IsEmpty()){
306 if(AddComma == TRUE){
308 MailingLabel.Append(wxT(",\n"));
313 MailingLabel.Append(txtTownCity->GetValue());
318 if (!txtCounty->IsEmpty()){
320 if(AddComma == TRUE){
322 MailingLabel.Append(wxT(",\n"));
327 MailingLabel.Append(txtCounty->GetValue());
332 if (!txtPostCode->IsEmpty()){
334 if(AddComma == TRUE){
336 MailingLabel.Append(wxT(",\n"));
341 MailingLabel.Append(txtPostCode->GetValue());
346 if (!txtCountry->IsEmpty()){
348 if(AddComma == TRUE){
350 MailingLabel.Append(wxT(",\n"));
355 MailingLabel.Append(txtCountry->GetValue());
360 txtLabel->SetValue(MailingLabel);
364 void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType )
366 // Set if the editor is adding or editing an address.
370 if (EditMode == FALSE){
373 btnAction->SetLabel(_("Add"));
374 this->SetTitle(_("Add Address"));
376 } else if (EditMode == TRUE){
379 btnAction->SetLabel(_("Modify"));
380 this->SetTitle(_("Modify Address"));
384 std::map<int,int>::iterator intiter;
385 std::map<int,wxString>::iterator striter;
387 // Load the data into the form.
389 striter = AddressListPtr->find(AddressListIndex);
391 if (striter->first == AddressListIndex){
393 txtAddress->SetValue(striter->second);
397 striter = AddressListTownPtr->find(AddressListIndex);
399 if (striter->first == AddressListIndex){
401 txtTownCity->SetValue(striter->second);
405 striter = AddressListCountyPtr->find(AddressListIndex);
407 if (striter->first == AddressListIndex){
409 txtCounty->SetValue(striter->second);
413 striter = AddressListPostCodePtr->find(AddressListIndex);
415 if (striter->first == AddressListIndex){
417 txtPostCode->SetValue(striter->second);
421 striter = AddressListCountryPtr->find(AddressListIndex);
423 if (striter->first == AddressListIndex){
425 txtCountry->SetValue(striter->second);
429 //CaptureString(&strValue, TRUE);
430 //->Replace(wxT("\;"), wxT("\;;"), TRUE);
434 intiter = AddressListPrefPtr->find(AddressListIndex);
436 if (intiter->first == AddressListIndex && intiter->second > 0 && intiter != AddressListPrefPtr->end()){
438 sliPriority->SetValue(intiter->second);
439 sliPriority->Enable();
440 chkUsePref->SetValue(TRUE);
446 striter = AddressListLabelPtr->find(AddressListIndex);
448 if (striter->first == AddressListIndex && striter != AddressListLabelPtr->end()){
450 strValue = striter->second;
451 if (strValue.Left(1) == "\"" && strValue.Right(1) == "\""){
452 strValue.erase(0, 1);
453 strValue.RemoveLast();
458 txtLabel->SetValue(strValue);
460 // Setup the Language, Geographic position and timezone.
462 striter = AddressListLangPtr->find(AddressListIndex);
464 if (striter->first == AddressListIndex && striter != AddressListLangPtr->end()){
466 strValue = striter->second;
470 cmbLanguage->SetValue(strValue);
472 striter = AddressListGeoPtr->find(AddressListIndex);
474 if (striter->first == AddressListIndex && striter != AddressListGeoPtr->end()){
476 strValue = striter->second;
480 txtGeo->SetValue(strValue);
482 striter = AddressListTimezonePtr->find(AddressListIndex);
484 if (striter->first == AddressListIndex && striter != AddressListTimezonePtr->end()){
486 strValue = striter->second;
490 txtTimezone->SetValue(strValue);
494 EditSectionType = SectType;
497 void frmContactEditorAddress::SetupPointers( std::map<int, wxString> *AddressList,
498 std::map<int, wxString> *AddressListTown,
499 std::map<int, wxString> *AddressListCounty,
500 std::map<int, wxString> *AddressListPostCode,
501 std::map<int, wxString> *AddressListCountry,
502 std::map<int, wxString> *AddressListLabel,
503 std::map<int, wxString> *AddressListLang,
504 std::map<int, wxString> *AddressListAltID,
505 std::map<int, wxString> *AddressListPID,
506 std::map<int, wxString> *AddressListTokens,
507 std::map<int, wxString> *AddressListGeo,
508 std::map<int, wxString> *AddressListTimezone,
509 std::map<int, wxString> *AddressListType,
510 std::map<int, wxString> *AddressListMediatype,
511 std::map<int, int> *AddressListPref,
512 wxListCtrl *AddressListCtrl,
516 AddressListPtr = AddressList;
517 AddressListTownPtr = AddressListTown;
518 AddressListCountyPtr = AddressListCounty;
519 AddressListPostCodePtr = AddressListPostCode;
520 AddressListCountryPtr = AddressListCountry;
521 AddressListLabelPtr = AddressListLabel;
522 AddressListLangPtr = AddressListLang;
523 AddressListAltIDPtr = AddressListAltID;
524 AddressListPIDPtr = AddressListPID;
525 AddressListTokensPtr = AddressListTokens;
526 AddressListGeoPtr = AddressListGeo;
527 AddressListTimezonePtr = AddressListTimezone;
528 AddressListTypePtr = AddressListType;
529 AddressListMediatypePtr = AddressListMediatype;
530 AddressListPrefPtr = AddressListPref;
531 AddressListCtrlPtr = AddressListCtrl;
532 AddressListIndex = AddressIndex;