Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and license header to the C++ source and header files in the contacte...
[xestiaab/.git] / source / contacteditor / frmContactEditorSound.cpp
1 // frmContactEditorSound.cpp - frmContactEditorSound form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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 #include <wx/tokenzr.h>
22 #include <wx/file.h>
23 #include <SFML/Audio.hpp>
25 #include "../common/textprocessing.h"
26 #include "../common/base64.h"
27 #include "../common/mime.h"
29 frmContactEditorSound::frmContactEditorSound( wxWindow* parent )
30 :
31 frmContactEditorSoundADT( parent )
32 {
33         EditorMode = FALSE;
34         sliPriority->Disable();
35         
36         cmbType->Append(wxT(""));
37         cmbType->Append(_("Home"));
38         cmbType->Append(_("Work"));     
39 }
41 void frmContactEditorSound::EnablePriority( wxCommandEvent& event )
42 {
43         if (chkUsePref->IsChecked()){
44                 sliPriority->Enable();
45         } else {
46                 sliPriority->Disable();
47         }
48 }
50 void frmContactEditorSound::ProcessData( wxCommandEvent& event )
51 {
52         long ListCtrlIndex;
53         
54         if (EditorMode == FALSE){
56                 // Load the file into memory.
57                 
58                 wxFile AudioFile;
59                 wxString wxSAudioString;
60                 wxString wxSAudioFilename;
61                 wxString wxSAudioMIMEType;
62                 sf::SoundBuffer AudioBuffer;
63                 wxFileOffset len;
64                 std::string b64enc;             
65                 
66                 wxSAudioFilename = fipSound->GetPath();
68 /*              
69 #if wxABI_VERSION < 20900
70                 if (AudioFile.Open(wxSAudioFilename.c_str(), wxT("rb"))){
71 #else
72                 if (AudioFile.Open(wxSAudioFilename, wxT("rb"))){
73 #endif
75 */
76                 if (AudioFile.Open(wxSAudioFilename, wxFile::read)){
77             ssize_t flen;
78                         len = AudioFile.Length();
79                         
80                         unsigned char* AudioFileData = new unsigned char[len];
81                         flen = AudioFile.Read(AudioFileData, (size_t)len);
83                         // Get MIME Type.
84                         
85                         /*const char *MIMEType;
86                         magic_t MagicCookie = magic_open(MAGIC_MIME);                   
87                         magic_setflags(MagicCookie, MAGIC_MIME_TYPE);
88                         
89                         if (!MagicCookie){
91                                 wxMessageBox(_("An error occured with the support library for getting the picture type."), _("Error opening picture file"), wxICON_ERROR);                      
92                                 return;
93                                 
94                         }
95                         
96                         if (magic_load(MagicCookie, NULL) != 0) {
97                         
98                                 wxMessageBox(_("An error occured whilst determining the picture type."), _("Error opening picture file"), wxICON_ERROR);
99                                 return;
100                         
101                         }
102                         
103                         MIMEType = magic_file(MagicCookie, wxSAudioFilename.mb_str());
104                         wxSAudioMIMEType = wxString::FromUTF8(MIMEType);
105                         magic_close(MagicCookie);*/
106                         
107                         wxSAudioMIMEType = GetMIME(wxSAudioFilename);
109                         // Check to make sure it is an audio file.
110                         
111                         if (!AudioBuffer.loadFromMemory(AudioFileData, (size_t)len)){
112                 
113                                 // Can't load file. We must flee...
114                                 // Also show an error message too.
115                         
116                                 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);                   
117                         
118                                 return;
119                 
120                         }
121                         
122                         // Covert the file into base64.
123                 
124                         b64enc = base64_encode(AudioFileData, (int)len);                        
125                         
126                         delete[] AudioFileData;
127         
128                 } else {
129         
130                         wxMessageBox(_("There was an error opening the audio file!"), _("Error opening audio file"), wxICON_ERROR);
131         
132                         return;
133         
134                 }               
136                 SoundListPtr->insert(std::make_pair(SoundListIndex, b64enc));           
138                 wxString strValue;              
139                 strValue.Clear();
140                 strValue = cmbType->GetString(cmbType->GetSelection());
142                 // Setup Sound Type.
144                 if (strValue == _("Home")) {
145                 
146                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
147                 
148                 } else if (strValue == _("Work")) {
149                 
150                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
151                 
152                 } else {
153                 
154                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("")));
155                 
156                 }
157                 
158                 // Setup Organisation Priority.
159                 
160                 if (chkUsePref->IsChecked()){
161                 
162                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
163                 
164                 } else {
165                 
166                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
167                 
168                 }
169                 
170                 // Setup MIME Type.
171                 
172                 SoundListAudioTypePtr->insert(std::make_pair(SoundListIndex, wxSAudioMIMEType));
173                 
174                 // Setup Encoding Type.
175                 
176                 SoundListAudioEncTypePtr->insert(std::make_pair(SoundListIndex, wxT("base64")));
177                                 
178                 // Add to form.
179                 
180                 wxListItem coldata;
181                 
182                 coldata.SetId(SoundListIndex);
183                 coldata.SetData(SoundListIndex);
184                 coldata.SetText(_("Sound"));
185                 ListCtrlIndex = SoundListCtrlPtr->InsertItem(coldata);
186                 
187                 if (strValue == _("Home")) {
188                 
189                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Home"));
190                 
191                 } else if (strValue == _("Work")) {
192                 
193                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Work"));
194                 
195                 } else {
196                 
198                 
199                 }               
200                 
201                 if (chkUsePref->IsChecked()){
202                 
203                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
204                 
205                 }
206                 
207                 this->Close();
208                 
209         } else if (EditorMode == TRUE) {
210         
211                 // Do not touch the audio file but update the settings
212                 // associated with the audio file.
213         
214                 
215         
216                 long longSelected = -1;
217                 wxString strValue;      
218                 
219                 // Update Category Type.
220                 
221                 SoundListTypePtr->erase(SoundListIndex);
222                 strValue = cmbType->GetString(cmbType->GetSelection());         
223                 
224                 if (strValue == _("Home")) {
225                 
226                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
227                 
228                 } else if (strValue == _("Work")) {
229                 
230                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
231                 
232                 }               
233                 
234                 // Update Category Priority.
235                 
236                 SoundListPrefPtr->erase(SoundListIndex);
237                 
238                 if (chkUsePref->IsChecked()){
239                 
240                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
241                 
242                 } else {
243                 
244                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
245                 
246                 }
247                 
248                 // Update form.
249                 
250                 longSelected = SoundListCtrlPtr->GetNextItem(longSelected, 
251                         wxLIST_NEXT_ALL,
252                         wxLIST_STATE_SELECTED);
253                         
254                 if (longSelected == -1){
255                         return;
256                 }               
257                 
258                 SoundListCtrlPtr->SetItem(longSelected, 0, wxT("Sound"));
259                 SoundListCtrlPtr->SetItem(longSelected, 1, strValue);
260                 
261                 if (chkUsePref->IsChecked()){
262                 
263                         SoundListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
264                 
265                 } else {
266                 
267                         SoundListCtrlPtr->SetItem(longSelected, 2, wxT(""));
268                 
269                 }
270                 
271                 this->Close();  
272         
273         }
276 void frmContactEditorSound::CloseWindow( wxCommandEvent& event )
278         this->Close();
281 void frmContactEditorSound::SetEditorMode(bool EditMode)
283         // Set if the editor is adding or editing an address.
284         // FALSE = Add
285         // TRUE = Edit
286         
287         if (EditMode == FALSE){
288         
289                 EditorMode = FALSE;
290                 btnAction->SetLabel(_("Add"));
291                 this->SetTitle(_("Add Sound"));
292         
293         } else if (EditMode == TRUE){
294         
295                 EditorMode = TRUE;
296                 btnAction->SetLabel(_("Modify"));
297                 this->SetTitle(_("Modify Sound"));
298                 fipSound->Disable();
299                 
300                 std::map<int,int>::iterator intiter;
301                 std::map<int,wxString>::iterator striter;               
302                 wxString strValue;
303                 
304                 // Load the data into the form. Get the website.
305                 
306                 striter = SoundListTypePtr->find(SoundListIndex);
307                  
308                 if (striter->first == SoundListIndex){
309                 
310                         strValue = striter->second;
311                 
312                 }
313                 
314                 if (strValue == wxT("home")){
315                 
316                         cmbType->SetSelection(1);
317                 
318                 } else if (strValue == wxT("work")){ 
319                 
320                         cmbType->SetSelection(2);
321                 
322                 } else {
323                 
324                         cmbType->SetSelection(0);
325                 
326                 }
327                 
328                 //strValue.Clear();
329                 
330                 // Get the website priority.
331                 
332                 intiter = SoundListPrefPtr->find(SoundListIndex);
333                 
334                 if (intiter->first == SoundListIndex && intiter->second > 0){
335                 
336                         sliPriority->SetValue(intiter->second);
337                         sliPriority->Enable();
338                         chkUsePref->SetValue(TRUE);
339                 
340                 }       
341                 
342         }
343         
344         
345                 
348 void frmContactEditorSound::SetupPointers(std::map<int, std::string> *SoundList,                        
349         std::map<int, wxString> *SoundListAltID,
350         std::map<int, wxString> *SoundListPID,
351         std::map<int, wxString> *SoundListType,
352         std::map<int, wxString> *SoundListAudioType,    
353         std::map<int, wxString> *SoundListAudioEncType,
354         std::map<int, wxString> *SoundListTokens,
355         std::map<int, wxString> *SoundListMediatype,    
356         std::map<int, int> *SoundListPref,
357         wxListCtrl *SoundListCtrl,
358         int SoundIndex )
361         SoundListPtr = SoundList;
362         SoundListAltIDPtr = SoundListAltID;
363         SoundListPIDPtr = SoundListPID;
364         SoundListTypePtr = SoundListType;
365         SoundListAudioTypePtr = SoundListAudioType;
366         SoundListAudioEncTypePtr = SoundListAudioEncType;
367         SoundListTokensPtr = SoundListTokens;
368         SoundListMediatypePtr = SoundListMediatype;     
369         SoundListPrefPtr = SoundListPref;
370         SoundListCtrlPtr = SoundListCtrl;
371         SoundListIndex = SoundIndex;
372         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy