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