// frmContactEditorAddress.cpp - frmContactEditorAddress form. // // (c) 2012-2015 Xestia Software Development. // // This file is part of Xestia Address Book. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see #include "frmContactEditorAddress.h" #include #include #include "../common/textprocessing.h" frmContactEditorAddress::frmContactEditorAddress( wxWindow* parent ) : frmContactEditorAddressADT( parent ) { // Setup the window. EditorMode = FALSE; sliPriority->Disable(); } void frmContactEditorAddress::InitAddressEditor( wxInitDialogEvent& event ) { // Do nothing with this subroutine at this time. } void frmContactEditorAddress::EnablePriority( wxCommandEvent& event ) { // Enable/disable the priority setting. if (chkUsePref->IsChecked()){ sliPriority->Enable(); } else { sliPriority->Disable(); } } void frmContactEditorAddress::ProcessData( wxCommandEvent& event ) { // Process data. // Check what edit mode we are in and go from there. long ListCtrlIndex; if (EditorMode == FALSE){ // Add the address to the list (maps). AddressListPtr->erase(AddressListIndex); AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue())); AddressListTownPtr->erase(AddressListIndex); AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue())); AddressListCountyPtr->erase(AddressListIndex); AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue())); AddressListPostCodePtr->erase(AddressListIndex); AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue())); AddressListCountryPtr->erase(AddressListIndex); AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue())); // Add the label to the list (maps). wxString LabelData = txtLabel->GetValue(); LabelData.Prepend("\""); LabelData.Append("\""); AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData)); // Add the language to the list (maps). AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue())); // No AltIDs at present. // No PIDs at present. // There are no tokens for a new address to add so this can be // ignored for the time being. // Add the Geopositioning to the list (maps). AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue())); // Add the Timezone to the list (maps). AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue())); if (EditSectionType == CE_GENERAL){ AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT(""))); } else if (EditSectionType == CE_HOME) { AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("home"))); } else if (EditSectionType == CE_WORK) { AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("work"))); } // Add the mediatype to the list (maps). AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain"))); if (chkUsePref->IsChecked()){ AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue())); } else { AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0)); } // Add to the form. wxListItem coldata; coldata.SetId(AddressListIndex); coldata.SetData(AddressListIndex); coldata.SetText(txtAddress->GetValue()); ListCtrlIndex = AddressListCtrlPtr->InsertItem(coldata); AddressListCtrlPtr->SetItem(ListCtrlIndex, 1, txtTownCity->GetValue()); AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue()); AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue()); if (chkUsePref->IsChecked()){ AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), sliPriority->GetValue())); } this->Close(); } else if (EditorMode == TRUE){ // Edit the address in the list. wxString strAddress; wxString strValue; long longSelected = -1; AddressListPtr->erase(AddressListIndex); AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue())); AddressListTownPtr->erase(AddressListIndex); AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue())); AddressListCountyPtr->erase(AddressListIndex); AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue())); AddressListPostCodePtr->erase(AddressListIndex); AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue())); AddressListCountryPtr->erase(AddressListIndex); AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue())); // Add the label to the list (maps). AddressListLabelPtr->erase(AddressListIndex); wxString LabelData = txtLabel->GetValue(); LabelData.Prepend("\""); LabelData.Append("\""); AddressListLabelPtr->insert(std::make_pair(AddressListIndex, LabelData)); // Add the language to the list (maps). AddressListLangPtr->erase(AddressListIndex); AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue())); //AddressListAltIDPtr = &AddressListAltID; // No AltIDs at present. // No PIDs at present. // There are no tokens for a new address to add so this can be // ignored for the time being. // Add the Geopositioning to the list (maps). AddressListGeoPtr->erase(AddressListIndex); AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue())); // Add the Timezone to the list (maps). AddressListTimezonePtr->erase(AddressListIndex); AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue())); // Add the mediatype to the list (maps). AddressListMediatypePtr->erase(AddressListIndex); AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain"))); AddressListPrefPtr->erase(AddressListIndex); if (chkUsePref->IsChecked()){ AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue())); } else { AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0)); } // Update the form with the new details. longSelected = AddressListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } AddressListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue()); AddressListCtrlPtr->SetItem(longSelected, 1, txtTownCity->GetValue()); AddressListCtrlPtr->SetItem(longSelected, 2, txtCounty->GetValue()); AddressListCtrlPtr->SetItem(longSelected, 3, txtPostCode->GetValue()); if (chkUsePref->IsChecked()){ AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), sliPriority->GetValue())); } else { AddressListCtrlPtr->SetItem(longSelected, 4, wxT("")); } this->Close(); } } void frmContactEditorAddress::CloseWindow( wxCommandEvent& event ) { // Close the window. this->Close(); } void frmContactEditorAddress::CopyAddress( wxCommandEvent& event ) { // Copy the address. wxString MailingLabel; bool AddComma = FALSE; if (!txtAddress->IsEmpty()){ MailingLabel.Append(txtAddress->GetValue()); AddComma = TRUE; } if (!txtTownCity->IsEmpty()){ if(AddComma == TRUE){ MailingLabel.Append(wxT(",\n")); AddComma = FALSE; } MailingLabel.Append(txtTownCity->GetValue()); AddComma = TRUE; } if (!txtCounty->IsEmpty()){ if(AddComma == TRUE){ MailingLabel.Append(wxT(",\n")); AddComma = FALSE; } MailingLabel.Append(txtCounty->GetValue()); AddComma = TRUE; } if (!txtPostCode->IsEmpty()){ if(AddComma == TRUE){ MailingLabel.Append(wxT(",\n")); AddComma = FALSE; } MailingLabel.Append(txtPostCode->GetValue()); AddComma = TRUE; } if (!txtCountry->IsEmpty()){ if(AddComma == TRUE){ MailingLabel.Append(wxT(",\n")); AddComma = FALSE; } MailingLabel.Append(txtCountry->GetValue()); AddComma = TRUE; } txtLabel->SetValue(MailingLabel); } void frmContactEditorAddress::SetEditorMode( bool EditMode, SectionType SectType ) { // Set the editor mode. // Set if the editor is adding or editing an address. // FALSE = Add // TRUE = Edit if (EditMode == FALSE){ EditorMode = FALSE; btnAction->SetLabel(_("Add")); this->SetTitle(_("Add Address")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Address")); wxString strValue; std::map::iterator intiter; std::map::iterator striter; // Load the data into the form. striter = AddressListPtr->find(AddressListIndex); if (striter->first == AddressListIndex && striter != AddressListPtr->end()){ txtAddress->SetValue(striter->second); } striter = AddressListTownPtr->find(AddressListIndex); if (striter->first == AddressListIndex && striter != AddressListTownPtr->end()){ txtTownCity->SetValue(striter->second); } striter = AddressListCountyPtr->find(AddressListIndex); if (striter->first == AddressListIndex && striter != AddressListCountyPtr->end()){ txtCounty->SetValue(striter->second); } striter = AddressListPostCodePtr->find(AddressListIndex); if (striter->first == AddressListIndex && striter != AddressListPostCodePtr->end()){ txtPostCode->SetValue(striter->second); } striter = AddressListCountryPtr->find(AddressListIndex); if (striter->first == AddressListIndex && striter != AddressListCountryPtr->end()){ txtCountry->SetValue(striter->second); } // Setup the Slider. intiter = AddressListPrefPtr->find(AddressListIndex); if (intiter->first == AddressListIndex && intiter->second > 0 && intiter != AddressListPrefPtr->end() && intiter != AddressListPrefPtr->end()){ sliPriority->SetValue(intiter->second); sliPriority->Enable(); chkUsePref->SetValue(TRUE); } // Setup the Label. striter = AddressListLabelPtr->find(AddressListIndex); if (striter->first == AddressListIndex && striter != AddressListLabelPtr->end() && striter != AddressListLabelPtr->end()){ strValue = striter->second; if (strValue.Left(1) == "\"" && strValue.Right(1) == "\""){ strValue.erase(0, 1); strValue.RemoveLast(); } } txtLabel->SetValue(strValue); // Setup the Language, Geographic position and timezone. striter = AddressListLangPtr->find(AddressListIndex); if (striter->first == AddressListIndex && striter != AddressListLangPtr->end()){ strValue = striter->second; } cmbLanguage->SetValue(strValue); striter = AddressListGeoPtr->find(AddressListIndex); if (striter->first == AddressListIndex && striter != AddressListGeoPtr->end()){ strValue = striter->second; } txtGeo->SetValue(strValue); striter = AddressListTimezonePtr->find(AddressListIndex); if (striter->first == AddressListIndex && striter != AddressListTimezonePtr->end()){ strValue = striter->second; } txtTimezone->SetValue(strValue); } EditSectionType = SectType; } void frmContactEditorAddress::SetupPointers( std::map *AddressList, std::map *AddressListTown, std::map *AddressListCounty, std::map *AddressListPostCode, std::map *AddressListCountry, std::map *AddressListLabel, std::map *AddressListLang, std::map *AddressListAltID, std::map *AddressListPID, std::map *AddressListTokens, std::map *AddressListGeo, std::map *AddressListTimezone, std::map *AddressListType, std::map *AddressListMediatype, std::map *AddressListPref, wxListCtrl *AddressListCtrl, int AddressIndex ) { // Setup the pointers. AddressListPtr = AddressList; AddressListTownPtr = AddressListTown; AddressListCountyPtr = AddressListCounty; AddressListPostCodePtr = AddressListPostCode; AddressListCountryPtr = AddressListCountry; AddressListLabelPtr = AddressListLabel; AddressListLangPtr = AddressListLang; AddressListAltIDPtr = AddressListAltID; AddressListPIDPtr = AddressListPID; AddressListTokensPtr = AddressListTokens; AddressListGeoPtr = AddressListGeo; AddressListTimezonePtr = AddressListTimezone; AddressListTypePtr = AddressListType; AddressListMediatypePtr = AddressListMediatype; AddressListPrefPtr = AddressListPref; AddressListCtrlPtr = AddressListCtrl; AddressListIndex = AddressIndex; }