// frmContactEditorSound.cpp - frmContactEditorSound 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 "frmContactEditorSound.h" frmContactEditorSound::frmContactEditorSound( wxWindow* parent ) : frmContactEditorSoundADT( parent ) { // Setup the window. EditorMode = FALSE; priorityCtrl = new XABPriorityCtrl(tabGeneral); szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5); szrGeneral->Layout(); cmbType->Append(wxT("")); cmbType->Append(_("Home")); cmbType->Append(_("Work")); } void frmContactEditorSound::ProcessData( wxCommandEvent& event ) { // Process audio data. long ListCtrlIndex; if (EditorMode == FALSE){ // Load the file into memory. wxFile AudioFile; wxString wxSAudioString; wxString wxSAudioFilename; wxString wxSAudioMIMEType; sf::SoundBuffer AudioBuffer; wxFileOffset len; std::string b64enc; wxSAudioFilename = fipSound->GetPath(); if (AudioFile.Open(wxSAudioFilename, wxFile::read)){ len = AudioFile.Length(); unsigned char* AudioFileData = new unsigned char[len]; wxSAudioMIMEType = GetMIME(wxSAudioFilename); // Check to make sure it is an audio file. if (!AudioBuffer.loadFromMemory(AudioFileData, (size_t)len)){ // Can't load file. We must flee... // Also show an error message too. wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR); return; } // Covert the file into base64. b64enc = base64_encode(AudioFileData, (int)len); delete[] AudioFileData; } else { wxMessageBox(_("There was an error opening the audio file!"), _("Error opening audio file"), wxICON_ERROR); return; } SoundListPtr->insert(std::make_pair(SoundListIndex, b64enc)); wxString strValue; strValue.Clear(); strValue = cmbType->GetString(cmbType->GetSelection()); // Setup Sound Type. if (strValue == _("Home")) { SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home"))); } else if (strValue == _("Work")) { SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work"))); } else { SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT(""))); } // Setup Organisation Priority. if (priorityCtrl->IsPriorityChecked()){ SoundListPrefPtr->insert(std::make_pair(SoundListIndex, priorityCtrl->GetValue())); } else { SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0)); } // Setup MIME Type. SoundListAudioTypePtr->insert(std::make_pair(SoundListIndex, wxSAudioMIMEType)); // Setup Encoding Type. SoundListAudioEncTypePtr->insert(std::make_pair(SoundListIndex, wxT("base64"))); // Add to form. wxListItem coldata; coldata.SetId(SoundListIndex); coldata.SetData(SoundListIndex); coldata.SetText(_("Sound")); ListCtrlIndex = SoundListCtrlPtr->InsertItem(coldata); if (strValue == _("Home")) { SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Home")); } else if (strValue == _("Work")) { SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Work")); } else { } if (priorityCtrl->IsPriorityChecked()){ SoundListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } this->Close(); } else if (EditorMode == TRUE) { // Do not touch the audio file but update the settings // associated with the audio file. long longSelected = -1; wxString strValue; // Update Category Type. SoundListTypePtr->erase(SoundListIndex); strValue = cmbType->GetString(cmbType->GetSelection()); if (strValue == _("Home")) { SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home"))); } else if (strValue == _("Work")) { SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work"))); } // Update Category Priority. SoundListPrefPtr->erase(SoundListIndex); if (priorityCtrl->IsPriorityChecked()){ SoundListPrefPtr->insert(std::make_pair(SoundListIndex, priorityCtrl->GetValue())); } else { SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0)); } // Update form. longSelected = SoundListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } SoundListCtrlPtr->SetItem(longSelected, 0, wxT("Sound")); SoundListCtrlPtr->SetItem(longSelected, 1, strValue); if (priorityCtrl->IsPriorityChecked()){ SoundListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } else { SoundListCtrlPtr->SetItem(longSelected, 2, wxT("")); } this->Close(); } } void frmContactEditorSound::CloseWindow( wxCommandEvent& event ) { // Close this window. this->Close(); } void frmContactEditorSound::SetEditorMode(bool EditMode) { // Set the editor mode. // Set if the editor is adding or editing an address. // FALSE = Add // TRUE = Edit if (EditMode == FALSE){ EditorMode = FALSE; btnAction->SetLabel(_("Add")); this->SetTitle(_("Add Sound")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Sound")); fipSound->Disable(); std::map::iterator intiter; std::map::iterator striter; wxString strValue; // Load the data into the form. Get the website. striter = SoundListTypePtr->find(SoundListIndex); if (striter->first == SoundListIndex){ strValue = striter->second; } if (strValue == wxT("home")){ cmbType->SetSelection(1); } else if (strValue == wxT("work")){ cmbType->SetSelection(2); } else { cmbType->SetSelection(0); } // Get the website priority. intiter = SoundListPrefPtr->find(SoundListIndex); if (intiter->first == SoundListIndex && intiter->second > 0 && intiter != SoundListPrefPtr->end()){ priorityCtrl->SetValue(intiter->second); priorityCtrl->EnablePriority(true); } } } void frmContactEditorSound::SetupPointers(std::map *SoundList, std::map *SoundListAltID, std::map *SoundListPID, std::map *SoundListType, std::map *SoundListAudioType, std::map *SoundListAudioEncType, std::map *SoundListTokens, std::map *SoundListMediatype, std::map *SoundListPref, wxListCtrl *SoundListCtrl, int SoundIndex ) { // Setup the pointers. SoundListPtr = SoundList; SoundListAltIDPtr = SoundListAltID; SoundListPIDPtr = SoundListPID; SoundListTypePtr = SoundListType; SoundListAudioTypePtr = SoundListAudioType; SoundListAudioEncTypePtr = SoundListAudioEncType; SoundListTokensPtr = SoundListTokens; SoundListMediatypePtr = SoundListMediatype; SoundListPrefPtr = SoundListPref; SoundListCtrlPtr = SoundListCtrl; SoundListIndex = SoundIndex; }