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 sliPriority->Disable();
35 void frmContactEditorTelephone::EnablePriority( wxCommandEvent& event )
38 // Enable/disable the priority setting.
40 if (chkUsePref->IsChecked()){
41 sliPriority->Enable();
43 sliPriority->Disable();
48 void frmContactEditorTelephone::ProcessAction( wxCommandEvent& event )
55 if (EditorMode == FALSE){
58 wxString strTelTypesLCtrl;
59 bool AddComma = FALSE;
61 // Add the telephone number.
64 TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));
66 // Add the telephone type.
68 if (EditSectionType == CE_GENERAL){
70 strTelTypes.Append(wxT(""));
72 } else if (EditSectionType == CE_HOME) {
74 strTelTypes.Append(wxT("home"));
77 } else if (EditSectionType == CE_WORK) {
79 strTelTypes.Append(wxT("work"));
84 if (chkVoice->IsChecked()){
88 strTelTypes.Append(wxT(","));
89 strTelTypesLCtrl.Append(wxT(","));
93 strTelTypes.Append(wxT("voice"));
94 strTelTypesLCtrl.Append(wxT("voice"));
99 if (chkFax->IsChecked()){
103 strTelTypes.Append(wxT(","));
104 strTelTypesLCtrl.Append(wxT(","));
108 strTelTypes.Append(wxT("fax"));
109 strTelTypesLCtrl.Append(wxT("fax"));
114 if (chkVideo->IsChecked()){
118 strTelTypes.Append(wxT(","));
119 strTelTypesLCtrl.Append(wxT(","));
123 strTelTypes.Append(wxT("video"));
124 strTelTypesLCtrl.Append(wxT("video"));
129 if (chkText->IsChecked()){
133 strTelTypes.Append(wxT(","));
134 strTelTypesLCtrl.Append(wxT(","));
138 strTelTypes.Append(wxT("text"));
139 strTelTypesLCtrl.Append(wxT("text"));
144 if (chkMobile->IsChecked()){
148 strTelTypes.Append(wxT(","));
149 strTelTypesLCtrl.Append(wxT(","));
153 strTelTypes.Append(wxT("cell"));
154 strTelTypesLCtrl.Append(wxT("cell"));
159 if (chkTextphone->IsChecked()){
163 strTelTypes.Append(wxT(","));
164 strTelTypesLCtrl.Append(wxT(","));
168 strTelTypes.Append(wxT("textphone"));
169 strTelTypesLCtrl.Append(wxT("textphone"));
174 if (chkPager->IsChecked()){
178 strTelTypes.Append(wxT(","));
179 strTelTypesLCtrl.Append(wxT(","));
183 strTelTypes.Append(wxT("pager"));
184 strTelTypesLCtrl.Append(wxT("pager"));
189 TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
191 TelephoneListTypeInfoPtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
193 // Add Telephone Priority.
195 if (chkUsePref->IsChecked()){
197 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, sliPriority->GetValue()));
201 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));
209 coldata.SetId(TelephoneListIndex);
210 coldata.SetData(TelephoneListIndex);
211 coldata.SetText(txtTelephone->GetValue());
212 ListCtrlIndex = TelephoneListCtrlPtr->InsertItem(coldata);
214 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
216 TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 1, strTelTypesLCtrl);
218 if (chkUsePref->IsChecked()){
220 TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
226 } else if (EditorMode == TRUE) {
228 wxString strTelTypes;
229 wxString strTelTypesLCtrl;
230 bool AddComma = FALSE;
231 long longSelected = -1;
233 // Edit the Telephone number.
236 TelephoneListPtr->erase(TelephoneListIndex);
237 TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));
239 // Edit the Telephone type.
241 if (EditSectionType == CE_GENERAL){
243 strTelTypes.Append(wxT(""));
245 } else if (EditSectionType == CE_HOME) {
247 strTelTypes.Append(wxT("home"));
250 } else if (EditSectionType == CE_WORK) {
252 strTelTypes.Append(wxT("work"));
257 if (chkVoice->IsChecked()){
261 strTelTypes.Append(wxT(","));
262 strTelTypesLCtrl.Append(wxT(","));
266 strTelTypes.Append(wxT("voice"));
267 strTelTypesLCtrl.Append(wxT("voice"));
272 if (chkFax->IsChecked()){
276 strTelTypes.Append(wxT(","));
277 strTelTypesLCtrl.Append(wxT(","));
281 strTelTypes.Append(wxT("fax"));
282 strTelTypesLCtrl.Append(wxT("fax"));
287 if (chkVideo->IsChecked()){
291 strTelTypes.Append(wxT(","));
292 strTelTypesLCtrl.Append(wxT(","));
296 strTelTypes.Append(wxT("video"));
297 strTelTypesLCtrl.Append(wxT("video"));
302 if (chkText->IsChecked()){
306 strTelTypes.Append(wxT(","));
307 strTelTypesLCtrl.Append(wxT(","));
311 strTelTypes.Append(wxT("text"));
312 strTelTypesLCtrl.Append(wxT("text"));
317 if (chkMobile->IsChecked()){
321 strTelTypes.Append(wxT(","));
322 strTelTypesLCtrl.Append(wxT(","));
326 strTelTypes.Append(wxT("cell"));
327 strTelTypesLCtrl.Append(wxT("cell"));
332 if (chkTextphone->IsChecked()){
336 strTelTypes.Append(wxT(","));
337 strTelTypesLCtrl.Append(wxT(","));
341 strTelTypes.Append(wxT("textphone"));
342 strTelTypesLCtrl.Append(wxT("textphone"));
347 if (chkPager->IsChecked()){
351 strTelTypes.Append(wxT(","));
352 strTelTypesLCtrl.Append(wxT(","));
356 strTelTypes.Append(wxT("pager"));
357 strTelTypesLCtrl.Append(wxT("pager"));
362 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
364 TelephoneListTypePtr->erase(TelephoneListIndex);
365 TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
367 TelephoneListTypeInfoPtr->erase(TelephoneListIndex);
368 TelephoneListTypeInfoPtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
370 // Edit the Telephone Priority.
372 TelephoneListPrefPtr->erase(TelephoneListIndex);
374 if (chkUsePref->IsChecked()){
376 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, sliPriority->GetValue()));
380 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));
386 longSelected = TelephoneListCtrlPtr->GetNextItem(longSelected,
388 wxLIST_STATE_SELECTED);
390 if (longSelected == -1){
394 TelephoneListCtrlPtr->SetItem(longSelected, 0, txtTelephone->GetValue());
395 TelephoneListCtrlPtr->SetItem(longSelected, 1, strTelTypesLCtrl);
397 if (chkUsePref->IsChecked()){
399 TelephoneListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
403 TelephoneListCtrlPtr->SetItem(longSelected, 2, wxT(""));
413 void frmContactEditorTelephone::CloseWindow( wxCommandEvent& event )
422 void frmContactEditorTelephone::SetEditorMode(bool EditMode, SectionType SectType)
425 // Set the editor mode.
427 // Set if the editor is adding or editing an address.
431 if (EditMode == FALSE){
434 btnAction->SetLabel(_("Add"));
435 this->SetTitle(_("Add Telephone"));
437 } else if (EditMode == TRUE){
440 btnAction->SetLabel(_("Modify"));
441 this->SetTitle(_("Modify Telephone"));
443 std::map<int,int>::iterator intiter;
444 std::map<int,wxString>::iterator striter;
447 // Load the data into the form. Get the phone number.
449 striter = TelephoneListPtr->find(TelephoneListIndex);
451 if (striter->first == TelephoneListIndex){
453 strValue = striter->second;
457 txtTelephone->SetValue(strValue);
461 // Get the phone types in.
464 if (TelephoneListTypeInfoPtr->find(TelephoneListIndex) !=
465 TelephoneListTypeInfoPtr->end()){
467 striter = TelephoneListTypeInfoPtr->find(TelephoneListIndex);
469 if (striter->first == TelephoneListIndex){
471 strValue = striter->second;
477 wxStringTokenizer TelephonePrefToken (strValue, wxT(","));
481 while(TelephonePrefToken.HasMoreTokens()){
483 strValue = TelephonePrefToken.GetNextToken();
485 if (strValue == wxT("home") || strValue == wxT("work")){
487 // Ignore these two since they aren't needed.
493 if (strValue == wxT("voice")){
495 chkVoice->SetValue(TRUE);
499 if (strValue == wxT("fax")){
501 chkFax->SetValue(TRUE);
505 if (strValue == wxT("video")){
507 chkVideo->SetValue(TRUE);
511 if (strValue == wxT("text")){
513 chkText->SetValue(TRUE);
517 if (strValue == wxT("cell")){
519 chkMobile->SetValue(TRUE);
523 if (strValue == wxT("textphone")){
525 chkTextphone->SetValue(TRUE);
529 if (strValue == wxT("pager")){
531 chkPager->SetValue(TRUE);
539 intiter = TelephoneListPrefPtr->find(TelephoneListIndex);
541 if (intiter->first == TelephoneListIndex && intiter->second > 0 &&
542 intiter != TelephoneListPrefPtr->end()){
544 sliPriority->SetValue(intiter->second);
545 sliPriority->Enable();
546 chkUsePref->SetValue(TRUE);
552 EditSectionType = SectType;
556 void frmContactEditorTelephone::SetupPointers(std::map<int, wxString> *TelephoneList,
557 std::map<int, wxString> *TelephoneListAltID,
558 std::map<int, wxString> *TelephoneListPID,
559 std::map<int, wxString> *TelephoneListType,
560 std::map<int, wxString> *TelephoneListTypeInfo,
561 std::map<int, wxString> *TelephoneListTokens,
562 std::map<int, int> *TelephoneListPref,
563 wxListCtrl *TelephoneListCtrl,
567 // Setup the pointers.
569 TelephoneListPtr = TelephoneList;
570 TelephoneListAltIDPtr = TelephoneListAltID;
571 TelephoneListPIDPtr = TelephoneListPID;
572 TelephoneListTypePtr = TelephoneListType;
573 TelephoneListTypeInfoPtr = TelephoneListTypeInfo;
574 TelephoneListTokensPtr = TelephoneListTokens;
575 TelephoneListPrefPtr = TelephoneListPref;
576 TelephoneListCtrlPtr = TelephoneListCtrl;
577 TelephoneListIndex = TelephoneIndex;