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 )
28 sliPriority->Disable();
30 cmbType->Append(wxT(""));
31 cmbType->Append(_("Home"));
32 cmbType->Append(_("Work"));
35 void frmContactEditorCategory::EnablePriority( wxCommandEvent& event )
37 if (chkUsePref->IsChecked()){
38 sliPriority->Enable();
40 sliPriority->Disable();
44 void frmContactEditorCategory::ProcessAction( wxCommandEvent& event )
49 if (EditorMode == FALSE){
53 // Setup Organisation Name.
55 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
59 strValue = cmbType->GetString(cmbType->GetSelection());
61 // Setup Category Type.
63 if (strValue == _("Home")) {
65 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
67 } else if (strValue == _("Work")) {
69 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
73 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("")));
77 // Setup Category Priority.
79 if (chkUsePref->IsChecked()){
81 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
85 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
93 coldata.SetId(CategoryListIndex);
94 coldata.SetData(CategoryListIndex);
95 coldata.SetText(txtCategory->GetValue());
96 ListCtrlIndex = CategoryListCtrlPtr->InsertItem(coldata);
98 if (chkUsePref->IsChecked()){
100 CategoryListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
106 } else if (EditorMode == TRUE) {
108 long longSelected = -1;
111 // Update Category Name.
113 CategoryListPtr->erase(CategoryListIndex);
114 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
116 // Update Category Type.
118 CategoryListTypePtr->erase(CategoryListIndex);
120 strValue = cmbType->GetString(cmbType->GetSelection());
122 if (strValue == _("Home")) {
124 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
126 } else if (strValue == _("Work")) {
128 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
132 // Update Category Priority.
134 CategoryListPrefPtr->erase(CategoryListIndex);
136 if (chkUsePref->IsChecked()){
138 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
142 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
148 longSelected = CategoryListCtrlPtr->GetNextItem(longSelected,
150 wxLIST_STATE_SELECTED);
152 if (longSelected == -1){
156 CategoryListCtrlPtr->SetItem(longSelected, 0, txtCategory->GetValue());
158 if (chkUsePref->IsChecked()){
160 CategoryListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
164 CategoryListCtrlPtr->SetItem(longSelected, 1, wxT(""));
174 void frmContactEditorCategory::SetEditorMode(bool EditMode)
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){
218 strValue = striter->second;
222 if (strValue == wxT("home")){
224 cmbType->SetSelection(1);
226 } else if (strValue == wxT("work")){
228 cmbType->SetSelection(2);
232 cmbType->SetSelection(0);
236 // Get the organisation priority.
238 intiter = CategoryListPrefPtr->find(CategoryListIndex);
240 if (intiter->first == CategoryListIndex && intiter->second > 0){
242 sliPriority->SetValue(intiter->second);
243 sliPriority->Enable();
244 chkUsePref->SetValue(TRUE);
252 void frmContactEditorCategory::CloseWindow( wxCommandEvent& event )
257 void frmContactEditorCategory::SetupPointers(std::map<int, wxString> *CategoryList,
258 std::map<int, wxString> *CategoryListAltID,
259 std::map<int, wxString> *CategoryListPID,
260 std::map<int, wxString> *CategoryListType,
261 std::map<int, wxString> *CategoryListTokens,
262 std::map<int, int> *CategoryListPref,
263 wxListCtrl *CategoryListCtrl,
267 CategoryListPtr = CategoryList;
268 //CategoryListSortAsPtr = CategoryListSortAs;
269 CategoryListAltIDPtr = CategoryListAltID;
270 CategoryListPIDPtr = CategoryListPID;
271 CategoryListTypePtr = CategoryListType;
272 CategoryListTokensPtr = CategoryListTokens;
273 CategoryListPrefPtr = CategoryListPref;
274 CategoryListCtrlPtr = CategoryListCtrl;
275 CategoryListIndex = CategoryIndex;