1 // frmContactEditorLanguages.cpp - frmContactEditorLanguages 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 "frmContactEditorLanguages.h"
20 #include "../common/textprocessing.h"
23 frmContactEditorLanguages::frmContactEditorLanguages( wxWindow* parent )
25 frmContactEditorLanguagesADT( parent )
28 sliPriority->Disable();
31 void frmContactEditorLanguages::EnablePriority( wxCommandEvent& event )
33 if (chkUsePref->IsChecked()){
34 sliPriority->Enable();
36 sliPriority->Disable();
40 void frmContactEditorLanguages::SetEditorMode(bool EditMode, SectionType SectType)
43 // Set the editor mode for adding or editing an email address.
45 if (EditMode == FALSE){
48 btnAction->SetLabel(_("Add"));
49 this->SetTitle(_("Add Language"));
51 } else if (EditMode == TRUE){
54 btnAction->SetLabel(_("Modify"));
55 this->SetTitle(_("Modify Language"));
57 std::map<int,int>::iterator intiter;
58 std::map<int,wxString>::iterator striter;
61 // Load the data into the form.
63 striter = LanguageListPtr->find(LanguageListIndex);
65 if (striter->first == LanguageListIndex){
67 strValue = striter->second;
71 txtLanguage->SetValue(strValue);
75 intiter = LanguageListPrefPtr->find(LanguageListIndex);
77 if (intiter->first == LanguageListIndex && intiter->second > 0 &&
78 intiter != LanguageListPrefPtr->end()){
80 sliPriority->SetValue(intiter->second);
81 sliPriority->Enable();
82 chkUsePref->SetValue(TRUE);
88 EditSectionType = SectType;
91 void frmContactEditorLanguages::ProcessAction( wxCommandEvent& event )
96 if (EditorMode == FALSE){
98 // Add the language to the list.
104 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
108 if (EditSectionType == CE_GENERAL){
110 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("")));
112 } else if (EditSectionType == CE_HOME) {
114 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("home")));
116 } else if (EditSectionType == CE_WORK) {
118 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("work")));
122 // Add Language priority.
124 if (chkUsePref->IsChecked()){
126 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, sliPriority->GetValue()));
130 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));
134 // Add the data to the form.
138 coldata.SetId(LanguageListIndex);
139 coldata.SetData(LanguageListIndex);
140 coldata.SetText(txtLanguage->GetValue());
141 ListCtrlIndex = LanguageListCtrlPtr->InsertItem(coldata);
143 if (chkUsePref->IsChecked()){
145 LanguageListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
151 } else if (EditorMode == TRUE){
153 // Edit the language.
157 long longSelected = -1;
159 LanguageListPtr->erase(LanguageListIndex);
160 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
162 LanguageListPrefPtr->erase(LanguageListIndex);
164 if (chkUsePref->IsChecked()){
166 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, sliPriority->GetValue()));
170 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));
174 longSelected = LanguageListCtrlPtr->GetNextItem(longSelected,
176 wxLIST_STATE_SELECTED);
178 if (longSelected == -1){
182 LanguageListCtrlPtr->SetItem(longSelected, 0, txtLanguage->GetValue());
184 if (chkUsePref->IsChecked()){
186 LanguageListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
190 LanguageListCtrlPtr->SetItem(longSelected, 1, wxT(""));
200 void frmContactEditorLanguages::CloseWindow( wxCommandEvent& event )
209 void frmContactEditorLanguages::SetupPointers(std::map<int, wxString> *LanguageList,
210 std::map<int, wxString> *LanguageListAltID,
211 std::map<int, wxString> *LanguageListPID,
212 std::map<int, wxString> *LanguageListType,
213 std::map<int, wxString> *LanguageListTokens,
214 std::map<int, int> *LanguageListPref,
215 wxListCtrl *LanguageListCtrl,
219 // Setup the pointers so that the data can be processed without
222 LanguageListPtr = LanguageList;
223 LanguageListAltIDPtr = LanguageListAltID;
224 LanguageListPIDPtr = LanguageListPID;
225 LanguageListTypePtr = LanguageListType;
226 LanguageListTokensPtr = LanguageListTokens;
227 LanguageListPrefPtr = LanguageListPref;
228 LanguageListCtrlPtr = LanguageListCtrl;
229 LanguageListIndex = LanguageIndex;