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 sliPriority->Disable();
33 cmbType->Append(wxT(""));
34 cmbType->Append(_("Home"));
35 cmbType->Append(_("Work"));
38 void frmContactEditorCategory::EnablePriority( wxCommandEvent& event )
41 // Enable/disable the priority setting.
43 if (chkUsePref->IsChecked()){
44 sliPriority->Enable();
46 sliPriority->Disable();
51 void frmContactEditorCategory::ProcessAction( wxCommandEvent& event )
58 if (EditorMode == FALSE){
62 // Setup Organisation Name.
64 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
68 strValue = cmbType->GetString(cmbType->GetSelection());
70 // Setup Category Type.
72 if (strValue == _("Home")) {
74 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
76 } else if (strValue == _("Work")) {
78 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
82 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("")));
86 // Setup Category Priority.
88 if (chkUsePref->IsChecked()){
90 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
94 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
102 coldata.SetId(CategoryListIndex);
103 coldata.SetData(CategoryListIndex);
104 coldata.SetText(txtCategory->GetValue());
105 ListCtrlIndex = CategoryListCtrlPtr->InsertItem(coldata);
107 if (chkUsePref->IsChecked()){
109 CategoryListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
115 } else if (EditorMode == TRUE) {
117 long longSelected = -1;
120 // Update Category Name.
122 CategoryListPtr->erase(CategoryListIndex);
123 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
125 // Update Category Type.
127 CategoryListTypePtr->erase(CategoryListIndex);
129 strValue = cmbType->GetString(cmbType->GetSelection());
131 if (strValue == _("Home")) {
133 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
135 } else if (strValue == _("Work")) {
137 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
141 // Update Category Priority.
143 CategoryListPrefPtr->erase(CategoryListIndex);
145 if (chkUsePref->IsChecked()){
147 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
151 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
157 longSelected = CategoryListCtrlPtr->GetNextItem(longSelected,
159 wxLIST_STATE_SELECTED);
161 if (longSelected == -1){
165 CategoryListCtrlPtr->SetItem(longSelected, 0, txtCategory->GetValue());
167 if (chkUsePref->IsChecked()){
169 CategoryListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
173 CategoryListCtrlPtr->SetItem(longSelected, 1, wxT(""));
183 void frmContactEditorCategory::SetEditorMode(bool EditMode)
186 // Set the editor mode.
188 // Set if the editor is adding or editing an address.
192 if (EditMode == FALSE){
195 btnAction->SetLabel(_("Add"));
196 this->SetTitle(_("Add Category"));
198 } else if (EditMode == TRUE){
201 btnAction->SetLabel(_("Modify"));
202 this->SetTitle(_("Modify Category"));
204 // Load the data into the form.
206 std::map<int,int>::iterator intiter;
207 std::map<int,wxString>::iterator striter;
210 // Get the organisation name.
212 striter = CategoryListPtr->find(CategoryListIndex);
214 if (striter->first == CategoryListIndex){
216 strValue = striter->second;
220 txtCategory->SetValue(strValue);
226 striter = CategoryListTypePtr->find(CategoryListIndex);
228 if (striter->first == CategoryListIndex &&
229 striter != CategoryListTypePtr->end()){
231 strValue = striter->second;
235 if (strValue == wxT("home")){
237 cmbType->SetSelection(1);
239 } else if (strValue == wxT("work")){
241 cmbType->SetSelection(2);
245 cmbType->SetSelection(0);
249 // Get the organisation priority.
251 intiter = CategoryListPrefPtr->find(CategoryListIndex);
253 if (intiter->first == CategoryListIndex && intiter->second > 0 &&
254 intiter != CategoryListPrefPtr->end()){
256 sliPriority->SetValue(intiter->second);
257 sliPriority->Enable();
258 chkUsePref->SetValue(TRUE);
266 void frmContactEditorCategory::CloseWindow( wxCommandEvent& event )
269 // Close this window.
275 void frmContactEditorCategory::SetupPointers(std::map<int, wxString> *CategoryList,
276 std::map<int, wxString> *CategoryListAltID,
277 std::map<int, wxString> *CategoryListPID,
278 std::map<int, wxString> *CategoryListType,
279 std::map<int, wxString> *CategoryListTokens,
280 std::map<int, int> *CategoryListPref,
281 wxListCtrl *CategoryListCtrl,
285 // Setup the pointers.
287 CategoryListPtr = CategoryList;
288 CategoryListAltIDPtr = CategoryListAltID;
289 CategoryListPIDPtr = CategoryListPID;
290 CategoryListTypePtr = CategoryListType;
291 CategoryListTokensPtr = CategoryListTokens;
292 CategoryListPrefPtr = CategoryListPref;
293 CategoryListCtrlPtr = CategoryListCtrl;
294 CategoryListIndex = CategoryIndex;