Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / contacteditor / frmContactEditorSound.cpp
1 #include "frmContactEditorSound.h"
3 #include <wx/tokenzr.h>
4 #include <wx/file.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 )
12 :
13 frmContactEditorSoundADT( parent )
14 {
15         EditorMode = FALSE;
16         sliPriority->Disable();
17         
18         cmbType->Append(wxT(""));
19         cmbType->Append(_("Home"));
20         cmbType->Append(_("Work"));     
21 }
23 void frmContactEditorSound::EnablePriority( wxCommandEvent& event )
24 {
25         if (chkUsePref->IsChecked()){
26                 sliPriority->Enable();
27         } else {
28                 sliPriority->Disable();
29         }
30 }
32 void frmContactEditorSound::ProcessData( wxCommandEvent& event )
33 {
34         long ListCtrlIndex;
35         
36         if (EditorMode == FALSE){
38                 // Load the file into memory.
39                 
40                 wxFile AudioFile;
41                 wxString wxSAudioString;
42                 wxString wxSAudioFilename;
43                 wxString wxSAudioMIMEType;
44                 sf::SoundBuffer AudioBuffer;
45                 size_t len;
46                 std::string b64enc;             
47                 
48                 wxSAudioFilename = fipSound->GetPath();
50 /*              
51 #if wxABI_VERSION < 20900
52                 if (AudioFile.Open(wxSAudioFilename.c_str(), wxT("rb"))){
53 #else
54                 if (AudioFile.Open(wxSAudioFilename, wxT("rb"))){
55 #endif
57 */
58                 if (AudioFile.Open(wxSAudioFilename, wxFile::read)){
59                         size_t flen;
60                         len = AudioFile.Length();
61                         
62                         unsigned char* AudioFileData = new unsigned char[len];
63                         flen = AudioFile.Read(AudioFileData, len);                      
65                         // Get MIME Type.
66                         
67                         /*const char *MIMEType;
68                         magic_t MagicCookie = magic_open(MAGIC_MIME);                   
69                         magic_setflags(MagicCookie, MAGIC_MIME_TYPE);
70                         
71                         if (!MagicCookie){
73                                 wxMessageBox(_("An error occured with the support library for getting the picture type."), _("Error opening picture file"), wxICON_ERROR);                      
74                                 return;
75                                 
76                         }
77                         
78                         if (magic_load(MagicCookie, NULL) != 0) {
79                         
80                                 wxMessageBox(_("An error occured whilst determining the picture type."), _("Error opening picture file"), wxICON_ERROR);
81                                 return;
82                         
83                         }
84                         
85                         MIMEType = magic_file(MagicCookie, wxSAudioFilename.mb_str());
86                         wxSAudioMIMEType = wxString::FromUTF8(MIMEType);
87                         magic_close(MagicCookie);*/
88                         
89                         wxSAudioMIMEType = GetMIME(wxSAudioFilename);
91                         // Check to make sure it is an audio file.
92                         
93                         if (!AudioBuffer.loadFromMemory(AudioFileData, len)){
94                 
95                                 // Can't load file. We must flee...
96                                 // Also show an error message too.
97                         
98                                 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);                   
99                         
100                                 return;
101                 
102                         }
103                         
104                         // Covert the file into base64.
105                 
106                         b64enc = base64_encode(AudioFileData, (int)len);                        
107                         
108                         delete[] AudioFileData;
109         
110                 } else {
111         
112                         wxMessageBox(_("There was an error opening the audio file!"), _("Error opening audio file"), wxICON_ERROR);
113         
114                         return;
115         
116                 }               
118                 SoundListPtr->insert(std::make_pair(SoundListIndex, b64enc));           
120                 wxString strValue;              
121                 strValue.Clear();
122                 strValue = cmbType->GetString(cmbType->GetSelection());
124                 // Setup Sound Type.
126                 if (strValue == _("Home")) {
127                 
128                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
129                 
130                 } else if (strValue == _("Work")) {
131                 
132                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
133                 
134                 } else {
135                 
136                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("")));
137                 
138                 }
139                 
140                 // Setup Organisation Priority.
141                 
142                 if (chkUsePref->IsChecked()){
143                 
144                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
145                 
146                 } else {
147                 
148                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
149                 
150                 }
151                 
152                 // Setup MIME Type.
153                 
154                 SoundListAudioTypePtr->insert(std::make_pair(SoundListIndex, wxSAudioMIMEType));
155                 
156                 // Setup Encoding Type.
157                 
158                 SoundListAudioEncTypePtr->insert(std::make_pair(SoundListIndex, wxT("base64")));
159                                 
160                 // Add to form.
161                 
162                 wxListItem coldata;
163                 
164                 coldata.SetId(SoundListIndex);
165                 coldata.SetData(SoundListIndex);
166                 coldata.SetText(_("Sound"));
167                 ListCtrlIndex = SoundListCtrlPtr->InsertItem(coldata);
168                 
169                 if (strValue == _("Home")) {
170                 
171                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Home"));
172                 
173                 } else if (strValue == _("Work")) {
174                 
175                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Work"));
176                 
177                 } else {
178                 
180                 
181                 }               
182                 
183                 if (chkUsePref->IsChecked()){
184                 
185                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
186                 
187                 }
188                 
189                 this->Close();
190                 
191         } else if (EditorMode == TRUE) {
192         
193                 // Do not touch the audio file but update the settings
194                 // associated with the audio file.
195         
196                 
197         
198                 long longSelected = -1;
199                 wxString strValue;      
200                 
201                 // Update Category Type.
202                 
203                 SoundListTypePtr->erase(SoundListIndex);
204                 strValue = cmbType->GetString(cmbType->GetSelection());         
205                 
206                 if (strValue == _("Home")) {
207                 
208                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
209                 
210                 } else if (strValue == _("Work")) {
211                 
212                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
213                 
214                 }               
215                 
216                 // Update Category Priority.
217                 
218                 SoundListPrefPtr->erase(SoundListIndex);
219                 
220                 if (chkUsePref->IsChecked()){
221                 
222                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
223                 
224                 } else {
225                 
226                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
227                 
228                 }
229                 
230                 // Update form.
231                 
232                 longSelected = SoundListCtrlPtr->GetNextItem(longSelected, 
233                         wxLIST_NEXT_ALL,
234                         wxLIST_STATE_SELECTED);
235                         
236                 if (longSelected == -1){
237                         return;
238                 }               
239                 
240                 SoundListCtrlPtr->SetItem(longSelected, 0, wxT("Sound"));
241                 SoundListCtrlPtr->SetItem(longSelected, 1, strValue);
242                 
243                 if (chkUsePref->IsChecked()){
244                 
245                         SoundListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
246                 
247                 } else {
248                 
249                         SoundListCtrlPtr->SetItem(longSelected, 2, wxT(""));
250                 
251                 }
252                 
253                 this->Close();  
254         
255         }
258 void frmContactEditorSound::CloseWindow( wxCommandEvent& event )
260         this->Close();
263 void frmContactEditorSound::SetEditorMode(bool EditMode)
265         // Set if the editor is adding or editing an address.
266         // FALSE = Add
267         // TRUE = Edit
268         
269         if (EditMode == FALSE){
270         
271                 EditorMode = FALSE;
272                 btnAction->SetLabel(_("Add"));
273                 this->SetTitle(_("Add Sound"));
274         
275         } else if (EditMode == TRUE){
276         
277                 EditorMode = TRUE;
278                 btnAction->SetLabel(_("Modify"));
279                 this->SetTitle(_("Modify Sound"));
280                 fipSound->Disable();
281                 
282                 std::map<int,int>::iterator intiter;
283                 std::map<int,wxString>::iterator striter;               
284                 wxString strValue;
285                 
286                 // Load the data into the form. Get the website.
287                 
288                 striter = SoundListTypePtr->find(SoundListIndex);
289                  
290                 if (striter->first == SoundListIndex){
291                 
292                         strValue = striter->second;
293                 
294                 }
295                 
296                 if (strValue == wxT("home")){
297                 
298                         cmbType->SetSelection(1);
299                 
300                 } else if (strValue == wxT("work")){ 
301                 
302                         cmbType->SetSelection(2);
303                 
304                 } else {
305                 
306                         cmbType->SetSelection(0);
307                 
308                 }
309                 
310                 //strValue.Clear();
311                 
312                 // Get the website priority.
313                 
314                 intiter = SoundListPrefPtr->find(SoundListIndex);
315                 
316                 if (intiter->first == SoundListIndex && intiter->second > 0){
317                 
318                         sliPriority->SetValue(intiter->second);
319                         sliPriority->Enable();
320                         chkUsePref->SetValue(TRUE);
321                 
322                 }       
323                 
324         }
325         
326         
327                 
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,
340         int SoundIndex )
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;
354         
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