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 &&
202 striter != NicknamesListLanguagePtr->end()){
204 strValue = striter->second;
208 cmbLanguage->SetValue(strValue);
211 // Get the website priority.
213 intiter = NicknamesListPrefPtr->find(NicknamesListIndex);
215 if (intiter->first == NicknamesListIndex && intiter->second > 0 &&
216 intiter != NicknamesListPrefPtr->end()){
218 sliPriority->SetValue(intiter->second);
219 sliPriority->Enable();
220 chkUsePref->SetValue(TRUE);
226 EditSectionType = SectType;
230 void frmContactEditorNickname::SetupPointers(std::map<int, wxString> *NicknamesList,
231 std::map<int, wxString> *NicknamesListAltID,
232 std::map<int, wxString> *NicknamesListPID,
233 std::map<int, wxString> *NicknamesListType,
234 std::map<int, wxString> *NicknamesListLanguage,
235 std::map<int, wxString> *NicknamesListTokens,
236 std::map<int, int> *NicknamesListPref,
237 wxListCtrl *NicknamesListCtrl,
241 NicknamesListPtr = NicknamesList;
242 NicknamesListAltIDPtr = NicknamesListAltID;
243 NicknamesListPIDPtr = NicknamesListPID;
244 NicknamesListTypePtr = NicknamesListType;
245 NicknamesListLanguagePtr = NicknamesListLanguage;
246 NicknamesListTokensPtr = NicknamesListTokens;
247 NicknamesListPrefPtr = NicknamesListPref;
248 NicknamesListCtrlPtr = NicknamesListCtrl;
249 NicknamesListIndex = NicknamesIndex;