1 // frmContactEditorTelephone.cpp - frmContactEditorTelephone form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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 )
25 frmContactEditorTelephoneADT( parent )
31 priorityCtrl = new XABPriorityCtrl(tabGeneral);
32 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
37 void frmContactEditorTelephone::ProcessAction( wxCommandEvent& event )
44 if (EditorMode == FALSE){
47 wxString strTelTypesLCtrl;
48 bool AddComma = FALSE;
50 // Add the telephone number.
53 TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));
55 // Add the telephone type.
57 if (EditSectionType == CE_GENERAL){
59 strTelTypes.Append(wxT(""));
61 } else if (EditSectionType == CE_HOME) {
63 strTelTypes.Append(wxT("home"));
66 } else if (EditSectionType == CE_WORK) {
68 strTelTypes.Append(wxT("work"));
73 if (chkVoice->IsChecked()){
77 strTelTypes.Append(wxT(","));
78 strTelTypesLCtrl.Append(wxT(","));
82 strTelTypes.Append(wxT("voice"));
83 strTelTypesLCtrl.Append(wxT("voice"));
88 if (chkFax->IsChecked()){
92 strTelTypes.Append(wxT(","));
93 strTelTypesLCtrl.Append(wxT(","));
97 strTelTypes.Append(wxT("fax"));
98 strTelTypesLCtrl.Append(wxT("fax"));
103 if (chkVideo->IsChecked()){
107 strTelTypes.Append(wxT(","));
108 strTelTypesLCtrl.Append(wxT(","));
112 strTelTypes.Append(wxT("video"));
113 strTelTypesLCtrl.Append(wxT("video"));
118 if (chkText->IsChecked()){
122 strTelTypes.Append(wxT(","));
123 strTelTypesLCtrl.Append(wxT(","));
127 strTelTypes.Append(wxT("text"));
128 strTelTypesLCtrl.Append(wxT("text"));
133 if (chkMobile->IsChecked()){
137 strTelTypes.Append(wxT(","));
138 strTelTypesLCtrl.Append(wxT(","));
142 strTelTypes.Append(wxT("cell"));
143 strTelTypesLCtrl.Append(wxT("cell"));
148 if (chkTextphone->IsChecked()){
152 strTelTypes.Append(wxT(","));
153 strTelTypesLCtrl.Append(wxT(","));
157 strTelTypes.Append(wxT("textphone"));
158 strTelTypesLCtrl.Append(wxT("textphone"));
163 if (chkPager->IsChecked()){
167 strTelTypes.Append(wxT(","));
168 strTelTypesLCtrl.Append(wxT(","));
172 strTelTypes.Append(wxT("pager"));
173 strTelTypesLCtrl.Append(wxT("pager"));
178 TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
180 TelephoneListTypeInfoPtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
182 // Add Telephone Priority.
184 if (priorityCtrl->IsPriorityChecked()){
186 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, priorityCtrl->GetValue()));
190 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));
198 coldata.SetId(TelephoneListIndex);
199 coldata.SetData(TelephoneListIndex);
200 coldata.SetText(txtTelephone->GetValue());
201 ListCtrlIndex = TelephoneListCtrlPtr->InsertItem(coldata);
203 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
205 TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 1, strTelTypesLCtrl);
207 if (priorityCtrl->IsPriorityChecked()){
209 TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
215 } else if (EditorMode == TRUE) {
217 wxString strTelTypes;
218 wxString strTelTypesLCtrl;
219 bool AddComma = FALSE;
220 long longSelected = -1;
222 // Edit the Telephone number.
225 TelephoneListPtr->erase(TelephoneListIndex);
226 TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));
228 // Edit the Telephone type.
230 if (EditSectionType == CE_GENERAL){
232 strTelTypes.Append(wxT(""));
234 } else if (EditSectionType == CE_HOME) {
236 strTelTypes.Append(wxT("home"));
239 } else if (EditSectionType == CE_WORK) {
241 strTelTypes.Append(wxT("work"));
246 if (chkVoice->IsChecked()){
250 strTelTypes.Append(wxT(","));
251 strTelTypesLCtrl.Append(wxT(","));
255 strTelTypes.Append(wxT("voice"));
256 strTelTypesLCtrl.Append(wxT("voice"));
261 if (chkFax->IsChecked()){
265 strTelTypes.Append(wxT(","));
266 strTelTypesLCtrl.Append(wxT(","));
270 strTelTypes.Append(wxT("fax"));
271 strTelTypesLCtrl.Append(wxT("fax"));
276 if (chkVideo->IsChecked()){
280 strTelTypes.Append(wxT(","));
281 strTelTypesLCtrl.Append(wxT(","));
285 strTelTypes.Append(wxT("video"));
286 strTelTypesLCtrl.Append(wxT("video"));
291 if (chkText->IsChecked()){
295 strTelTypes.Append(wxT(","));
296 strTelTypesLCtrl.Append(wxT(","));
300 strTelTypes.Append(wxT("text"));
301 strTelTypesLCtrl.Append(wxT("text"));
306 if (chkMobile->IsChecked()){
310 strTelTypes.Append(wxT(","));
311 strTelTypesLCtrl.Append(wxT(","));
315 strTelTypes.Append(wxT("cell"));
316 strTelTypesLCtrl.Append(wxT("cell"));
321 if (chkTextphone->IsChecked()){
325 strTelTypes.Append(wxT(","));
326 strTelTypesLCtrl.Append(wxT(","));
330 strTelTypes.Append(wxT("textphone"));
331 strTelTypesLCtrl.Append(wxT("textphone"));
336 if (chkPager->IsChecked()){
340 strTelTypes.Append(wxT(","));
341 strTelTypesLCtrl.Append(wxT(","));
345 strTelTypes.Append(wxT("pager"));
346 strTelTypesLCtrl.Append(wxT("pager"));
351 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
353 TelephoneListTypePtr->erase(TelephoneListIndex);
354 TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
356 TelephoneListTypeInfoPtr->erase(TelephoneListIndex);
357 TelephoneListTypeInfoPtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
359 // Edit the Telephone Priority.
361 TelephoneListPrefPtr->erase(TelephoneListIndex);
363 if (priorityCtrl->IsPriorityChecked()){
365 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, priorityCtrl->GetValue()));
369 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));
375 longSelected = TelephoneListCtrlPtr->GetNextItem(longSelected,
377 wxLIST_STATE_SELECTED);
379 if (longSelected == -1){
383 TelephoneListCtrlPtr->SetItem(longSelected, 0, txtTelephone->GetValue());
384 TelephoneListCtrlPtr->SetItem(longSelected, 1, strTelTypesLCtrl);
386 if (priorityCtrl->IsPriorityChecked()){
388 TelephoneListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
392 TelephoneListCtrlPtr->SetItem(longSelected, 2, wxT(""));
402 void frmContactEditorTelephone::CloseWindow( wxCommandEvent& event )
411 void frmContactEditorTelephone::SetEditorMode(bool EditMode, SectionType SectType)
414 // Set the editor mode.
416 // Set if the editor is adding or editing an address.
420 if (EditMode == FALSE){
423 btnAction->SetLabel(_("Add"));
424 this->SetTitle(_("Add Telephone"));
426 } else if (EditMode == TRUE){
429 btnAction->SetLabel(_("Modify"));
430 this->SetTitle(_("Modify Telephone"));
432 std::map<int,int>::iterator intiter;
433 std::map<int,wxString>::iterator striter;
436 // Load the data into the form. Get the phone number.
438 striter = TelephoneListPtr->find(TelephoneListIndex);
440 if (striter->first == TelephoneListIndex){
442 strValue = striter->second;
446 txtTelephone->SetValue(strValue);
450 // Get the phone types in.
453 if (TelephoneListTypeInfoPtr->find(TelephoneListIndex) !=
454 TelephoneListTypeInfoPtr->end()){
456 striter = TelephoneListTypeInfoPtr->find(TelephoneListIndex);
458 if (striter->first == TelephoneListIndex){
460 strValue = striter->second;
466 wxStringTokenizer TelephonePrefToken (strValue, wxT(","));
470 while(TelephonePrefToken.HasMoreTokens()){
472 strValue = TelephonePrefToken.GetNextToken();
474 if (strValue == wxT("home") || strValue == wxT("work")){
476 // Ignore these two since they aren't needed.
482 if (strValue == wxT("voice")){
484 chkVoice->SetValue(TRUE);
488 if (strValue == wxT("fax")){
490 chkFax->SetValue(TRUE);
494 if (strValue == wxT("video")){
496 chkVideo->SetValue(TRUE);
500 if (strValue == wxT("text")){
502 chkText->SetValue(TRUE);
506 if (strValue == wxT("cell")){
508 chkMobile->SetValue(TRUE);
512 if (strValue == wxT("textphone")){
514 chkTextphone->SetValue(TRUE);
518 if (strValue == wxT("pager")){
520 chkPager->SetValue(TRUE);
528 intiter = TelephoneListPrefPtr->find(TelephoneListIndex);
530 if (intiter->first == TelephoneListIndex && intiter->second > 0 &&
531 intiter != TelephoneListPrefPtr->end()){
533 priorityCtrl->SetValue(intiter->second);
534 priorityCtrl->EnablePriority(true);
540 EditSectionType = SectType;
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,
555 // Setup the pointers.
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;