// frmContactEditorEmail.cpp - frmContactEditorEmail form. // // (c) 2012-2015 Xestia Software Development. // // This file is part of Xestia Address Book. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see #include "frmContactEditorEmail.h" #include #include "../common/textprocessing.h" frmContactEditorEmail::frmContactEditorEmail( wxWindow* parent ) : frmContactEditorEmailADT( parent ) { // Setup the window. EditorMode = FALSE; priorityCtrl = new XABPriorityCtrl(tabGeneral); szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5); szrGeneral->Layout(); } void frmContactEditorEmail::ProcessData( wxCommandEvent& event ) { // Process action. long ListCtrlIndex; if (EditorMode == FALSE){ // Add the email address to the list. wxString strAddress; wxString strValue; // Add Email address. EmailListPtr->insert(std::make_pair(EmailListIndex, txtEmail->GetValue())); // Add Email type. if (EditSectionType == CE_GENERAL){ EmailListTypePtr->insert(std::make_pair(EmailListIndex, wxT(""))); } else if (EditSectionType == CE_HOME) { EmailListTypePtr->insert(std::make_pair(EmailListIndex, wxT("home"))); } else if (EditSectionType == CE_WORK) { EmailListTypePtr->insert(std::make_pair(EmailListIndex, wxT("work"))); } // Add Email priority. if (priorityCtrl->IsPriorityChecked()){ EmailListPrefPtr->insert(std::make_pair(EmailListIndex, priorityCtrl->GetValue())); } else { EmailListPrefPtr->insert(std::make_pair(EmailListIndex, 0)); } // Add the data to the form. wxListItem coldata; coldata.SetId(EmailListIndex); coldata.SetData(EmailListIndex); coldata.SetText(txtEmail->GetValue()); ListCtrlIndex = EmailListCtrlPtr->InsertItem(coldata); if (priorityCtrl->IsPriorityChecked()){ EmailListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } this->Close(); } else if (EditorMode == TRUE){ // Edit the email address. wxString strAddress; wxString strValue; long longSelected = -1; EmailListPtr->erase(EmailListIndex); EmailListPtr->insert(std::make_pair(EmailListIndex, txtEmail->GetValue())); EmailListPrefPtr->erase(EmailListIndex); if (priorityCtrl->IsPriorityChecked()){ EmailListPrefPtr->insert(std::make_pair(EmailListIndex, priorityCtrl->GetValue())); } else { EmailListPrefPtr->insert(std::make_pair(EmailListIndex, 0)); } longSelected = EmailListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } EmailListCtrlPtr->SetItem(longSelected, 0, txtEmail->GetValue()); if (priorityCtrl->IsPriorityChecked()){ EmailListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } else { EmailListCtrlPtr->SetItem(longSelected, 1, wxT("")); } this->Close(); } } void frmContactEditorEmail::CloseWindow( wxCommandEvent& event ) { // Close this window. this->Close(); } void frmContactEditorEmail::SetEditorMode(bool EditMode, SectionType SectType) { // Set the editor mode. // Set the editor mode for adding or editing an email address. if (EditMode == FALSE){ EditorMode = FALSE; btnAction->SetLabel(_("Add")); this->SetTitle(_("Add Email")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Email")); std::map::iterator intiter; std::map::iterator striter; wxString strValue; // Load the data into the form. striter = EmailListPtr->find(EmailListIndex); if (striter->first == EmailListIndex){ strValue = striter->second; } txtEmail->SetValue(strValue); // Setup the Slider. intiter = EmailListPrefPtr->find(EmailListIndex); if (intiter->first == EmailListIndex && intiter->second > 0 && intiter != EmailListPrefPtr->end()){ priorityCtrl->SetValue(intiter->second); priorityCtrl->EnablePriority(true); } } EditSectionType = SectType; } void frmContactEditorEmail::SetupPointers(std::map *EmailList, std::map *EmailListAltID, std::map *EmailListPID, std::map *EmailListType, std::map *EmailListTokens, std::map *EmailListPref, wxListCtrl *EmailListCtrl, int EmailIndex ) { // Setup the pointers so that the data can be processed without // duplication. EmailListPtr = EmailList; EmailListAltIDPtr = EmailListAltID; EmailListPIDPtr = EmailListPID; EmailListTypePtr = EmailListType; EmailListTokensPtr = EmailListTokens; EmailListPrefPtr = EmailListPref; EmailListCtrlPtr = EmailListCtrl; EmailListIndex = EmailIndex; }