1 #include "frmContactEditorCalAdr.h"
2 #include <wx/tokenzr.h>
3 #include "../common/textprocessing.h"
5 frmContactEditorCalAdr::frmContactEditorCalAdr( wxWindow* parent )
7 frmContactEditorCalAdrADT( parent )
10 sliPriority->Disable();
12 cmbType->Append(wxT(""));
13 cmbType->Append(_("Home"));
14 cmbType->Append(_("Work"));
17 void frmContactEditorCalAdr::EnablePriority( wxCommandEvent& event )
19 if (chkUsePref->IsChecked()){
20 sliPriority->Enable();
22 sliPriority->Disable();
26 void frmContactEditorCalAdr::ProcessAction( wxCommandEvent& event )
30 if (EditorMode == FALSE){
34 // Setup Calendar Address.
36 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
40 strValue = cmbType->GetString(cmbType->GetSelection());
42 // Setup Calendar Type.
44 if (strValue == _("Home")) {
46 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
48 } else if (strValue == _("Work")) {
50 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
54 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("")));
58 // Setup Calendar Priority.
60 if (chkUsePref->IsChecked()){
62 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
66 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
74 coldata.SetId(CalAdrListIndex);
75 coldata.SetData(CalAdrListIndex);
76 coldata.SetText(txtAddress->GetValue());
77 ListCtrlIndex = CalAdrListCtrlPtr->InsertItem(coldata);
79 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);
81 if (chkUsePref->IsChecked()){
83 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
89 } else if (EditorMode == TRUE) {
91 long longSelected = -1;
94 // Update Category Name.
96 CalAdrListPtr->erase(CalAdrListIndex);
97 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
99 // Update Category Type.
101 CalAdrListTypePtr->erase(CalAdrListIndex);
104 strValue = cmbType->GetString(cmbType->GetSelection());
106 if (strValue == _("Home")) {
108 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
110 } else if (strValue == _("Work")) {
112 CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
116 // Update Category Priority.
118 CalAdrListPrefPtr->erase(CalAdrListIndex);
120 if (chkUsePref->IsChecked()){
122 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, sliPriority->GetValue()));
126 CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
132 longSelected = CalAdrListCtrlPtr->GetNextItem(longSelected,
134 wxLIST_STATE_SELECTED);
136 if (longSelected == -1){
140 CalAdrListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
141 CalAdrListCtrlPtr->SetItem(longSelected, 1, strValue);
143 if (chkUsePref->IsChecked()){
145 CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
149 CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT(""));
158 void frmContactEditorCalAdr::SetEditorMode(bool EditMode)
160 // Set if the editor is adding or editing an address.
164 if (EditMode == FALSE){
167 btnAction->SetLabel(_("Add"));
168 this->SetTitle(_("Add Calendar Address"));
170 } else if (EditMode == TRUE){
173 btnAction->SetLabel(_("Modify"));
174 this->SetTitle(_("Modify Calendar Address"));
176 std::map<int,int>::iterator intiter;
177 std::map<int,wxString>::iterator striter;
180 // Get the organisation name.
182 striter = CalAdrListPtr->find(CalAdrListIndex);
184 if (striter->first == CalAdrListIndex){
186 strValue = striter->second;
190 txtAddress->SetValue(strValue);
196 striter = CalAdrListTypePtr->find(CalAdrListIndex);
198 if (striter->first == CalAdrListIndex){
200 strValue = striter->second;
204 if (strValue == wxT("home")){
206 cmbType->SetSelection(1);
208 } else if (strValue == wxT("work")){
210 cmbType->SetSelection(2);
214 cmbType->SetSelection(0);
218 // Get the organisation priority.
220 intiter = CalAdrListPrefPtr->find(CalAdrListIndex);
222 if (intiter->first == CalAdrListIndex && intiter->second > 0){
224 sliPriority->SetValue(intiter->second);
225 sliPriority->Enable();
226 chkUsePref->SetValue(TRUE);
234 void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event )
239 void frmContactEditorCalAdr::SetupPointers(std::map<int, wxString> *CalAdrList,
240 std::map<int, wxString> *CalAdrListAltID,
241 std::map<int, wxString> *CalAdrListPID,
242 std::map<int, wxString> *CalAdrListType,
243 std::map<int, wxString> *CalAdrListTokens,
244 std::map<int, int> *CalAdrListPref,
245 wxListCtrl *CalAdrListCtrl,
249 CalAdrListPtr = CalAdrList;
250 CalAdrListAltIDPtr = CalAdrListAltID;
251 CalAdrListPIDPtr = CalAdrListPID;
252 CalAdrListTypePtr = CalAdrListType;
253 CalAdrListTokensPtr = CalAdrListTokens;
254 CalAdrListPrefPtr = CalAdrListPref;
255 CalAdrListCtrlPtr = CalAdrListCtrl;
256 CalAdrListIndex = CalAdrIndex;