// frmContactEditorTimezones.cpp - frmContactEditorTimezones 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 "frmContactEditorTimezones.h" #include #include "../common/textprocessing.h" #include "../widgets/XABPriorityCtrl.h" frmContactEditorTimezones::frmContactEditorTimezones( wxWindow* parent ) : frmContactEditorTimezonesADT( parent ) { // Setup the window. EditorMode = FALSE; priorityCtrl = new XABPriorityCtrl(tabGeneral); szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5); } void frmContactEditorTimezones::SetEditorMode(bool EditMode, SectionType SectType) { // Set the editor mode for adding or editing a timezone. if (EditMode == FALSE){ EditorMode = FALSE; btnAction->SetLabel(_("Add")); this->SetTitle(_("Add Timezone")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Timezone")); std::map::iterator intiter; std::map::iterator striter; wxString strValue; // Load the data into the form. striter = TZListPtr->find(TZListIndex); if (striter->first == TZListIndex){ strValue = striter->second; } cmbTimezone->SetValue(strValue); // Setup the Slider. intiter = TZListPrefPtr->find(TZListIndex); if (intiter->first == TZListIndex && intiter->second > 0){ priorityCtrl->SetValue(intiter->second); priorityCtrl->EnablePriority(true); } } EditSectionType = SectType; } void frmContactEditorTimezones::ProcessAction( wxCommandEvent& event ) { // Process action. long ListCtrlIndex; if (EditorMode == FALSE){ // Add the language to the list. wxString strValue; // Add language. TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue())); // Add Email type. if (EditSectionType == CE_GENERAL){ TZListTypePtr->insert(std::make_pair(TZListIndex, wxT(""))); } else if (EditSectionType == CE_HOME) { TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("home"))); } else if (EditSectionType == CE_WORK) { TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("work"))); } // Add Language priority. if (priorityCtrl->IsPriorityChecked()){ TZListPrefPtr->insert(std::make_pair(TZListIndex, priorityCtrl->GetValue())); } else { TZListPrefPtr->insert(std::make_pair(TZListIndex, 0)); } // Add the data to the form. wxListItem coldata; coldata.SetId(TZListIndex); coldata.SetData(TZListIndex); coldata.SetText(cmbTimezone->GetValue()); ListCtrlIndex = TZListCtrlPtr->InsertItem(coldata); if (priorityCtrl->IsPriorityChecked()){ TZListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } this->Close(); } else if (EditorMode == TRUE){ // Edit the language. wxString strAddress; wxString strValue; long longSelected = -1; TZListPtr->erase(TZListIndex); TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue())); TZListPrefPtr->erase(TZListIndex); if (priorityCtrl->IsPriorityChecked()){ TZListPrefPtr->insert(std::make_pair(TZListIndex, priorityCtrl->GetValue())); } else { TZListPrefPtr->insert(std::make_pair(TZListIndex, 0)); } longSelected = TZListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } TZListCtrlPtr->SetItem(longSelected, 0, cmbTimezone->GetValue()); if (priorityCtrl->IsPriorityChecked()){ TZListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } else { TZListCtrlPtr->SetItem(longSelected, 1, wxT("")); } this->Close(); } } void frmContactEditorTimezones::CloseWindow( wxCommandEvent& event ) { // Close this window. this->Close(); } void frmContactEditorTimezones::SetupPointers(std::map *TZList, std::map *TZListAltID, std::map *TZListPID, std::map *TZListType, std::map *TZListTokens, std::map *TZListMediatype, std::map *TZListPref, wxListCtrl *TZListCtrl, int TZIndex ) { // Setup the pointers so that the data can be processed without // duplication. TZListPtr = TZList; TZListAltIDPtr = TZListAltID; TZListPIDPtr = TZListPID; TZListTypePtr = TZListType; TZListTokensPtr = TZListTokens; TZListPrefPtr = TZListPref; TZListCtrlPtr = TZListCtrl; TZListIndex = TZIndex; }