1 // frmContactEditorCategory.cpp - frmContactEditorCategory 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 "frmContactEditorCategory.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
23 frmContactEditorCategory::frmContactEditorCategory( wxWindow* parent )
25 frmContactEditorCategoryADT( parent )
31 priorityCtrl = new XABPriorityCtrl(tabGeneral);
32 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
34 cmbType->Append(wxT(""));
35 cmbType->Append(_("Home"));
36 cmbType->Append(_("Work"));
39 void frmContactEditorCategory::ProcessAction( wxCommandEvent& event )
46 if (EditorMode == FALSE){
50 // Setup Organisation Name.
52 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
56 strValue = cmbType->GetString(cmbType->GetSelection());
58 // Setup Category Type.
60 if (strValue == _("Home")) {
62 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
64 } else if (strValue == _("Work")) {
66 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
70 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("")));
74 // Setup Category Priority.
76 if (priorityCtrl->IsPriorityChecked()){
78 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, priorityCtrl->GetValue()));
82 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
90 coldata.SetId(CategoryListIndex);
91 coldata.SetData(CategoryListIndex);
92 coldata.SetText(txtCategory->GetValue());
93 ListCtrlIndex = CategoryListCtrlPtr->InsertItem(coldata);
95 if (priorityCtrl->IsPriorityChecked()){
97 CategoryListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
103 } else if (EditorMode == TRUE) {
105 long longSelected = -1;
108 // Update Category Name.
110 CategoryListPtr->erase(CategoryListIndex);
111 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
113 // Update Category Type.
115 CategoryListTypePtr->erase(CategoryListIndex);
117 strValue = cmbType->GetString(cmbType->GetSelection());
119 if (strValue == _("Home")) {
121 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
123 } else if (strValue == _("Work")) {
125 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
129 // Update Category Priority.
131 CategoryListPrefPtr->erase(CategoryListIndex);
133 if (priorityCtrl->IsPriorityChecked()){
135 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, priorityCtrl->GetValue()));
139 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
145 longSelected = CategoryListCtrlPtr->GetNextItem(longSelected,
147 wxLIST_STATE_SELECTED);
149 if (longSelected == -1){
153 CategoryListCtrlPtr->SetItem(longSelected, 0, txtCategory->GetValue());
155 if (priorityCtrl->IsPriorityChecked()){
157 CategoryListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
161 CategoryListCtrlPtr->SetItem(longSelected, 1, wxT(""));
171 void frmContactEditorCategory::SetEditorMode(bool EditMode)
174 // Set the editor mode.
176 // Set if the editor is adding or editing an address.
180 if (EditMode == FALSE){
183 btnAction->SetLabel(_("Add"));
184 this->SetTitle(_("Add Category"));
186 } else if (EditMode == TRUE){
189 btnAction->SetLabel(_("Modify"));
190 this->SetTitle(_("Modify Category"));
192 // Load the data into the form.
194 std::map<int,int>::iterator intiter;
195 std::map<int,wxString>::iterator striter;
198 // Get the organisation name.
200 striter = CategoryListPtr->find(CategoryListIndex);
202 if (striter->first == CategoryListIndex){
204 strValue = striter->second;
208 txtCategory->SetValue(strValue);
214 striter = CategoryListTypePtr->find(CategoryListIndex);
216 if (striter->first == CategoryListIndex &&
217 striter != CategoryListTypePtr->end()){
219 strValue = striter->second;
223 if (strValue == wxT("home")){
225 cmbType->SetSelection(1);
227 } else if (strValue == wxT("work")){
229 cmbType->SetSelection(2);
233 cmbType->SetSelection(0);
237 // Get the organisation priority.
239 intiter = CategoryListPrefPtr->find(CategoryListIndex);
241 if (intiter->first == CategoryListIndex && intiter->second > 0 &&
242 intiter != CategoryListPrefPtr->end()){
244 priorityCtrl->SetValue(intiter->second);
245 priorityCtrl->EnablePriority(true);
253 void frmContactEditorCategory::CloseWindow( wxCommandEvent& event )
256 // Close this window.
262 void frmContactEditorCategory::SetupPointers(std::map<int, wxString> *CategoryList,
263 std::map<int, wxString> *CategoryListAltID,
264 std::map<int, wxString> *CategoryListPID,
265 std::map<int, wxString> *CategoryListType,
266 std::map<int, wxString> *CategoryListTokens,
267 std::map<int, int> *CategoryListPref,
268 wxListCtrl *CategoryListCtrl,
272 // Setup the pointers.
274 CategoryListPtr = CategoryList;
275 CategoryListAltIDPtr = CategoryListAltID;
276 CategoryListPIDPtr = CategoryListPID;
277 CategoryListTypePtr = CategoryListType;
278 CategoryListTokensPtr = CategoryListTokens;
279 CategoryListPrefPtr = CategoryListPref;
280 CategoryListCtrlPtr = CategoryListCtrl;
281 CategoryListIndex = CategoryIndex;