1 // frmContactEditorNickname.cpp - frmContactEditorNickname form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmContactEditorNickname.h"
20 #include "../common/textprocessing.h"
22 frmContactEditorNickname::frmContactEditorNickname( wxWindow* parent )
24 frmContactEditorNicknameADT( parent )
29 void frmContactEditorNickname::InitAddressEditor( wxInitDialogEvent& event )
31 // Do nothing with this subroutine for the time being.
34 void frmContactEditorNickname::EnablePriority( wxCommandEvent& event )
36 if (chkUsePref->IsChecked()){
37 sliPriority->Enable();
39 sliPriority->Disable();
43 void frmContactEditorNickname::ProcessData( wxCommandEvent& event )
47 if (EditorMode == FALSE){
49 // Add the language to the list.
55 NicknamesListPtr->insert(std::make_pair(NicknamesListIndex, txtNickname->GetValue()));
59 if (EditSectionType == CE_GENERAL){
61 NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("")));
63 } else if (EditSectionType == CE_HOME) {
65 NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("home")));
67 } else if (EditSectionType == CE_WORK) {
69 NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("work")));
73 // Add nickname language.
75 NicknamesListLanguagePtr->insert(std::make_pair(NicknamesListIndex, cmbLanguage->GetValue()));
77 // Add nickname priority.
79 if (chkUsePref->IsChecked()){
81 NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, sliPriority->GetValue()));
85 NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, 0));
89 // Add the data to the form.
93 coldata.SetId(NicknamesListIndex);
94 coldata.SetData(NicknamesListIndex);
95 coldata.SetText(txtNickname->GetValue());
96 ListCtrlIndex = NicknamesListCtrlPtr->InsertItem(coldata);
98 if (chkUsePref->IsChecked()){
100 NicknamesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
106 } else if (EditorMode == TRUE){
108 // Edit the language.
112 long longSelected = -1;
114 NicknamesListPtr->erase(NicknamesListIndex);
115 NicknamesListPtr->insert(std::make_pair(NicknamesListIndex, txtNickname->GetValue()));
117 NicknamesListPrefPtr->erase(NicknamesListIndex);
119 if (chkUsePref->IsChecked()){
121 NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, sliPriority->GetValue()));
125 NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, 0));
129 NicknamesListLanguagePtr->erase(NicknamesListIndex);
130 NicknamesListLanguagePtr->insert(std::make_pair(NicknamesListIndex, cmbLanguage->GetValue()));
132 longSelected = NicknamesListCtrlPtr->GetNextItem(longSelected,
134 wxLIST_STATE_SELECTED);
136 if (longSelected == -1){
140 NicknamesListCtrlPtr->SetItem(longSelected, 0, txtNickname->GetValue());
142 if (chkUsePref->IsChecked()){
144 NicknamesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
148 NicknamesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
158 void frmContactEditorNickname::CloseWindow( wxCommandEvent& event )
163 void frmContactEditorNickname::SetEditorMode(bool EditMode, SectionType SectType)
165 // Set if the editor is adding or editing an address.
169 if (EditMode == FALSE){
172 btnAction->SetLabel(_("Add"));
173 this->SetTitle(_("Add Nickname"));
175 } else if (EditMode == TRUE){
178 btnAction->SetLabel(_("Modify"));
179 this->SetTitle(_("Modify Nickname"));
181 std::map<int,int>::iterator intiter;
182 std::map<int,wxString>::iterator striter;
185 // Load the data into the form. Get the website.
187 striter = NicknamesListPtr->find(NicknamesListIndex);
189 if (striter->first == NicknamesListIndex){
191 strValue = striter->second;
195 txtNickname->SetValue(strValue);
199 striter = NicknamesListLanguagePtr->find(NicknamesListIndex);
201 if (striter->first == NicknamesListIndex){
203 strValue = striter->second;
207 cmbLanguage->SetValue(strValue);
210 // Get the website priority.
212 intiter = NicknamesListPrefPtr->find(NicknamesListIndex);
214 if (intiter->first == NicknamesListIndex && intiter->second > 0){
216 sliPriority->SetValue(intiter->second);
217 sliPriority->Enable();
218 chkUsePref->SetValue(TRUE);
224 EditSectionType = SectType;
228 void frmContactEditorNickname::SetupPointers(std::map<int, wxString> *NicknamesList,
229 std::map<int, wxString> *NicknamesListAltID,
230 std::map<int, wxString> *NicknamesListPID,
231 std::map<int, wxString> *NicknamesListType,
232 std::map<int, wxString> *NicknamesListLanguage,
233 std::map<int, wxString> *NicknamesListTokens,
234 std::map<int, int> *NicknamesListPref,
235 wxListCtrl *NicknamesListCtrl,
239 NicknamesListPtr = NicknamesList;
240 NicknamesListAltIDPtr = NicknamesListAltID;
241 NicknamesListPIDPtr = NicknamesListPID;
242 NicknamesListTypePtr = NicknamesListType;
243 NicknamesListLanguagePtr = NicknamesListLanguage;
244 NicknamesListTokensPtr = NicknamesListTokens;
245 NicknamesListPrefPtr = NicknamesListPref;
246 NicknamesListCtrlPtr = NicknamesListCtrl;
247 NicknamesListIndex = NicknamesIndex;