Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditorTimezones: 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"
22 #include "../widgets/XABPriorityCtrl.h"
24 frmContactEditorTimezones::frmContactEditorTimezones( wxWindow* parent )
25 :
26 frmContactEditorTimezonesADT( parent )
27 {
28         
29         // Setup the window.
30         
31         EditorMode = FALSE;
32         priorityCtrl = new XABPriorityCtrl(tabGeneral);
33         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
34         
35 }
37 void frmContactEditorTimezones::SetEditorMode(bool EditMode, SectionType SectType)
38 {
40         // Set the editor mode for adding or editing a timezone.
42         if (EditMode == FALSE){
43         
44                 EditorMode = FALSE;
45                 btnAction->SetLabel(_("Add"));
46                 this->SetTitle(_("Add Timezone"));
47         
48         } else if (EditMode == TRUE){
49         
50                 EditorMode = TRUE;
51                 btnAction->SetLabel(_("Modify"));
52                 this->SetTitle(_("Modify Timezone"));
53         
54                 std::map<int,int>::iterator intiter;
55                 std::map<int,wxString>::iterator striter;
56                 wxString strValue;
57                 
58                 // Load the data into the form.
59                 
60                 striter = TZListPtr->find(TZListIndex);
61                  
62                 if (striter->first == TZListIndex){
63                 
64                         strValue = striter->second;
65                 
66                 }
67                 
68                 cmbTimezone->SetValue(strValue);
69                 
70                 // Setup the Slider.
71                 
72                 intiter = TZListPrefPtr->find(TZListIndex);
73                 
74                 if (intiter->first == TZListIndex && intiter->second > 0){
75                 
76                         priorityCtrl->SetValue(intiter->second);
77                         priorityCtrl->EnablePriority(true);
78                 
79                 }       
80                 
81         }
82         
83         EditSectionType = SectType;
84         
85 }
87 void frmContactEditorTimezones::ProcessAction( wxCommandEvent& event )
88 {
90         // Process action.
91         
92         long ListCtrlIndex;
94         if (EditorMode == FALSE){
95         
96                 // Add the language to the list.
98                 wxString strValue;
99                 
100                 // Add language.
101                 
102                 TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue()));
103                 
104                 // Add Email type.
105                 
106                 if (EditSectionType == CE_GENERAL){
107                 
108                         TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("")));
109                 
110                 } else if (EditSectionType == CE_HOME) {
111                 
112                         TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("home")));
113                 
114                 } else if (EditSectionType == CE_WORK) {
115                 
116                         TZListTypePtr->insert(std::make_pair(TZListIndex, wxT("work")));
117                 
118                 }
119                 
120                 // Add Language priority.
121                 
122                 if (priorityCtrl->IsPriorityChecked()){
123                 
124                         TZListPrefPtr->insert(std::make_pair(TZListIndex, priorityCtrl->GetValue()));
125                 
126                 } else {
127                 
128                         TZListPrefPtr->insert(std::make_pair(TZListIndex, 0));          
129                 
130                 }               
131                 
132                 // Add the data to the form.
133                 
134                 wxListItem coldata;
135                 
136                 coldata.SetId(TZListIndex);
137                 coldata.SetData(TZListIndex);           
138                 coldata.SetText(cmbTimezone->GetValue());
139                 ListCtrlIndex = TZListCtrlPtr->InsertItem(coldata);
140                 
141                 if (priorityCtrl->IsPriorityChecked()){
142                 
143                         TZListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
144                 
145                 }
146                 
147                 this->Close();          
148         
149         } else if (EditorMode == TRUE){
150         
151                 // Edit the language.
152                 
153                 wxString strAddress;
154                 wxString strValue;
155                 long longSelected = -1;
157                 TZListPtr->erase(TZListIndex);
158                 TZListPtr->insert(std::make_pair(TZListIndex, cmbTimezone->GetValue()));
159                 
160                 TZListPrefPtr->erase(TZListIndex);
161                 
162                 if (priorityCtrl->IsPriorityChecked()){
163                 
164                         TZListPrefPtr->insert(std::make_pair(TZListIndex, priorityCtrl->GetValue()));
165                 
166                 } else {
167                 
168                         TZListPrefPtr->insert(std::make_pair(TZListIndex, 0));          
169                 
170                 }
171                 
172                 longSelected = TZListCtrlPtr->GetNextItem(longSelected, 
173                         wxLIST_NEXT_ALL,
174                         wxLIST_STATE_SELECTED);
175                         
176                 if (longSelected == -1){
177                         return;
178                 }
179                 
180                 TZListCtrlPtr->SetItem(longSelected, 0, cmbTimezone->GetValue());               
181                 
182                 if (priorityCtrl->IsPriorityChecked()){
183                 
184                         TZListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
185                 
186                 } else {
187                 
188                         TZListCtrlPtr->SetItem(longSelected, 1, wxT(""));
189                 
190                 }       
191                         
192                 this->Close();
193         
194         }
195         
198 void frmContactEditorTimezones::CloseWindow( wxCommandEvent& event )
200         
201         // Close this window.
202         
203         this->Close();
204         
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,
215         int TZIndex )
218         // Setup the pointers so that the data can be processed without
219         // duplication.
221         TZListPtr = TZList;
222         TZListAltIDPtr = TZListAltID;
223         TZListPIDPtr = TZListPID;
224         TZListTypePtr = TZListType;
225         TZListTokensPtr = TZListTokens;
226         TZListPrefPtr = TZListPref;
227         TZListCtrlPtr = TZListCtrl;
228         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