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);
32 cmbType->Append(wxT(""));
33 cmbType->Append(_("Home"));
34 cmbType->Append(_("Work"));
38 void frmContactEditorSound::ProcessData( wxCommandEvent& event )
41 // Process audio data.
45 if (EditorMode == FALSE){
47 // Load the file into memory.
50 wxString wxSAudioString;
51 wxString wxSAudioFilename;
52 wxString wxSAudioMIMEType;
53 sf::SoundBuffer AudioBuffer;
57 wxSAudioFilename = fipSound->GetPath();
59 if (AudioFile.Open(wxSAudioFilename, wxFile::read)){
61 len = AudioFile.Length();
63 unsigned char* AudioFileData = new unsigned char[len];
65 wxSAudioMIMEType = GetMIME(wxSAudioFilename);
67 // Check to make sure it is an audio file.
69 if (!AudioBuffer.loadFromMemory(AudioFileData, (size_t)len)){
71 // Can't load file. We must flee...
72 // Also show an error message too.
74 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);
80 // Covert the file into base64.
82 b64enc = base64_encode(AudioFileData, (int)len);
84 delete[] AudioFileData;
88 wxMessageBox(_("There was an error opening the audio file!"), _("Error opening audio file"), wxICON_ERROR);
94 SoundListPtr->insert(std::make_pair(SoundListIndex, b64enc));
98 strValue = cmbType->GetString(cmbType->GetSelection());
102 if (strValue == _("Home")) {
104 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
106 } else if (strValue == _("Work")) {
108 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
112 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("")));
116 // Setup Organisation Priority.
118 if (priorityCtrl->IsPriorityChecked()){
120 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, priorityCtrl->GetValue()));
124 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
130 SoundListAudioTypePtr->insert(std::make_pair(SoundListIndex, wxSAudioMIMEType));
132 // Setup Encoding Type.
134 SoundListAudioEncTypePtr->insert(std::make_pair(SoundListIndex, wxT("base64")));
140 coldata.SetId(SoundListIndex);
141 coldata.SetData(SoundListIndex);
142 coldata.SetText(_("Sound"));
143 ListCtrlIndex = SoundListCtrlPtr->InsertItem(coldata);
145 if (strValue == _("Home")) {
147 SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Home"));
149 } else if (strValue == _("Work")) {
151 SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Work"));
159 if (priorityCtrl->IsPriorityChecked()){
161 SoundListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
167 } else if (EditorMode == TRUE) {
169 // Do not touch the audio file but update the settings
170 // associated with the audio file.
172 long longSelected = -1;
175 // Update Category Type.
177 SoundListTypePtr->erase(SoundListIndex);
178 strValue = cmbType->GetString(cmbType->GetSelection());
180 if (strValue == _("Home")) {
182 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
184 } else if (strValue == _("Work")) {
186 SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
190 // Update Category Priority.
192 SoundListPrefPtr->erase(SoundListIndex);
194 if (priorityCtrl->IsPriorityChecked()){
196 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, priorityCtrl->GetValue()));
200 SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
206 longSelected = SoundListCtrlPtr->GetNextItem(longSelected,
208 wxLIST_STATE_SELECTED);
210 if (longSelected == -1){
214 SoundListCtrlPtr->SetItem(longSelected, 0, wxT("Sound"));
215 SoundListCtrlPtr->SetItem(longSelected, 1, strValue);
217 if (priorityCtrl->IsPriorityChecked()){
219 SoundListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
223 SoundListCtrlPtr->SetItem(longSelected, 2, wxT(""));
232 void frmContactEditorSound::CloseWindow( wxCommandEvent& event )
235 // Close this window.
241 void frmContactEditorSound::SetEditorMode(bool EditMode)
244 // Set the editor mode.
246 // Set if the editor is adding or editing an address.
250 if (EditMode == FALSE){
253 btnAction->SetLabel(_("Add"));
254 this->SetTitle(_("Add Sound"));
256 } else if (EditMode == TRUE){
259 btnAction->SetLabel(_("Modify"));
260 this->SetTitle(_("Modify Sound"));
263 std::map<int,int>::iterator intiter;
264 std::map<int,wxString>::iterator striter;
267 // Load the data into the form. Get the website.
269 striter = SoundListTypePtr->find(SoundListIndex);
271 if (striter->first == SoundListIndex){
273 strValue = striter->second;
277 if (strValue == wxT("home")){
279 cmbType->SetSelection(1);
281 } else if (strValue == wxT("work")){
283 cmbType->SetSelection(2);
287 cmbType->SetSelection(0);
291 // Get the website priority.
293 intiter = SoundListPrefPtr->find(SoundListIndex);
295 if (intiter->first == SoundListIndex && intiter->second > 0 &&
296 intiter != SoundListPrefPtr->end()){
298 priorityCtrl->SetValue(intiter->second);
299 priorityCtrl->EnablePriority(true);
309 void frmContactEditorSound::SetupPointers(std::map<int, std::string> *SoundList,
310 std::map<int, wxString> *SoundListAltID,
311 std::map<int, wxString> *SoundListPID,
312 std::map<int, wxString> *SoundListType,
313 std::map<int, wxString> *SoundListAudioType,
314 std::map<int, wxString> *SoundListAudioEncType,
315 std::map<int, wxString> *SoundListTokens,
316 std::map<int, wxString> *SoundListMediatype,
317 std::map<int, int> *SoundListPref,
318 wxListCtrl *SoundListCtrl,
322 // Setup the pointers.
324 SoundListPtr = SoundList;
325 SoundListAltIDPtr = SoundListAltID;
326 SoundListPIDPtr = SoundListPID;
327 SoundListTypePtr = SoundListType;
328 SoundListAudioTypePtr = SoundListAudioType;
329 SoundListAudioEncTypePtr = SoundListAudioEncType;
330 SoundListTokensPtr = SoundListTokens;
331 SoundListMediatypePtr = SoundListMediatype;
332 SoundListPrefPtr = SoundListPref;
333 SoundListCtrlPtr = SoundListCtrl;
334 SoundListIndex = SoundIndex;