// frmContactEditorNickname.cpp - frmContactEditorNickname 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 "frmContactEditorNickname.h"
#include "../common/textprocessing.h"
frmContactEditorNickname::frmContactEditorNickname( wxWindow* parent )
:
frmContactEditorNicknameADT( parent )
{
}
void frmContactEditorNickname::InitAddressEditor( wxInitDialogEvent& event )
{
// Do nothing with this subroutine for the time being.
}
void frmContactEditorNickname::EnablePriority( wxCommandEvent& event )
{
if (chkUsePref->IsChecked()){
sliPriority->Enable();
} else {
sliPriority->Disable();
}
}
void frmContactEditorNickname::ProcessData( wxCommandEvent& event )
{
long ListCtrlIndex;
if (EditorMode == FALSE){
// Add the language to the list.
wxString strValue;
// Add nickname.
NicknamesListPtr->insert(std::make_pair(NicknamesListIndex, txtNickname->GetValue()));
// Add nickname type.
if (EditSectionType == CE_GENERAL){
NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("")));
} else if (EditSectionType == CE_HOME) {
NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("home")));
} else if (EditSectionType == CE_WORK) {
NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("work")));
}
// Add nickname language.
NicknamesListLanguagePtr->insert(std::make_pair(NicknamesListIndex, cmbLanguage->GetValue()));
// Add nickname priority.
if (chkUsePref->IsChecked()){
NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, sliPriority->GetValue()));
} else {
NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, 0));
}
// Add the data to the form.
wxListItem coldata;
coldata.SetId(NicknamesListIndex);
coldata.SetData(NicknamesListIndex);
coldata.SetText(txtNickname->GetValue());
ListCtrlIndex = NicknamesListCtrlPtr->InsertItem(coldata);
if (chkUsePref->IsChecked()){
NicknamesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
}
this->Close();
} else if (EditorMode == TRUE){
// Edit the language.
wxString strAddress;
wxString strValue;
long longSelected = -1;
NicknamesListPtr->erase(NicknamesListIndex);
NicknamesListPtr->insert(std::make_pair(NicknamesListIndex, txtNickname->GetValue()));
NicknamesListPrefPtr->erase(NicknamesListIndex);
if (chkUsePref->IsChecked()){
NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, sliPriority->GetValue()));
} else {
NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, 0));
}
NicknamesListLanguagePtr->erase(NicknamesListIndex);
NicknamesListLanguagePtr->insert(std::make_pair(NicknamesListIndex, cmbLanguage->GetValue()));
longSelected = NicknamesListCtrlPtr->GetNextItem(longSelected,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
if (longSelected == -1){
return;
}
NicknamesListCtrlPtr->SetItem(longSelected, 0, txtNickname->GetValue());
if (chkUsePref->IsChecked()){
NicknamesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
} else {
NicknamesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
}
this->Close();
}
}
void frmContactEditorNickname::CloseWindow( wxCommandEvent& event )
{
this->Close();
}
void frmContactEditorNickname::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 Nickname"));
} else if (EditMode == TRUE){
EditorMode = TRUE;
btnAction->SetLabel(_("Modify"));
this->SetTitle(_("Modify Nickname"));
std::map::iterator intiter;
std::map::iterator striter;
wxString strValue;
// Load the data into the form. Get the website.
striter = NicknamesListPtr->find(NicknamesListIndex);
if (striter->first == NicknamesListIndex){
strValue = striter->second;
}
txtNickname->SetValue(strValue);
strValue.Clear();
striter = NicknamesListLanguagePtr->find(NicknamesListIndex);
if (striter->first == NicknamesListIndex){
strValue = striter->second;
}
cmbLanguage->SetValue(strValue);
strValue.Clear();
// Get the website priority.
intiter = NicknamesListPrefPtr->find(NicknamesListIndex);
if (intiter->first == NicknamesListIndex && intiter->second > 0){
sliPriority->SetValue(intiter->second);
sliPriority->Enable();
chkUsePref->SetValue(TRUE);
}
}
EditSectionType = SectType;
}
void frmContactEditorNickname::SetupPointers(std::map *NicknamesList,
std::map *NicknamesListAltID,
std::map *NicknamesListPID,
std::map *NicknamesListType,
std::map *NicknamesListLanguage,
std::map *NicknamesListTokens,
std::map *NicknamesListPref,
wxListCtrl *NicknamesListCtrl,
int NicknamesIndex )
{
NicknamesListPtr = NicknamesList;
NicknamesListAltIDPtr = NicknamesListAltID;
NicknamesListPIDPtr = NicknamesListPID;
NicknamesListTypePtr = NicknamesListType;
NicknamesListLanguagePtr = NicknamesListLanguage;
NicknamesListTokensPtr = NicknamesListTokens;
NicknamesListPrefPtr = NicknamesListPref;
NicknamesListCtrlPtr = NicknamesListCtrl;
NicknamesListIndex = NicknamesIndex;
}