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);
36 void frmContactEditorGeoposition::SetEditorMode(bool EditMode, SectionType SectType)
39 // Setup the editor mode.
41 // Set the editor mode for adding or editing a timezone.
43 if (EditMode == FALSE){
46 btnAction->SetLabel(_("Add"));
47 this->SetTitle(_("Add Geoposition"));
49 } else if (EditMode == TRUE){
52 btnAction->SetLabel(_("Modify"));
53 this->SetTitle(_("Modify Geoposition"));
55 std::map<int,int>::iterator intiter;
56 std::map<int,wxString>::iterator striter;
59 // Load the data into the form.
61 striter = GeopositionListPtr->find(GeopositionListIndex);
63 if (striter->first == GeopositionListIndex){
65 strValue = striter->second;
69 txtGeoposition->SetValue(strValue);
73 intiter = GeopositionListPrefPtr->find(GeopositionListIndex);
75 if (intiter->first == GeopositionListIndex && intiter->second > 0 &&
76 intiter != GeopositionListPrefPtr->end()){
78 priorityCtrl->SetValue(intiter->second);
79 priorityCtrl->EnablePriority(true);
85 EditSectionType = SectType;
89 void frmContactEditorGeoposition::ProcessAction( wxCommandEvent& event )
96 if (EditorMode == FALSE){
98 // Add the language to the list.
102 strValue = txtGeoposition->GetValue();
106 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, strValue));
110 if (EditSectionType == CE_GENERAL){
112 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("")));
114 } else if (EditSectionType == CE_HOME) {
116 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("home")));
118 } else if (EditSectionType == CE_WORK) {
120 GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("work")));
124 // Add Language priority.
126 if (priorityCtrl->IsPriorityChecked()){
128 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, priorityCtrl->GetValue()));
132 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));
136 // Add the data to the form.
140 coldata.SetId(GeopositionListIndex);
141 coldata.SetData(GeopositionListIndex);
142 coldata.SetText(txtGeoposition->GetValue());
143 ListCtrlIndex = GeopositionListCtrlPtr->InsertItem(coldata);
145 if (priorityCtrl->IsPriorityChecked()){
147 GeopositionListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
153 } else if (EditorMode == TRUE){
155 // Edit the language.
159 long longSelected = -1;
161 GeopositionListPtr->erase(GeopositionListIndex);
162 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, txtGeoposition->GetValue()));
164 GeopositionListPrefPtr->erase(GeopositionListIndex);
166 if (priorityCtrl->IsPriorityChecked()){
168 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, priorityCtrl->GetValue()));
172 GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));
176 longSelected = GeopositionListCtrlPtr->GetNextItem(longSelected,
178 wxLIST_STATE_SELECTED);
180 if (longSelected == -1){
184 GeopositionListCtrlPtr->SetItem(longSelected, 0, txtGeoposition->GetValue());
186 if (priorityCtrl->IsPriorityChecked()){
188 GeopositionListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
192 GeopositionListCtrlPtr->SetItem(longSelected, 1, wxT(""));
202 void frmContactEditorGeoposition::CloseWindow( wxCommandEvent& event )
205 // Close this window.
211 void frmContactEditorGeoposition::SetupPointers(std::map<int, wxString> *GeopositionList,
212 std::map<int, wxString> *GeopositionListAltID,
213 std::map<int, wxString> *GeopositionListPID,
214 std::map<int, wxString> *GeopositionListType,
215 std::map<int, wxString> *GeopositionListDataType,
216 std::map<int, wxString> *GeopositionListTokens,
217 std::map<int, wxString> *GeopositionListMediatype,
218 std::map<int, int> *GeopositionListPref,
219 wxListCtrl *GeopositionListCtrl,
220 int GeopositionIndex )
223 // Setup the pointers so that the data can be processed without
226 GeopositionListPtr = GeopositionList;
227 GeopositionListAltIDPtr = GeopositionListAltID;
228 GeopositionListPIDPtr = GeopositionListPID;
229 GeopositionListTypePtr = GeopositionListType;
230 GeopositionListDataTypePtr = GeopositionListDataType;
231 GeopositionListTokensPtr = GeopositionListTokens;
232 GeopositionListPrefPtr = GeopositionListPref;
233 GeopositionListCtrlPtr = GeopositionListCtrl;
234 GeopositionListIndex = GeopositionIndex;