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 )
28 sliPriority->Disable();
31 void frmContactEditorGeoposition::EnablePriority( wxCommandEvent& event )
34 if (chkUsePref->IsChecked()){
35 sliPriority->Enable();
37 sliPriority->Disable();
42 void frmContactEditorGeoposition::SetEditorMode(bool EditMode, SectionType SectType)
45 // Set the editor mode for adding or editing a timezone.
47 if (EditMode == FALSE){
50 btnAction->SetLabel(_("Add"));
51 this->SetTitle(_("Add Geoposition"));
53 } else if (EditMode == TRUE){
56 btnAction->SetLabel(_("Modify"));
57 this->SetTitle(_("Modify Geoposition"));
59 std::map<int,int>::iterator intiter;
60 std::map<int,wxString>::iterator striter;
63 // Load the data into the form.
65 striter = GeopositionListPtr->find(GeopositionListIndex);
67 if (striter->first == GeopositionListIndex){
69 strValue = striter->second;
73 txtGeoposition->SetValue(strValue);
77 intiter = GeopositionListPrefPtr->find(GeopositionListIndex);
79 if (intiter->first == GeopositionListIndex && intiter->second > 0){
81 sliPriority->SetValue(intiter->second);
82 sliPriority->Enable();
83 chkUsePref->SetValue(TRUE);
89 EditSectionType = SectType;
93 void frmContactEditorGeoposition::ProcessAction( wxCommandEvent& event )
98 if (EditorMode == FALSE){
100 // Add the language to the list.
104 strValue = txtGeoposition->GetValue();
108 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, strValue));
112 if (EditSectionType == CE_GENERAL){
114 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("")));
116 } else if (EditSectionType == CE_HOME) {
118 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("home")));
120 } else if (EditSectionType == CE_WORK) {
122 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("work")));
126 // Add Language priority.
128 if (chkUsePref->IsChecked()){
130 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, sliPriority->GetValue()));
134 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));
138 // Add the data to the form.
142 coldata.SetId(GeopositionListIndex);
143 coldata.SetData(GeopositionListIndex);
144 coldata.SetText(txtGeoposition->GetValue());
145 ListCtrlIndex = GeopositionListCtrlPtr->InsertItem(coldata);
147 if (chkUsePref->IsChecked()){
149 GeopositionListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
155 } else if (EditorMode == TRUE){
157 // Edit the language.
161 long longSelected = -1;
163 GeopositionListPtr->erase(GeopositionListIndex);
164 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, txtGeoposition->GetValue()));
166 GeopositionListPrefPtr->erase(GeopositionListIndex);
168 if (chkUsePref->IsChecked()){
170 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, sliPriority->GetValue()));
174 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));
178 longSelected = GeopositionListCtrlPtr->GetNextItem(longSelected,
180 wxLIST_STATE_SELECTED);
182 if (longSelected == -1){
186 GeopositionListCtrlPtr->SetItem(longSelected, 0, txtGeoposition->GetValue());
188 if (chkUsePref->IsChecked()){
190 GeopositionListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
194 GeopositionListCtrlPtr->SetItem(longSelected, 1, wxT(""));
204 void frmContactEditorGeoposition::CloseWindow( wxCommandEvent& event )
209 void frmContactEditorGeoposition::SetupPointers(std::map<int, wxString> *GeopositionList,
210 std::map<int, wxString> *GeopositionListAltID,
211 std::map<int, wxString> *GeopositionListPID,
212 std::map<int, wxString> *GeopositionListType,
213 std::map<int, wxString> *GeopositionListTokens,
214 std::map<int, wxString> *GeopositionListMediatype,
215 std::map<int, int> *GeopositionListPref,
216 wxListCtrl *GeopositionListCtrl,
217 int GeopositionIndex )
220 // Setup the pointers so that the data can be processed without
223 GeopositionListPtr = GeopositionList;
224 GeopositionListAltIDPtr = GeopositionListAltID;
225 GeopositionListPIDPtr = GeopositionListPID;
226 GeopositionListTypePtr = GeopositionListType;
227 GeopositionListTokensPtr = GeopositionListTokens;
228 GeopositionListPrefPtr = GeopositionListPref;
229 GeopositionListCtrlPtr = GeopositionListCtrl;
230 GeopositionListIndex = GeopositionIndex;