Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor: Stop XAB crashing when pressing Modify/Delete
[xestiaab/.git] / source / contacteditor / frmContactEditorWebsites.cpp
1 // frmContactEditorWebsites.cpp - frmContactEditorWebsites 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 "frmContactEditorWebsites.h"
21 #include <map>
22 #include "../enums.h"
23 #include "../common/textprocessing.h"
25 frmContactEditorWebsites::frmContactEditorWebsites( wxWindow* parent )
26 :
27 frmContactEditorWebsitesADT( parent )
28 {
29         
30         // Setup the window.
31         
32         EditorMode = FALSE;
33         priorityCtrl = new XABPriorityCtrl(tabGeneral);
34         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
35         
36 }
38 void frmContactEditorWebsites::ProcessAction( wxCommandEvent& event )
39 {
40         
41         // Set if the editor is adding or editing an address.
42         // FALSE = Add
43         // TRUE = Edit
45         long ListCtrlIndex;
46         
47         if (EditorMode == FALSE){
48         
49                 wxString strValue;
50                 
51                 // Get the website address.
52                 
53                 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
54                 
55                 // Get the type of website.
56                 
57                 if (EditSectionType == CE_GENERAL){
58                 
59                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("")));
60                 
61                 } else if (EditSectionType == CE_HOME) {
62                 
63                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("home")));
64                 
65                 } else if (EditSectionType == CE_WORK) {
66                 
67                         WebsiteListTypePtr->insert(std::make_pair(WebsiteListIndex, wxT("work")));
68                 
69                 }
70                 
71                 // Add the website priority.
72                 
73                 if (priorityCtrl->IsPriorityChecked()){
74                 
75                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, priorityCtrl->GetValue()));
76                 
77                 } else {
78                 
79                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));                
80                 
81                 }
82                 
83                 // Add to the form.
84                 
85                 wxListItem coldata;
86                 
87                 coldata.SetId(WebsiteListIndex);
88                 coldata.SetData(WebsiteListIndex);              
89                 coldata.SetText(txtWebsite->GetValue());
90                 ListCtrlIndex = WebsiteListCtrlPtr->InsertItem(coldata);
91                 
92                 if (priorityCtrl->IsPriorityChecked()){
93                 
94                         WebsiteListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
95                 
96                 }               
97         
98                 this->Close();          
99         
100         } else {
101         
102                 // Update the website address.
103                 long longSelected = -1;         
104                 wxString strValue;              
105                 WebsiteListPtr->erase(WebsiteListIndex);
106                 WebsiteListPtr->insert(std::make_pair(WebsiteListIndex, txtWebsite->GetValue()));
107                 
108                 // Update the slider priority.
109                 
110                 WebsiteListPrefPtr->erase(WebsiteListIndex);
111                 
112                 if (priorityCtrl->IsPriorityChecked()){
113                 
114                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, priorityCtrl->GetValue()));
115                 
116                 } else {
117                 
118                         WebsiteListPrefPtr->insert(std::make_pair(WebsiteListIndex, 0));
119                 
120                 }               
121                 
122                 // Update the form.
123                 
124                 longSelected = WebsiteListCtrlPtr->GetNextItem(longSelected, 
125                         wxLIST_NEXT_ALL,
126                         wxLIST_STATE_SELECTED);
127                         
128                 if (longSelected == -1){
129                         return;
130                 }               
131                 
132                 WebsiteListCtrlPtr->SetItem(longSelected, 0, txtWebsite->GetValue());
133                 
134                 if (priorityCtrl->IsPriorityChecked()){
135                 
136                         WebsiteListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
137                 
138                 } else {
139                 
140                         WebsiteListCtrlPtr->SetItem(longSelected, 1, wxT(""));
141                 
142                 }               
143         
144                 this->Close();
145         
146         }
147         
150 void frmContactEditorWebsites::SetEditorMode(bool EditMode, SectionType SectType)
152         
153         // Set if the editor is adding or editing an address.
154         // FALSE = Add
155         // TRUE = Edit
156         
157         if (EditMode == FALSE){
158         
159                 EditorMode = FALSE;
160                 btnAction->SetLabel(_("Add"));
161                 this->SetTitle(_("Add Website"));
162         
163         } else if (EditMode == TRUE){
164         
165                 EditorMode = TRUE;
166                 btnAction->SetLabel(_("Modify"));
167                 this->SetTitle(_("Modify Website"));
168                 
169                 std::map<int,int>::iterator intiter;
170                 std::map<int,wxString>::iterator striter;               
171                 wxString strValue;
172                 
173                 // Load the data into the form. Get the website.
174                 
175                 striter = WebsiteListPtr->find(WebsiteListIndex);
176                  
177                 if (striter->first == WebsiteListIndex){
178                 
179                         strValue = striter->second;
180                 
181                 }
182                 
183                 txtWebsite->SetValue(strValue);
184                 
185                 strValue.Clear();
186                 
187                 // Get the website priority.
188                 
189                 intiter = WebsiteListPrefPtr->find(WebsiteListIndex);
190                 
191                 if (intiter->first == WebsiteListIndex && intiter->second > 0 &&
192                         intiter != WebsiteListPrefPtr->end()){
193                 
194                         priorityCtrl->SetValue(intiter->second);
195                         priorityCtrl->EnablePriority(true);
196                 
197                 }               
198                 
199         }
200         
201         EditSectionType = SectType;
202                 
205 void frmContactEditorWebsites::CloseWindow( wxCommandEvent& event )
207         
208         // Close the window.
209         
210         this->Close();
211         
214 void frmContactEditorWebsites::SetupPointers(std::map<int, wxString> *WebsiteList,
215         std::map<int, wxString> *WebsiteListAltID,
216         std::map<int, wxString> *WebsiteListPID,
217         std::map<int, wxString> *WebsiteListType,
218         std::map<int, wxString> *WebsiteListTokens,
219         std::map<int, wxString> *WebsiteListMediatype,
220         std::map<int, int> *WebsiteListPref,
221         wxListCtrl *WebsiteListCtrl,
222         int WebsiteIndex )
225         // Setup the pointers.
226         
227         WebsiteListPtr = WebsiteList;
228         WebsiteListAltIDPtr = WebsiteListAltID;
229         WebsiteListPIDPtr = WebsiteListPID;
230         WebsiteListTypePtr = WebsiteListType;
231         WebsiteListTokensPtr = WebsiteListTokens;
232         WebsiteListMediatypePtr = WebsiteListMediatype;
233         WebsiteListPrefPtr = WebsiteListPref;
234         WebsiteListCtrlPtr = WebsiteListCtrl;
235         WebsiteListIndex = WebsiteIndex;
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