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 sliPriority->Disable();
31 cmbType->Append(wxT(""));
32 cmbType->Append(_("Home"));
33 cmbType->Append(_("Work"));
37 void frmContactEditorSound::EnablePriority( wxCommandEvent& event )
40 // Enable/disable the priority setting.
42 if (chkUsePref->IsChecked()){
43 sliPriority->Enable();
45 sliPriority->Disable();
50 void frmContactEditorSound::ProcessData( wxCommandEvent& event )
53 // Process audio data.
57 if (EditorMode == FALSE){
59 // Load the file into memory.
62 wxString wxSAudioString;
63 wxString wxSAudioFilename;
64 wxString wxSAudioMIMEType;
65 sf::SoundBuffer AudioBuffer;
69 wxSAudioFilename = fipSound->GetPath();
71 if (AudioFile.Open(wxSAudioFilename, wxFile::read)){
73 len = AudioFile.Length();
75 unsigned char* AudioFileData = new unsigned char[len];
77 wxSAudioMIMEType = GetMIME(wxSAudioFilename);
79 // Check to make sure it is an audio file.
81 if (!AudioBuffer.loadFromMemory(AudioFileData, (size_t)len)){
83 // Can't load file. We must flee...
84 // Also show an error message too.
86 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);
92 // Covert the file into base64.
94 b64enc = base64_encode(AudioFileData, (int)len);
96 delete[] AudioFileData;
100 wxMessageBox(_("There was an error opening the audio file!"), _("Error opening audio file"), wxICON_ERROR);
106 SoundListPtr->insert(std::make_pair(SoundListIndex, b64enc));
110 strValue = cmbType->GetString(cmbType->GetSelection());
114 if (strValue == _("Home")) {
116 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
118 } else if (strValue == _("Work")) {
120 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
124 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("")));
128 // Setup Organisation Priority.
130 if (chkUsePref->IsChecked()){
132 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
136 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
142 SoundListAudioTypePtr->insert(std::make_pair(SoundListIndex, wxSAudioMIMEType));
144 // Setup Encoding Type.
146 SoundListAudioEncTypePtr->insert(std::make_pair(SoundListIndex, wxT("base64")));
152 coldata.SetId(SoundListIndex);
153 coldata.SetData(SoundListIndex);
154 coldata.SetText(_("Sound"));
155 ListCtrlIndex = SoundListCtrlPtr->InsertItem(coldata);
157 if (strValue == _("Home")) {
159 SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Home"));
161 } else if (strValue == _("Work")) {
163 SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Work"));
171 if (chkUsePref->IsChecked()){
173 SoundListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
179 } else if (EditorMode == TRUE) {
181 // Do not touch the audio file but update the settings
182 // associated with the audio file.
184 long longSelected = -1;
187 // Update Category Type.
189 SoundListTypePtr->erase(SoundListIndex);
190 strValue = cmbType->GetString(cmbType->GetSelection());
192 if (strValue == _("Home")) {
194 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
196 } else if (strValue == _("Work")) {
198 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
202 // Update Category Priority.
204 SoundListPrefPtr->erase(SoundListIndex);
206 if (chkUsePref->IsChecked()){
208 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
212 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
218 longSelected = SoundListCtrlPtr->GetNextItem(longSelected,
220 wxLIST_STATE_SELECTED);
222 if (longSelected == -1){
226 SoundListCtrlPtr->SetItem(longSelected, 0, wxT("Sound"));
227 SoundListCtrlPtr->SetItem(longSelected, 1, strValue);
229 if (chkUsePref->IsChecked()){
231 SoundListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
235 SoundListCtrlPtr->SetItem(longSelected, 2, wxT(""));
244 void frmContactEditorSound::CloseWindow( wxCommandEvent& event )
247 // Close this window.
253 void frmContactEditorSound::SetEditorMode(bool EditMode)
256 // Set the editor mode.
258 // Set if the editor is adding or editing an address.
262 if (EditMode == FALSE){
265 btnAction->SetLabel(_("Add"));
266 this->SetTitle(_("Add Sound"));
268 } else if (EditMode == TRUE){
271 btnAction->SetLabel(_("Modify"));
272 this->SetTitle(_("Modify Sound"));
275 std::map<int,int>::iterator intiter;
276 std::map<int,wxString>::iterator striter;
279 // Load the data into the form. Get the website.
281 striter = SoundListTypePtr->find(SoundListIndex);
283 if (striter->first == SoundListIndex){
285 strValue = striter->second;
289 if (strValue == wxT("home")){
291 cmbType->SetSelection(1);
293 } else if (strValue == wxT("work")){
295 cmbType->SetSelection(2);
299 cmbType->SetSelection(0);
303 // Get the website priority.
305 intiter = SoundListPrefPtr->find(SoundListIndex);
307 if (intiter->first == SoundListIndex && intiter->second > 0 &&
308 intiter != SoundListPrefPtr->end()){
310 sliPriority->SetValue(intiter->second);
311 sliPriority->Enable();
312 chkUsePref->SetValue(TRUE);
322 void frmContactEditorSound::SetupPointers(std::map<int, std::string> *SoundList,
323 std::map<int, wxString> *SoundListAltID,
324 std::map<int, wxString> *SoundListPID,
325 std::map<int, wxString> *SoundListType,
326 std::map<int, wxString> *SoundListAudioType,
327 std::map<int, wxString> *SoundListAudioEncType,
328 std::map<int, wxString> *SoundListTokens,
329 std::map<int, wxString> *SoundListMediatype,
330 std::map<int, int> *SoundListPref,
331 wxListCtrl *SoundListCtrl,
335 // Setup the pointers.
337 SoundListPtr = SoundList;
338 SoundListAltIDPtr = SoundListAltID;
339 SoundListPIDPtr = SoundListPID;
340 SoundListTypePtr = SoundListType;
341 SoundListAudioTypePtr = SoundListAudioType;
342 SoundListAudioEncTypePtr = SoundListAudioEncType;
343 SoundListTokensPtr = SoundListTokens;
344 SoundListMediatypePtr = SoundListMediatype;
345 SoundListPrefPtr = SoundListPref;
346 SoundListCtrlPtr = SoundListCtrl;
347 SoundListIndex = SoundIndex;