Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditorLanguages: Implemented priority control
[xestiaab/.git] / source / contacteditor / frmContactEditorTimezones.cpp
1 // frmContactEditorTimezones.cpp - frmContactEditorTimezones form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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"
20 #include <map>
21 #include "../common/textprocessing.h"
23 frmContactEditorTimezones::frmContactEditorTimezones( wxWindow* parent )
24 :
25 frmContactEditorTimezonesADT( parent )
26 {
27         
28         // Setup the window.
29         
30         EditorMode = FALSE;
31         sliPriority->Disable();
32         
33 }
35 void frmContactEditorTimezones::EnablePriority( wxCommandEvent& event )
36 {
37         
38         // Enable/disable the priority setting.
39         
40         if (chkUsePref->IsChecked()){
41                 sliPriority->Enable();
42         } else {
43                 sliPriority->Disable();
44         }
45 }
47 void frmContactEditorTimezones::SetEditorMode(bool EditMode, SectionType SectType)
48 {
50         // Set the editor mode for adding or editing a timezone.
52         if (EditMode == FALSE){
53         
54                 EditorMode = FALSE;
55                 btnAction->SetLabel(_("Add"));
56                 this->SetTitle(_("Add Timezone"));
57         
58         } else if (EditMode == TRUE){
59         
60                 EditorMode = TRUE;
61                 btnAction->SetLabel(_("Modify"));
62                 this->SetTitle(_("Modify Timezone"));
63         
64                 std::map<int,int>::iterator intiter;
65                 std::map<int,wxString>::iterator striter;
66                 wxString strValue;
67                 
68                 // Load the data into the form.
69                 
70                 striter = TZListPtr->find(TZListIndex);
71                  
72                 if (striter->first == TZListIndex){
73                 
74                         strValue = striter->second;
75                 
76                 }
77                 
78                 cmbTimezone->SetValue(strValue);
79                 
80                 // Setup the Slider.
81                 
82                 intiter = TZListPrefPtr->find(TZListIndex);
83                 
84                 if (intiter->first == TZListIndex && intiter->second > 0){
85                 
86                         sliPriority->SetValue(intiter->second);
87                         sliPriority->Enable();
88                         chkUsePref->SetValue(TRUE);
89                 
90                 }       
91                 
92         }
93         
94         EditSectionType = SectType;
95         
96 }
98 void frmContactEditorTimezones::ProcessAction( wxCommandEvent& event )
99 {
101         // Process action.
102         
103         long ListCtrlIndex;
105         if (EditorMode == FALSE){
106         
107                 // Add the language to the list.
109                 wxString strValue;
110                 
111                 // Add language.
112                 
113                 TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue()));
114                 
115                 // Add Email type.
116                 
117                 if (EditSectionType == CE_GENERAL){
118                 
119                         TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("")));
120                 
121                 } else if (EditSectionType == CE_HOME) {
122                 
123                         TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("home")));
124                 
125                 } else if (EditSectionType == CE_WORK) {
126                 
127                         TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("work")));
128                 
129                 }
130                 
131                 // Add Language priority.
132                 
133                 if (chkUsePref->IsChecked()){
134                 
135                         TZListPrefPtr->insert(std::make_pair(TZListIndex, sliPriority->GetValue()));
136                 
137                 } else {
138                 
139                         TZListPrefPtr->insert(std::make_pair(TZListIndex, 0));          
140                 
141                 }               
142                 
143                 // Add the data to the form.
144                 
145                 wxListItem coldata;
146                 
147                 coldata.SetId(TZListIndex);
148                 coldata.SetData(TZListIndex);           
149                 coldata.SetText(cmbTimezone->GetValue());
150                 ListCtrlIndex = TZListCtrlPtr->InsertItem(coldata);
151                 
152                 if (chkUsePref->IsChecked()){
153                 
154                         TZListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
155                 
156                 }
157                 
158                 this->Close();          
159         
160         } else if (EditorMode == TRUE){
161         
162                 // Edit the language.
163                 
164                 wxString strAddress;
165                 wxString strValue;
166                 long longSelected = -1;
168                 TZListPtr->erase(TZListIndex);
169                 TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue()));
170                 
171                 TZListPrefPtr->erase(TZListIndex);
172                 
173                 if (chkUsePref->IsChecked()){
174                 
175                         TZListPrefPtr->insert(std::make_pair(TZListIndex, sliPriority->GetValue()));
176                 
177                 } else {
178                 
179                         TZListPrefPtr->insert(std::make_pair(TZListIndex, 0));          
180                 
181                 }
182                 
183                 longSelected = TZListCtrlPtr->GetNextItem(longSelected, 
184                         wxLIST_NEXT_ALL,
185                         wxLIST_STATE_SELECTED);
186                         
187                 if (longSelected == -1){
188                         return;
189                 }
190                 
191                 TZListCtrlPtr->SetItem(longSelected, 0, cmbTimezone->GetValue());               
192                 
193                 if (chkUsePref->IsChecked()){
194                 
195                         TZListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
196                 
197                 } else {
198                 
199                         TZListCtrlPtr->SetItem(longSelected, 1, wxT(""));
200                 
201                 }       
202                         
203                 this->Close();
204         
205         }
206         
209 void frmContactEditorTimezones::CloseWindow( wxCommandEvent& event )
211         
212         // Close this window.
213         
214         this->Close();
215         
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,
226         int TZIndex )
229         // Setup the pointers so that the data can be processed without
230         // duplication.
232         TZListPtr = TZList;
233         TZListAltIDPtr = TZListAltID;
234         TZListPIDPtr = TZListPID;
235         TZListTypePtr = TZListType;
236         TZListTokensPtr = TZListTokens;
237         TZListPrefPtr = TZListPref;
238         TZListCtrlPtr = TZListCtrl;
239         TZListIndex = TZIndex;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy