Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor: Stop XAB crashing when pressing Modify/Delete
[xestiaab/.git] / source / contacteditor / frmContactEditorEmail.cpp
1 // frmContactEditorEmail.cpp - frmContactEditorEmail 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 "frmContactEditorEmail.h"
20 #include <map>
21 #include "../common/textprocessing.h"
23 frmContactEditorEmail::frmContactEditorEmail( wxWindow* parent )
24 :
25 frmContactEditorEmailADT( 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 frmContactEditorEmail::ProcessData( wxCommandEvent& event )
37 {
38         
39         // Process action.
40         
41         long ListCtrlIndex;
42         
43         if (EditorMode == FALSE){
44         
45                 // Add the email address to the list.
46         
47                 wxString strAddress;
48                 wxString strValue;
49                 
50                 // Add Email address.
51                 
52                 EmailListPtr->insert(std::make_pair(EmailListIndex, txtEmail->GetValue()));
53                 
54                 // Add Email type.
55                 
56                 if (EditSectionType == CE_GENERAL){
57                 
58                         EmailListTypePtr->insert(std::make_pair(EmailListIndex, wxT("")));
59                 
60                 } else if (EditSectionType == CE_HOME) {
61                 
62                         EmailListTypePtr->insert(std::make_pair(EmailListIndex, wxT("home")));
63                 
64                 } else if (EditSectionType == CE_WORK) {
65                 
66                         EmailListTypePtr->insert(std::make_pair(EmailListIndex, wxT("work")));
67                 
68                 }
69                 
70                 // Add Email priority.
71                 
72                 if (priorityCtrl->IsPriorityChecked()){
73                 
74                         EmailListPrefPtr->insert(std::make_pair(EmailListIndex, priorityCtrl->GetValue()));
75                 
76                 } else {
77                 
78                         EmailListPrefPtr->insert(std::make_pair(EmailListIndex, 0));            
79                 
80                 }               
81                 
82                 // Add the data to the form.
83                 
84                 wxListItem coldata;
85                 
86                 coldata.SetId(EmailListIndex);
87                 coldata.SetData(EmailListIndex);                
88                 coldata.SetText(txtEmail->GetValue());
89                 ListCtrlIndex = EmailListCtrlPtr->InsertItem(coldata);
90                 
91                 if (priorityCtrl->IsPriorityChecked()){
92                 
93                         EmailListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
94                 
95                 }
96                 
97                 this->Close();
98         
99         } else if (EditorMode == TRUE){
100         
101                 // Edit the email address.
102                 
103                 wxString strAddress;
104                 wxString strValue;
105                 long longSelected = -1;
107                 EmailListPtr->erase(EmailListIndex);
108                 EmailListPtr->insert(std::make_pair(EmailListIndex, txtEmail->GetValue()));
109                 
110                 EmailListPrefPtr->erase(EmailListIndex);
111                 
112                 if (priorityCtrl->IsPriorityChecked()){
113                 
114                         EmailListPrefPtr->insert(std::make_pair(EmailListIndex, priorityCtrl->GetValue()));
115                 
116                 } else {
117                 
118                         EmailListPrefPtr->insert(std::make_pair(EmailListIndex, 0));            
119                 
120                 }
121                 
122                 longSelected = EmailListCtrlPtr->GetNextItem(longSelected, 
123                         wxLIST_NEXT_ALL,
124                         wxLIST_STATE_SELECTED);
125                         
126                 if (longSelected == -1){
127                         return;
128                 }
129                 
130                 EmailListCtrlPtr->SetItem(longSelected, 0, txtEmail->GetValue());               
131                 
132                 if (priorityCtrl->IsPriorityChecked()){
133                 
134                         EmailListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
135                 
136                 } else {
137                 
138                         EmailListCtrlPtr->SetItem(longSelected, 1, wxT(""));
139                 
140                 }       
141                         
142                 this->Close();  
143         
144         }       
145         
148 void frmContactEditorEmail::CloseWindow( wxCommandEvent& event )
150         
151         // Close this window.
152         
153         this->Close();
154         
157 void frmContactEditorEmail::SetEditorMode(bool EditMode, SectionType SectType)
160         // Set the editor mode.
161         
162         // Set the editor mode for adding or editing an email address.
164         if (EditMode == FALSE){
165         
166                 EditorMode = FALSE;
167                 btnAction->SetLabel(_("Add"));
168                 this->SetTitle(_("Add Email"));
169         
170         } else if (EditMode == TRUE){
171         
172                 EditorMode = TRUE;
173                 btnAction->SetLabel(_("Modify"));
174                 this->SetTitle(_("Modify Email"));
175         
176                 std::map<int,int>::iterator intiter;
177                 std::map<int,wxString>::iterator striter;
178                 wxString strValue;
179                 
180                 // Load the data into the form.
181                 
182                 striter = EmailListPtr->find(EmailListIndex);
183                  
184                 if (striter->first == EmailListIndex){
185                 
186                         strValue = striter->second;
187                 
188                 }
189                 
190                 txtEmail->SetValue(strValue);
191                 
192                 // Setup the Slider.
193                 
194                 intiter = EmailListPrefPtr->find(EmailListIndex);
195                 
196                 if (intiter->first == EmailListIndex && intiter->second > 0 &&
197                         intiter != EmailListPrefPtr->end()){
198                 
199                         priorityCtrl->SetValue(intiter->second);
200                         priorityCtrl->EnablePriority(true);
201                 
202                 }
203                 
204         }
205         
206         EditSectionType = SectType;
207         
210 void frmContactEditorEmail::SetupPointers(std::map<int, wxString> *EmailList,
211         std::map<int, wxString> *EmailListAltID,
212         std::map<int, wxString> *EmailListPID,
213         std::map<int, wxString> *EmailListType,
214         std::map<int, wxString> *EmailListTokens,
215         std::map<int, int> *EmailListPref,
216         wxListCtrl *EmailListCtrl,
217         int EmailIndex )
220         // Setup the pointers so that the data can be processed without
221         // duplication.
223         EmailListPtr = EmailList;
224         EmailListAltIDPtr = EmailListAltID;
225         EmailListPIDPtr = EmailListPID;
226         EmailListTypePtr = EmailListType;
227         EmailListTokensPtr = EmailListTokens;
228         EmailListPrefPtr = EmailListPref;
229         EmailListCtrlPtr = EmailListCtrl;
230         EmailListIndex = EmailIndex;
231         
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