1 // frmContactEditorSound.cpp - frmContactEditorSound 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 "frmContactEditorSound.h"
21 frmContactEditorSound::frmContactEditorSound( wxWindow* parent )
23 frmContactEditorSoundADT( parent )
29 priorityCtrl = new XABPriorityCtrl(tabGeneral);
30 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
33 cmbType->Append(wxT(""));
34 cmbType->Append(_("Home"));
35 cmbType->Append(_("Work"));
39 void frmContactEditorSound::ProcessData( wxCommandEvent& event )
42 // Process audio data.
46 if (EditorMode == FALSE){
48 // Load the file into memory.
51 wxString wxSAudioString;
52 wxString wxSAudioFilename;
53 wxString wxSAudioMIMEType;
54 sf::SoundBuffer AudioBuffer;
58 wxSAudioFilename = fipSound->GetPath();
60 if (AudioFile.Open(wxSAudioFilename, wxFile::read)){
62 len = AudioFile.Length();
64 unsigned char* AudioFileData = new unsigned char[len];
66 wxSAudioMIMEType = GetMIME(wxSAudioFilename);
68 // Check to make sure it is an audio file.
70 if (!AudioBuffer.loadFromMemory(AudioFileData, (size_t)len)){
72 // Can't load file. We must flee...
73 // Also show an error message too.
75 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);
81 // Covert the file into base64.
83 b64enc = base64_encode(AudioFileData, (int)len);
85 delete[] AudioFileData;
89 wxMessageBox(_("There was an error opening the audio file!"), _("Error opening audio file"), wxICON_ERROR);
95 SoundListPtr->insert(std::make_pair(SoundListIndex, b64enc));
99 strValue = cmbType->GetString(cmbType->GetSelection());
103 if (strValue == _("Home")) {
105 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
107 } else if (strValue == _("Work")) {
109 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
113 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("")));
117 // Setup Organisation Priority.
119 if (priorityCtrl->IsPriorityChecked()){
121 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, priorityCtrl->GetValue()));
125 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
131 SoundListAudioTypePtr->insert(std::make_pair(SoundListIndex, wxSAudioMIMEType));
133 // Setup Encoding Type.
135 SoundListAudioEncTypePtr->insert(std::make_pair(SoundListIndex, wxT("base64")));
141 coldata.SetId(SoundListIndex);
142 coldata.SetData(SoundListIndex);
143 coldata.SetText(_("Sound"));
144 ListCtrlIndex = SoundListCtrlPtr->InsertItem(coldata);
146 if (strValue == _("Home")) {
148 SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Home"));
150 } else if (strValue == _("Work")) {
152 SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Work"));
160 if (priorityCtrl->IsPriorityChecked()){
162 SoundListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
168 } else if (EditorMode == TRUE) {
170 // Do not touch the audio file but update the settings
171 // associated with the audio file.
173 long longSelected = -1;
176 // Update Category Type.
178 SoundListTypePtr->erase(SoundListIndex);
179 strValue = cmbType->GetString(cmbType->GetSelection());
181 if (strValue == _("Home")) {
183 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
185 } else if (strValue == _("Work")) {
187 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
191 // Update Category Priority.
193 SoundListPrefPtr->erase(SoundListIndex);
195 if (priorityCtrl->IsPriorityChecked()){
197 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, priorityCtrl->GetValue()));
201 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
207 longSelected = SoundListCtrlPtr->GetNextItem(longSelected,
209 wxLIST_STATE_SELECTED);
211 if (longSelected == -1){
215 SoundListCtrlPtr->SetItem(longSelected, 0, wxT("Sound"));
216 SoundListCtrlPtr->SetItem(longSelected, 1, strValue);
218 if (priorityCtrl->IsPriorityChecked()){
220 SoundListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
224 SoundListCtrlPtr->SetItem(longSelected, 2, wxT(""));
233 void frmContactEditorSound::CloseWindow( wxCommandEvent& event )
236 // Close this window.
242 void frmContactEditorSound::SetEditorMode(bool EditMode)
245 // Set the editor mode.
247 // Set if the editor is adding or editing an address.
251 if (EditMode == FALSE){
254 btnAction->SetLabel(_("Add"));
255 this->SetTitle(_("Add Sound"));
257 } else if (EditMode == TRUE){
260 btnAction->SetLabel(_("Modify"));
261 this->SetTitle(_("Modify Sound"));
264 std::map<int,int>::iterator intiter;
265 std::map<int,wxString>::iterator striter;
268 // Load the data into the form. Get the website.
270 striter = SoundListTypePtr->find(SoundListIndex);
272 if (striter->first == SoundListIndex){
274 strValue = striter->second;
278 if (strValue == wxT("home")){
280 cmbType->SetSelection(1);
282 } else if (strValue == wxT("work")){
284 cmbType->SetSelection(2);
288 cmbType->SetSelection(0);
292 // Get the website priority.
294 intiter = SoundListPrefPtr->find(SoundListIndex);
296 if (intiter->first == SoundListIndex && intiter->second > 0 &&
297 intiter != SoundListPrefPtr->end()){
299 priorityCtrl->SetValue(intiter->second);
300 priorityCtrl->EnablePriority(true);
310 void frmContactEditorSound::SetupPointers(std::map<int, std::string> *SoundList,
311 std::map<int, wxString> *SoundListAltID,
312 std::map<int, wxString> *SoundListPID,
313 std::map<int, wxString> *SoundListType,
314 std::map<int, wxString> *SoundListAudioType,
315 std::map<int, wxString> *SoundListAudioEncType,
316 std::map<int, wxString> *SoundListTokens,
317 std::map<int, wxString> *SoundListMediatype,
318 std::map<int, int> *SoundListPref,
319 wxListCtrl *SoundListCtrl,
323 // Setup the pointers.
325 SoundListPtr = SoundList;
326 SoundListAltIDPtr = SoundListAltID;
327 SoundListPIDPtr = SoundListPID;
328 SoundListTypePtr = SoundListType;
329 SoundListAudioTypePtr = SoundListAudioType;
330 SoundListAudioEncTypePtr = SoundListAudioEncType;
331 SoundListTokensPtr = SoundListTokens;
332 SoundListMediatypePtr = SoundListMediatype;
333 SoundListPrefPtr = SoundListPref;
334 SoundListCtrlPtr = SoundListCtrl;
335 SoundListIndex = SoundIndex;