Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / contacteditor / frmContactEditorCalAdr.cpp
1 #include "frmContactEditorCalAdr.h"
2 #include <wx/tokenzr.h>
3 #include "../common/textprocessing.h"
5 frmContactEditorCalAdr::frmContactEditorCalAdr( wxWindow* parent )
6 :
7 frmContactEditorCalAdrADT( parent )
8 {
9         EditorMode = FALSE;
10         sliPriority->Disable();
11         
12         cmbType->Append(wxT(""));
13         cmbType->Append(_("Home"));
14         cmbType->Append(_("Work"));     
15 }
17 void frmContactEditorCalAdr::EnablePriority( wxCommandEvent& event )
18 {
19         if (chkUsePref->IsChecked()){
20                 sliPriority->Enable();
21         } else {
22                 sliPriority->Disable();
23         }
24 }
26 void frmContactEditorCalAdr::ProcessAction( wxCommandEvent& event )
27 {
28         long ListCtrlIndex;
29         
30         if (EditorMode == FALSE){
32                 wxString strValue;
33         
34                 // Setup Calendar Address.
35                 
36                 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
38                 strValue.Clear();
39                 
40                 strValue = cmbType->GetString(cmbType->GetSelection());
42                 // Setup Calendar Type.
44                 if (strValue == _("Home")) {
45                 
46                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
47                 
48                 } else if (strValue == _("Work")) {
49                 
50                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
51                 
52                 } else {
53                 
54                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("")));
55                 
56                 }
57                 
58                 // Setup Calendar Priority.
59                 
60                 if (chkUsePref->IsChecked()){
61                 
62                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
63                 
64                 } else {
65                 
66                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
67                 
68                 }
69                 
70                 // Add to form.
71                 
72                 wxListItem coldata;
73                 
74                 coldata.SetId(CalAdrListIndex);
75                 coldata.SetData(CalAdrListIndex);
76                 coldata.SetText(txtAddress->GetValue());
77                 ListCtrlIndex = CalAdrListCtrlPtr->InsertItem(coldata);
78                 
79                 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);
80                 
81                 if (chkUsePref->IsChecked()){
82                 
83                         CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
84                 
85                 }
86                 
87                 this->Close();
88                 
89         } else if (EditorMode == TRUE) {
90         
91                 long longSelected = -1;
92                 wxString strValue;      
93         
94                 // Update Category Name.
95                 
96                 CalAdrListPtr->erase(CalAdrListIndex);
97                 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
98                 
99                 // Update Category Type.
100                 
101                 CalAdrListTypePtr->erase(CalAdrListIndex);
102                 
103                 strValue.Clear();
104                 strValue = cmbType->GetString(cmbType->GetSelection());
105                 
106                 if (strValue == _("Home")) {
107                 
108                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
109                 
110                 } else if (strValue == _("Work")) {
111                 
112                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
113                 
114                 }               
115                 
116                 // Update Category Priority.
117                 
118                 CalAdrListPrefPtr->erase(CalAdrListIndex);
119                 
120                 if (chkUsePref->IsChecked()){
121                 
122                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
123                 
124                 } else {
125                 
126                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
127                 
128                 }
129                 
130                 // Update form.
131                 
132                 longSelected = CalAdrListCtrlPtr->GetNextItem(longSelected, 
133                         wxLIST_NEXT_ALL,
134                         wxLIST_STATE_SELECTED);
135                         
136                 if (longSelected == -1){
137                         return;
138                 }               
139                 
140                 CalAdrListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
141                 CalAdrListCtrlPtr->SetItem(longSelected, 1, strValue);          
142                 
143                 if (chkUsePref->IsChecked()){
144                 
145                         CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
146                 
147                 } else {
148                 
149                         CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT(""));
150                 
151                 }
152                 
153                 this->Close();  
154         
155         }
158 void frmContactEditorCalAdr::SetEditorMode(bool EditMode)
160         // Set if the editor is adding or editing an address.
161         // FALSE = Add
162         // TRUE = Edit
163         
164         if (EditMode == FALSE){
165         
166                 EditorMode = FALSE;
167                 btnAction->SetLabel(_("Add"));
168                 this->SetTitle(_("Add Calendar Address"));
169         
170         } else if (EditMode == TRUE){
171         
172                 EditorMode = TRUE;
173                 btnAction->SetLabel(_("Modify"));
174                 this->SetTitle(_("Modify Calendar Address"));
175                 
176                 std::map<int,int>::iterator intiter;
177                 std::map<int,wxString>::iterator striter;               
178                 wxString strValue;              
179                         
180                 // Get the organisation name.
181                 
182                 striter = CalAdrListPtr->find(CalAdrListIndex);
183                  
184                 if (striter->first == CalAdrListIndex){
185                 
186                         strValue = striter->second;
187                 
188                 }
189                 
190                 txtAddress->SetValue(strValue);
191                 
192                 strValue.Clear();
193                 
194                 // Get the type.
195                 
196                 striter = CalAdrListTypePtr->find(CalAdrListIndex);     
197                 
198                 if (striter->first == CalAdrListIndex){
199                 
200                         strValue = striter->second;
201                 
202                 }
203                 
204                 if (strValue == wxT("home")){
205                 
206                         cmbType->SetSelection(1);
207                 
208                 } else if (strValue == wxT("work")){
209                 
210                         cmbType->SetSelection(2);       
211                 
212                 } else {
213                 
214                         cmbType->SetSelection(0);
215                 
216                 }
217                 
218                 // Get the organisation priority.
219                 
220                 intiter = CalAdrListPrefPtr->find(CalAdrListIndex);
221                 
222                 if (intiter->first == CalAdrListIndex && intiter->second > 0){
223                 
224                         sliPriority->SetValue(intiter->second);
225                         sliPriority->Enable();
226                         chkUsePref->SetValue(TRUE);
227                 
228                 }
229                 
230         }
231                 
234 void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event )
236         this->Close();
239 void frmContactEditorCalAdr::SetupPointers(std::map<int, wxString> *CalAdrList,
240         std::map<int, wxString> *CalAdrListAltID,
241         std::map<int, wxString> *CalAdrListPID,
242         std::map<int, wxString> *CalAdrListType,
243         std::map<int, wxString> *CalAdrListTokens,
244         std::map<int, int> *CalAdrListPref,
245         wxListCtrl *CalAdrListCtrl,
246         int CalAdrIndex )
249         CalAdrListPtr = CalAdrList;
250         CalAdrListAltIDPtr = CalAdrListAltID;
251         CalAdrListPIDPtr = CalAdrListPID;
252         CalAdrListTypePtr = CalAdrListType;
253         CalAdrListTokensPtr = CalAdrListTokens;
254         CalAdrListPrefPtr = CalAdrListPref;
255         CalAdrListCtrlPtr = CalAdrListCtrl;
256         CalAdrListIndex = CalAdrIndex;
257         
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