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 )
34 priorityCtrl = new XABPriorityCtrl(tabGeneral);
35 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
39 void frmContactEditorRoles::ProcessAction( wxCommandEvent& event )
44 // Set if the editor is adding or editing an address.
50 if (EditorMode == FALSE){
54 // Get the website address.
56 RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue()));
58 // Get the type of website.
60 if (EditSectionType == CE_GENERAL){
62 RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("")));
64 } else if (EditSectionType == CE_HOME) {
66 RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("home")));
68 } else if (EditSectionType == CE_WORK) {
70 RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("work")));
74 // Add the roles priority.
76 if (priorityCtrl->IsPriorityChecked()){
78 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, priorityCtrl->GetValue()));
82 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0));
90 coldata.SetId(RolesListIndex);
91 coldata.SetData(RolesListIndex);
92 coldata.SetText(txtRole->GetValue());
93 ListCtrlIndex = RolesListCtrlPtr->InsertItem(coldata);
95 if (priorityCtrl->IsPriorityChecked()){
97 RolesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
106 long longSelected = -1;
108 RolesListPtr->erase(RolesListIndex);
109 RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue()));
111 // Update the slider priority.
113 RolesListPrefPtr->erase(RolesListIndex);
115 if (priorityCtrl->IsPriorityChecked()){
117 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, priorityCtrl->GetValue()));
121 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0));
127 longSelected = RolesListCtrlPtr->GetNextItem(longSelected,
129 wxLIST_STATE_SELECTED);
131 if (longSelected == -1){
135 RolesListCtrlPtr->SetItem(longSelected, 0, txtRole->GetValue());
137 if (priorityCtrl->IsPriorityChecked()){
139 RolesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
143 RolesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
152 void frmContactEditorRoles::SetEditorMode(bool EditMode, SectionType SectType)
155 // Set the editor mode.
157 // Set if the editor is adding or editing an address.
161 if (EditMode == FALSE){
164 btnAction->SetLabel(_("Add"));
165 this->SetTitle(_("Add Title"));
167 } else if (EditMode == TRUE){
170 btnAction->SetLabel(_("Modify"));
171 this->SetTitle(_("Modify Title"));
173 std::map<int,int>::iterator intiter;
174 std::map<int,wxString>::iterator striter;
177 // Load the data into the form. Get the website.
179 striter = RolesListPtr->find(RolesListIndex);
181 if (striter->first == RolesListIndex){
183 strValue = striter->second;
187 txtRole->SetValue(strValue);
191 // Get the website priority.
193 intiter = RolesListPrefPtr->find(RolesListIndex);
195 if (intiter->first == RolesListIndex && intiter->second > 0 &&
196 intiter != RolesListPrefPtr->end()){
198 priorityCtrl->SetValue(intiter->second);
199 priorityCtrl->EnablePriority(true);
205 EditSectionType = SectType;
209 void frmContactEditorRoles::CloseWindow( wxCommandEvent& event )
212 // Close this window.
218 void frmContactEditorRoles::SetupPointers(std::map<int, wxString> *RolesList,
219 std::map<int, wxString> *RolesListLanguage,
220 std::map<int, wxString> *RolesListAltID,
221 std::map<int, wxString> *RolesListPID,
222 std::map<int, wxString> *RolesListType,
223 std::map<int, wxString> *RolesListTokens,
224 std::map<int, int> *RolesListPref,
225 wxListCtrl *RolesListCtrl,
229 // Setup the pointers.
231 RolesListPtr = RolesList;
232 RolesListLanguagePtr = RolesListLanguage;
233 RolesListAltIDPtr = RolesListAltID;
234 RolesListPIDPtr = RolesListPID;
235 RolesListTypePtr = RolesListType;
236 RolesListTokensPtr = RolesListTokens;
237 RolesListPrefPtr = RolesListPref;
238 RolesListCtrlPtr = RolesListCtrl;
239 RolesListIndex = RolesIndex;