1 #include "frmContactEditorAddress.h"
3 #include <wx/tokenzr.h>
5 #include "../common/textprocessing.h"
7 frmContactEditorAddress::frmContactEditorAddress( wxWindow* parent )
9 frmContactEditorAddressADT( parent )
12 sliPriority->Disable();
15 void frmContactEditorAddress::InitAddressEditor( wxInitDialogEvent& event )
17 // Do nothing with this subroutine at this time.
20 void frmContactEditorAddress::EnablePriority( wxCommandEvent& event )
22 if (chkUsePref->IsChecked()){
23 sliPriority->Enable();
25 sliPriority->Disable();
29 void frmContactEditorAddress::ProcessData( wxCommandEvent& event )
32 // Check what edit mode we are in and go from there.
36 if (EditorMode == FALSE){
38 // Add the address to the list (maps).
40 AddressListPtr->erase(AddressListIndex);
41 AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
43 AddressListTownPtr->erase(AddressListIndex);
44 AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue()));
46 AddressListCountyPtr->erase(AddressListIndex);
47 AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue()));
49 AddressListPostCodePtr->erase(AddressListIndex);
50 AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue()));
52 AddressListCountryPtr->erase(AddressListIndex);
53 AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
55 // Add the label to the list (maps).
57 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, txtLabel->GetValue()));
59 // Add the language to the list (maps).
61 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
63 // No AltIDs at present.
65 // No PIDs at present.
67 // There are no tokens for a new address to add so this can be
68 // ignored for the time being.
70 // Add the Geopositioning to the list (maps).
72 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
74 // Add the Timezone to the list (maps).
76 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
78 if (EditSectionType == CE_GENERAL){
80 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("")));
82 } else if (EditSectionType == CE_HOME) {
84 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("home")));
86 } else if (EditSectionType == CE_WORK) {
88 AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("work")));
92 //AddressListTypePtr = &AddressListType;
94 // Add the mediatype to the list (maps).
96 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
98 //AddressListMediatypePtr = &AddressListMediatype;
99 //AddressListPrefPtr = &AddressListPref;
101 if (chkUsePref->IsChecked()){
103 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
107 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
115 coldata.SetId(AddressListIndex);
116 coldata.SetData(AddressListIndex);
117 coldata.SetText(txtAddress->GetValue());
118 ListCtrlIndex = AddressListCtrlPtr->InsertItem(coldata);
120 AddressListCtrlPtr->SetItem(ListCtrlIndex, 1, txtTownCity->GetValue());
121 AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue());
122 AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue());
124 if (chkUsePref->IsChecked()){
126 AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
132 } else if (EditorMode == TRUE){
134 // Edit the address in the list.
138 long longSelected = -1;
141 strAddress.Append(wxT(";;"));
143 strAddress.Append(txtAddress->GetValue());
144 strAddress.Append(wxT(";"));
146 strAddress.Append(txtTownCity->GetValue());
147 strAddress.Append(wxT(";"));
149 strAddress.Append(txtCounty->GetValue());
150 strAddress.Append(wxT(";"));
152 strAddress.Append(txtPostCode->GetValue());
153 strAddress.Append(wxT(";"));
155 strAddress.Append(txtCountry->GetValue());
158 AddressListPtr->erase(AddressListIndex);
159 AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue()));
161 AddressListTownPtr->erase(AddressListIndex);
162 AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue()));
164 AddressListCountyPtr->erase(AddressListIndex);
165 AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue()));
167 AddressListPostCodePtr->erase(AddressListIndex);
168 AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue()));
170 AddressListCountryPtr->erase(AddressListIndex);
171 AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue()));
173 //AddressListLabelPtr = &AddressListLabel;
175 // Add the label to the list (maps).
177 AddressListLabelPtr->erase(AddressListIndex);
178 AddressListLabelPtr->insert(std::make_pair(AddressListIndex, txtLabel->GetValue()));
180 // Add the language to the list (maps).
182 //AddressListLangPtr = &AddressListLang;
184 AddressListLangPtr->erase(AddressListIndex);
185 AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue()));
187 //AddressListAltIDPtr = &AddressListAltID;
189 // No AltIDs at present.
191 // No PIDs at present.
193 // There are no tokens for a new address to add so this can be
194 // ignored for the time being.
196 // Add the Geopositioning to the list (maps).
198 AddressListGeoPtr->erase(AddressListIndex);
199 AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue()));
201 // Add the Timezone to the list (maps).
203 AddressListTimezonePtr->erase(AddressListIndex);
204 AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue()));
206 // No need to update type since it will not have changed.
208 //AddressListTypePtr = &AddressListType;
210 // Add the mediatype to the list (maps).
212 AddressListMediatypePtr->erase(AddressListIndex);
213 AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain")));
215 //AddressListMediatypePtr = &AddressListMediatype;
216 //AddressListPrefPtr = &AddressListPref;
218 AddressListPrefPtr->erase(AddressListIndex);
220 if (chkUsePref->IsChecked()){
222 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue()));
226 AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0));
230 // Update the form with the new details.
232 longSelected = AddressListCtrlPtr->GetNextItem(longSelected,
234 wxLIST_STATE_SELECTED);
236 if (longSelected == -1){
240 AddressListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
241 AddressListCtrlPtr->SetItem(longSelected, 1, txtTownCity->GetValue());
242 AddressListCtrlPtr->SetItem(longSelected, 2, txtCounty->GetValue());
243 AddressListCtrlPtr->SetItem(longSelected, 3, txtPostCode->GetValue());
245 if (chkUsePref->IsChecked()){
247 AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), sliPriority->GetValue()));
251 AddressListCtrlPtr->SetItem(longSelected, 4, wxT(""));
261 void frmContactEditorAddress::CloseWindow( wxCommandEvent& event )
266 void frmContactEditorAddress::CopyAddress( wxCommandEvent& event )
269 wxString MailingLabel;
270 bool AddComma = FALSE;
272 if (!txtAddress->IsEmpty()){
274 MailingLabel.Append(txtAddress->GetValue());
279 if (!txtTownCity->IsEmpty()){
281 if(AddComma == TRUE){
283 MailingLabel.Append(wxT(",\n"));
288 MailingLabel.Append(txtTownCity->GetValue());
293 if (!txtCounty->IsEmpty()){
295 if(AddComma == TRUE){
297 MailingLabel.Append(wxT(",\n"));
302 MailingLabel.Append(txtCounty->GetValue());
307 if (!txtPostCode->IsEmpty()){
309 if(AddComma == TRUE){
311 MailingLabel.Append(wxT(",\n"));
316 MailingLabel.Append(txtPostCode->GetValue());
321 if (!txtCountry->IsEmpty()){
323 if(AddComma == TRUE){
325 MailingLabel.Append(wxT(",\n"));
330 MailingLabel.Append(txtCountry->GetValue());
335 txtLabel->SetValue(MailingLabel);
339 void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType )
341 // Set if the editor is adding or editing an address.
345 if (EditMode == FALSE){
348 btnAction->SetLabel(_("Add"));
349 this->SetTitle(_("Add Address"));
351 } else if (EditMode == TRUE){
354 btnAction->SetLabel(_("Modify"));
355 this->SetTitle(_("Modify Address"));
359 std::map<int,int>::iterator intiter;
360 std::map<int,wxString>::iterator striter;
362 // Load the data into the form.
364 striter = AddressListPtr->find(AddressListIndex);
366 if (striter->first == AddressListIndex){
368 txtAddress->SetValue(striter->second);
372 striter = AddressListTownPtr->find(AddressListIndex);
374 if (striter->first == AddressListIndex){
376 txtTownCity->SetValue(striter->second);
380 striter = AddressListCountyPtr->find(AddressListIndex);
382 if (striter->first == AddressListIndex){
384 txtCounty->SetValue(striter->second);
388 striter = AddressListPostCodePtr->find(AddressListIndex);
390 if (striter->first == AddressListIndex){
392 txtPostCode->SetValue(striter->second);
396 striter = AddressListCountryPtr->find(AddressListIndex);
398 if (striter->first == AddressListIndex){
400 txtCountry->SetValue(striter->second);
404 //CaptureString(&strValue, TRUE);
405 //->Replace(wxT("\;"), wxT("\;;"), TRUE);
409 intiter = AddressListPrefPtr->find(AddressListIndex);
411 if (intiter->first == AddressListIndex && intiter->second > 0){
413 sliPriority->SetValue(intiter->second);
414 sliPriority->Enable();
415 chkUsePref->SetValue(TRUE);
421 striter = AddressListLabelPtr->find(AddressListIndex);
423 if (striter->first == AddressListIndex){
425 strValue = striter->second;
429 txtLabel->SetValue(strValue);
431 // Setup the Language, Geographic position and timezone.
433 striter = AddressListLangPtr->find(AddressListIndex);
435 if (striter->first == AddressListIndex){
437 strValue = striter->second;
441 cmbLanguage->SetValue(strValue);
443 striter = AddressListGeoPtr->find(AddressListIndex);
445 if (striter->first == AddressListIndex){
447 strValue = striter->second;
451 txtGeo->SetValue(strValue);
453 striter = AddressListTimezonePtr->find(AddressListIndex);
455 if (striter->first == AddressListIndex){
457 strValue = striter->second;
461 txtTimezone->SetValue(strValue);
465 EditSectionType = SectType;
468 void frmContactEditorAddress::SetupPointers( std::map<int, wxString> *AddressList,
469 std::map<int, wxString> *AddressListTown,
470 std::map<int, wxString> *AddressListCounty,
471 std::map<int, wxString> *AddressListPostCode,
472 std::map<int, wxString> *AddressListCountry,
473 std::map<int, wxString> *AddressListLabel,
474 std::map<int, wxString> *AddressListLang,
475 std::map<int, wxString> *AddressListAltID,
476 std::map<int, wxString> *AddressListPID,
477 std::map<int, wxString> *AddressListTokens,
478 std::map<int, wxString> *AddressListGeo,
479 std::map<int, wxString> *AddressListTimezone,
480 std::map<int, wxString> *AddressListType,
481 std::map<int, wxString> *AddressListMediatype,
482 std::map<int, int> *AddressListPref,
483 wxListCtrl *AddressListCtrl,
487 AddressListPtr = AddressList;
488 AddressListTownPtr = AddressListTown;
489 AddressListCountyPtr = AddressListCounty;
490 AddressListPostCodePtr = AddressListPostCode;
491 AddressListCountryPtr = AddressListCountry;
492 AddressListLabelPtr = AddressListLabel;
493 AddressListLangPtr = AddressListLang;
494 AddressListAltIDPtr = AddressListAltID;
495 AddressListPIDPtr = AddressListPID;
496 AddressListTokensPtr = AddressListTokens;
497 AddressListGeoPtr = AddressListGeo;
498 AddressListTimezonePtr = AddressListTimezone;
499 AddressListTypePtr = AddressListType;
500 AddressListMediatypePtr = AddressListMediatype;
501 AddressListPrefPtr = AddressListPref;
502 AddressListCtrlPtr = AddressListCtrl;
503 AddressListIndex = AddressIndex;