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 sliPriority->Disable();
33 cmbType->Append(wxT(""));
34 cmbType->Append(_("Home"));
35 cmbType->Append(_("Work"));
39 void frmContactEditorCalAdr::EnablePriority( wxCommandEvent& event )
42 // Enable/disable the priority setting.
44 if (chkUsePref->IsChecked()){
45 sliPriority->Enable();
47 sliPriority->Disable();
52 void frmContactEditorCalAdr::ProcessAction( wxCommandEvent& event )
59 if (EditorMode == FALSE){
63 // Setup Calendar Address.
65 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
69 strValue = cmbType->GetString(cmbType->GetSelection());
71 // Setup Calendar Type.
73 if (strValue == _("Home")) {
75 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
77 } else if (strValue == _("Work")) {
79 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
83 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("")));
87 // Setup Calendar Priority.
89 if (chkUsePref->IsChecked()){
91 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
95 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
103 coldata.SetId(CalAdrListIndex);
104 coldata.SetData(CalAdrListIndex);
105 coldata.SetText(txtAddress->GetValue());
106 ListCtrlIndex = CalAdrListCtrlPtr->InsertItem(coldata);
108 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);
110 if (chkUsePref->IsChecked()){
112 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
118 } else if (EditorMode == TRUE) {
120 long longSelected = -1;
123 // Update Category Name.
125 CalAdrListPtr->erase(CalAdrListIndex);
126 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
128 // Update Category Type.
130 CalAdrListTypePtr->erase(CalAdrListIndex);
133 strValue = cmbType->GetString(cmbType->GetSelection());
135 if (strValue == _("Home")) {
137 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
139 } else if (strValue == _("Work")) {
141 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
145 // Update Category Priority.
147 CalAdrListPrefPtr->erase(CalAdrListIndex);
149 if (chkUsePref->IsChecked()){
151 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
155 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
161 longSelected = CalAdrListCtrlPtr->GetNextItem(longSelected,
163 wxLIST_STATE_SELECTED);
165 if (longSelected == -1){
169 CalAdrListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
170 CalAdrListCtrlPtr->SetItem(longSelected, 1, strValue);
172 if (chkUsePref->IsChecked()){
174 CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
178 CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT(""));
188 void frmContactEditorCalAdr::SetEditorMode(bool EditMode)
191 // Set the editor mode.
193 // Set if the editor is adding or editing an address.
197 if (EditMode == FALSE){
200 btnAction->SetLabel(_("Add"));
201 this->SetTitle(_("Add Calendar Address"));
203 } else if (EditMode == TRUE){
206 btnAction->SetLabel(_("Modify"));
207 this->SetTitle(_("Modify Calendar Address"));
209 std::map<int,int>::iterator intiter;
210 std::map<int,wxString>::iterator striter;
213 // Get the organisation name.
215 striter = CalAdrListPtr->find(CalAdrListIndex);
217 if (striter->first == CalAdrListIndex){
219 strValue = striter->second;
223 txtAddress->SetValue(strValue);
229 striter = CalAdrListTypePtr->find(CalAdrListIndex);
231 if (striter->first == CalAdrListIndex &&
232 striter != CalAdrListTypePtr->end()){
234 strValue = striter->second;
238 if (strValue == wxT("home")){
240 cmbType->SetSelection(1);
242 } else if (strValue == wxT("work")){
244 cmbType->SetSelection(2);
248 cmbType->SetSelection(0);
252 // Get the organisation priority.
254 intiter = CalAdrListPrefPtr->find(CalAdrListIndex);
256 if (intiter->first == CalAdrListIndex && intiter->second > 0 &&
257 intiter != CalAdrListPrefPtr->end()){
259 sliPriority->SetValue(intiter->second);
260 sliPriority->Enable();
261 chkUsePref->SetValue(TRUE);
269 void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event )
278 void frmContactEditorCalAdr::SetupPointers(std::map<int, wxString> *CalAdrList,
279 std::map<int, wxString> *CalAdrListAltID,
280 std::map<int, wxString> *CalAdrListPID,
281 std::map<int, wxString> *CalAdrListType,
282 std::map<int, wxString> *CalAdrListTokens,
283 std::map<int, int> *CalAdrListPref,
284 wxListCtrl *CalAdrListCtrl,
288 // Setup the pointers.
290 CalAdrListPtr = CalAdrList;
291 CalAdrListAltIDPtr = CalAdrListAltID;
292 CalAdrListPIDPtr = CalAdrListPID;
293 CalAdrListTypePtr = CalAdrListType;
294 CalAdrListTokensPtr = CalAdrListTokens;
295 CalAdrListPrefPtr = CalAdrListPref;
296 CalAdrListCtrlPtr = CalAdrListCtrl;
297 CalAdrListIndex = CalAdrIndex;