Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / contacteditor / frmContactEditorTelephone.cpp
1 #include "frmContactEditorTelephone.h"
2 #include "../common/textprocessing.h"
3 #include <wx/tokenzr.h>
5 frmContactEditorTelephone::frmContactEditorTelephone( wxWindow* parent )
6 :
7 frmContactEditorTelephoneADT( parent )
8 {
9         EditorMode = FALSE;
10         sliPriority->Disable(); 
11 }
13 void frmContactEditorTelephone::EnablePriority( wxCommandEvent& event )
14 {
15         if (chkUsePref->IsChecked()){
16                 sliPriority->Enable();
17         } else {
18                 sliPriority->Disable();
19         }
20 }
22 void frmContactEditorTelephone::ProcessAction( wxCommandEvent& event )
23 {
24         long ListCtrlIndex;
25         
26         if (EditorMode == FALSE){
28                 wxString strTelTypes;
29                 wxString strTelTypesLCtrl;
30                 bool AddComma = FALSE;
31                 
32                 // Add the telephone number.
33                 
34                 wxString strValue;
35                 TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));
36                 
37                 // Add the telephone type.
38                 
39                 if (EditSectionType == CE_GENERAL){
40                 
41                         strTelTypes.Append(wxT(""));
42                 
43                 } else if (EditSectionType == CE_HOME) {
44                 
45                         strTelTypes.Append(wxT("home"));
46                         AddComma = TRUE;
47                 
48                 } else if (EditSectionType == CE_WORK) {
49                 
50                         strTelTypes.Append(wxT("work"));
51                         AddComma = TRUE;
52                 
53                 }
54                 
55                 if (chkVoice->IsChecked()){
56                 
57                         if (AddComma){
58                         
59                                 strTelTypes.Append(wxT(","));
60                                 strTelTypesLCtrl.Append(wxT(","));
61                         
62                         }               
63                 
64                         strTelTypes.Append(wxT("voice"));
65                         strTelTypesLCtrl.Append(wxT("voice"));
66                         AddComma = TRUE;
67                 
68                 }
69                 
70                 if (chkFax->IsChecked()){
71                 
72                         if (AddComma){
73                         
74                                 strTelTypes.Append(wxT(","));
75                                 strTelTypesLCtrl.Append(wxT(","));                              
76                         
77                         }
78                 
79                         strTelTypes.Append(wxT("fax"));
80                         strTelTypesLCtrl.Append(wxT("fax"));
81                         AddComma = TRUE;
82                 
83                 }
84                 
85                 if (chkVideo->IsChecked()){
86                 
87                         if (AddComma){
88                         
89                                 strTelTypes.Append(wxT(","));
90                                 strTelTypesLCtrl.Append(wxT(","));                              
91                         
92                         }
93                 
94                         strTelTypes.Append(wxT("video"));
95                         strTelTypesLCtrl.Append(wxT("video"));
96                         AddComma = TRUE;                        
97                 
98                 }
99                 
100                 if (chkText->IsChecked()){
101                 
102                         if (AddComma){
103                         
104                                 strTelTypes.Append(wxT(","));
105                                 strTelTypesLCtrl.Append(wxT(","));                              
106                         
107                         }
108                 
109                         strTelTypes.Append(wxT("text"));
110                         strTelTypesLCtrl.Append(wxT("text"));                   
111                         AddComma = TRUE;
112                 
113                 }
114                 
115                 if (chkMobile->IsChecked()){
116                 
117                         if (AddComma){
118                         
119                                 strTelTypes.Append(wxT(","));
120                                 strTelTypesLCtrl.Append(wxT(","));                              
121                         
122                         }
123                 
124                         strTelTypes.Append(wxT("cell"));
125                         strTelTypesLCtrl.Append(wxT("cell"));
126                         AddComma = TRUE;                        
127                 
128                 }
129                 
130                 if (chkTextphone->IsChecked()){
131                 
132                         if (AddComma){
133                         
134                                 strTelTypes.Append(wxT(","));
135                                 strTelTypesLCtrl.Append(wxT(","));                              
136                         
137                         }
138                 
139                         strTelTypes.Append(wxT("textphone"));
140                         strTelTypesLCtrl.Append(wxT("textphone"));                      
141                         AddComma = TRUE;                        
142                 
143                 }
144                 
145                 if (chkPager->IsChecked()){
146                 
147                         if (AddComma){
148                         
149                                 strTelTypes.Append(wxT(","));
150                                 strTelTypesLCtrl.Append(wxT(","));                              
151                         
152                         }
153                 
154                         strTelTypes.Append(wxT("pager"));
155                         strTelTypesLCtrl.Append(wxT("pager"));                  
156                         AddComma = TRUE;                        
157                 
158                 }
159                                 
160                 TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));          
161                 
162                 // Add Telephone Priority.
163                 
164                 if (chkUsePref->IsChecked()){
165                 
166                         TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, sliPriority->GetValue()));
167                 
168                 } else {
169                 
170                         TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));            
171                 
172                 }
173                 
174                 // Add to the form.
175                 
176                 wxListItem coldata;
177                 
178                 coldata.SetId(TelephoneListIndex);
179                 coldata.SetData(TelephoneListIndex);            
180                 coldata.SetText(txtTelephone->GetValue());
181                 ListCtrlIndex = TelephoneListCtrlPtr->InsertItem(coldata);
182                 
183                 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
184                 
185                 TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 1, strTelTypesLCtrl);
186                 
187                 if (chkUsePref->IsChecked()){
188                 
189                         TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
190                 
191                 }               
192         
193                 this->Close();
194         
195         } else if (EditorMode == TRUE) {
196         
197                 wxString strTelTypes;
198                 wxString strTelTypesLCtrl;
199                 bool AddComma = FALSE;
200                 long longSelected = -1;         
201                 
202                 // Edit the Telephone number.
203                 
204                 wxString strValue;              
205                 TelephoneListPtr->erase(TelephoneListIndex);
206                 TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));         
207                 
208                 // Edit the Telephone type.
209                 
210                 if (EditSectionType == CE_GENERAL){
211                 
212                         strTelTypes.Append(wxT(""));
213                 
214                 } else if (EditSectionType == CE_HOME) {
215                 
216                         strTelTypes.Append(wxT("home"));
217                         AddComma = TRUE;
218                 
219                 } else if (EditSectionType == CE_WORK) {
220                 
221                         strTelTypes.Append(wxT("work"));
222                         AddComma = TRUE;
223                 
224                 }
225                 
226                 if (chkVoice->IsChecked()){
227                 
228                         if (AddComma){
229                         
230                                 strTelTypes.Append(wxT(","));
231                                 strTelTypesLCtrl.Append(wxT(","));
232                         
233                         }               
234                 
235                         strTelTypes.Append(wxT("voice"));
236                         strTelTypesLCtrl.Append(wxT("voice"));
237                         AddComma = TRUE;
238                 
239                 }
240                 
241                 if (chkFax->IsChecked()){
242                 
243                         if (AddComma){
244                         
245                                 strTelTypes.Append(wxT(","));
246                                 strTelTypesLCtrl.Append(wxT(","));                              
247                         
248                         }
249                 
250                         strTelTypes.Append(wxT("fax"));
251                         strTelTypesLCtrl.Append(wxT("fax"));
252                         AddComma = TRUE;
253                 
254                 }
255                 
256                 if (chkVideo->IsChecked()){
257                 
258                         if (AddComma){
259                         
260                                 strTelTypes.Append(wxT(","));
261                                 strTelTypesLCtrl.Append(wxT(","));                              
262                         
263                         }
264                 
265                         strTelTypes.Append(wxT("video"));
266                         strTelTypesLCtrl.Append(wxT("video"));
267                         AddComma = TRUE;                        
268                 
269                 }
270                 
271                 if (chkText->IsChecked()){
272                 
273                         if (AddComma){
274                         
275                                 strTelTypes.Append(wxT(","));
276                                 strTelTypesLCtrl.Append(wxT(","));                              
277                         
278                         }
279                 
280                         strTelTypes.Append(wxT("text"));
281                         strTelTypesLCtrl.Append(wxT("text"));                   
282                         AddComma = TRUE;
283                 
284                 }
285                 
286                 if (chkMobile->IsChecked()){
287                 
288                         if (AddComma){
289                         
290                                 strTelTypes.Append(wxT(","));
291                                 strTelTypesLCtrl.Append(wxT(","));                              
292                         
293                         }
294                 
295                         strTelTypes.Append(wxT("cell"));
296                         strTelTypesLCtrl.Append(wxT("cell"));                   
297                         AddComma = TRUE;                        
298                 
299                 }
300                 
301                 if (chkTextphone->IsChecked()){
302                 
303                         if (AddComma){
304                         
305                                 strTelTypes.Append(wxT(","));
306                                 strTelTypesLCtrl.Append(wxT(","));                              
307                         
308                         }
309                 
310                         strTelTypes.Append(wxT("textphone"));
311                         strTelTypesLCtrl.Append(wxT("textphone"));                      
312                         AddComma = TRUE;                        
313                 
314                 }
315                 
316                 if (chkPager->IsChecked()){
317                 
318                         if (AddComma){
319                         
320                                 strTelTypes.Append(wxT(","));
321                                 strTelTypesLCtrl.Append(wxT(","));                              
322                         
323                         }
324                 
325                         strTelTypes.Append(wxT("pager"));
326                         strTelTypesLCtrl.Append(wxT("pager"));                  
327                         AddComma = TRUE;                        
328                 
329                 }
330                 
331                 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);             
332                                 
333                 TelephoneListTypePtr->erase(TelephoneListIndex);
334                 TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));          
335                 
336                 // Edit the Telephone Priority.
337                 
338                 TelephoneListPrefPtr->erase(TelephoneListIndex);
339                 
340                 if (chkUsePref->IsChecked()){
341                 
342                         TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, sliPriority->GetValue()));
343                 
344                 } else {
345                 
346                         TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));            
347                 
348                 }               
349                 
350                 // Update the form.
351                 
352                 longSelected = TelephoneListCtrlPtr->GetNextItem(longSelected, 
353                         wxLIST_NEXT_ALL,
354                         wxLIST_STATE_SELECTED);
355                         
356                 if (longSelected == -1){
357                         return;
358                 }               
359                 
360                 TelephoneListCtrlPtr->SetItem(longSelected, 0, txtTelephone->GetValue());
361                 TelephoneListCtrlPtr->SetItem(longSelected, 1, strTelTypesLCtrl);
362                 
363                 if (chkUsePref->IsChecked()){
364                 
365                         TelephoneListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
366                 
367                 } else {
368                 
369                         TelephoneListCtrlPtr->SetItem(longSelected, 2, wxT(""));
370                 
371                 }       
372         
373                 this->Close();
374         
375         }
376         
379 void frmContactEditorTelephone::CloseWindow( wxCommandEvent& event )
382         this->Close();
386 void frmContactEditorTelephone::SetEditorMode(bool EditMode, SectionType SectType)
388         // Set if the editor is adding or editing an address.
389         // FALSE = Add
390         // TRUE = Edit
391         
392         if (EditMode == FALSE){
393         
394                 EditorMode = FALSE;
395                 btnAction->SetLabel(_("Add"));
396                 this->SetTitle(_("Add Telephone"));
397         
398         } else if (EditMode == TRUE){
399         
400                 EditorMode = TRUE;
401                 btnAction->SetLabel(_("Modify"));
402                 this->SetTitle(_("Modify Telephone"));
403                 
404                 std::map<int,int>::iterator intiter;
405                 std::map<int,wxString>::iterator striter;               
406                 wxString strValue;
407                 
408                 // Load the data into the form. Get the phone number.
409                 
410                 striter = TelephoneListPtr->find(TelephoneListIndex);
411                  
412                 if (striter->first == TelephoneListIndex){
413                 
414                         strValue = striter->second;
415                 
416                 }
417                 
418                 txtTelephone->SetValue(strValue);
419                 
420                 strValue.Clear();
421                 
422                 // Get the phone types in.
423                 
424                 striter = TelephoneListTypePtr->find(TelephoneListIndex);
425                  
426                 if (striter->first == TelephoneListIndex){
427                 
428                         strValue = striter->second;
429                 
430                 }               
431                 
432                 wxStringTokenizer TelephonePrefToken (strValue, wxT(","));
433                 
434                 strValue.Clear();
435                 
436                 while(TelephonePrefToken.HasMoreTokens()){
437                         
438                         strValue = TelephonePrefToken.GetNextToken();                   
439                         
440                         if (strValue == wxT("home") || strValue == wxT("work")){
441                         
442                                 // Ignore these two since they aren't needed.
443                         
444                                 continue;
445                         
446                         }
447                         
448                         if (strValue == wxT("voice")){
449                         
450                                 chkVoice->SetValue(TRUE);
451                         
452                         }
453                         
454                         if (strValue == wxT("fax")){
455                         
456                                 chkFax->SetValue(TRUE);
457                         
458                         }
459                         
460                         if (strValue == wxT("video")){
461                         
462                                 chkVideo->SetValue(TRUE);
463                         
464                         }
465                         
466                         if (strValue == wxT("text")){
467                         
468                                 chkText->SetValue(TRUE);
469                         
470                         }
471                         
472                         if (strValue == wxT("cell")){
473                         
474                                 chkMobile->SetValue(TRUE);
475                         
476                         }
477                         
478                         if (strValue == wxT("textphone")){
479                         
480                                 chkTextphone->SetValue(TRUE);
481                         
482                         }               
483                         
484                         if (strValue == wxT("pager")){
485                         
486                                 chkPager->SetValue(TRUE);
487                         
488                         }
489                 
490                 }
491                 
492                 // Setup the Slider.
493                 
494                 intiter = TelephoneListPrefPtr->find(TelephoneListIndex);
495                 
496                 if (intiter->first == TelephoneListIndex && intiter->second > 0){
497                 
498                         sliPriority->SetValue(intiter->second);
499                         sliPriority->Enable();
500                         chkUsePref->SetValue(TRUE);
501                 
502                 }               
503                 
504         }
505         
506         EditSectionType = SectType;     
507         
510 void frmContactEditorTelephone::SetupPointers(std::map<int, wxString> *TelephoneList,
511         std::map<int, wxString> *TelephoneListAltID,
512         std::map<int, wxString> *TelephoneListPID,
513         std::map<int, wxString> *TelephoneListType,
514         std::map<int, wxString> *TelephoneListTokens,
515         std::map<int, int> *TelephoneListPref,
516         wxListCtrl *TelephoneListCtrl,
517         int TelephoneIndex )
520         TelephoneListPtr = TelephoneList;
521         TelephoneListAltIDPtr = TelephoneListAltID;
522         TelephoneListPIDPtr = TelephoneListPID;
523         TelephoneListTypePtr = TelephoneListType;
524         TelephoneListTokensPtr = TelephoneListTokens;
525         TelephoneListPrefPtr = TelephoneListPref;
526         TelephoneListCtrlPtr = TelephoneListCtrl;
527         TelephoneListIndex = TelephoneIndex;
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