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