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"
23 frmContactEditorTimezones::frmContactEditorTimezones( wxWindow* parent )
25 frmContactEditorTimezonesADT( parent )
31 sliPriority->Disable();
35 void frmContactEditorTimezones::EnablePriority( wxCommandEvent& event )
38 // Enable/disable the priority setting.
40 if (chkUsePref->IsChecked()){
41 sliPriority->Enable();
43 sliPriority->Disable();
47 void frmContactEditorTimezones::SetEditorMode(bool EditMode, SectionType SectType)
50 // Set the editor mode for adding or editing a timezone.
52 if (EditMode == FALSE){
55 btnAction->SetLabel(_("Add"));
56 this->SetTitle(_("Add Timezone"));
58 } else if (EditMode == TRUE){
61 btnAction->SetLabel(_("Modify"));
62 this->SetTitle(_("Modify Timezone"));
64 std::map<int,int>::iterator intiter;
65 std::map<int,wxString>::iterator striter;
68 // Load the data into the form.
70 striter = TZListPtr->find(TZListIndex);
72 if (striter->first == TZListIndex){
74 strValue = striter->second;
78 cmbTimezone->SetValue(strValue);
82 intiter = TZListPrefPtr->find(TZListIndex);
84 if (intiter->first == TZListIndex && intiter->second > 0){
86 sliPriority->SetValue(intiter->second);
87 sliPriority->Enable();
88 chkUsePref->SetValue(TRUE);
94 EditSectionType = SectType;
98 void frmContactEditorTimezones::ProcessAction( wxCommandEvent& event )
105 if (EditorMode == FALSE){
107 // Add the language to the list.
113 TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue()));
117 if (EditSectionType == CE_GENERAL){
119 TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("")));
121 } else if (EditSectionType == CE_HOME) {
123 TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("home")));
125 } else if (EditSectionType == CE_WORK) {
127 TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("work")));
131 // Add Language priority.
133 if (chkUsePref->IsChecked()){
135 TZListPrefPtr->insert(std::make_pair(TZListIndex, sliPriority->GetValue()));
139 TZListPrefPtr->insert(std::make_pair(TZListIndex, 0));
143 // Add the data to the form.
147 coldata.SetId(TZListIndex);
148 coldata.SetData(TZListIndex);
149 coldata.SetText(cmbTimezone->GetValue());
150 ListCtrlIndex = TZListCtrlPtr->InsertItem(coldata);
152 if (chkUsePref->IsChecked()){
154 TZListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
160 } else if (EditorMode == TRUE){
162 // Edit the language.
166 long longSelected = -1;
168 TZListPtr->erase(TZListIndex);
169 TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue()));
171 TZListPrefPtr->erase(TZListIndex);
173 if (chkUsePref->IsChecked()){
175 TZListPrefPtr->insert(std::make_pair(TZListIndex, sliPriority->GetValue()));
179 TZListPrefPtr->insert(std::make_pair(TZListIndex, 0));
183 longSelected = TZListCtrlPtr->GetNextItem(longSelected,
185 wxLIST_STATE_SELECTED);
187 if (longSelected == -1){
191 TZListCtrlPtr->SetItem(longSelected, 0, cmbTimezone->GetValue());
193 if (chkUsePref->IsChecked()){
195 TZListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
199 TZListCtrlPtr->SetItem(longSelected, 1, wxT(""));
209 void frmContactEditorTimezones::CloseWindow( wxCommandEvent& event )
212 // Close this window.
218 void frmContactEditorTimezones::SetupPointers(std::map<int, wxString> *TZList,
219 std::map<int, wxString> *TZListAltID,
220 std::map<int, wxString> *TZListPID,
221 std::map<int, wxString> *TZListType,
222 std::map<int, wxString> *TZListTokens,
223 std::map<int, wxString> *TZListMediatype,
224 std::map<int, int> *TZListPref,
225 wxListCtrl *TZListCtrl,
229 // Setup the pointers so that the data can be processed without
233 TZListAltIDPtr = TZListAltID;
234 TZListPIDPtr = TZListPID;
235 TZListTypePtr = TZListType;
236 TZListTokensPtr = TZListTokens;
237 TZListPrefPtr = TZListPref;
238 TZListCtrlPtr = TZListCtrl;
239 TZListIndex = TZIndex;