Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor: Stop XAB crashing when pressing Modify/Delete
[xestiaab/.git] / source / contacteditor / frmContactEditorGeoposition.cpp
1 // frmContactEditorGeoposition.cpp - frmContactEditorGeoposition form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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"
20 #include <map>
21 #include "../common/textprocessing.h"
23 frmContactEditorGeoposition::frmContactEditorGeoposition( wxWindow* parent )
24 :
25 frmContactEditorGeopositionADT( parent )
26 {
27         
28         // Setup the window.
29         
30         EditorMode = FALSE;
31         priorityCtrl = new XABPriorityCtrl(tabGeneral);
32         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
33         
34 }
36 void frmContactEditorGeoposition::SetEditorMode(bool EditMode, SectionType SectType)
37 {
39         // Setup the editor mode.
40         
41         // Set the editor mode for adding or editing a timezone.
43         if (EditMode == FALSE){
44         
45                 EditorMode = FALSE;
46                 btnAction->SetLabel(_("Add"));
47                 this->SetTitle(_("Add Geoposition"));
48         
49         } else if (EditMode == TRUE){
50         
51                 EditorMode = TRUE;
52                 btnAction->SetLabel(_("Modify"));
53                 this->SetTitle(_("Modify Geoposition"));
54         
55                 std::map<int,int>::iterator intiter;
56                 std::map<int,wxString>::iterator striter;
57                 wxString strValue;
58                 
59                 // Load the data into the form.
60                 
61                 striter = GeopositionListPtr->find(GeopositionListIndex);
62                  
63                 if (striter->first == GeopositionListIndex){
64                 
65                         strValue = striter->second;
66                 
67                 }               
68                 
69                 txtGeoposition->SetValue(strValue);
70                 
71                 // Setup the Slider.
72                 
73                 intiter = GeopositionListPrefPtr->find(GeopositionListIndex);
74                 
75                 if (intiter->first == GeopositionListIndex && intiter->second > 0 &&
76                         intiter != GeopositionListPrefPtr->end()){
77                 
78                         priorityCtrl->SetValue(intiter->second);
79                         priorityCtrl->EnablePriority(true);
80                 
81                 }       
82                 
83         }
84         
85         EditSectionType = SectType;
86         
87 }
89 void frmContactEditorGeoposition::ProcessAction( wxCommandEvent& event )
90 {
92         // Process action.
93         
94         long ListCtrlIndex;
96         if (EditorMode == FALSE){
97         
98                 // Add the language to the list.
100                 wxString strValue;
101                 
102                 strValue = txtGeoposition->GetValue();
103                 
104                 // Add language.
105                 
106                 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, strValue));
107                 
108                 // Add Email type.
109                 
110                 if (EditSectionType == CE_GENERAL){
111                 
112                         GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("")));
113                 
114                 } else if (EditSectionType == CE_HOME) {
115                 
116                         GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("home")));
117                 
118                 } else if (EditSectionType == CE_WORK) {
119                 
120                         GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("work")));
121                 
122                 }
123                 
124                 // Add Language priority.
125                 
126                 if (priorityCtrl->IsPriorityChecked()){
127                 
128                         GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, priorityCtrl->GetValue()));
129                 
130                 } else {
131                 
132                         GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));                
133                 
134                 }               
135                 
136                 // Add the data to the form.
137                 
138                 wxListItem coldata;
139                 
140                 coldata.SetId(GeopositionListIndex);
141                 coldata.SetData(GeopositionListIndex);          
142                 coldata.SetText(txtGeoposition->GetValue());
143                 ListCtrlIndex = GeopositionListCtrlPtr->InsertItem(coldata);
144                 
145                 if (priorityCtrl->IsPriorityChecked()){
146                 
147                         GeopositionListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
148                 
149                 }
150                 
151                 this->Close();          
152         
153         } else if (EditorMode == TRUE){
154         
155                 // Edit the language.
156                 
157                 wxString strAddress;
158                 wxString strValue;
159                 long longSelected = -1;
161                 GeopositionListPtr->erase(GeopositionListIndex);
162                 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, txtGeoposition->GetValue()));
163                 
164                 GeopositionListPrefPtr->erase(GeopositionListIndex);
165                 
166                 if (priorityCtrl->IsPriorityChecked()){
167                 
168                         GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, priorityCtrl->GetValue()));
169                 
170                 } else {
171                 
172                         GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));                
173                 
174                 }
175                 
176                 longSelected = GeopositionListCtrlPtr->GetNextItem(longSelected, 
177                         wxLIST_NEXT_ALL,
178                         wxLIST_STATE_SELECTED);
179                         
180                 if (longSelected == -1){
181                         return;
182                 }
183                 
184                 GeopositionListCtrlPtr->SetItem(longSelected, 0, txtGeoposition->GetValue());
185                 
186                 if (priorityCtrl->IsPriorityChecked()){
187                 
188                         GeopositionListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
189                 
190                 } else {
191                 
192                         GeopositionListCtrlPtr->SetItem(longSelected, 1, wxT(""));
193                 
194                 }       
195                         
196                 this->Close();
197         
198         }
202 void frmContactEditorGeoposition::CloseWindow( wxCommandEvent& event )
204         
205         // Close this window.
206         
207         this->Close();
208         
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
224         // duplication.
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;
235         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy