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);
34 cmbType->Append(wxT(""));
35 cmbType->Append(_("Home"));
36 cmbType->Append(_("Work"));
40 void frmContactEditorCalAdr::ProcessAction( wxCommandEvent& event )
47 if (EditorMode == FALSE){
51 // Setup Calendar Address.
53 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
57 strValue = cmbType->GetString(cmbType->GetSelection());
59 // Setup Calendar Type.
61 if (strValue == _("Home")) {
63 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
65 } else if (strValue == _("Work")) {
67 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
71 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("")));
75 // Setup Calendar Priority.
77 if (priorityCtrl->IsPriorityChecked()){
79 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, priorityCtrl->GetValue()));
83 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
91 coldata.SetId(CalAdrListIndex);
92 coldata.SetData(CalAdrListIndex);
93 coldata.SetText(txtAddress->GetValue());
94 ListCtrlIndex = CalAdrListCtrlPtr->InsertItem(coldata);
96 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);
98 if (priorityCtrl->IsPriorityChecked()){
100 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
106 } else if (EditorMode == TRUE) {
108 long longSelected = -1;
111 // Update Category Name.
113 CalAdrListPtr->erase(CalAdrListIndex);
114 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
116 // Update Category Type.
118 CalAdrListTypePtr->erase(CalAdrListIndex);
121 strValue = cmbType->GetString(cmbType->GetSelection());
123 if (strValue == _("Home")) {
125 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
127 } else if (strValue == _("Work")) {
129 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
133 // Update Category Priority.
135 CalAdrListPrefPtr->erase(CalAdrListIndex);
137 if (priorityCtrl->IsPriorityChecked()){
139 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, priorityCtrl->GetValue()));
143 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
149 longSelected = CalAdrListCtrlPtr->GetNextItem(longSelected,
151 wxLIST_STATE_SELECTED);
153 if (longSelected == -1){
157 CalAdrListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
158 CalAdrListCtrlPtr->SetItem(longSelected, 1, strValue);
160 if (priorityCtrl->IsPriorityChecked()){
162 CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
166 CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT(""));
176 void frmContactEditorCalAdr::SetEditorMode(bool EditMode)
179 // Set the editor mode.
181 // Set if the editor is adding or editing an address.
185 if (EditMode == FALSE){
188 btnAction->SetLabel(_("Add"));
189 this->SetTitle(_("Add Calendar Address"));
191 } else if (EditMode == TRUE){
194 btnAction->SetLabel(_("Modify"));
195 this->SetTitle(_("Modify Calendar Address"));
197 std::map<int,int>::iterator intiter;
198 std::map<int,wxString>::iterator striter;
201 // Get the organisation name.
203 striter = CalAdrListPtr->find(CalAdrListIndex);
205 if (striter->first == CalAdrListIndex){
207 strValue = striter->second;
211 txtAddress->SetValue(strValue);
217 striter = CalAdrListTypePtr->find(CalAdrListIndex);
219 if (striter->first == CalAdrListIndex &&
220 striter != CalAdrListTypePtr->end()){
222 strValue = striter->second;
226 if (strValue == wxT("home")){
228 cmbType->SetSelection(1);
230 } else if (strValue == wxT("work")){
232 cmbType->SetSelection(2);
236 cmbType->SetSelection(0);
240 // Get the organisation priority.
242 intiter = CalAdrListPrefPtr->find(CalAdrListIndex);
244 if (intiter->first == CalAdrListIndex && intiter->second > 0 &&
245 intiter != CalAdrListPrefPtr->end()){
247 priorityCtrl->SetValue(intiter->second);
248 priorityCtrl->EnablePriority(true);
256 void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event )
265 void frmContactEditorCalAdr::SetupPointers(std::map<int, wxString> *CalAdrList,
266 std::map<int, wxString> *CalAdrListAltID,
267 std::map<int, wxString> *CalAdrListPID,
268 std::map<int, wxString> *CalAdrListType,
269 std::map<int, wxString> *CalAdrListTokens,
270 std::map<int, int> *CalAdrListPref,
271 wxListCtrl *CalAdrListCtrl,
275 // Setup the pointers.
277 CalAdrListPtr = CalAdrList;
278 CalAdrListAltIDPtr = CalAdrListAltID;
279 CalAdrListPIDPtr = CalAdrListPID;
280 CalAdrListTypePtr = CalAdrListType;
281 CalAdrListTokensPtr = CalAdrListTokens;
282 CalAdrListPrefPtr = CalAdrListPref;
283 CalAdrListCtrlPtr = CalAdrListCtrl;
284 CalAdrListIndex = CalAdrIndex;