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);
35 cmbType->Append(wxT(""));
36 cmbType->Append(_("Home"));
37 cmbType->Append(_("Work"));
40 void frmContactEditorCategory::ProcessAction( wxCommandEvent& event )
47 if (EditorMode == FALSE){
51 // Setup Organisation Name.
53 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
57 strValue = cmbType->GetString(cmbType->GetSelection());
59 // Setup Category Type.
61 if (strValue == _("Home")) {
63 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
65 } else if (strValue == _("Work")) {
67 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
71 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("")));
75 // Setup Category Priority.
77 if (priorityCtrl->IsPriorityChecked()){
79 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, priorityCtrl->GetValue()));
83 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
91 coldata.SetId(CategoryListIndex);
92 coldata.SetData(CategoryListIndex);
93 coldata.SetText(txtCategory->GetValue());
94 ListCtrlIndex = CategoryListCtrlPtr->InsertItem(coldata);
96 if (priorityCtrl->IsPriorityChecked()){
98 CategoryListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
104 } else if (EditorMode == TRUE) {
106 long longSelected = -1;
109 // Update Category Name.
111 CategoryListPtr->erase(CategoryListIndex);
112 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
114 // Update Category Type.
116 CategoryListTypePtr->erase(CategoryListIndex);
118 strValue = cmbType->GetString(cmbType->GetSelection());
120 if (strValue == _("Home")) {
122 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
124 } else if (strValue == _("Work")) {
126 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
130 // Update Category Priority.
132 CategoryListPrefPtr->erase(CategoryListIndex);
134 if (priorityCtrl->IsPriorityChecked()){
136 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, priorityCtrl->GetValue()));
140 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
146 longSelected = CategoryListCtrlPtr->GetNextItem(longSelected,
148 wxLIST_STATE_SELECTED);
150 if (longSelected == -1){
154 CategoryListCtrlPtr->SetItem(longSelected, 0, txtCategory->GetValue());
156 if (priorityCtrl->IsPriorityChecked()){
158 CategoryListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
162 CategoryListCtrlPtr->SetItem(longSelected, 1, wxT(""));
172 void frmContactEditorCategory::SetEditorMode(bool EditMode)
175 // Set the editor mode.
177 // Set if the editor is adding or editing an address.
181 if (EditMode == FALSE){
184 btnAction->SetLabel(_("Add"));
185 this->SetTitle(_("Add Category"));
187 } else if (EditMode == TRUE){
190 btnAction->SetLabel(_("Modify"));
191 this->SetTitle(_("Modify Category"));
193 // Load the data into the form.
195 std::map<int,int>::iterator intiter;
196 std::map<int,wxString>::iterator striter;
199 // Get the organisation name.
201 striter = CategoryListPtr->find(CategoryListIndex);
203 if (striter->first == CategoryListIndex){
205 strValue = striter->second;
209 txtCategory->SetValue(strValue);
215 striter = CategoryListTypePtr->find(CategoryListIndex);
217 if (striter->first == CategoryListIndex &&
218 striter != CategoryListTypePtr->end()){
220 strValue = striter->second;
224 if (strValue == wxT("home")){
226 cmbType->SetSelection(1);
228 } else if (strValue == wxT("work")){
230 cmbType->SetSelection(2);
234 cmbType->SetSelection(0);
238 // Get the organisation priority.
240 intiter = CategoryListPrefPtr->find(CategoryListIndex);
242 if (intiter->first == CategoryListIndex && intiter->second > 0 &&
243 intiter != CategoryListPrefPtr->end()){
245 priorityCtrl->SetValue(intiter->second);
246 priorityCtrl->EnablePriority(true);
254 void frmContactEditorCategory::CloseWindow( wxCommandEvent& event )
257 // Close this window.
263 void frmContactEditorCategory::SetupPointers(std::map<int, wxString> *CategoryList,
264 std::map<int, wxString> *CategoryListAltID,
265 std::map<int, wxString> *CategoryListPID,
266 std::map<int, wxString> *CategoryListType,
267 std::map<int, wxString> *CategoryListTokens,
268 std::map<int, int> *CategoryListPref,
269 wxListCtrl *CategoryListCtrl,
273 // Setup the pointers.
275 CategoryListPtr = CategoryList;
276 CategoryListAltIDPtr = CategoryListAltID;
277 CategoryListPIDPtr = CategoryListPID;
278 CategoryListTypePtr = CategoryListType;
279 CategoryListTokensPtr = CategoryListTokens;
280 CategoryListPrefPtr = CategoryListPref;
281 CategoryListCtrlPtr = CategoryListCtrl;
282 CategoryListIndex = CategoryIndex;