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