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 &&
80 intiter != GeopositionListPrefPtr->end()){
82 sliPriority->SetValue(intiter->second);
83 sliPriority->Enable();
84 chkUsePref->SetValue(TRUE);
90 EditSectionType = SectType;
94 void frmContactEditorGeoposition::ProcessAction( wxCommandEvent& event )
99 if (EditorMode == FALSE){
101 // Add the language to the list.
105 strValue = txtGeoposition->GetValue();
109 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, strValue));
113 if (EditSectionType == CE_GENERAL){
115 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("")));
117 } else if (EditSectionType == CE_HOME) {
119 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("home")));
121 } else if (EditSectionType == CE_WORK) {
123 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("work")));
127 // Add Language priority.
129 if (chkUsePref->IsChecked()){
131 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, sliPriority->GetValue()));
135 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));
139 // Add the data to the form.
143 coldata.SetId(GeopositionListIndex);
144 coldata.SetData(GeopositionListIndex);
145 coldata.SetText(txtGeoposition->GetValue());
146 ListCtrlIndex = GeopositionListCtrlPtr->InsertItem(coldata);
148 if (chkUsePref->IsChecked()){
150 GeopositionListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
156 } else if (EditorMode == TRUE){
158 // Edit the language.
162 long longSelected = -1;
164 GeopositionListPtr->erase(GeopositionListIndex);
165 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, txtGeoposition->GetValue()));
167 GeopositionListPrefPtr->erase(GeopositionListIndex);
169 if (chkUsePref->IsChecked()){
171 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, sliPriority->GetValue()));
175 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));
179 longSelected = GeopositionListCtrlPtr->GetNextItem(longSelected,
181 wxLIST_STATE_SELECTED);
183 if (longSelected == -1){
187 GeopositionListCtrlPtr->SetItem(longSelected, 0, txtGeoposition->GetValue());
189 if (chkUsePref->IsChecked()){
191 GeopositionListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
195 GeopositionListCtrlPtr->SetItem(longSelected, 1, wxT(""));
205 void frmContactEditorGeoposition::CloseWindow( wxCommandEvent& event )
210 void frmContactEditorGeoposition::SetupPointers(std::map<int, wxString> *GeopositionList,
211 std::map<int, wxString> *GeopositionListAltID,
212 std::map<int, wxString> *GeopositionListPID,
213 std::map<int, wxString> *GeopositionListType,
214 std::map<int, wxString> *GeopositionListDataType,
215 std::map<int, wxString> *GeopositionListTokens,
216 std::map<int, wxString> *GeopositionListMediatype,
217 std::map<int, int> *GeopositionListPref,
218 wxListCtrl *GeopositionListCtrl,
219 int GeopositionIndex )
222 // Setup the pointers so that the data can be processed without
225 GeopositionListPtr = GeopositionList;
226 GeopositionListAltIDPtr = GeopositionListAltID;
227 GeopositionListPIDPtr = GeopositionListPID;
228 GeopositionListTypePtr = GeopositionListType;
229 GeopositionListDataTypePtr = GeopositionListDataType;
230 GeopositionListTokensPtr = GeopositionListTokens;
231 GeopositionListPrefPtr = GeopositionListPref;
232 GeopositionListCtrlPtr = GeopositionListCtrl;
233 GeopositionListIndex = GeopositionIndex;