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 )
31 sliPriority->Disable();
34 void frmContactEditorLanguages::EnablePriority( wxCommandEvent& event )
37 // Enable/disable the priority setting.
39 if (chkUsePref->IsChecked()){
40 sliPriority->Enable();
42 sliPriority->Disable();
47 void frmContactEditorLanguages::SetEditorMode(bool EditMode, SectionType SectType)
50 // Set the editor mode for adding or editing an email address.
52 if (EditMode == FALSE){
55 btnAction->SetLabel(_("Add"));
56 this->SetTitle(_("Add Language"));
58 } else if (EditMode == TRUE){
61 btnAction->SetLabel(_("Modify"));
62 this->SetTitle(_("Modify Language"));
64 std::map<int,int>::iterator intiter;
65 std::map<int,wxString>::iterator striter;
68 // Load the data into the form.
70 striter = LanguageListPtr->find(LanguageListIndex);
72 if (striter->first == LanguageListIndex){
74 strValue = striter->second;
78 txtLanguage->SetValue(strValue);
82 intiter = LanguageListPrefPtr->find(LanguageListIndex);
84 if (intiter->first == LanguageListIndex && intiter->second > 0 &&
85 intiter != LanguageListPrefPtr->end()){
87 sliPriority->SetValue(intiter->second);
88 sliPriority->Enable();
89 chkUsePref->SetValue(TRUE);
95 EditSectionType = SectType;
98 void frmContactEditorLanguages::ProcessAction( wxCommandEvent& event )
101 // Process the action.
105 if (EditorMode == FALSE){
107 // Add the language to the list.
113 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
117 if (EditSectionType == CE_GENERAL){
119 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("")));
121 } else if (EditSectionType == CE_HOME) {
123 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("home")));
125 } else if (EditSectionType == CE_WORK) {
127 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("work")));
131 // Add Language priority.
133 if (chkUsePref->IsChecked()){
135 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, sliPriority->GetValue()));
139 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));
143 // Add the data to the form.
147 coldata.SetId(LanguageListIndex);
148 coldata.SetData(LanguageListIndex);
149 coldata.SetText(txtLanguage->GetValue());
150 ListCtrlIndex = LanguageListCtrlPtr->InsertItem(coldata);
152 if (chkUsePref->IsChecked()){
154 LanguageListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
160 } else if (EditorMode == TRUE){
162 // Edit the language.
166 long longSelected = -1;
168 LanguageListPtr->erase(LanguageListIndex);
169 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
171 LanguageListPrefPtr->erase(LanguageListIndex);
173 if (chkUsePref->IsChecked()){
175 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, sliPriority->GetValue()));
179 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));
183 longSelected = LanguageListCtrlPtr->GetNextItem(longSelected,
185 wxLIST_STATE_SELECTED);
187 if (longSelected == -1){
191 LanguageListCtrlPtr->SetItem(longSelected, 0, txtLanguage->GetValue());
193 if (chkUsePref->IsChecked()){
195 LanguageListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
199 LanguageListCtrlPtr->SetItem(longSelected, 1, wxT(""));
209 void frmContactEditorLanguages::CloseWindow( wxCommandEvent& event )
218 void frmContactEditorLanguages::SetupPointers(std::map<int, wxString> *LanguageList,
219 std::map<int, wxString> *LanguageListAltID,
220 std::map<int, wxString> *LanguageListPID,
221 std::map<int, wxString> *LanguageListType,
222 std::map<int, wxString> *LanguageListTokens,
223 std::map<int, int> *LanguageListPref,
224 wxListCtrl *LanguageListCtrl,
228 // Setup the pointers so that the data can be processed without
231 LanguageListPtr = LanguageList;
232 LanguageListAltIDPtr = LanguageListAltID;
233 LanguageListPIDPtr = LanguageListPID;
234 LanguageListTypePtr = LanguageListType;
235 LanguageListTokensPtr = LanguageListTokens;
236 LanguageListPrefPtr = LanguageListPref;
237 LanguageListCtrlPtr = LanguageListCtrl;
238 LanguageListIndex = LanguageIndex;