1 #include "frmContactEditorTelephone.h"
2 #include "../common/textprocessing.h"
3 #include <wx/tokenzr.h>
5 frmContactEditorTelephone::frmContactEditorTelephone( wxWindow* parent )
7 frmContactEditorTelephoneADT( parent )
10 sliPriority->Disable();
13 void frmContactEditorTelephone::EnablePriority( wxCommandEvent& event )
15 if (chkUsePref->IsChecked()){
16 sliPriority->Enable();
18 sliPriority->Disable();
22 void frmContactEditorTelephone::ProcessAction( wxCommandEvent& event )
26 if (EditorMode == FALSE){
29 wxString strTelTypesLCtrl;
30 bool AddComma = FALSE;
32 // Add the telephone number.
35 TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));
37 // Add the telephone type.
39 if (EditSectionType == CE_GENERAL){
41 strTelTypes.Append(wxT(""));
43 } else if (EditSectionType == CE_HOME) {
45 strTelTypes.Append(wxT("home"));
48 } else if (EditSectionType == CE_WORK) {
50 strTelTypes.Append(wxT("work"));
55 if (chkVoice->IsChecked()){
59 strTelTypes.Append(wxT(","));
60 strTelTypesLCtrl.Append(wxT(","));
64 strTelTypes.Append(wxT("voice"));
65 strTelTypesLCtrl.Append(wxT("voice"));
70 if (chkFax->IsChecked()){
74 strTelTypes.Append(wxT(","));
75 strTelTypesLCtrl.Append(wxT(","));
79 strTelTypes.Append(wxT("fax"));
80 strTelTypesLCtrl.Append(wxT("fax"));
85 if (chkVideo->IsChecked()){
89 strTelTypes.Append(wxT(","));
90 strTelTypesLCtrl.Append(wxT(","));
94 strTelTypes.Append(wxT("video"));
95 strTelTypesLCtrl.Append(wxT("video"));
100 if (chkText->IsChecked()){
104 strTelTypes.Append(wxT(","));
105 strTelTypesLCtrl.Append(wxT(","));
109 strTelTypes.Append(wxT("text"));
110 strTelTypesLCtrl.Append(wxT("text"));
115 if (chkMobile->IsChecked()){
119 strTelTypes.Append(wxT(","));
120 strTelTypesLCtrl.Append(wxT(","));
124 strTelTypes.Append(wxT("cell"));
125 strTelTypesLCtrl.Append(wxT("cell"));
130 if (chkTextphone->IsChecked()){
134 strTelTypes.Append(wxT(","));
135 strTelTypesLCtrl.Append(wxT(","));
139 strTelTypes.Append(wxT("textphone"));
140 strTelTypesLCtrl.Append(wxT("textphone"));
145 if (chkPager->IsChecked()){
149 strTelTypes.Append(wxT(","));
150 strTelTypesLCtrl.Append(wxT(","));
154 strTelTypes.Append(wxT("pager"));
155 strTelTypesLCtrl.Append(wxT("pager"));
160 TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
162 // Add Telephone Priority.
164 if (chkUsePref->IsChecked()){
166 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, sliPriority->GetValue()));
170 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));
178 coldata.SetId(TelephoneListIndex);
179 coldata.SetData(TelephoneListIndex);
180 coldata.SetText(txtTelephone->GetValue());
181 ListCtrlIndex = TelephoneListCtrlPtr->InsertItem(coldata);
183 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
185 TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 1, strTelTypesLCtrl);
187 if (chkUsePref->IsChecked()){
189 TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
195 } else if (EditorMode == TRUE) {
197 wxString strTelTypes;
198 wxString strTelTypesLCtrl;
199 bool AddComma = FALSE;
200 long longSelected = -1;
202 // Edit the Telephone number.
205 TelephoneListPtr->erase(TelephoneListIndex);
206 TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));
208 // Edit the Telephone type.
210 if (EditSectionType == CE_GENERAL){
212 strTelTypes.Append(wxT(""));
214 } else if (EditSectionType == CE_HOME) {
216 strTelTypes.Append(wxT("home"));
219 } else if (EditSectionType == CE_WORK) {
221 strTelTypes.Append(wxT("work"));
226 if (chkVoice->IsChecked()){
230 strTelTypes.Append(wxT(","));
231 strTelTypesLCtrl.Append(wxT(","));
235 strTelTypes.Append(wxT("voice"));
236 strTelTypesLCtrl.Append(wxT("voice"));
241 if (chkFax->IsChecked()){
245 strTelTypes.Append(wxT(","));
246 strTelTypesLCtrl.Append(wxT(","));
250 strTelTypes.Append(wxT("fax"));
251 strTelTypesLCtrl.Append(wxT("fax"));
256 if (chkVideo->IsChecked()){
260 strTelTypes.Append(wxT(","));
261 strTelTypesLCtrl.Append(wxT(","));
265 strTelTypes.Append(wxT("video"));
266 strTelTypesLCtrl.Append(wxT("video"));
271 if (chkText->IsChecked()){
275 strTelTypes.Append(wxT(","));
276 strTelTypesLCtrl.Append(wxT(","));
280 strTelTypes.Append(wxT("text"));
281 strTelTypesLCtrl.Append(wxT("text"));
286 if (chkMobile->IsChecked()){
290 strTelTypes.Append(wxT(","));
291 strTelTypesLCtrl.Append(wxT(","));
295 strTelTypes.Append(wxT("cell"));
296 strTelTypesLCtrl.Append(wxT("cell"));
301 if (chkTextphone->IsChecked()){
305 strTelTypes.Append(wxT(","));
306 strTelTypesLCtrl.Append(wxT(","));
310 strTelTypes.Append(wxT("textphone"));
311 strTelTypesLCtrl.Append(wxT("textphone"));
316 if (chkPager->IsChecked()){
320 strTelTypes.Append(wxT(","));
321 strTelTypesLCtrl.Append(wxT(","));
325 strTelTypes.Append(wxT("pager"));
326 strTelTypesLCtrl.Append(wxT("pager"));
331 strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
333 TelephoneListTypePtr->erase(TelephoneListIndex);
334 TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
336 // Edit the Telephone Priority.
338 TelephoneListPrefPtr->erase(TelephoneListIndex);
340 if (chkUsePref->IsChecked()){
342 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, sliPriority->GetValue()));
346 TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));
352 longSelected = TelephoneListCtrlPtr->GetNextItem(longSelected,
354 wxLIST_STATE_SELECTED);
356 if (longSelected == -1){
360 TelephoneListCtrlPtr->SetItem(longSelected, 0, txtTelephone->GetValue());
361 TelephoneListCtrlPtr->SetItem(longSelected, 1, strTelTypesLCtrl);
363 if (chkUsePref->IsChecked()){
365 TelephoneListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
369 TelephoneListCtrlPtr->SetItem(longSelected, 2, wxT(""));
379 void frmContactEditorTelephone::CloseWindow( wxCommandEvent& event )
386 void frmContactEditorTelephone::SetEditorMode(bool EditMode, SectionType SectType)
388 // Set if the editor is adding or editing an address.
392 if (EditMode == FALSE){
395 btnAction->SetLabel(_("Add"));
396 this->SetTitle(_("Add Telephone"));
398 } else if (EditMode == TRUE){
401 btnAction->SetLabel(_("Modify"));
402 this->SetTitle(_("Modify Telephone"));
404 std::map<int,int>::iterator intiter;
405 std::map<int,wxString>::iterator striter;
408 // Load the data into the form. Get the phone number.
410 striter = TelephoneListPtr->find(TelephoneListIndex);
412 if (striter->first == TelephoneListIndex){
414 strValue = striter->second;
418 txtTelephone->SetValue(strValue);
422 // Get the phone types in.
424 striter = TelephoneListTypePtr->find(TelephoneListIndex);
426 if (striter->first == TelephoneListIndex){
428 strValue = striter->second;
432 wxStringTokenizer TelephonePrefToken (strValue, wxT(","));
436 while(TelephonePrefToken.HasMoreTokens()){
438 strValue = TelephonePrefToken.GetNextToken();
440 if (strValue == wxT("home") || strValue == wxT("work")){
442 // Ignore these two since they aren't needed.
448 if (strValue == wxT("voice")){
450 chkVoice->SetValue(TRUE);
454 if (strValue == wxT("fax")){
456 chkFax->SetValue(TRUE);
460 if (strValue == wxT("video")){
462 chkVideo->SetValue(TRUE);
466 if (strValue == wxT("text")){
468 chkText->SetValue(TRUE);
472 if (strValue == wxT("cell")){
474 chkMobile->SetValue(TRUE);
478 if (strValue == wxT("textphone")){
480 chkTextphone->SetValue(TRUE);
484 if (strValue == wxT("pager")){
486 chkPager->SetValue(TRUE);
494 intiter = TelephoneListPrefPtr->find(TelephoneListIndex);
496 if (intiter->first == TelephoneListIndex && intiter->second > 0){
498 sliPriority->SetValue(intiter->second);
499 sliPriority->Enable();
500 chkUsePref->SetValue(TRUE);
506 EditSectionType = SectType;
510 void frmContactEditorTelephone::SetupPointers(std::map<int, wxString> *TelephoneList,
511 std::map<int, wxString> *TelephoneListAltID,
512 std::map<int, wxString> *TelephoneListPID,
513 std::map<int, wxString> *TelephoneListType,
514 std::map<int, wxString> *TelephoneListTokens,
515 std::map<int, int> *TelephoneListPref,
516 wxListCtrl *TelephoneListCtrl,
520 TelephoneListPtr = TelephoneList;
521 TelephoneListAltIDPtr = TelephoneListAltID;
522 TelephoneListPIDPtr = TelephoneListPID;
523 TelephoneListTypePtr = TelephoneListType;
524 TelephoneListTokensPtr = TelephoneListTokens;
525 TelephoneListPrefPtr = TelephoneListPref;
526 TelephoneListCtrlPtr = TelephoneListCtrl;
527 TelephoneListIndex = TelephoneIndex;