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