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);
40 void frmContactEditorRoles::ProcessAction( wxCommandEvent& event )
45 // Set if the editor is adding or editing an address.
51 if (EditorMode == FALSE){
55 // Get the website address.
57 RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue()));
59 // Get the type of website.
61 if (EditSectionType == CE_GENERAL){
63 RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("")));
65 } else if (EditSectionType == CE_HOME) {
67 RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("home")));
69 } else if (EditSectionType == CE_WORK) {
71 RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("work")));
75 // Add the roles priority.
77 if (priorityCtrl->IsPriorityChecked()){
79 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, priorityCtrl->GetValue()));
83 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0));
91 coldata.SetId(RolesListIndex);
92 coldata.SetData(RolesListIndex);
93 coldata.SetText(txtRole->GetValue());
94 ListCtrlIndex = RolesListCtrlPtr->InsertItem(coldata);
96 if (priorityCtrl->IsPriorityChecked()){
98 RolesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
107 long longSelected = -1;
109 RolesListPtr->erase(RolesListIndex);
110 RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue()));
112 // Update the slider priority.
114 RolesListPrefPtr->erase(RolesListIndex);
116 if (priorityCtrl->IsPriorityChecked()){
118 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, priorityCtrl->GetValue()));
122 RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0));
128 longSelected = RolesListCtrlPtr->GetNextItem(longSelected,
130 wxLIST_STATE_SELECTED);
132 if (longSelected == -1){
136 RolesListCtrlPtr->SetItem(longSelected, 0, txtRole->GetValue());
138 if (priorityCtrl->IsPriorityChecked()){
140 RolesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
144 RolesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
153 void frmContactEditorRoles::SetEditorMode(bool EditMode, SectionType SectType)
156 // Set the editor mode.
158 // Set if the editor is adding or editing an address.
162 if (EditMode == FALSE){
165 btnAction->SetLabel(_("Add"));
166 this->SetTitle(_("Add Title"));
168 } else if (EditMode == TRUE){
171 btnAction->SetLabel(_("Modify"));
172 this->SetTitle(_("Modify Title"));
174 std::map<int,int>::iterator intiter;
175 std::map<int,wxString>::iterator striter;
178 // Load the data into the form. Get the website.
180 striter = RolesListPtr->find(RolesListIndex);
182 if (striter->first == RolesListIndex){
184 strValue = striter->second;
188 txtRole->SetValue(strValue);
192 // Get the website priority.
194 intiter = RolesListPrefPtr->find(RolesListIndex);
196 if (intiter->first == RolesListIndex && intiter->second > 0 &&
197 intiter != RolesListPrefPtr->end()){
199 priorityCtrl->SetValue(intiter->second);
200 priorityCtrl->EnablePriority(true);
206 EditSectionType = SectType;
210 void frmContactEditorRoles::CloseWindow( wxCommandEvent& event )
213 // Close this window.
219 void frmContactEditorRoles::SetupPointers(std::map<int, wxString> *RolesList,
220 std::map<int, wxString> *RolesListLanguage,
221 std::map<int, wxString> *RolesListAltID,
222 std::map<int, wxString> *RolesListPID,
223 std::map<int, wxString> *RolesListType,
224 std::map<int, wxString> *RolesListTokens,
225 std::map<int, int> *RolesListPref,
226 wxListCtrl *RolesListCtrl,
230 // Setup the pointers.
232 RolesListPtr = RolesList;
233 RolesListLanguagePtr = RolesListLanguage;
234 RolesListAltIDPtr = RolesListAltID;
235 RolesListPIDPtr = RolesListPID;
236 RolesListTypePtr = RolesListType;
237 RolesListTokensPtr = RolesListTokens;
238 RolesListPrefPtr = RolesListPref;
239 RolesListCtrlPtr = RolesListCtrl;
240 RolesListIndex = RolesIndex;