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 )
31 priorityCtrl = new XABPriorityCtrl(tabGeneral);
32 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
35 cmbType->Append(wxT(""));
36 cmbType->Append(_("Home"));
37 cmbType->Append(_("Work"));
41 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 (priorityCtrl->IsPriorityChecked()){
80 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, priorityCtrl->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 (priorityCtrl->IsPriorityChecked()){
101 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->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 (priorityCtrl->IsPriorityChecked()){
140 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, priorityCtrl->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 (priorityCtrl->IsPriorityChecked()){
163 CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
167 CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT(""));
177 void frmContactEditorCalAdr::SetEditorMode(bool EditMode)
180 // Set the editor mode.
182 // Set if the editor is adding or editing an address.
186 if (EditMode == FALSE){
189 btnAction->SetLabel(_("Add"));
190 this->SetTitle(_("Add Calendar Address"));
192 } else if (EditMode == TRUE){
195 btnAction->SetLabel(_("Modify"));
196 this->SetTitle(_("Modify Calendar Address"));
198 std::map<int,int>::iterator intiter;
199 std::map<int,wxString>::iterator striter;
202 // Get the organisation name.
204 striter = CalAdrListPtr->find(CalAdrListIndex);
206 if (striter->first == CalAdrListIndex){
208 strValue = striter->second;
212 txtAddress->SetValue(strValue);
218 striter = CalAdrListTypePtr->find(CalAdrListIndex);
220 if (striter->first == CalAdrListIndex &&
221 striter != CalAdrListTypePtr->end()){
223 strValue = striter->second;
227 if (strValue == wxT("home")){
229 cmbType->SetSelection(1);
231 } else if (strValue == wxT("work")){
233 cmbType->SetSelection(2);
237 cmbType->SetSelection(0);
241 // Get the organisation priority.
243 intiter = CalAdrListPrefPtr->find(CalAdrListIndex);
245 if (intiter->first == CalAdrListIndex && intiter->second > 0 &&
246 intiter != CalAdrListPrefPtr->end()){
248 priorityCtrl->SetValue(intiter->second);
249 priorityCtrl->EnablePriority(true);
257 void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event )
266 void frmContactEditorCalAdr::SetupPointers(std::map<int, wxString> *CalAdrList,
267 std::map<int, wxString> *CalAdrListAltID,
268 std::map<int, wxString> *CalAdrListPID,
269 std::map<int, wxString> *CalAdrListType,
270 std::map<int, wxString> *CalAdrListTokens,
271 std::map<int, int> *CalAdrListPref,
272 wxListCtrl *CalAdrListCtrl,
276 // Setup the pointers.
278 CalAdrListPtr = CalAdrList;
279 CalAdrListAltIDPtr = CalAdrListAltID;
280 CalAdrListPIDPtr = CalAdrListPID;
281 CalAdrListTypePtr = CalAdrListType;
282 CalAdrListTokensPtr = CalAdrListTokens;
283 CalAdrListPrefPtr = CalAdrListPref;
284 CalAdrListCtrlPtr = CalAdrListCtrl;
285 CalAdrListIndex = CalAdrIndex;