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"
21 frmContactEditorNickname::frmContactEditorNickname( wxWindow* parent )
23 frmContactEditorNicknameADT( parent )
26 std::vector<std::string> LanguageCodeList = GetLanguageCodeList();
28 wxArrayString LanguageList;
30 for (auto LanguageItem : LanguageCodeList){
32 LanguageList.Add((wxString)LanguageItem, 1);
36 cmbLanguage->Append(LanguageList);
40 void frmContactEditorNickname::InitAddressEditor( wxInitDialogEvent& event )
42 // Do nothing with this subroutine for the time being.
45 void frmContactEditorNickname::EnablePriority( wxCommandEvent& event )
48 // Enable/disable the priority.
50 if (chkUsePref->IsChecked()){
51 sliPriority->Enable();
53 sliPriority->Disable();
58 void frmContactEditorNickname::ProcessData( wxCommandEvent& event )
65 if (EditorMode == FALSE){
67 // Add the language to the list.
73 NicknamesListPtr->insert(std::make_pair(NicknamesListIndex, txtNickname->GetValue()));
77 if (EditSectionType == CE_GENERAL){
79 NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("")));
81 } else if (EditSectionType == CE_HOME) {
83 NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("home")));
85 } else if (EditSectionType == CE_WORK) {
87 NicknamesListTypePtr->insert(std::make_pair(NicknamesListIndex, wxT("work")));
91 // Add nickname language.
93 NicknamesListLanguagePtr->insert(std::make_pair(NicknamesListIndex, cmbLanguage->GetValue()));
95 // Add nickname priority.
97 if (chkUsePref->IsChecked()){
99 NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, sliPriority->GetValue()));
103 NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, 0));
107 // Add the data to the form.
111 coldata.SetId(NicknamesListIndex);
112 coldata.SetData(NicknamesListIndex);
113 coldata.SetText(txtNickname->GetValue());
114 ListCtrlIndex = NicknamesListCtrlPtr->InsertItem(coldata);
116 if (chkUsePref->IsChecked()){
118 NicknamesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
124 } else if (EditorMode == TRUE){
126 // Edit the language.
130 long longSelected = -1;
132 NicknamesListPtr->erase(NicknamesListIndex);
133 NicknamesListPtr->insert(std::make_pair(NicknamesListIndex, txtNickname->GetValue()));
135 NicknamesListPrefPtr->erase(NicknamesListIndex);
137 if (chkUsePref->IsChecked()){
139 NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, sliPriority->GetValue()));
143 NicknamesListPrefPtr->insert(std::make_pair(NicknamesListIndex, 0));
147 NicknamesListLanguagePtr->erase(NicknamesListIndex);
148 NicknamesListLanguagePtr->insert(std::make_pair(NicknamesListIndex, cmbLanguage->GetValue()));
150 longSelected = NicknamesListCtrlPtr->GetNextItem(longSelected,
152 wxLIST_STATE_SELECTED);
154 if (longSelected == -1){
158 NicknamesListCtrlPtr->SetItem(longSelected, 0, txtNickname->GetValue());
160 if (chkUsePref->IsChecked()){
162 NicknamesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
166 NicknamesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
176 void frmContactEditorNickname::CloseWindow( wxCommandEvent& event )
179 // Close this window.
185 void frmContactEditorNickname::SetEditorMode(bool EditMode, SectionType SectType)
188 // Set if the editor is adding or editing an address.
192 if (EditMode == FALSE){
195 btnAction->SetLabel(_("Add"));
196 this->SetTitle(_("Add Nickname"));
198 } else if (EditMode == TRUE){
201 btnAction->SetLabel(_("Modify"));
202 this->SetTitle(_("Modify Nickname"));
204 std::map<int,int>::iterator intiter;
205 std::map<int,wxString>::iterator striter;
208 // Load the data into the form. Get the website.
210 striter = NicknamesListPtr->find(NicknamesListIndex);
212 if (striter->first == NicknamesListIndex){
214 strValue = striter->second;
218 txtNickname->SetValue(strValue);
222 striter = NicknamesListLanguagePtr->find(NicknamesListIndex);
224 if (striter->first == NicknamesListIndex &&
225 striter != NicknamesListLanguagePtr->end()){
227 strValue = striter->second;
231 cmbLanguage->SetValue(strValue);
234 // Get the website priority.
236 intiter = NicknamesListPrefPtr->find(NicknamesListIndex);
238 if (intiter->first == NicknamesListIndex && intiter->second > 0 &&
239 intiter != NicknamesListPrefPtr->end()){
241 sliPriority->SetValue(intiter->second);
242 sliPriority->Enable();
243 chkUsePref->SetValue(TRUE);
249 EditSectionType = SectType;
253 void frmContactEditorNickname::SetupPointers(std::map<int, wxString> *NicknamesList,
254 std::map<int, wxString> *NicknamesListAltID,
255 std::map<int, wxString> *NicknamesListPID,
256 std::map<int, wxString> *NicknamesListType,
257 std::map<int, wxString> *NicknamesListLanguage,
258 std::map<int, wxString> *NicknamesListTokens,
259 std::map<int, int> *NicknamesListPref,
260 wxListCtrl *NicknamesListCtrl,
264 // Setup the pointers.
266 NicknamesListPtr = NicknamesList;
267 NicknamesListAltIDPtr = NicknamesListAltID;
268 NicknamesListPIDPtr = NicknamesListPID;
269 NicknamesListTypePtr = NicknamesListType;
270 NicknamesListLanguagePtr = NicknamesListLanguage;
271 NicknamesListTokensPtr = NicknamesListTokens;
272 NicknamesListPrefPtr = NicknamesListPref;
273 NicknamesListCtrlPtr = NicknamesListCtrl;
274 NicknamesListIndex = NicknamesIndex;