// 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"
frmContactEditorNickname::frmContactEditorNickname( wxWindow* parent )
:
frmContactEditorNicknameADT( parent )
{
std::vector LanguageCodeList = GetLanguageCodeList();
wxArrayString LanguageList;
for (auto LanguageItem : LanguageCodeList){
LanguageList.Add((wxString)LanguageItem, 1);
}
cmbLanguage->Append(LanguageList);
priorityCtrl = new XABPriorityCtrl(tabGeneral);
szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
}
void frmContactEditorNickname::InitAddressEditor( wxInitDialogEvent& event )
{
// Do nothing with this subroutine for the time being.
}
void frmContactEditorNickname::ProcessData( wxCommandEvent& event )
{
// Process the data.
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 (priorityCtrl->IsPriorityChecked()){
NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, priorityCtrl->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 (priorityCtrl->IsPriorityChecked()){
NicknamesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->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 (priorityCtrl->IsPriorityChecked()){
NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, priorityCtrl->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 (priorityCtrl->IsPriorityChecked()){
NicknamesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
} else {
NicknamesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
}
this->Close();
}
}
void frmContactEditorNickname::CloseWindow( wxCommandEvent& event )
{
// Close this window.
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 &&
striter != NicknamesListLanguagePtr->end()){
strValue = striter->second;
}
cmbLanguage->SetValue(strValue);
strValue.Clear();
// Get the website priority.
intiter = NicknamesListPrefPtr->find(NicknamesListIndex);
if (intiter->first == NicknamesListIndex && intiter->second > 0 &&
intiter != NicknamesListPrefPtr->end()){
priorityCtrl->SetValue(intiter->second);
priorityCtrl->EnablePriority(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 )
{
// Setup the pointers.
NicknamesListPtr = NicknamesList;
NicknamesListAltIDPtr = NicknamesListAltID;
NicknamesListPIDPtr = NicknamesListPID;
NicknamesListTypePtr = NicknamesListType;
NicknamesListLanguagePtr = NicknamesListLanguage;
NicknamesListTokensPtr = NicknamesListTokens;
NicknamesListPrefPtr = NicknamesListPref;
NicknamesListCtrlPtr = NicknamesListCtrl;
NicknamesListIndex = NicknamesIndex;
}