1 // frmContactEditorTitles.cpp - frmContactEditorTitles 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 "frmContactEditorTitles.h"
23 #include "../common/textprocessing.h"
25 frmContactEditorTitles::frmContactEditorTitles( wxWindow* parent )
27 frmContactEditorTitlesADT( parent )
33 sliPriority->Disable();
36 void frmContactEditorTitles::EnablePriority( wxCommandEvent& event )
39 // Enable/disable the priority setting.
41 if (chkUsePref->IsChecked()){
42 sliPriority->Enable();
44 sliPriority->Disable();
49 void frmContactEditorTitles::ProcessAction( wxCommandEvent& event )
54 // Set if the editor is adding or editing an address.
60 if (EditorMode == FALSE){
64 // Get the website address.
66 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
68 // Get the type of website.
70 if (EditSectionType == CE_GENERAL){
72 TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("")));
74 } else if (EditSectionType == CE_HOME) {
76 TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("home")));
78 } else if (EditSectionType == CE_WORK) {
80 TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("work")));
84 // Add the website priority.
86 if (chkUsePref->IsChecked()){
88 TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, sliPriority->GetValue()));
92 TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));
100 coldata.SetId(TitlesListIndex);
101 coldata.SetData(TitlesListIndex);
102 coldata.SetText(txtTitle->GetValue());
103 ListCtrlIndex = TitlesListCtrlPtr->InsertItem(coldata);
105 if (chkUsePref->IsChecked()){
107 TitlesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
116 long longSelected = -1;
118 TitlesListPtr->erase(TitlesListIndex);
119 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
121 // Update the slider priority.
123 TitlesListPrefPtr->erase(TitlesListIndex);
125 if (chkUsePref->IsChecked()){
127 TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, sliPriority->GetValue()));
131 TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));
137 longSelected = TitlesListCtrlPtr->GetNextItem(longSelected,
139 wxLIST_STATE_SELECTED);
141 if (longSelected == -1){
145 TitlesListCtrlPtr->SetItem(longSelected, 0, txtTitle->GetValue());
147 if (chkUsePref->IsChecked()){
149 TitlesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
153 TitlesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
162 void frmContactEditorTitles::SetEditorMode(bool EditMode, SectionType SectType)
165 // Set the editor mode.
167 // Set if the editor is adding or editing an address.
171 if (EditMode == FALSE){
174 btnAction->SetLabel(_("Add"));
175 this->SetTitle(_("Add Title"));
177 } else if (EditMode == TRUE){
180 btnAction->SetLabel(_("Modify"));
181 this->SetTitle(_("Modify Title"));
183 std::map<int,int>::iterator intiter;
184 std::map<int,wxString>::iterator striter;
187 // Load the data into the form. Get the website.
189 striter = TitlesListPtr->find(TitlesListIndex);
191 if (striter->first == TitlesListIndex &&
192 striter != TitlesListPtr->end()){
194 strValue = striter->second;
198 txtTitle->SetValue(strValue);
202 // Get the website priority.
204 intiter = TitlesListPrefPtr->find(TitlesListIndex);
206 if (intiter->first == TitlesListIndex && intiter->second > 0 &&
207 intiter != TitlesListPrefPtr->end()){
209 sliPriority->SetValue(intiter->second);
210 sliPriority->Enable();
211 chkUsePref->SetValue(TRUE);
217 EditSectionType = SectType;
221 void frmContactEditorTitles::CloseWindow( wxCommandEvent& event )
230 void frmContactEditorTitles::SetupPointers(std::map<int, wxString> *TitlesList,
231 std::map<int, wxString> *TitlesListLanguage,
232 std::map<int, wxString> *TitlesListAltID,
233 std::map<int, wxString> *TitlesListPID,
234 std::map<int, wxString> *TitlesListType,
235 std::map<int, wxString> *TitlesListTokens,
236 std::map<int, int> *TitlesListPref,
237 wxListCtrl *TitlesListCtrl,
241 // Setup the pointers.
243 TitlesListPtr = TitlesList;
244 TitlesListLanguagePtr = TitlesListLanguage;
245 TitlesListAltIDPtr = TitlesListAltID;
246 TitlesListPIDPtr = TitlesListPID;
247 TitlesListTypePtr = TitlesListType;
248 TitlesListTokensPtr = TitlesListTokens;
249 TitlesListPrefPtr = TitlesListPref;
250 TitlesListCtrlPtr = TitlesListCtrl;
251 TitlesListIndex = TitlesIndex;