Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmMain: Be able to add a contact from the right-click contact list menu if account...
[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         priorityCtrl = new XABPriorityCtrl(tabGeneral);
32         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
33         szrGeneral->Layout();
34         
35 }
37 void frmContactEditorTelephone::ProcessAction( wxCommandEvent& event )
38 {
39         
40         // Process action.
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));
180                 TelephoneListTypeInfoPtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
181                 
182                 // Add Telephone Priority.
183                 
184                 if (priorityCtrl->IsPriorityChecked()){
185                 
186                         TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, priorityCtrl->GetValue()));
187                 
188                 } else {
189                 
190                         TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));            
191                 
192                 }
193                 
194                 // Add to the form.
195                 
196                 wxListItem coldata;
197                 
198                 coldata.SetId(TelephoneListIndex);
199                 coldata.SetData(TelephoneListIndex);            
200                 coldata.SetText(txtTelephone->GetValue());
201                 ListCtrlIndex = TelephoneListCtrlPtr->InsertItem(coldata);
202                 
203                 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
204                 
205                 TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 1, strTelTypesLCtrl);
206                 
207                 if (priorityCtrl->IsPriorityChecked()){
208                 
209                         TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
210                 
211                 }               
212         
213                 this->Close();
214         
215         } else if (EditorMode == TRUE) {
216         
217                 wxString strTelTypes;
218                 wxString strTelTypesLCtrl;
219                 bool AddComma = FALSE;
220                 long longSelected = -1;         
221                 
222                 // Edit the Telephone number.
223                 
224                 wxString strValue;              
225                 TelephoneListPtr->erase(TelephoneListIndex);
226                 TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));         
227                 
228                 // Edit the Telephone type.
229                 
230                 if (EditSectionType == CE_GENERAL){
231                 
232                         strTelTypes.Append(wxT(""));
233                 
234                 } else if (EditSectionType == CE_HOME) {
235                 
236                         strTelTypes.Append(wxT("home"));
237                         AddComma = TRUE;
238                 
239                 } else if (EditSectionType == CE_WORK) {
240                 
241                         strTelTypes.Append(wxT("work"));
242                         AddComma = TRUE;
243                 
244                 }
245                 
246                 if (chkVoice->IsChecked()){
247                 
248                         if (AddComma){
249                         
250                                 strTelTypes.Append(wxT(","));
251                                 strTelTypesLCtrl.Append(wxT(","));
252                         
253                         }               
254                 
255                         strTelTypes.Append(wxT("voice"));
256                         strTelTypesLCtrl.Append(wxT("voice"));
257                         AddComma = TRUE;
258                 
259                 }
260                 
261                 if (chkFax->IsChecked()){
262                 
263                         if (AddComma){
264                         
265                                 strTelTypes.Append(wxT(","));
266                                 strTelTypesLCtrl.Append(wxT(","));                              
267                         
268                         }
269                 
270                         strTelTypes.Append(wxT("fax"));
271                         strTelTypesLCtrl.Append(wxT("fax"));
272                         AddComma = TRUE;
273                 
274                 }
275                 
276                 if (chkVideo->IsChecked()){
277                 
278                         if (AddComma){
279                         
280                                 strTelTypes.Append(wxT(","));
281                                 strTelTypesLCtrl.Append(wxT(","));                              
282                         
283                         }
284                 
285                         strTelTypes.Append(wxT("video"));
286                         strTelTypesLCtrl.Append(wxT("video"));
287                         AddComma = TRUE;                        
288                 
289                 }
290                 
291                 if (chkText->IsChecked()){
292                 
293                         if (AddComma){
294                         
295                                 strTelTypes.Append(wxT(","));
296                                 strTelTypesLCtrl.Append(wxT(","));                              
297                         
298                         }
299                 
300                         strTelTypes.Append(wxT("text"));
301                         strTelTypesLCtrl.Append(wxT("text"));                   
302                         AddComma = TRUE;
303                 
304                 }
305                 
306                 if (chkMobile->IsChecked()){
307                 
308                         if (AddComma){
309                         
310                                 strTelTypes.Append(wxT(","));
311                                 strTelTypesLCtrl.Append(wxT(","));                              
312                         
313                         }
314                 
315                         strTelTypes.Append(wxT("cell"));
316                         strTelTypesLCtrl.Append(wxT("cell"));                   
317                         AddComma = TRUE;                        
318                 
319                 }
320                 
321                 if (chkTextphone->IsChecked()){
322                 
323                         if (AddComma){
324                         
325                                 strTelTypes.Append(wxT(","));
326                                 strTelTypesLCtrl.Append(wxT(","));                              
327                         
328                         }
329                 
330                         strTelTypes.Append(wxT("textphone"));
331                         strTelTypesLCtrl.Append(wxT("textphone"));                      
332                         AddComma = TRUE;                        
333                 
334                 }
335                 
336                 if (chkPager->IsChecked()){
337                 
338                         if (AddComma){
339                         
340                                 strTelTypes.Append(wxT(","));
341                                 strTelTypesLCtrl.Append(wxT(","));                              
342                         
343                         }
344                 
345                         strTelTypes.Append(wxT("pager"));
346                         strTelTypesLCtrl.Append(wxT("pager"));                  
347                         AddComma = TRUE;                        
348                 
349                 }
350                 
351                 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);             
352                                 
353                 TelephoneListTypePtr->erase(TelephoneListIndex);
354                 TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));          
355                 
356                 TelephoneListTypeInfoPtr->erase(TelephoneListIndex);
357                 TelephoneListTypeInfoPtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));              
358                 
359                 // Edit the Telephone Priority.
360                 
361                 TelephoneListPrefPtr->erase(TelephoneListIndex);
362                 
363                 if (priorityCtrl->IsPriorityChecked()){
364                 
365                         TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, priorityCtrl->GetValue()));
366                 
367                 } else {
368                 
369                         TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));            
370                 
371                 }               
372                 
373                 // Update the form.
374                 
375                 longSelected = TelephoneListCtrlPtr->GetNextItem(longSelected, 
376                         wxLIST_NEXT_ALL,
377                         wxLIST_STATE_SELECTED);
378                         
379                 if (longSelected == -1){
380                         return;
381                 }               
382                 
383                 TelephoneListCtrlPtr->SetItem(longSelected, 0, txtTelephone->GetValue());
384                 TelephoneListCtrlPtr->SetItem(longSelected, 1, strTelTypesLCtrl);
385                 
386                 if (priorityCtrl->IsPriorityChecked()){
387                 
388                         TelephoneListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
389                 
390                 } else {
391                 
392                         TelephoneListCtrlPtr->SetItem(longSelected, 2, wxT(""));
393                 
394                 }       
395         
396                 this->Close();
397         
398         }
399         
402 void frmContactEditorTelephone::CloseWindow( wxCommandEvent& event )
405         // Close the window.
406         
407         this->Close();
411 void frmContactEditorTelephone::SetEditorMode(bool EditMode, SectionType SectType)
413         
414         // Set the editor mode.
415         
416         // Set if the editor is adding or editing an address.
417         // FALSE = Add
418         // TRUE = Edit
419         
420         if (EditMode == FALSE){
421         
422                 EditorMode = FALSE;
423                 btnAction->SetLabel(_("Add"));
424                 this->SetTitle(_("Add Telephone"));
425         
426         } else if (EditMode == TRUE){
427         
428                 EditorMode = TRUE;
429                 btnAction->SetLabel(_("Modify"));
430                 this->SetTitle(_("Modify Telephone"));
431                 
432                 std::map<int,int>::iterator intiter;
433                 std::map<int,wxString>::iterator striter;               
434                 wxString strValue;
435                 
436                 // Load the data into the form. Get the phone number.
437                 
438                 striter = TelephoneListPtr->find(TelephoneListIndex);
439                  
440                 if (striter->first == TelephoneListIndex){
441                 
442                         strValue = striter->second;
443                 
444                 }
445                 
446                 txtTelephone->SetValue(strValue);
447                 
448                 strValue.Clear();
449                 
450                 // Get the phone types in.
451                 
452                 
453                 if (TelephoneListTypeInfoPtr->find(TelephoneListIndex) !=
454                         TelephoneListTypeInfoPtr->end()){
455                 
456                         striter = TelephoneListTypeInfoPtr->find(TelephoneListIndex);
457                  
458                         if (striter->first == TelephoneListIndex){
459                 
460                                 strValue = striter->second;
461                 
462                         }       
463                 
464                 }       
465                 
466                 wxStringTokenizer TelephonePrefToken (strValue, wxT(","));
467                 
468                 strValue.Clear();
469                 
470                 while(TelephonePrefToken.HasMoreTokens()){
471                         
472                         strValue = TelephonePrefToken.GetNextToken();                   
473                         
474                         if (strValue == wxT("home") || strValue == wxT("work")){
475                         
476                                 // Ignore these two since they aren't needed.
477                         
478                                 continue;
479                         
480                         }
481                         
482                         if (strValue == wxT("voice")){
483                         
484                                 chkVoice->SetValue(TRUE);
485                         
486                         }
487                         
488                         if (strValue == wxT("fax")){
489                         
490                                 chkFax->SetValue(TRUE);
491                         
492                         }
493                         
494                         if (strValue == wxT("video")){
495                         
496                                 chkVideo->SetValue(TRUE);
497                         
498                         }
499                         
500                         if (strValue == wxT("text")){
501                         
502                                 chkText->SetValue(TRUE);
503                         
504                         }
505                         
506                         if (strValue == wxT("cell")){
507                         
508                                 chkMobile->SetValue(TRUE);
509                         
510                         }
511                         
512                         if (strValue == wxT("textphone")){
513                         
514                                 chkTextphone->SetValue(TRUE);
515                         
516                         }               
517                         
518                         if (strValue == wxT("pager")){
519                         
520                                 chkPager->SetValue(TRUE);
521                         
522                         }
523                 
524                 }
525                 
526                 // Setup the Slider.
527                 
528                 intiter = TelephoneListPrefPtr->find(TelephoneListIndex);
529                 
530                 if (intiter->first == TelephoneListIndex && intiter->second > 0 &&
531                         intiter != TelephoneListPrefPtr->end()){
532                 
533                         priorityCtrl->SetValue(intiter->second);
534                         priorityCtrl->EnablePriority(true);
535                 
536                 }               
537                 
538         }
539         
540         EditSectionType = SectType;     
541         
544 void frmContactEditorTelephone::SetupPointers(std::map<int, wxString> *TelephoneList,
545         std::map<int, wxString> *TelephoneListAltID,
546         std::map<int, wxString> *TelephoneListPID,
547         std::map<int, wxString> *TelephoneListType,
548         std::map<int, wxString> *TelephoneListTypeInfo,
549         std::map<int, wxString> *TelephoneListTokens,
550         std::map<int, int> *TelephoneListPref,
551         wxListCtrl *TelephoneListCtrl,
552         int TelephoneIndex )
555         // Setup the pointers.
556         
557         TelephoneListPtr = TelephoneList;
558         TelephoneListAltIDPtr = TelephoneListAltID;
559         TelephoneListPIDPtr = TelephoneListPID;
560         TelephoneListTypePtr = TelephoneListType;
561         TelephoneListTypeInfoPtr = TelephoneListTypeInfo;
562         TelephoneListTokensPtr = TelephoneListTokens;
563         TelephoneListPrefPtr = TelephoneListPref;
564         TelephoneListCtrlPtr = TelephoneListCtrl;
565         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