1 // frmContactEditorTimezones.cpp - frmContactEditorTimezones 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 "frmContactEditorTimezones.h"
21 #include "../common/textprocessing.h"
22 #include "../widgets/XABPriorityCtrl.h"
24 frmContactEditorTimezones::frmContactEditorTimezones( wxWindow* parent )
26 frmContactEditorTimezonesADT( parent )
32 priorityCtrl = new XABPriorityCtrl(tabGeneral);
33 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
37 void frmContactEditorTimezones::SetEditorMode(bool EditMode, SectionType SectType)
40 // Set the editor mode for adding or editing a timezone.
42 if (EditMode == FALSE){
45 btnAction->SetLabel(_("Add"));
46 this->SetTitle(_("Add Timezone"));
48 } else if (EditMode == TRUE){
51 btnAction->SetLabel(_("Modify"));
52 this->SetTitle(_("Modify Timezone"));
54 std::map<int,int>::iterator intiter;
55 std::map<int,wxString>::iterator striter;
58 // Load the data into the form.
60 striter = TZListPtr->find(TZListIndex);
62 if (striter->first == TZListIndex){
64 strValue = striter->second;
68 cmbTimezone->SetValue(strValue);
72 intiter = TZListPrefPtr->find(TZListIndex);
74 if (intiter->first == TZListIndex && intiter->second > 0){
76 priorityCtrl->SetValue(intiter->second);
77 priorityCtrl->EnablePriority(true);
83 EditSectionType = SectType;
87 void frmContactEditorTimezones::ProcessAction( wxCommandEvent& event )
94 if (EditorMode == FALSE){
96 // Add the language to the list.
102 TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue()));
106 if (EditSectionType == CE_GENERAL){
108 TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("")));
110 } else if (EditSectionType == CE_HOME) {
112 TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("home")));
114 } else if (EditSectionType == CE_WORK) {
116 TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("work")));
120 // Add Language priority.
122 if (priorityCtrl->IsPriorityChecked()){
124 TZListPrefPtr->insert(std::make_pair(TZListIndex, priorityCtrl->GetValue()));
128 TZListPrefPtr->insert(std::make_pair(TZListIndex, 0));
132 // Add the data to the form.
136 coldata.SetId(TZListIndex);
137 coldata.SetData(TZListIndex);
138 coldata.SetText(cmbTimezone->GetValue());
139 ListCtrlIndex = TZListCtrlPtr->InsertItem(coldata);
141 if (priorityCtrl->IsPriorityChecked()){
143 TZListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
149 } else if (EditorMode == TRUE){
151 // Edit the language.
155 long longSelected = -1;
157 TZListPtr->erase(TZListIndex);
158 TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue()));
160 TZListPrefPtr->erase(TZListIndex);
162 if (priorityCtrl->IsPriorityChecked()){
164 TZListPrefPtr->insert(std::make_pair(TZListIndex, priorityCtrl->GetValue()));
168 TZListPrefPtr->insert(std::make_pair(TZListIndex, 0));
172 longSelected = TZListCtrlPtr->GetNextItem(longSelected,
174 wxLIST_STATE_SELECTED);
176 if (longSelected == -1){
180 TZListCtrlPtr->SetItem(longSelected, 0, cmbTimezone->GetValue());
182 if (priorityCtrl->IsPriorityChecked()){
184 TZListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
188 TZListCtrlPtr->SetItem(longSelected, 1, wxT(""));
198 void frmContactEditorTimezones::CloseWindow( wxCommandEvent& event )
201 // Close this window.
207 void frmContactEditorTimezones::SetupPointers(std::map<int, wxString> *TZList,
208 std::map<int, wxString> *TZListAltID,
209 std::map<int, wxString> *TZListPID,
210 std::map<int, wxString> *TZListType,
211 std::map<int, wxString> *TZListTokens,
212 std::map<int, wxString> *TZListMediatype,
213 std::map<int, int> *TZListPref,
214 wxListCtrl *TZListCtrl,
218 // Setup the pointers so that the data can be processed without
222 TZListAltIDPtr = TZListAltID;
223 TZListPIDPtr = TZListPID;
224 TZListTypePtr = TZListType;
225 TZListTokensPtr = TZListTokens;
226 TZListPrefPtr = TZListPref;
227 TZListCtrlPtr = TZListCtrl;
228 TZListIndex = TZIndex;