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);
38 void frmContactEditorTimezones::SetEditorMode(bool EditMode, SectionType SectType)
41 // Set the editor mode for adding or editing a timezone.
43 if (EditMode == FALSE){
46 btnAction->SetLabel(_("Add"));
47 this->SetTitle(_("Add Timezone"));
49 } else if (EditMode == TRUE){
52 btnAction->SetLabel(_("Modify"));
53 this->SetTitle(_("Modify Timezone"));
55 std::map<int,int>::iterator intiter;
56 std::map<int,wxString>::iterator striter;
59 // Load the data into the form.
61 striter = TZListPtr->find(TZListIndex);
63 if (striter->first == TZListIndex){
65 strValue = striter->second;
69 cmbTimezone->SetValue(strValue);
73 intiter = TZListPrefPtr->find(TZListIndex);
75 if (intiter->first == TZListIndex && intiter->second > 0){
77 priorityCtrl->SetValue(intiter->second);
78 priorityCtrl->EnablePriority(true);
84 EditSectionType = SectType;
88 void frmContactEditorTimezones::ProcessAction( wxCommandEvent& event )
95 if (EditorMode == FALSE){
97 // Add the language to the list.
103 TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue()));
107 if (EditSectionType == CE_GENERAL){
109 TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("")));
111 } else if (EditSectionType == CE_HOME) {
113 TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("home")));
115 } else if (EditSectionType == CE_WORK) {
117 TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("work")));
121 // Add Language priority.
123 if (priorityCtrl->IsPriorityChecked()){
125 TZListPrefPtr->insert(std::make_pair(TZListIndex, priorityCtrl->GetValue()));
129 TZListPrefPtr->insert(std::make_pair(TZListIndex, 0));
133 // Add the data to the form.
137 coldata.SetId(TZListIndex);
138 coldata.SetData(TZListIndex);
139 coldata.SetText(cmbTimezone->GetValue());
140 ListCtrlIndex = TZListCtrlPtr->InsertItem(coldata);
142 if (priorityCtrl->IsPriorityChecked()){
144 TZListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
150 } else if (EditorMode == TRUE){
152 // Edit the language.
156 long longSelected = -1;
158 TZListPtr->erase(TZListIndex);
159 TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue()));
161 TZListPrefPtr->erase(TZListIndex);
163 if (priorityCtrl->IsPriorityChecked()){
165 TZListPrefPtr->insert(std::make_pair(TZListIndex, priorityCtrl->GetValue()));
169 TZListPrefPtr->insert(std::make_pair(TZListIndex, 0));
173 longSelected = TZListCtrlPtr->GetNextItem(longSelected,
175 wxLIST_STATE_SELECTED);
177 if (longSelected == -1){
181 TZListCtrlPtr->SetItem(longSelected, 0, cmbTimezone->GetValue());
183 if (priorityCtrl->IsPriorityChecked()){
185 TZListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
189 TZListCtrlPtr->SetItem(longSelected, 1, wxT(""));
199 void frmContactEditorTimezones::CloseWindow( wxCommandEvent& event )
202 // Close this window.
208 void frmContactEditorTimezones::SetupPointers(std::map<int, wxString> *TZList,
209 std::map<int, wxString> *TZListAltID,
210 std::map<int, wxString> *TZListPID,
211 std::map<int, wxString> *TZListType,
212 std::map<int, wxString> *TZListTokens,
213 std::map<int, wxString> *TZListMediatype,
214 std::map<int, int> *TZListPref,
215 wxListCtrl *TZListCtrl,
219 // Setup the pointers so that the data can be processed without
223 TZListAltIDPtr = TZListAltID;
224 TZListPIDPtr = TZListPID;
225 TZListTypePtr = TZListType;
226 TZListTokensPtr = TZListTokens;
227 TZListPrefPtr = TZListPref;
228 TZListCtrlPtr = TZListCtrl;
229 TZListIndex = TZIndex;