1 // frmContactEditorGeoposition.cpp - frmContactEditorGeoposition 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 "frmContactEditorGeoposition.h"
21 #include "../common/textprocessing.h"
23 frmContactEditorGeoposition::frmContactEditorGeoposition( wxWindow* parent )
25 frmContactEditorGeopositionADT( parent )
31 sliPriority->Disable();
34 void frmContactEditorGeoposition::EnablePriority( wxCommandEvent& event )
37 // Enable/Disable the priority setting.
39 if (chkUsePref->IsChecked()){
40 sliPriority->Enable();
42 sliPriority->Disable();
47 void frmContactEditorGeoposition::SetEditorMode(bool EditMode, SectionType SectType)
50 // Setup the editor mode.
52 // Set the editor mode for adding or editing a timezone.
54 if (EditMode == FALSE){
57 btnAction->SetLabel(_("Add"));
58 this->SetTitle(_("Add Geoposition"));
60 } else if (EditMode == TRUE){
63 btnAction->SetLabel(_("Modify"));
64 this->SetTitle(_("Modify Geoposition"));
66 std::map<int,int>::iterator intiter;
67 std::map<int,wxString>::iterator striter;
70 // Load the data into the form.
72 striter = GeopositionListPtr->find(GeopositionListIndex);
74 if (striter->first == GeopositionListIndex){
76 strValue = striter->second;
80 txtGeoposition->SetValue(strValue);
84 intiter = GeopositionListPrefPtr->find(GeopositionListIndex);
86 if (intiter->first == GeopositionListIndex && intiter->second > 0 &&
87 intiter != GeopositionListPrefPtr->end()){
89 sliPriority->SetValue(intiter->second);
90 sliPriority->Enable();
91 chkUsePref->SetValue(TRUE);
97 EditSectionType = SectType;
101 void frmContactEditorGeoposition::ProcessAction( wxCommandEvent& event )
108 if (EditorMode == FALSE){
110 // Add the language to the list.
114 strValue = txtGeoposition->GetValue();
118 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, strValue));
122 if (EditSectionType == CE_GENERAL){
124 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("")));
126 } else if (EditSectionType == CE_HOME) {
128 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("home")));
130 } else if (EditSectionType == CE_WORK) {
132 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("work")));
136 // Add Language priority.
138 if (chkUsePref->IsChecked()){
140 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, sliPriority->GetValue()));
144 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));
148 // Add the data to the form.
152 coldata.SetId(GeopositionListIndex);
153 coldata.SetData(GeopositionListIndex);
154 coldata.SetText(txtGeoposition->GetValue());
155 ListCtrlIndex = GeopositionListCtrlPtr->InsertItem(coldata);
157 if (chkUsePref->IsChecked()){
159 GeopositionListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
165 } else if (EditorMode == TRUE){
167 // Edit the language.
171 long longSelected = -1;
173 GeopositionListPtr->erase(GeopositionListIndex);
174 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, txtGeoposition->GetValue()));
176 GeopositionListPrefPtr->erase(GeopositionListIndex);
178 if (chkUsePref->IsChecked()){
180 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, sliPriority->GetValue()));
184 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));
188 longSelected = GeopositionListCtrlPtr->GetNextItem(longSelected,
190 wxLIST_STATE_SELECTED);
192 if (longSelected == -1){
196 GeopositionListCtrlPtr->SetItem(longSelected, 0, txtGeoposition->GetValue());
198 if (chkUsePref->IsChecked()){
200 GeopositionListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
204 GeopositionListCtrlPtr->SetItem(longSelected, 1, wxT(""));
214 void frmContactEditorGeoposition::CloseWindow( wxCommandEvent& event )
217 // Close this window.
223 void frmContactEditorGeoposition::SetupPointers(std::map<int, wxString> *GeopositionList,
224 std::map<int, wxString> *GeopositionListAltID,
225 std::map<int, wxString> *GeopositionListPID,
226 std::map<int, wxString> *GeopositionListType,
227 std::map<int, wxString> *GeopositionListDataType,
228 std::map<int, wxString> *GeopositionListTokens,
229 std::map<int, wxString> *GeopositionListMediatype,
230 std::map<int, int> *GeopositionListPref,
231 wxListCtrl *GeopositionListCtrl,
232 int GeopositionIndex )
235 // Setup the pointers so that the data can be processed without
238 GeopositionListPtr = GeopositionList;
239 GeopositionListAltIDPtr = GeopositionListAltID;
240 GeopositionListPIDPtr = GeopositionListPID;
241 GeopositionListTypePtr = GeopositionListType;
242 GeopositionListDataTypePtr = GeopositionListDataType;
243 GeopositionListTokensPtr = GeopositionListTokens;
244 GeopositionListPrefPtr = GeopositionListPref;
245 GeopositionListCtrlPtr = GeopositionListCtrl;
246 GeopositionListIndex = GeopositionIndex;