// frmContactEditorCalAdr.cpp - frmContactEditorCalAdr 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 "frmContactEditorCalAdr.h"
#include
#include "../common/textprocessing.h"
frmContactEditorCalAdr::frmContactEditorCalAdr( wxWindow* parent )
:
frmContactEditorCalAdrADT( parent )
{
EditorMode = FALSE;
sliPriority->Disable();
cmbType->Append(wxT(""));
cmbType->Append(_("Home"));
cmbType->Append(_("Work"));
}
void frmContactEditorCalAdr::EnablePriority( wxCommandEvent& event )
{
if (chkUsePref->IsChecked()){
sliPriority->Enable();
} else {
sliPriority->Disable();
}
}
void frmContactEditorCalAdr::ProcessAction( wxCommandEvent& event )
{
long ListCtrlIndex;
if (EditorMode == FALSE){
wxString strValue;
// Setup Calendar Address.
CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
strValue.Clear();
strValue = cmbType->GetString(cmbType->GetSelection());
// Setup Calendar Type.
if (strValue == _("Home")) {
CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
} else if (strValue == _("Work")) {
CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
} else {
CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("")));
}
// Setup Calendar Priority.
if (chkUsePref->IsChecked()){
CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
} else {
CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
}
// Add to form.
wxListItem coldata;
coldata.SetId(CalAdrListIndex);
coldata.SetData(CalAdrListIndex);
coldata.SetText(txtAddress->GetValue());
ListCtrlIndex = CalAdrListCtrlPtr->InsertItem(coldata);
CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);
if (chkUsePref->IsChecked()){
CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
}
this->Close();
} else if (EditorMode == TRUE) {
long longSelected = -1;
wxString strValue;
// Update Category Name.
CalAdrListPtr->erase(CalAdrListIndex);
CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
// Update Category Type.
CalAdrListTypePtr->erase(CalAdrListIndex);
strValue.Clear();
strValue = cmbType->GetString(cmbType->GetSelection());
if (strValue == _("Home")) {
CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
} else if (strValue == _("Work")) {
CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
}
// Update Category Priority.
CalAdrListPrefPtr->erase(CalAdrListIndex);
if (chkUsePref->IsChecked()){
CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
} else {
CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
}
// Update form.
longSelected = CalAdrListCtrlPtr->GetNextItem(longSelected,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
if (longSelected == -1){
return;
}
CalAdrListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
CalAdrListCtrlPtr->SetItem(longSelected, 1, strValue);
if (chkUsePref->IsChecked()){
CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
} else {
CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT(""));
}
this->Close();
}
}
void frmContactEditorCalAdr::SetEditorMode(bool EditMode)
{
// 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 Calendar Address"));
} else if (EditMode == TRUE){
EditorMode = TRUE;
btnAction->SetLabel(_("Modify"));
this->SetTitle(_("Modify Calendar Address"));
std::map::iterator intiter;
std::map::iterator striter;
wxString strValue;
// Get the organisation name.
striter = CalAdrListPtr->find(CalAdrListIndex);
if (striter->first == CalAdrListIndex){
strValue = striter->second;
}
txtAddress->SetValue(strValue);
strValue.Clear();
// Get the type.
striter = CalAdrListTypePtr->find(CalAdrListIndex);
if (striter->first == CalAdrListIndex){
strValue = striter->second;
}
if (strValue == wxT("home")){
cmbType->SetSelection(1);
} else if (strValue == wxT("work")){
cmbType->SetSelection(2);
} else {
cmbType->SetSelection(0);
}
// Get the organisation priority.
intiter = CalAdrListPrefPtr->find(CalAdrListIndex);
if (intiter->first == CalAdrListIndex && intiter->second > 0){
sliPriority->SetValue(intiter->second);
sliPriority->Enable();
chkUsePref->SetValue(TRUE);
}
}
}
void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event )
{
this->Close();
}
void frmContactEditorCalAdr::SetupPointers(std::map *CalAdrList,
std::map *CalAdrListAltID,
std::map *CalAdrListPID,
std::map *CalAdrListType,
std::map *CalAdrListTokens,
std::map *CalAdrListPref,
wxListCtrl *CalAdrListCtrl,
int CalAdrIndex )
{
CalAdrListPtr = CalAdrList;
CalAdrListAltIDPtr = CalAdrListAltID;
CalAdrListPIDPtr = CalAdrListPID;
CalAdrListTypePtr = CalAdrListType;
CalAdrListTokensPtr = CalAdrListTokens;
CalAdrListPrefPtr = CalAdrListPref;
CalAdrListCtrlPtr = CalAdrListCtrl;
CalAdrListIndex = CalAdrIndex;
}