// frmContactEditorCalAdr.cpp - frmContactEditorCalAdr 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 "frmContactEditorCalAdr.h" #include #include "../common/textprocessing.h" frmContactEditorCalAdr::frmContactEditorCalAdr( wxWindow* parent ) : frmContactEditorCalAdrADT( parent ) { // Setup the window. EditorMode = FALSE; priorityCtrl = new XABPriorityCtrl(tabGeneral); szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5); szrGeneral->Layout(); cmbType->Append(wxT("")); cmbType->Append(_("Home")); cmbType->Append(_("Work")); } void frmContactEditorCalAdr::ProcessAction( wxCommandEvent& event ) { // Process action. long ListCtrlIndex; if (EditorMode == FALSE){ wxString strValue; // Setup Calendar Address. CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue())); strValue.Clear(); strValue = cmbType->GetString(cmbType->GetSelection()); // Setup Calendar Type. if (strValue == _("Home")) { CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home"))); } else if (strValue == _("Work")) { CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work"))); } else { CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT(""))); } // Setup Calendar Priority. if (priorityCtrl->IsPriorityChecked()){ CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, priorityCtrl->GetValue())); } else { CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0)); } // Add to form. wxListItem coldata; coldata.SetId(CalAdrListIndex); coldata.SetData(CalAdrListIndex); coldata.SetText(txtAddress->GetValue()); ListCtrlIndex = CalAdrListCtrlPtr->InsertItem(coldata); CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue); if (priorityCtrl->IsPriorityChecked()){ CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } this->Close(); } else if (EditorMode == TRUE) { long longSelected = -1; wxString strValue; // Update Category Name. CalAdrListPtr->erase(CalAdrListIndex); CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue())); // Update Category Type. CalAdrListTypePtr->erase(CalAdrListIndex); strValue.Clear(); strValue = cmbType->GetString(cmbType->GetSelection()); if (strValue == _("Home")) { CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home"))); } else if (strValue == _("Work")) { CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work"))); } // Update Category Priority. CalAdrListPrefPtr->erase(CalAdrListIndex); if (priorityCtrl->IsPriorityChecked()){ CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, priorityCtrl->GetValue())); } else { CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0)); } // Update form. longSelected = CalAdrListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } CalAdrListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue()); CalAdrListCtrlPtr->SetItem(longSelected, 1, strValue); if (priorityCtrl->IsPriorityChecked()){ CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } else { CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT("")); } this->Close(); } } void frmContactEditorCalAdr::SetEditorMode(bool EditMode) { // 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 Calendar Address")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Calendar Address")); std::map::iterator intiter; std::map::iterator striter; wxString strValue; // Get the organisation name. striter = CalAdrListPtr->find(CalAdrListIndex); if (striter->first == CalAdrListIndex){ strValue = striter->second; } txtAddress->SetValue(strValue); strValue.Clear(); // Get the type. striter = CalAdrListTypePtr->find(CalAdrListIndex); if (striter->first == CalAdrListIndex && striter != CalAdrListTypePtr->end()){ strValue = striter->second; } if (strValue == wxT("home")){ cmbType->SetSelection(1); } else if (strValue == wxT("work")){ cmbType->SetSelection(2); } else { cmbType->SetSelection(0); } // Get the organisation priority. intiter = CalAdrListPrefPtr->find(CalAdrListIndex); if (intiter->first == CalAdrListIndex && intiter->second > 0 && intiter != CalAdrListPrefPtr->end()){ priorityCtrl->SetValue(intiter->second); priorityCtrl->EnablePriority(true); } } } void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event ) { // Close the window. this->Close(); } void frmContactEditorCalAdr::SetupPointers(std::map *CalAdrList, std::map *CalAdrListAltID, std::map *CalAdrListPID, std::map *CalAdrListType, std::map *CalAdrListTokens, std::map *CalAdrListPref, wxListCtrl *CalAdrListCtrl, int CalAdrIndex ) { // Setup the pointers. CalAdrListPtr = CalAdrList; CalAdrListAltIDPtr = CalAdrListAltID; CalAdrListPIDPtr = CalAdrListPID; CalAdrListTypePtr = CalAdrListType; CalAdrListTokensPtr = CalAdrListTokens; CalAdrListPrefPtr = CalAdrListPref; CalAdrListCtrlPtr = CalAdrListCtrl; CalAdrListIndex = CalAdrIndex; }