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