// frmContactEditorRelated.cpp - frmContactEditorRelated 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 "frmContactEditorRelated.h" #include #include "../common/textprocessing.h" #include "../enums.h" frmContactEditorRelated::frmContactEditorRelated( wxWindow* parent ) : frmContactEditorRelatedADT( parent ) { // Setup the window. EditorMode = FALSE; priorityCtrl = new XABPriorityCtrl(tabGeneral); szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5); // Setup the list of types for the related drop down box. cmbType->Append(_("Contact")); cmbType->Append(_("Acquaintance")); cmbType->Append(_("Friend")); cmbType->Append(_("Met")); cmbType->Append(_("Co-worker")); cmbType->Append(_("Colleague")); cmbType->Append(_("Co-resident")); cmbType->Append(_("Neighbour")); cmbType->Append(_("Child")); cmbType->Append(_("Parent")); cmbType->Append(_("Sibling")); cmbType->Append(_("Spouse")); cmbType->Append(_("Kin")); cmbType->Append(_("Muse")); cmbType->Append(_("Crush")); cmbType->Append(_("Date")); cmbType->Append(_("Sweetheart")); cmbType->Append(_("Me")); cmbType->Append(_("Agent")); cmbType->Append(_("Emergency")); } void frmContactEditorRelated::SetEditorMode(bool EditMode, SectionType SectType) { // Set the editor mode. if (EditMode == FALSE){ EditorMode = FALSE; btnAction->SetLabel(_("Add")); this->SetTitle(_("Add Related")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Related")); std::map::iterator intiter; std::map::iterator striter; wxString strValue; // Get the related data. striter = RelatedListPtr->find(RelatedListIndex); if (striter->first == RelatedListIndex){ strValue = striter->second; } txtRelated->SetValue(strValue); strValue.Clear(); // Get the related type. striter = RelatedListRelTypePtr->find(RelatedListIndex); if (striter->first == RelatedListIndex && striter != RelatedListRelTypePtr->end()){ strValue = striter->second; } if (strValue == wxT("contact")){ cmbType->SetValue(_("Contact")); } else if (strValue == wxT("acquaintance")){ cmbType->SetValue(_("Acquaintance")); } else if (strValue == wxT("friend")){ cmbType->SetValue(_("Friend")); } else if (strValue == wxT("met")){ cmbType->SetValue(_("Met")); } else if (strValue == wxT("co-worker")){ cmbType->SetValue(_("Co-worker")); } else if (strValue == wxT("colleague")){ cmbType->SetValue(_("Colleague")); } else if (strValue == wxT("co-resident")){ cmbType->SetValue(_("Co-resident")); } else if (strValue == wxT("neighbor")){ cmbType->SetValue(_("Neighbour")); } else if (strValue == wxT("child")){ cmbType->SetValue(_("Child")); } else if (strValue == wxT("parent")){ cmbType->SetValue(_("Parent")); } else if (strValue == wxT("sibling")){ cmbType->SetValue(_("Sibling")); } else if (strValue == wxT("spouse")){ cmbType->SetValue(_("Spouse")); } else if (strValue == wxT("kin")){ cmbType->SetValue(_("Kin")); } else if (strValue == wxT("muse")){ cmbType->SetValue(_("Muse")); } else if (strValue == wxT("crush")){ cmbType->SetValue(_("Crush")); } else if (strValue == wxT("date")){ cmbType->SetValue(_("Date")); } else if (strValue == wxT("sweetheart")){ cmbType->SetValue(_("Sweetheart")); } else if (strValue == wxT("me")){ cmbType->SetValue(_("Me")); } else if (strValue == wxT("agent")){ cmbType->SetValue(_("Agent")); } else if (strValue == wxT("emergency")){ cmbType->SetValue(_("Emergency")); } else { cmbType->SetValue(strValue); } // Setup the Slider. intiter = RelatedListPrefPtr->find(RelatedListIndex); if (intiter->first == RelatedListIndex && intiter->second > 0 && intiter != RelatedListPrefPtr->end()){ priorityCtrl->SetValue(intiter->second); priorityCtrl->EnablePriority(true); } } EditSectionType = SectType; } void frmContactEditorRelated::ProcessData( wxCommandEvent& event ) { // Process data. long ListCtrlIndex; if (EditorMode == FALSE){ wxString strValue; RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue())); // Work out the type of contact. strValue = cmbType->GetValue(); if (strValue == _("Contact")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact"))); } else if (strValue == _("Acquaintance")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance"))); } else if (strValue == _("Friend")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend"))); } else if (strValue == _("Met")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met"))); } else if (strValue == _("Co-worker")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker"))); } else if (strValue == _("Colleague")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague"))); } else if (strValue == _("Co-resident")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident"))); } else if (strValue == _("Neighbour")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor"))); } else if (strValue == _("Child")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child"))); } else if (strValue == _("Parent")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent"))); } else if (strValue == _("Sibling")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling"))); } else if (strValue == _("Spouse")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse"))); } else if (strValue == _("Kin")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin"))); } else if (strValue == _("Muse")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse"))); } else if (strValue == _("Crush")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush"))); } else if (strValue == _("Date")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date"))); } else if (strValue == _("Sweetheart")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart"))); } else if (strValue == _("Me")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me"))); } else if (strValue == _("Agent")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent"))); } else if (strValue == _("Emergency")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency"))); } else { RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue)); } // Add Related type. if (EditSectionType == CE_GENERAL){ RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT(""))); } else if (EditSectionType == CE_HOME) { RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("home"))); } else if (EditSectionType == CE_WORK) { RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("work"))); } // Add Related Priority. if (priorityCtrl->IsPriorityChecked()){ RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, priorityCtrl->GetValue())); } else { RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0)); } // Add to the form. wxListItem coldata; coldata.SetId(RelatedListIndex); coldata.SetData(RelatedListIndex); coldata.SetText(cmbType->GetValue()); ListCtrlIndex = RelatedListCtrlPtr->InsertItem(coldata); RelatedListCtrlPtr->SetItem(ListCtrlIndex, 1, txtRelated->GetValue()); if (priorityCtrl->IsPriorityChecked()){ RelatedListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } this->Close(); } else if (EditorMode == TRUE) { wxString strValue; long longSelected = -1; // Work out the type of contact. strValue = cmbType->GetValue(); RelatedListRelTypePtr->erase(RelatedListIndex); if (strValue == _("Contact")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact"))); } else if (strValue == _("Acquaintance")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance"))); } else if (strValue == _("Friend")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend"))); } else if (strValue == _("Met")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met"))); } else if (strValue == _("Co-worker")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker"))); } else if (strValue == _("Colleague")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague"))); } else if (strValue == _("Co-resident")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident"))); } else if (strValue == _("Neighbour")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor"))); } else if (strValue == _("Child")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child"))); } else if (strValue == _("Parent")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent"))); } else if (strValue == _("Sibling")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling"))); } else if (strValue == _("Spouse")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse"))); } else if (strValue == _("Kin")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin"))); } else if (strValue == _("Muse")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse"))); } else if (strValue == _("Crush")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush"))); } else if (strValue == _("Date")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date"))); } else if (strValue == _("Sweetheart")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart"))); } else if (strValue == _("Me")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me"))); } else if (strValue == _("Agent")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent"))); } else if (strValue == _("Emergency")){ RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency"))); } else { RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue)); } RelatedListPrefPtr->erase(RelatedListIndex); if (priorityCtrl->IsPriorityChecked()){ RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, priorityCtrl->GetValue())); } else { RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0)); } // Get the related person/details. RelatedListPtr->erase(RelatedListIndex); RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue())); // Update the form. longSelected = RelatedListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } RelatedListCtrlPtr->SetItem(longSelected, 0, cmbType->GetValue()); RelatedListCtrlPtr->SetItem(longSelected, 1, txtRelated->GetValue()); if (priorityCtrl->IsPriorityChecked()){ RelatedListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } else { RelatedListCtrlPtr->SetItem(longSelected, 2, wxT("")); } this->Close(); } } void frmContactEditorRelated::CloseWindow( wxCommandEvent& event ) { // Close this window. this->Close(); } void frmContactEditorRelated::SetupPointers(std::map *RelatedList, std::map *RelatedListRelType, std::map *RelatedListAltID, std::map *RelatedListPID, std::map *RelatedListType, std::map *RelatedListTokens, std::map *RelatedListPref, wxListCtrl *RelatedListCtrl, int RelatedIndex ) { // Setup the pointers. RelatedListPtr = RelatedList; RelatedListRelTypePtr = RelatedListRelType; RelatedListAltIDPtr = RelatedListAltID; RelatedListPIDPtr = RelatedListPID; RelatedListTypePtr = RelatedListType; RelatedListTokensPtr = RelatedListTokens; RelatedListPrefPtr = RelatedListPref; RelatedListCtrlPtr = RelatedListCtrl; RelatedListIndex = RelatedIndex; }