1 #include "frmContactEditorSound.h"
3 #include <wx/tokenzr.h>
5 #include <SFML/Audio.hpp>
7 #include "../common/textprocessing.h"
8 #include "../common/base64.h"
9 #include "../common/mime.h"
11 frmContactEditorSound::frmContactEditorSound( wxWindow* parent )
13 frmContactEditorSoundADT( parent )
16 sliPriority->Disable();
18 cmbType->Append(wxT(""));
19 cmbType->Append(_("Home"));
20 cmbType->Append(_("Work"));
23 void frmContactEditorSound::EnablePriority( wxCommandEvent& event )
25 if (chkUsePref->IsChecked()){
26 sliPriority->Enable();
28 sliPriority->Disable();
32 void frmContactEditorSound::ProcessData( wxCommandEvent& event )
36 if (EditorMode == FALSE){
38 // Load the file into memory.
41 wxString wxSAudioString;
42 wxString wxSAudioFilename;
43 wxString wxSAudioMIMEType;
44 sf::SoundBuffer AudioBuffer;
48 wxSAudioFilename = fipSound->GetPath();
51 #if wxABI_VERSION < 20900
52 if (AudioFile.Open(wxSAudioFilename.c_str(), wxT("rb"))){
54 if (AudioFile.Open(wxSAudioFilename, wxT("rb"))){
58 if (AudioFile.Open(wxSAudioFilename, wxFile::read)){
60 len = AudioFile.Length();
62 unsigned char* AudioFileData = new unsigned char[len];
63 flen = AudioFile.Read(AudioFileData, len);
67 /*const char *MIMEType;
68 magic_t MagicCookie = magic_open(MAGIC_MIME);
69 magic_setflags(MagicCookie, MAGIC_MIME_TYPE);
73 wxMessageBox(_("An error occured with the support library for getting the picture type."), _("Error opening picture file"), wxICON_ERROR);
78 if (magic_load(MagicCookie, NULL) != 0) {
80 wxMessageBox(_("An error occured whilst determining the picture type."), _("Error opening picture file"), wxICON_ERROR);
85 MIMEType = magic_file(MagicCookie, wxSAudioFilename.mb_str());
86 wxSAudioMIMEType = wxString::FromUTF8(MIMEType);
87 magic_close(MagicCookie);*/
89 wxSAudioMIMEType = GetMIME(wxSAudioFilename);
91 // Check to make sure it is an audio file.
93 if (!AudioBuffer.loadFromMemory(AudioFileData, len)){
95 // Can't load file. We must flee...
96 // Also show an error message too.
98 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);
104 // Covert the file into base64.
106 b64enc = base64_encode(AudioFileData, (int)len);
108 delete[] AudioFileData;
112 wxMessageBox(_("There was an error opening the audio file!"), _("Error opening audio file"), wxICON_ERROR);
118 SoundListPtr->insert(std::make_pair(SoundListIndex, b64enc));
122 strValue = cmbType->GetString(cmbType->GetSelection());
126 if (strValue == _("Home")) {
128 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
130 } else if (strValue == _("Work")) {
132 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
136 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("")));
140 // Setup Organisation Priority.
142 if (chkUsePref->IsChecked()){
144 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
148 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
154 SoundListAudioTypePtr->insert(std::make_pair(SoundListIndex, wxSAudioMIMEType));
156 // Setup Encoding Type.
158 SoundListAudioEncTypePtr->insert(std::make_pair(SoundListIndex, wxT("base64")));
164 coldata.SetId(SoundListIndex);
165 coldata.SetData(SoundListIndex);
166 coldata.SetText(_("Sound"));
167 ListCtrlIndex = SoundListCtrlPtr->InsertItem(coldata);
169 if (strValue == _("Home")) {
171 SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Home"));
173 } else if (strValue == _("Work")) {
175 SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Work"));
183 if (chkUsePref->IsChecked()){
185 SoundListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
191 } else if (EditorMode == TRUE) {
193 // Do not touch the audio file but update the settings
194 // associated with the audio file.
198 long longSelected = -1;
201 // Update Category Type.
203 SoundListTypePtr->erase(SoundListIndex);
204 strValue = cmbType->GetString(cmbType->GetSelection());
206 if (strValue == _("Home")) {
208 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
210 } else if (strValue == _("Work")) {
212 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
216 // Update Category Priority.
218 SoundListPrefPtr->erase(SoundListIndex);
220 if (chkUsePref->IsChecked()){
222 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
226 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
232 longSelected = SoundListCtrlPtr->GetNextItem(longSelected,
234 wxLIST_STATE_SELECTED);
236 if (longSelected == -1){
240 SoundListCtrlPtr->SetItem(longSelected, 0, wxT("Sound"));
241 SoundListCtrlPtr->SetItem(longSelected, 1, strValue);
243 if (chkUsePref->IsChecked()){
245 SoundListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
249 SoundListCtrlPtr->SetItem(longSelected, 2, wxT(""));
258 void frmContactEditorSound::CloseWindow( wxCommandEvent& event )
263 void frmContactEditorSound::SetEditorMode(bool EditMode)
265 // Set if the editor is adding or editing an address.
269 if (EditMode == FALSE){
272 btnAction->SetLabel(_("Add"));
273 this->SetTitle(_("Add Sound"));
275 } else if (EditMode == TRUE){
278 btnAction->SetLabel(_("Modify"));
279 this->SetTitle(_("Modify Sound"));
282 std::map<int,int>::iterator intiter;
283 std::map<int,wxString>::iterator striter;
286 // Load the data into the form. Get the website.
288 striter = SoundListTypePtr->find(SoundListIndex);
290 if (striter->first == SoundListIndex){
292 strValue = striter->second;
296 if (strValue == wxT("home")){
298 cmbType->SetSelection(1);
300 } else if (strValue == wxT("work")){
302 cmbType->SetSelection(2);
306 cmbType->SetSelection(0);
312 // Get the website priority.
314 intiter = SoundListPrefPtr->find(SoundListIndex);
316 if (intiter->first == SoundListIndex && intiter->second > 0){
318 sliPriority->SetValue(intiter->second);
319 sliPriority->Enable();
320 chkUsePref->SetValue(TRUE);
330 void frmContactEditorSound::SetupPointers(std::map<int, std::string> *SoundList,
331 std::map<int, wxString> *SoundListAltID,
332 std::map<int, wxString> *SoundListPID,
333 std::map<int, wxString> *SoundListType,
334 std::map<int, wxString> *SoundListAudioType,
335 std::map<int, wxString> *SoundListAudioEncType,
336 std::map<int, wxString> *SoundListTokens,
337 std::map<int, wxString> *SoundListMediatype,
338 std::map<int, int> *SoundListPref,
339 wxListCtrl *SoundListCtrl,
343 SoundListPtr = SoundList;
344 SoundListAltIDPtr = SoundListAltID;
345 SoundListPIDPtr = SoundListPID;
346 SoundListTypePtr = SoundListType;
347 SoundListAudioTypePtr = SoundListAudioType;
348 SoundListAudioEncTypePtr = SoundListAudioEncType;
349 SoundListTokensPtr = SoundListTokens;
350 SoundListMediatypePtr = SoundListMediatype;
351 SoundListPrefPtr = SoundListPref;
352 SoundListCtrlPtr = SoundListCtrl;
353 SoundListIndex = SoundIndex;