Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Fixed potential crash with frmContactEditorGeoposition in Edit mode.
[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         EditorMode = FALSE;
28         sliPriority->Disable();
29 }
31 void frmContactEditorGeoposition::EnablePriority( wxCommandEvent& event )
32 {
34         if (chkUsePref->IsChecked()){
35                 sliPriority->Enable();
36         } else {
37                 sliPriority->Disable();
38         }
39         
40 }
42 void frmContactEditorGeoposition::SetEditorMode(bool EditMode, SectionType SectType)
43 {
45         // Set the editor mode for adding or editing a timezone.
47         if (EditMode == FALSE){
48         
49                 EditorMode = FALSE;
50                 btnAction->SetLabel(_("Add"));
51                 this->SetTitle(_("Add Geoposition"));
52         
53         } else if (EditMode == TRUE){
54         
55                 EditorMode = TRUE;
56                 btnAction->SetLabel(_("Modify"));
57                 this->SetTitle(_("Modify Geoposition"));
58         
59                 std::map<int,int>::iterator intiter;
60                 std::map<int,wxString>::iterator striter;
61                 wxString strValue;
62                 
63                 // Load the data into the form.
64                 
65                 striter = GeopositionListPtr->find(GeopositionListIndex);
66                  
67                 if (striter->first == GeopositionListIndex){
68                 
69                         strValue = striter->second;
70                 
71                 }               
72                 
73                 txtGeoposition->SetValue(strValue);
74                 
75                 // Setup the Slider.
76                 
77                 intiter = GeopositionListPrefPtr->find(GeopositionListIndex);
78                 
79                 if (intiter->first == GeopositionListIndex && intiter->second > 0 &&
80                         intiter != GeopositionListPrefPtr->end()){
81                 
82                         sliPriority->SetValue(intiter->second);
83                         sliPriority->Enable();
84                         chkUsePref->SetValue(TRUE);
85                 
86                 }       
87                 
88         }
89         
90         EditSectionType = SectType;
91         
92 }
94 void frmContactEditorGeoposition::ProcessAction( wxCommandEvent& event )
95 {
97         long ListCtrlIndex;
99         if (EditorMode == FALSE){
100         
101                 // Add the language to the list.
103                 wxString strValue;
104                 
105                 strValue = txtGeoposition->GetValue();
106                 
107                 // Add language.
108                 
109                 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, strValue));
110                 
111                 // Add Email type.
112                 
113                 if (EditSectionType == CE_GENERAL){
114                 
115                         GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("")));
116                 
117                 } else if (EditSectionType == CE_HOME) {
118                 
119                         GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("home")));
120                 
121                 } else if (EditSectionType == CE_WORK) {
122                 
123                         GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("work")));
124                 
125                 }
126                 
127                 // Add Language priority.
128                 
129                 if (chkUsePref->IsChecked()){
130                 
131                         GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, sliPriority->GetValue()));
132                 
133                 } else {
134                 
135                         GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));                
136                 
137                 }               
138                 
139                 // Add the data to the form.
140                 
141                 wxListItem coldata;
142                 
143                 coldata.SetId(GeopositionListIndex);
144                 coldata.SetData(GeopositionListIndex);          
145                 coldata.SetText(txtGeoposition->GetValue());
146                 ListCtrlIndex = GeopositionListCtrlPtr->InsertItem(coldata);
147                 
148                 if (chkUsePref->IsChecked()){
149                 
150                         GeopositionListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
151                 
152                 }
153                 
154                 this->Close();          
155         
156         } else if (EditorMode == TRUE){
157         
158                 // Edit the language.
159                 
160                 wxString strAddress;
161                 wxString strValue;
162                 long longSelected = -1;
164                 GeopositionListPtr->erase(GeopositionListIndex);
165                 GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, txtGeoposition->GetValue()));
166                 
167                 GeopositionListPrefPtr->erase(GeopositionListIndex);
168                 
169                 if (chkUsePref->IsChecked()){
170                 
171                         GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, sliPriority->GetValue()));
172                 
173                 } else {
174                 
175                         GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0));                
176                 
177                 }
178                 
179                 longSelected = GeopositionListCtrlPtr->GetNextItem(longSelected, 
180                         wxLIST_NEXT_ALL,
181                         wxLIST_STATE_SELECTED);
182                         
183                 if (longSelected == -1){
184                         return;
185                 }
186                 
187                 GeopositionListCtrlPtr->SetItem(longSelected, 0, txtGeoposition->GetValue());
188                 
189                 if (chkUsePref->IsChecked()){
190                 
191                         GeopositionListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
192                 
193                 } else {
194                 
195                         GeopositionListCtrlPtr->SetItem(longSelected, 1, wxT(""));
196                 
197                 }       
198                         
199                 this->Close();
200         
201         }
205 void frmContactEditorGeoposition::CloseWindow( wxCommandEvent& event )
207         this->Close();
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
223         // duplication.
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;
234         
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