// frmContactEditor.cpp - Main frmContactEditor form section. // // (c) 2012-2016 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 #include #include #include #include #include #include #include #include #include #include #include "frmContactEditor.h" #include "frmContactEditorNickname.h" #include "frmContactEditorAddress.h" #include "frmContactEditorEmail.h" #include "frmContactEditorIM.h" #include "frmContactEditorTelephone.h" #include "frmContactEditorLanguages.h" #include "frmContactEditorTimezones.h" #include "frmContactEditorRelated.h" #include "frmContactEditorWebsites.h" #include "frmContactEditorTitles.h" #include "frmContactEditorRoles.h" #include "frmContactEditorGeoposition.h" #include "frmContactEditorGroups.h" #include "frmContactEditorOrganisations.h" #include "frmContactEditorNotes.h" #include "frmContactEditorCategory.h" #include "frmContactEditorSound.h" #include "frmContactEditorPicture.h" #include "frmContactEditorCalAdr.h" #include "frmContactEditorKey.h" #include "frmContactEditorVendor.h" #include "frmContactEditorXToken.h" #include "../frmMain.h" #include "../enums.h" #include "../version.h" #include "../vcard/vcard.h" #include "../vcard/vcard34conv.h" #include "../bitmaps.h" #include "../common/base64.h" #include "../common/textprocessing.h" #include "../common/preferences.h" #include "../common/uuid.h" #include "../common/dirs.h" // TODO: Investigate problems with SFML & PulseAudio - CPU usage problems when // not being used. // Replace intResult with intValueSeek. BEGIN_EVENT_TABLE(frmContactEditor, wxFrame) EVT_COMMAND(wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, frmContactEditor::ContactFileChanged) END_EVENT_TABLE() frmContactEditor::frmContactEditor( wxWindow* parent ) : frmContactEditorADT( parent ) { boolContactModified = FALSE; wxDateTime NoDate; dapAnniversary->SetValue(NoDate); dapBirthday->SetValue(NoDate); tabMembers->Hide(); // Setup the buttons. wxMemoryInputStream istream(buttons_play_png, sizeof(buttons_play_png)); wxImage button_play_pngi(istream, wxBITMAP_TYPE_PNG); wxBitmap playiconbmp(button_play_pngi, -1); btnPlay->SetBitmapLabel(playiconbmp); wxMemoryInputStream istream2(buttons_stop_png, sizeof(buttons_stop_png)); wxImage button_stop_pngi(istream2, wxBITMAP_TYPE_PNG); wxBitmap stopiconbmp(button_stop_pngi, -1); btnStop->SetBitmapLabel(stopiconbmp); btnStop->Disable(); FMTimer.SetupPointers(this); //wxIcon contacticon; //contacticon.CopyFromBitmap(contacticonbmp); nbkContact->SetSelection(0); } frmContactEditor::~frmContactEditor() { if (AudioStreamPlaybackPointer != nullptr) { delete AudioStreamPlaybackPointer; AudioStreamPlaybackPointer = nullptr; } } void frmContactEditor::CloseContact( wxCommandEvent& event ) { Close(); } void frmContactEditor::CloseWindow( wxCloseEvent& event ) { // TODO: Check if any changes have been made, // ask if the changes should be made, process // action based on question and then close. WindowData *WData = new WindowData; if (StartupEditMode == FALSE){ WData->DataType = 1; WData->WindowPointer = this; WData->WindowID = ContactEditorUID; wxCommandEvent delevent(WINDOW_CLOSE); delevent.SetClientData(WData); wxPostEvent(GetParent(), delevent); } Destroy(); } void frmContactEditor::CutText( wxCommandEvent& event ) { // This function left empty for future implementation. } void frmContactEditor::CopyText( wxCommandEvent& event ) { // This function left empty for future implementation. } void frmContactEditor::PasteText( wxCommandEvent& event ) { // This function left empty for future implementation. } void frmContactEditor::SetupContact( wxString AccountName ) { wxSContactAccount = AccountName; } void frmContactEditor::SetupAccountData(bool UnsupportedAccount){ boolUnsupportedAccount = UnsupportedAccount; } int frmContactEditor::GetLastInt(std::map *MapData){ /* int intResult = 0; std::map::iterator iwxsit; for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){ intResult = (*iwxsit).first; } return intResult; */ intValueSeek++; return intValueSeek; } int frmContactEditor::GetLastInt(std::map *MapData){ /* int intResult = 0; std::map::iterator iwxsit; for( iwxsit=(*MapData).begin(); iwxsit != (*MapData).end(); iwxsit++){ intResult = (*iwxsit).first; }*/ intValueSeek++; return intValueSeek; } bool frmContactEditor::GetSelectedItem(wxListCtrl *ListCtrlPtr, long *longSelected, int *intSelectedData){ *longSelected = -1; *intSelectedData = 0; *longSelected = ListCtrlPtr->GetNextItem(*longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (*longSelected == -1){ return FALSE; } *intSelectedData = (int)ListCtrlPtr->GetItemData(*longSelected); return TRUE; } void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map* MapData){ MapData->erase(IndexNum); } void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map* MapData){ MapData->erase(IndexNum); } void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map* MapData){ MapData->erase(IndexNum); } void frmContactEditor::DeleteMapDataProcess(int IndexNum, std::map* MapData){ MapData->erase(IndexNum); } void frmContactEditor::ProcessSaveDataProc( wxString PropName, std::map* MapData){ int intIterVal = (*iterDataPtr)->first; std::map::iterator intIter; intIter = MapData->find(intIterVal); int intPropValue; if (intIter->first == intIterVal){ intPropValue = intIter->second; if (intPropValue){ if (*boolAdditionalPtr == TRUE){ strPropertyPtr->Append(wxT(";")); } else { *boolAdditionalPtr = TRUE; } strPropertyPtr->Append(PropName + wxT("=") + wxString::Format(wxT("%i"), intPropValue)); *boolExtraPtr = TRUE; } } } void frmContactEditor::ProcessSaveDataProc( wxString PropName, std::map* MapData){ int intIterVal; intIterVal = (*iterDataPtr)->first; std::map::iterator strIter; strIter = MapData->find(intIterVal); if (strIter == MapData->end()){ return; } wxString strPropValue; if (strIter->first == intIterVal){ strPropValue = strIter->second; if (!strPropValue.IsEmpty() && PropName.IsEmpty()){ strPropValue.Trim(); strPropValue.Trim(); if (*boolAdditionalPtr == TRUE){ strPropertyPtr->Append(wxT(";")); } else { *boolAdditionalPtr = TRUE; } strPropertyPtr->Append(strPropValue); *boolExtraPtr = TRUE; return; } if (!strPropValue.IsEmpty()){ strPropValue.Trim(); strPropValue.Trim(); if (*boolAdditionalPtr == TRUE){ strPropertyPtr->Append(wxT(";")); } else { *boolAdditionalPtr = TRUE; } // Look for semi-colon in property name and if there is then // quote the value. if (PropName != wxT("TYPE")){ EscapeString(&strPropValue, FALSE); } if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND && strPropValue.find(wxT(",")) == wxNOT_FOUND){ strPropertyPtr->Append(PropName + wxT("=") + strPropValue); } else { strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\"")); } *boolExtraPtr = TRUE; } } } void frmContactEditor::ProcessSaveDataStrProc( wxString PropName, std::map* MapData){ int intIterVal = (*iterDataStringPtr)->first; //std::map::iterator strIter; std::map::iterator stdstrIter; stdstrIter = MapData->find(intIterVal); if (stdstrIter->first == intIterVal){ wxString strPropValue(stdstrIter->second.c_str(), wxConvUTF8); if (!strPropValue.IsEmpty() && PropName.IsEmpty()){ strPropValue.Trim(); strPropValue.Trim(); if (*boolAdditionalPtr == TRUE){ strPropertyPtr->Append(wxT(";")); } else { *boolAdditionalPtr = TRUE; } strPropertyPtr->Append(strPropValue); *boolExtraPtr = TRUE; return; } if (!strPropValue.IsEmpty()){ strPropValue.Trim(); strPropValue.Trim(); if (*boolAdditionalPtr == TRUE){ strPropertyPtr->Append(wxT(";")); } else { *boolAdditionalPtr = TRUE; } // Look for semi-colon in property name and if there is then // quote the value. if (PropName != wxT("TYPE")){ EscapeString(&strPropValue, FALSE); } if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND && strPropValue.find(wxT(",")) == wxNOT_FOUND){ strPropertyPtr->Append(PropName + wxT("=") + strPropValue); } else { strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\"")); } *boolExtraPtr = TRUE; } } } void frmContactEditor::ProcessSaveDataStrProc( wxString PropName, std::map* MapData){ int intIterVal = (*iterDataStringPtr)->first; std::map::iterator intIter; intIter = MapData->find(intIterVal); int intPropValue; if (intIter->first == intIterVal){ intPropValue = intIter->second; if (intPropValue){ if (*boolAdditionalPtr == TRUE){ strPropertyPtr->Append(wxT(";")); } else { *boolAdditionalPtr = TRUE; } strPropertyPtr->Append(PropName + wxT("=") + wxString::Format(wxT("%i"), intPropValue)); *boolExtraPtr = TRUE; } } } void frmContactEditor::ProcessSaveDataStrProc( wxString PropName, std::map* MapData){ int intIterVal; intIterVal = (*iterDataStringPtr)->first; std::map::iterator strIter; strIter = MapData->find(intIterVal); if (strIter == MapData->end()){ // Ignore this section and return. return; } wxString strPropValue; if (strIter->first == intIterVal){ strPropValue = strIter->second; if (!strPropValue.IsEmpty() && PropName.IsEmpty()){ strPropValue.Trim(); strPropValue.Trim(); if (*boolAdditionalPtr == TRUE){ strPropertyPtr->Append(wxT(";")); } else { *boolAdditionalPtr = TRUE; } strPropertyPtr->Append(strPropValue); *boolExtraPtr = TRUE; return; } if (!strPropValue.IsEmpty()){ strPropValue.Trim(); strPropValue.Trim(); if (*boolAdditionalPtr == TRUE){ strPropertyPtr->Append(wxT(";")); } else { *boolAdditionalPtr = TRUE; } // Look for semi-colon in property name and if there is then // quote the value. if (PropName != wxT("TYPE")){ EscapeString(&strPropValue, FALSE); } if (strPropValue.find(wxT(";")) == wxNOT_FOUND && strPropValue.find(wxT(":")) == wxNOT_FOUND && strPropValue.find(wxT(",")) == wxNOT_FOUND){ strPropertyPtr->Append(PropName + wxT("=") + strPropValue); } else { strPropertyPtr->Append(PropName + wxT("=\"") + strPropValue + wxT("\"")); } *boolExtraPtr = TRUE; } } } void frmContactEditor::ProcessCaptureStringsProc(wxString *strCapture){ CaptureString(strCapture, FALSE); } void frmContactEditor::ResetSaveProcessData(){ strValue.Clear(); strValue2.Clear(); strValue3.Clear(); boolValue = FALSE; boolValue2 = FALSE; intValue2 = 0; intValue = 0; } void frmContactEditor::SetupPointers(frmActivityMgr *ActMgr, wxETagProcessTimer *ETagProc, frmMain *MainPtrInc){ ActMgrPtr = ActMgr; ETagTmrPtr = ETagProc; MainPtr = MainPtrInc; } void frmContactEditor::ContactFileChanged( wxCommandEvent &event ){ // Stop the timer. FMTimer.Stop(); // Check if a dialog is already open. if (DialogOpen == TRUE){ FMTimer.Start(1000, FALSE); return; } // Bring up a Yes/No modal dialog asking if the changed file should be reloaded. int QuestionResponse; QuestionResponse = wxMessageBox(_("This contact has changed. Saving the contact may overwrite or lose any changes done by that change. Do you want to reload the contact with the changes made?"), _("Contact information has changed"), wxYES_NO, this); if (QuestionResponse == wxYES){ // Reload the contact. wxString wxSReloadContactName = wxSContactFilename; ClearContact(); LoadContact(wxSReloadContactName); } else { // Do nothing other than update the timestamp so this message // doesn't appear until the next time it changes. FMTimer.UpdateTimestamp(); } // Start the timer. FMTimer.Start(); } void frmContactEditor::UpdateMembersTab( wxCommandEvent &event ){ if (cmbType->GetCurrentSelection() == 2){ tabMembers->Show(); } else { tabMembers->Hide(); } } void frmContactEditor::SetUID(int UID){ ContactEditorUID = UID; } void frmContactEditor::SetMode(bool StartupEditModeIn){ StartupEditMode = StartupEditModeIn; }