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 )
28 sliPriority->Disable();
31 void frmContactEditorTelephone::EnablePriority( wxCommandEvent& event )
33 if (chkUsePref->IsChecked()){
34 sliPriority->Enable();
36 sliPriority->Disable();
40 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 // Add Telephone Priority.
182 if (chkUsePref->IsChecked()){
184 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, sliPriority->GetValue()));
188 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));
196 coldata.SetId(TelephoneListIndex);
197 coldata.SetData(TelephoneListIndex);
198 coldata.SetText(txtTelephone->GetValue());
199 ListCtrlIndex = TelephoneListCtrlPtr->InsertItem(coldata);
201 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
203 TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 1, strTelTypesLCtrl);
205 if (chkUsePref->IsChecked()){
207 TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
213 } else if (EditorMode == TRUE) {
215 wxString strTelTypes;
216 wxString strTelTypesLCtrl;
217 bool AddComma = FALSE;
218 long longSelected = -1;
220 // Edit the Telephone number.
223 TelephoneListPtr->erase(TelephoneListIndex);
224 TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));
226 // Edit the Telephone type.
228 if (EditSectionType == CE_GENERAL){
230 strTelTypes.Append(wxT(""));
232 } else if (EditSectionType == CE_HOME) {
234 strTelTypes.Append(wxT("home"));
237 } else if (EditSectionType == CE_WORK) {
239 strTelTypes.Append(wxT("work"));
244 if (chkVoice->IsChecked()){
248 strTelTypes.Append(wxT(","));
249 strTelTypesLCtrl.Append(wxT(","));
253 strTelTypes.Append(wxT("voice"));
254 strTelTypesLCtrl.Append(wxT("voice"));
259 if (chkFax->IsChecked()){
263 strTelTypes.Append(wxT(","));
264 strTelTypesLCtrl.Append(wxT(","));
268 strTelTypes.Append(wxT("fax"));
269 strTelTypesLCtrl.Append(wxT("fax"));
274 if (chkVideo->IsChecked()){
278 strTelTypes.Append(wxT(","));
279 strTelTypesLCtrl.Append(wxT(","));
283 strTelTypes.Append(wxT("video"));
284 strTelTypesLCtrl.Append(wxT("video"));
289 if (chkText->IsChecked()){
293 strTelTypes.Append(wxT(","));
294 strTelTypesLCtrl.Append(wxT(","));
298 strTelTypes.Append(wxT("text"));
299 strTelTypesLCtrl.Append(wxT("text"));
304 if (chkMobile->IsChecked()){
308 strTelTypes.Append(wxT(","));
309 strTelTypesLCtrl.Append(wxT(","));
313 strTelTypes.Append(wxT("cell"));
314 strTelTypesLCtrl.Append(wxT("cell"));
319 if (chkTextphone->IsChecked()){
323 strTelTypes.Append(wxT(","));
324 strTelTypesLCtrl.Append(wxT(","));
328 strTelTypes.Append(wxT("textphone"));
329 strTelTypesLCtrl.Append(wxT("textphone"));
334 if (chkPager->IsChecked()){
338 strTelTypes.Append(wxT(","));
339 strTelTypesLCtrl.Append(wxT(","));
343 strTelTypes.Append(wxT("pager"));
344 strTelTypesLCtrl.Append(wxT("pager"));
349 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
351 TelephoneListTypePtr->erase(TelephoneListIndex);
352 TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
354 // Edit the Telephone Priority.
356 TelephoneListPrefPtr->erase(TelephoneListIndex);
358 if (chkUsePref->IsChecked()){
360 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, sliPriority->GetValue()));
364 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));
370 longSelected = TelephoneListCtrlPtr->GetNextItem(longSelected,
372 wxLIST_STATE_SELECTED);
374 if (longSelected == -1){
378 TelephoneListCtrlPtr->SetItem(longSelected, 0, txtTelephone->GetValue());
379 TelephoneListCtrlPtr->SetItem(longSelected, 1, strTelTypesLCtrl);
381 if (chkUsePref->IsChecked()){
383 TelephoneListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
387 TelephoneListCtrlPtr->SetItem(longSelected, 2, wxT(""));
397 void frmContactEditorTelephone::CloseWindow( wxCommandEvent& event )
404 void frmContactEditorTelephone::SetEditorMode(bool EditMode, SectionType SectType)
406 // Set if the editor is adding or editing an address.
410 if (EditMode == FALSE){
413 btnAction->SetLabel(_("Add"));
414 this->SetTitle(_("Add Telephone"));
416 } else if (EditMode == TRUE){
419 btnAction->SetLabel(_("Modify"));
420 this->SetTitle(_("Modify Telephone"));
422 std::map<int,int>::iterator intiter;
423 std::map<int,wxString>::iterator striter;
426 // Load the data into the form. Get the phone number.
428 striter = TelephoneListPtr->find(TelephoneListIndex);
430 if (striter->first == TelephoneListIndex){
432 strValue = striter->second;
436 txtTelephone->SetValue(strValue);
440 // Get the phone types in.
443 if (TelephoneListTypeInfoPtr->find(TelephoneListIndex) !=
444 TelephoneListTypeInfoPtr->end()){
446 striter = TelephoneListTypeInfoPtr->find(TelephoneListIndex);
448 if (striter->first == TelephoneListIndex){
450 strValue = striter->second;
456 wxStringTokenizer TelephonePrefToken (strValue, wxT(","));
460 while(TelephonePrefToken.HasMoreTokens()){
462 strValue = TelephonePrefToken.GetNextToken();
464 if (strValue == wxT("home") || strValue == wxT("work")){
466 // Ignore these two since they aren't needed.
472 if (strValue == wxT("voice")){
474 chkVoice->SetValue(TRUE);
478 if (strValue == wxT("fax")){
480 chkFax->SetValue(TRUE);
484 if (strValue == wxT("video")){
486 chkVideo->SetValue(TRUE);
490 if (strValue == wxT("text")){
492 chkText->SetValue(TRUE);
496 if (strValue == wxT("cell")){
498 chkMobile->SetValue(TRUE);
502 if (strValue == wxT("textphone")){
504 chkTextphone->SetValue(TRUE);
508 if (strValue == wxT("pager")){
510 chkPager->SetValue(TRUE);
518 intiter = TelephoneListPrefPtr->find(TelephoneListIndex);
520 if (intiter->first == TelephoneListIndex && intiter->second > 0){
522 sliPriority->SetValue(intiter->second);
523 sliPriority->Enable();
524 chkUsePref->SetValue(TRUE);
530 EditSectionType = SectType;
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,
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;