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 priorityCtrl = new XABPriorityCtrl(tabGeneral);
32 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
37 void frmContactEditorGeoposition::SetEditorMode(bool EditMode, SectionType SectType)
40 // Setup the editor mode.
42 // Set the editor mode for adding or editing a timezone.
44 if (EditMode == FALSE){
47 btnAction->SetLabel(_("Add"));
48 this->SetTitle(_("Add Geoposition"));
50 } else if (EditMode == TRUE){
53 btnAction->SetLabel(_("Modify"));
54 this->SetTitle(_("Modify Geoposition"));
56 std::map<int,int>::iterator intiter;
57 std::map<int,wxString>::iterator striter;
60 // Load the data into the form.
62 striter = GeopositionListPtr->find(GeopositionListIndex);
64 if (striter->first == GeopositionListIndex){
66 strValue = striter->second;
70 txtGeoposition->SetValue(strValue);
74 intiter = GeopositionListPrefPtr->find(GeopositionListIndex);
76 if (intiter->first == GeopositionListIndex && intiter->second > 0 &&
77 intiter != GeopositionListPrefPtr->end()){
79 priorityCtrl->SetValue(intiter->second);
80 priorityCtrl->EnablePriority(true);
86 EditSectionType = SectType;
90 void frmContactEditorGeoposition::ProcessAction( wxCommandEvent& event )
97 if (EditorMode == FALSE){
99 // Add the language to the list.
103 strValue = txtGeoposition->GetValue();
107 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, strValue));
111 if (EditSectionType == CE_GENERAL){
113 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("")));
115 } else if (EditSectionType == CE_HOME) {
117 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("home")));
119 } else if (EditSectionType == CE_WORK) {
121 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("work")));
125 // Add Language priority.
127 if (priorityCtrl->IsPriorityChecked()){
129 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, priorityCtrl->GetValue()));
133 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));
137 // Add the data to the form.
141 coldata.SetId(GeopositionListIndex);
142 coldata.SetData(GeopositionListIndex);
143 coldata.SetText(txtGeoposition->GetValue());
144 ListCtrlIndex = GeopositionListCtrlPtr->InsertItem(coldata);
146 if (priorityCtrl->IsPriorityChecked()){
148 GeopositionListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
154 } else if (EditorMode == TRUE){
156 // Edit the language.
160 long longSelected = -1;
162 GeopositionListPtr->erase(GeopositionListIndex);
163 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, txtGeoposition->GetValue()));
165 GeopositionListPrefPtr->erase(GeopositionListIndex);
167 if (priorityCtrl->IsPriorityChecked()){
169 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, priorityCtrl->GetValue()));
173 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));
177 longSelected = GeopositionListCtrlPtr->GetNextItem(longSelected,
179 wxLIST_STATE_SELECTED);
181 if (longSelected == -1){
185 GeopositionListCtrlPtr->SetItem(longSelected, 0, txtGeoposition->GetValue());
187 if (priorityCtrl->IsPriorityChecked()){
189 GeopositionListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
193 GeopositionListCtrlPtr->SetItem(longSelected, 1, wxT(""));
203 void frmContactEditorGeoposition::CloseWindow( wxCommandEvent& event )
206 // Close this window.
212 void frmContactEditorGeoposition::SetupPointers(std::map<int, wxString> *GeopositionList,
213 std::map<int, wxString> *GeopositionListAltID,
214 std::map<int, wxString> *GeopositionListPID,
215 std::map<int, wxString> *GeopositionListType,
216 std::map<int, wxString> *GeopositionListDataType,
217 std::map<int, wxString> *GeopositionListTokens,
218 std::map<int, wxString> *GeopositionListMediatype,
219 std::map<int, int> *GeopositionListPref,
220 wxListCtrl *GeopositionListCtrl,
221 int GeopositionIndex )
224 // Setup the pointers so that the data can be processed without
227 GeopositionListPtr = GeopositionList;
228 GeopositionListAltIDPtr = GeopositionListAltID;
229 GeopositionListPIDPtr = GeopositionListPID;
230 GeopositionListTypePtr = GeopositionListType;
231 GeopositionListDataTypePtr = GeopositionListDataType;
232 GeopositionListTokensPtr = GeopositionListTokens;
233 GeopositionListPrefPtr = GeopositionListPref;
234 GeopositionListCtrlPtr = GeopositionListCtrl;
235 GeopositionListIndex = GeopositionIndex;