1 // frmContactEditorRoles.cpp - frmContactEditorRoles 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 "frmContactEditorRoles.h"
23 #include "../common/textprocessing.h"
25 frmContactEditorRoles::frmContactEditorRoles( wxWindow* parent )
27 frmContactEditorRolesADT( parent )
33 sliPriority->Disable();
36 void frmContactEditorRoles::EnablePriority( wxCommandEvent& event )
39 // Enable/disable the priority setting.
41 if (chkUsePref->IsChecked()){
42 sliPriority->Enable();
44 sliPriority->Disable();
49 void frmContactEditorRoles::ProcessAction( wxCommandEvent& event )
54 // Set if the editor is adding or editing an address.
60 if (EditorMode == FALSE){
64 // Get the website address.
66 RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue()));
68 // Get the type of website.
70 if (EditSectionType == CE_GENERAL){
72 RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("")));
74 } else if (EditSectionType == CE_HOME) {
76 RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("home")));
78 } else if (EditSectionType == CE_WORK) {
80 RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("work")));
84 // Add the website priority.
86 if (chkUsePref->IsChecked()){
88 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, sliPriority->GetValue()));
92 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0));
100 coldata.SetId(RolesListIndex);
101 coldata.SetData(RolesListIndex);
102 coldata.SetText(txtRole->GetValue());
103 ListCtrlIndex = RolesListCtrlPtr->InsertItem(coldata);
105 if (chkUsePref->IsChecked()){
107 RolesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
116 long longSelected = -1;
118 RolesListPtr->erase(RolesListIndex);
119 RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue()));
121 // Update the slider priority.
123 RolesListPrefPtr->erase(RolesListIndex);
125 if (chkUsePref->IsChecked()){
127 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, sliPriority->GetValue()));
131 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0));
137 longSelected = RolesListCtrlPtr->GetNextItem(longSelected,
139 wxLIST_STATE_SELECTED);
141 if (longSelected == -1){
145 RolesListCtrlPtr->SetItem(longSelected, 0, txtRole->GetValue());
147 if (chkUsePref->IsChecked()){
149 RolesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
153 RolesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
162 void frmContactEditorRoles::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 = RolesListPtr->find(RolesListIndex);
191 if (striter->first == RolesListIndex){
193 strValue = striter->second;
197 txtRole->SetValue(strValue);
201 // Get the website priority.
203 intiter = RolesListPrefPtr->find(RolesListIndex);
205 if (intiter->first == RolesListIndex && intiter->second > 0 &&
206 intiter != RolesListPrefPtr->end()){
208 sliPriority->SetValue(intiter->second);
209 sliPriority->Enable();
210 chkUsePref->SetValue(TRUE);
216 EditSectionType = SectType;
220 void frmContactEditorRoles::CloseWindow( wxCommandEvent& event )
223 // Close this window.
229 void frmContactEditorRoles::SetupPointers(std::map<int, wxString> *RolesList,
230 std::map<int, wxString> *RolesListLanguage,
231 std::map<int, wxString> *RolesListAltID,
232 std::map<int, wxString> *RolesListPID,
233 std::map<int, wxString> *RolesListType,
234 std::map<int, wxString> *RolesListTokens,
235 std::map<int, int> *RolesListPref,
236 wxListCtrl *RolesListCtrl,
240 // Setup the pointers.
242 RolesListPtr = RolesList;
243 RolesListLanguagePtr = RolesListLanguage;
244 RolesListAltIDPtr = RolesListAltID;
245 RolesListPIDPtr = RolesListPID;
246 RolesListTypePtr = RolesListType;
247 RolesListTokensPtr = RolesListTokens;
248 RolesListPrefPtr = RolesListPref;
249 RolesListCtrlPtr = RolesListCtrl;
250 RolesListIndex = RolesIndex;