1 // frmContactEditorCalAdr.cpp - frmContactEditorCalAdr 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 "frmContactEditorCalAdr.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
23 frmContactEditorCalAdr::frmContactEditorCalAdr( wxWindow* parent )
25 frmContactEditorCalAdrADT( parent )
28 sliPriority->Disable();
30 cmbType->Append(wxT(""));
31 cmbType->Append(_("Home"));
32 cmbType->Append(_("Work"));
35 void frmContactEditorCalAdr::EnablePriority( wxCommandEvent& event )
37 if (chkUsePref->IsChecked()){
38 sliPriority->Enable();
40 sliPriority->Disable();
44 void frmContactEditorCalAdr::ProcessAction( wxCommandEvent& event )
48 if (EditorMode == FALSE){
52 // Setup Calendar Address.
54 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
58 strValue = cmbType->GetString(cmbType->GetSelection());
60 // Setup Calendar Type.
62 if (strValue == _("Home")) {
64 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
66 } else if (strValue == _("Work")) {
68 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
72 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("")));
76 // Setup Calendar Priority.
78 if (chkUsePref->IsChecked()){
80 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
84 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
92 coldata.SetId(CalAdrListIndex);
93 coldata.SetData(CalAdrListIndex);
94 coldata.SetText(txtAddress->GetValue());
95 ListCtrlIndex = CalAdrListCtrlPtr->InsertItem(coldata);
97 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);
99 if (chkUsePref->IsChecked()){
101 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
107 } else if (EditorMode == TRUE) {
109 long longSelected = -1;
112 // Update Category Name.
114 CalAdrListPtr->erase(CalAdrListIndex);
115 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
117 // Update Category Type.
119 CalAdrListTypePtr->erase(CalAdrListIndex);
122 strValue = cmbType->GetString(cmbType->GetSelection());
124 if (strValue == _("Home")) {
126 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
128 } else if (strValue == _("Work")) {
130 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
134 // Update Category Priority.
136 CalAdrListPrefPtr->erase(CalAdrListIndex);
138 if (chkUsePref->IsChecked()){
140 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
144 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
150 longSelected = CalAdrListCtrlPtr->GetNextItem(longSelected,
152 wxLIST_STATE_SELECTED);
154 if (longSelected == -1){
158 CalAdrListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
159 CalAdrListCtrlPtr->SetItem(longSelected, 1, strValue);
161 if (chkUsePref->IsChecked()){
163 CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
167 CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT(""));
176 void frmContactEditorCalAdr::SetEditorMode(bool EditMode)
178 // Set if the editor is adding or editing an address.
182 if (EditMode == FALSE){
185 btnAction->SetLabel(_("Add"));
186 this->SetTitle(_("Add Calendar Address"));
188 } else if (EditMode == TRUE){
191 btnAction->SetLabel(_("Modify"));
192 this->SetTitle(_("Modify Calendar Address"));
194 std::map<int,int>::iterator intiter;
195 std::map<int,wxString>::iterator striter;
198 // Get the organisation name.
200 striter = CalAdrListPtr->find(CalAdrListIndex);
202 if (striter->first == CalAdrListIndex){
204 strValue = striter->second;
208 txtAddress->SetValue(strValue);
214 striter = CalAdrListTypePtr->find(CalAdrListIndex);
216 if (striter->first == CalAdrListIndex){
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 = CalAdrListPrefPtr->find(CalAdrListIndex);
240 if (intiter->first == CalAdrListIndex && intiter->second > 0){
242 sliPriority->SetValue(intiter->second);
243 sliPriority->Enable();
244 chkUsePref->SetValue(TRUE);
252 void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event )
257 void frmContactEditorCalAdr::SetupPointers(std::map<int, wxString> *CalAdrList,
258 std::map<int, wxString> *CalAdrListAltID,
259 std::map<int, wxString> *CalAdrListPID,
260 std::map<int, wxString> *CalAdrListType,
261 std::map<int, wxString> *CalAdrListTokens,
262 std::map<int, int> *CalAdrListPref,
263 wxListCtrl *CalAdrListCtrl,
267 CalAdrListPtr = CalAdrList;
268 CalAdrListAltIDPtr = CalAdrListAltID;
269 CalAdrListPIDPtr = CalAdrListPID;
270 CalAdrListTypePtr = CalAdrListType;
271 CalAdrListTokensPtr = CalAdrListTokens;
272 CalAdrListPrefPtr = CalAdrListPref;
273 CalAdrListCtrlPtr = CalAdrListCtrl;
274 CalAdrListIndex = CalAdrIndex;