// frmContactEditorTelephone.cpp - frmContactEditorTelephone form.
//
// (c) 2012-2015 Xestia Software Development.
//
// This file is part of Xestia Address Book.
//
// Xestia Address Book is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
// Xestia Address Book is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with Xestia Address Book. If not, see
#include "frmContactEditorTelephone.h"
#include "../common/textprocessing.h"
#include
frmContactEditorTelephone::frmContactEditorTelephone( wxWindow* parent )
:
frmContactEditorTelephoneADT( parent )
{
EditorMode = FALSE;
sliPriority->Disable();
}
void frmContactEditorTelephone::EnablePriority( wxCommandEvent& event )
{
if (chkUsePref->IsChecked()){
sliPriority->Enable();
} else {
sliPriority->Disable();
}
}
void frmContactEditorTelephone::ProcessAction( wxCommandEvent& event )
{
long ListCtrlIndex;
if (EditorMode == FALSE){
wxString strTelTypes;
wxString strTelTypesLCtrl;
bool AddComma = FALSE;
// Add the telephone number.
wxString strValue;
TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));
// Add the telephone type.
if (EditSectionType == CE_GENERAL){
strTelTypes.Append(wxT(""));
} else if (EditSectionType == CE_HOME) {
strTelTypes.Append(wxT("home"));
AddComma = TRUE;
} else if (EditSectionType == CE_WORK) {
strTelTypes.Append(wxT("work"));
AddComma = TRUE;
}
if (chkVoice->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("voice"));
strTelTypesLCtrl.Append(wxT("voice"));
AddComma = TRUE;
}
if (chkFax->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("fax"));
strTelTypesLCtrl.Append(wxT("fax"));
AddComma = TRUE;
}
if (chkVideo->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("video"));
strTelTypesLCtrl.Append(wxT("video"));
AddComma = TRUE;
}
if (chkText->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("text"));
strTelTypesLCtrl.Append(wxT("text"));
AddComma = TRUE;
}
if (chkMobile->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("cell"));
strTelTypesLCtrl.Append(wxT("cell"));
AddComma = TRUE;
}
if (chkTextphone->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("textphone"));
strTelTypesLCtrl.Append(wxT("textphone"));
AddComma = TRUE;
}
if (chkPager->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("pager"));
strTelTypesLCtrl.Append(wxT("pager"));
AddComma = TRUE;
}
TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
TelephoneListTypeInfoPtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
// Add Telephone Priority.
if (chkUsePref->IsChecked()){
TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, sliPriority->GetValue()));
} else {
TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));
}
// Add to the form.
wxListItem coldata;
coldata.SetId(TelephoneListIndex);
coldata.SetData(TelephoneListIndex);
coldata.SetText(txtTelephone->GetValue());
ListCtrlIndex = TelephoneListCtrlPtr->InsertItem(coldata);
strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 1, strTelTypesLCtrl);
if (chkUsePref->IsChecked()){
TelephoneListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
}
this->Close();
} else if (EditorMode == TRUE) {
wxString strTelTypes;
wxString strTelTypesLCtrl;
bool AddComma = FALSE;
long longSelected = -1;
// Edit the Telephone number.
wxString strValue;
TelephoneListPtr->erase(TelephoneListIndex);
TelephoneListPtr->insert(std::make_pair(TelephoneListIndex, txtTelephone->GetValue()));
// Edit the Telephone type.
if (EditSectionType == CE_GENERAL){
strTelTypes.Append(wxT(""));
} else if (EditSectionType == CE_HOME) {
strTelTypes.Append(wxT("home"));
AddComma = TRUE;
} else if (EditSectionType == CE_WORK) {
strTelTypes.Append(wxT("work"));
AddComma = TRUE;
}
if (chkVoice->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("voice"));
strTelTypesLCtrl.Append(wxT("voice"));
AddComma = TRUE;
}
if (chkFax->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("fax"));
strTelTypesLCtrl.Append(wxT("fax"));
AddComma = TRUE;
}
if (chkVideo->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("video"));
strTelTypesLCtrl.Append(wxT("video"));
AddComma = TRUE;
}
if (chkText->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("text"));
strTelTypesLCtrl.Append(wxT("text"));
AddComma = TRUE;
}
if (chkMobile->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("cell"));
strTelTypesLCtrl.Append(wxT("cell"));
AddComma = TRUE;
}
if (chkTextphone->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("textphone"));
strTelTypesLCtrl.Append(wxT("textphone"));
AddComma = TRUE;
}
if (chkPager->IsChecked()){
if (AddComma){
strTelTypes.Append(wxT(","));
strTelTypesLCtrl.Append(wxT(","));
}
strTelTypes.Append(wxT("pager"));
strTelTypesLCtrl.Append(wxT("pager"));
AddComma = TRUE;
}
strTelTypesLCtrl.Replace(wxT(","), wxT(""), FALSE);
TelephoneListTypePtr->erase(TelephoneListIndex);
TelephoneListTypePtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
TelephoneListTypeInfoPtr->erase(TelephoneListIndex);
TelephoneListTypeInfoPtr->insert(std::make_pair(TelephoneListIndex, strTelTypes));
// Edit the Telephone Priority.
TelephoneListPrefPtr->erase(TelephoneListIndex);
if (chkUsePref->IsChecked()){
TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, sliPriority->GetValue()));
} else {
TelephoneListPrefPtr->insert(std::make_pair(TelephoneListIndex, 0));
}
// Update the form.
longSelected = TelephoneListCtrlPtr->GetNextItem(longSelected,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
if (longSelected == -1){
return;
}
TelephoneListCtrlPtr->SetItem(longSelected, 0, txtTelephone->GetValue());
TelephoneListCtrlPtr->SetItem(longSelected, 1, strTelTypesLCtrl);
if (chkUsePref->IsChecked()){
TelephoneListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
} else {
TelephoneListCtrlPtr->SetItem(longSelected, 2, wxT(""));
}
this->Close();
}
}
void frmContactEditorTelephone::CloseWindow( wxCommandEvent& event )
{
this->Close();
}
void frmContactEditorTelephone::SetEditorMode(bool EditMode, SectionType SectType)
{
// Set if the editor is adding or editing an address.
// FALSE = Add
// TRUE = Edit
if (EditMode == FALSE){
EditorMode = FALSE;
btnAction->SetLabel(_("Add"));
this->SetTitle(_("Add Telephone"));
} else if (EditMode == TRUE){
EditorMode = TRUE;
btnAction->SetLabel(_("Modify"));
this->SetTitle(_("Modify Telephone"));
std::map::iterator intiter;
std::map::iterator striter;
wxString strValue;
// Load the data into the form. Get the phone number.
striter = TelephoneListPtr->find(TelephoneListIndex);
if (striter->first == TelephoneListIndex){
strValue = striter->second;
}
txtTelephone->SetValue(strValue);
strValue.Clear();
// Get the phone types in.
if (TelephoneListTypeInfoPtr->find(TelephoneListIndex) !=
TelephoneListTypeInfoPtr->end()){
striter = TelephoneListTypeInfoPtr->find(TelephoneListIndex);
if (striter->first == TelephoneListIndex){
strValue = striter->second;
}
}
wxStringTokenizer TelephonePrefToken (strValue, wxT(","));
strValue.Clear();
while(TelephonePrefToken.HasMoreTokens()){
strValue = TelephonePrefToken.GetNextToken();
if (strValue == wxT("home") || strValue == wxT("work")){
// Ignore these two since they aren't needed.
continue;
}
if (strValue == wxT("voice")){
chkVoice->SetValue(TRUE);
}
if (strValue == wxT("fax")){
chkFax->SetValue(TRUE);
}
if (strValue == wxT("video")){
chkVideo->SetValue(TRUE);
}
if (strValue == wxT("text")){
chkText->SetValue(TRUE);
}
if (strValue == wxT("cell")){
chkMobile->SetValue(TRUE);
}
if (strValue == wxT("textphone")){
chkTextphone->SetValue(TRUE);
}
if (strValue == wxT("pager")){
chkPager->SetValue(TRUE);
}
}
// Setup the Slider.
intiter = TelephoneListPrefPtr->find(TelephoneListIndex);
if (intiter->first == TelephoneListIndex && intiter->second > 0){
sliPriority->SetValue(intiter->second);
sliPriority->Enable();
chkUsePref->SetValue(TRUE);
}
}
EditSectionType = SectType;
}
void frmContactEditorTelephone::SetupPointers(std::map *TelephoneList,
std::map *TelephoneListAltID,
std::map *TelephoneListPID,
std::map *TelephoneListType,
std::map *TelephoneListTypeInfo,
std::map *TelephoneListTokens,
std::map *TelephoneListPref,
wxListCtrl *TelephoneListCtrl,
int TelephoneIndex )
{
TelephoneListPtr = TelephoneList;
TelephoneListAltIDPtr = TelephoneListAltID;
TelephoneListPIDPtr = TelephoneListPID;
TelephoneListTypePtr = TelephoneListType;
TelephoneListTypeInfoPtr = TelephoneListTypeInfo;
TelephoneListTokensPtr = TelephoneListTokens;
TelephoneListPrefPtr = TelephoneListPref;
TelephoneListCtrlPtr = TelephoneListCtrl;
TelephoneListIndex = TelephoneIndex;
}