Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmPreferences: Removed std::cout printing contact background colour
[xestiaab/.git] / source / contacteditor / frmContactEditorCalAdr.cpp
1 // frmContactEditorCalAdr.cpp - frmContactEditorCalAdr 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 "frmContactEditorCalAdr.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
23 frmContactEditorCalAdr::frmContactEditorCalAdr( wxWindow* parent )
24 :
25 frmContactEditorCalAdrADT( parent )
26 {
27         
28         // Setup the window.
29         
30         EditorMode = FALSE;
31         sliPriority->Disable();
32         
33         cmbType->Append(wxT(""));
34         cmbType->Append(_("Home"));
35         cmbType->Append(_("Work"));
36         
37 }
39 void frmContactEditorCalAdr::EnablePriority( wxCommandEvent& event )
40 {
41         
42         // Enable/disable the priority setting.
43         
44         if (chkUsePref->IsChecked()){
45                 sliPriority->Enable();
46         } else {
47                 sliPriority->Disable();
48         }
49         
50 }
52 void frmContactEditorCalAdr::ProcessAction( wxCommandEvent& event )
53 {
54         
55         // Process action.
56         
57         long ListCtrlIndex;
58         
59         if (EditorMode == FALSE){
61                 wxString strValue;
62         
63                 // Setup Calendar Address.
64                 
65                 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
67                 strValue.Clear();
68                 
69                 strValue = cmbType->GetString(cmbType->GetSelection());
71                 // Setup Calendar Type.
73                 if (strValue == _("Home")) {
74                 
75                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
76                 
77                 } else if (strValue == _("Work")) {
78                 
79                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
80                 
81                 } else {
82                 
83                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("")));
84                 
85                 }
86                 
87                 // Setup Calendar Priority.
88                 
89                 if (chkUsePref->IsChecked()){
90                 
91                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
92                 
93                 } else {
94                 
95                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
96                 
97                 }
98                 
99                 // Add to form.
100                 
101                 wxListItem coldata;
102                 
103                 coldata.SetId(CalAdrListIndex);
104                 coldata.SetData(CalAdrListIndex);
105                 coldata.SetText(txtAddress->GetValue());
106                 ListCtrlIndex = CalAdrListCtrlPtr->InsertItem(coldata);
107                 
108                 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);
109                 
110                 if (chkUsePref->IsChecked()){
111                 
112                         CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
113                 
114                 }
115                 
116                 this->Close();
117                 
118         } else if (EditorMode == TRUE) {
119         
120                 long longSelected = -1;
121                 wxString strValue;      
122         
123                 // Update Category Name.
124                 
125                 CalAdrListPtr->erase(CalAdrListIndex);
126                 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
127                 
128                 // Update Category Type.
129                 
130                 CalAdrListTypePtr->erase(CalAdrListIndex);
131                 
132                 strValue.Clear();
133                 strValue = cmbType->GetString(cmbType->GetSelection());
134                 
135                 if (strValue == _("Home")) {
136                 
137                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
138                 
139                 } else if (strValue == _("Work")) {
140                 
141                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
142                 
143                 }               
144                 
145                 // Update Category Priority.
146                 
147                 CalAdrListPrefPtr->erase(CalAdrListIndex);
148                 
149                 if (chkUsePref->IsChecked()){
150                 
151                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
152                 
153                 } else {
154                 
155                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
156                 
157                 }
158                 
159                 // Update form.
160                 
161                 longSelected = CalAdrListCtrlPtr->GetNextItem(longSelected, 
162                         wxLIST_NEXT_ALL,
163                         wxLIST_STATE_SELECTED);
164                         
165                 if (longSelected == -1){
166                         return;
167                 }               
168                 
169                 CalAdrListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
170                 CalAdrListCtrlPtr->SetItem(longSelected, 1, strValue);          
171                 
172                 if (chkUsePref->IsChecked()){
173                 
174                         CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
175                 
176                 } else {
177                 
178                         CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT(""));
179                 
180                 }
181                 
182                 this->Close();  
183         
184         }
185         
188 void frmContactEditorCalAdr::SetEditorMode(bool EditMode)
190         
191         // Set the editor mode.
192         
193         // Set if the editor is adding or editing an address.
194         // FALSE = Add
195         // TRUE = Edit
196         
197         if (EditMode == FALSE){
198         
199                 EditorMode = FALSE;
200                 btnAction->SetLabel(_("Add"));
201                 this->SetTitle(_("Add Calendar Address"));
202         
203         } else if (EditMode == TRUE){
204         
205                 EditorMode = TRUE;
206                 btnAction->SetLabel(_("Modify"));
207                 this->SetTitle(_("Modify Calendar Address"));
208                 
209                 std::map<int,int>::iterator intiter;
210                 std::map<int,wxString>::iterator striter;               
211                 wxString strValue;              
212                         
213                 // Get the organisation name.
214                 
215                 striter = CalAdrListPtr->find(CalAdrListIndex);
216                  
217                 if (striter->first == CalAdrListIndex){
218                 
219                         strValue = striter->second;
220                 
221                 }
222                 
223                 txtAddress->SetValue(strValue);
224                 
225                 strValue.Clear();
226                 
227                 // Get the type.
228                 
229                 striter = CalAdrListTypePtr->find(CalAdrListIndex);     
230                 
231                 if (striter->first == CalAdrListIndex && 
232                         striter != CalAdrListTypePtr->end()){
233                 
234                         strValue = striter->second;
235                 
236                 }
237                 
238                 if (strValue == wxT("home")){
239                 
240                         cmbType->SetSelection(1);
241                 
242                 } else if (strValue == wxT("work")){
243                 
244                         cmbType->SetSelection(2);       
245                 
246                 } else {
247                 
248                         cmbType->SetSelection(0);
249                 
250                 }
251                 
252                 // Get the organisation priority.
253                 
254                 intiter = CalAdrListPrefPtr->find(CalAdrListIndex);
255                 
256                 if (intiter->first == CalAdrListIndex && intiter->second > 0 &&
257                         intiter != CalAdrListPrefPtr->end()){
258                 
259                         sliPriority->SetValue(intiter->second);
260                         sliPriority->Enable();
261                         chkUsePref->SetValue(TRUE);
262                 
263                 }
264                 
265         }
266                 
269 void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event )
271         
272         // Close the window.
273         
274         this->Close();
275         
278 void frmContactEditorCalAdr::SetupPointers(std::map<int, wxString> *CalAdrList,
279         std::map<int, wxString> *CalAdrListAltID,
280         std::map<int, wxString> *CalAdrListPID,
281         std::map<int, wxString> *CalAdrListType,
282         std::map<int, wxString> *CalAdrListTokens,
283         std::map<int, int> *CalAdrListPref,
284         wxListCtrl *CalAdrListCtrl,
285         int CalAdrIndex )
288         // Setup the pointers.
289         
290         CalAdrListPtr = CalAdrList;
291         CalAdrListAltIDPtr = CalAdrListAltID;
292         CalAdrListPIDPtr = CalAdrListPID;
293         CalAdrListTypePtr = CalAdrListType;
294         CalAdrListTokensPtr = CalAdrListTokens;
295         CalAdrListPrefPtr = CalAdrListPref;
296         CalAdrListCtrlPtr = CalAdrListCtrl;
297         CalAdrListIndex = CalAdrIndex;
298         
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