1 // frmContactEditorEmail.cpp - frmContactEditorEmail form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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"
21 #include "../common/textprocessing.h"
23 frmContactEditorEmail::frmContactEditorEmail( wxWindow* parent )
25 frmContactEditorEmailADT( parent )
28 sliPriority->Disable();
31 void frmContactEditorEmail::EnablePriority( wxCommandEvent& event )
33 if (chkUsePref->IsChecked()){
34 sliPriority->Enable();
36 sliPriority->Disable();
40 void frmContactEditorEmail::ProcessData( wxCommandEvent& event )
44 if (EditorMode == FALSE){
46 // Add the email address to the list.
53 EmailListPtr->insert(std::make_pair(EmailListIndex, txtEmail->GetValue()));
57 if (EditSectionType == CE_GENERAL){
59 EmailListTypePtr->insert(std::make_pair(EmailListIndex, wxT("")));
61 } else if (EditSectionType == CE_HOME) {
63 EmailListTypePtr->insert(std::make_pair(EmailListIndex, wxT("home")));
65 } else if (EditSectionType == CE_WORK) {
67 EmailListTypePtr->insert(std::make_pair(EmailListIndex, wxT("work")));
71 // Add Email priority.
73 if (chkUsePref->IsChecked()){
75 EmailListPrefPtr->insert(std::make_pair(EmailListIndex, sliPriority->GetValue()));
79 EmailListPrefPtr->insert(std::make_pair(EmailListIndex, 0));
83 // Add the data to the form.
87 coldata.SetId(EmailListIndex);
88 coldata.SetData(EmailListIndex);
89 coldata.SetText(txtEmail->GetValue());
90 ListCtrlIndex = EmailListCtrlPtr->InsertItem(coldata);
92 if (chkUsePref->IsChecked()){
94 EmailListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
100 } else if (EditorMode == TRUE){
102 // Edit the email address.
106 long longSelected = -1;
108 EmailListPtr->erase(EmailListIndex);
109 EmailListPtr->insert(std::make_pair(EmailListIndex, txtEmail->GetValue()));
111 EmailListPrefPtr->erase(EmailListIndex);
113 if (chkUsePref->IsChecked()){
115 EmailListPrefPtr->insert(std::make_pair(EmailListIndex, sliPriority->GetValue()));
119 EmailListPrefPtr->insert(std::make_pair(EmailListIndex, 0));
123 longSelected = EmailListCtrlPtr->GetNextItem(longSelected,
125 wxLIST_STATE_SELECTED);
127 if (longSelected == -1){
131 EmailListCtrlPtr->SetItem(longSelected, 0, txtEmail->GetValue());
133 if (chkUsePref->IsChecked()){
135 EmailListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
139 EmailListCtrlPtr->SetItem(longSelected, 1, wxT(""));
149 void frmContactEditorEmail::CloseWindow( wxCommandEvent& event )
154 void frmContactEditorEmail::SetEditorMode(bool EditMode, SectionType SectType)
157 // Set the editor mode for adding or editing an email address.
159 if (EditMode == FALSE){
162 btnAction->SetLabel(_("Add"));
163 this->SetTitle(_("Add Email"));
165 } else if (EditMode == TRUE){
168 btnAction->SetLabel(_("Modify"));
169 this->SetTitle(_("Modify Email"));
171 std::map<int,int>::iterator intiter;
172 std::map<int,wxString>::iterator striter;
175 // Load the data into the form.
177 striter = EmailListPtr->find(EmailListIndex);
179 if (striter->first == EmailListIndex){
181 strValue = striter->second;
185 txtEmail->SetValue(strValue);
189 intiter = EmailListPrefPtr->find(EmailListIndex);
191 if (intiter->first == EmailListIndex && intiter->second > 0 &&
192 intiter != EmailListPrefPtr->end()){
194 sliPriority->SetValue(intiter->second);
195 sliPriority->Enable();
196 chkUsePref->SetValue(TRUE);
202 EditSectionType = SectType;
206 void frmContactEditorEmail::SetupPointers(std::map<int, wxString> *EmailList,
207 std::map<int, wxString> *EmailListAltID,
208 std::map<int, wxString> *EmailListPID,
209 std::map<int, wxString> *EmailListType,
210 std::map<int, wxString> *EmailListTokens,
211 std::map<int, int> *EmailListPref,
212 wxListCtrl *EmailListCtrl,
216 // Setup the pointers so that the data can be processed without
219 EmailListPtr = EmailList;
220 EmailListAltIDPtr = EmailListAltID;
221 EmailListPIDPtr = EmailListPID;
222 EmailListTypePtr = EmailListType;
223 EmailListTokensPtr = EmailListTokens;
224 EmailListPrefPtr = EmailListPref;
225 EmailListCtrlPtr = EmailListCtrl;
226 EmailListIndex = EmailIndex;