Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed flen from frmContactEditorSound::ProcessData()
[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                 if (AudioFile.Open(wxSAudioFilename, wxFile::read)){
80                         
81                         len = AudioFile.Length();
82                         
83                         unsigned char* AudioFileData = new unsigned char[len];
84                         
85                         wxSAudioMIMEType = GetMIME(wxSAudioFilename);
87                         // Check to make sure it is an audio file.
88                         
89                         if (!AudioBuffer.loadFromMemory(AudioFileData, (size_t)len)){
90                 
91                                 // Can't load file. We must flee...
92                                 // Also show an error message too.
93                         
94                                 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);                   
95                         
96                                 return;
97                 
98                         }
99                         
100                         // Covert the file into base64.
101                 
102                         b64enc = base64_encode(AudioFileData, (int)len);                        
103                         
104                         delete[] AudioFileData;
105         
106                 } else {
107         
108                         wxMessageBox(_("There was an error opening the audio file!"), _("Error opening audio file"), wxICON_ERROR);
109         
110                         return;
111         
112                 }               
114                 SoundListPtr->insert(std::make_pair(SoundListIndex, b64enc));           
116                 wxString strValue;              
117                 strValue.Clear();
118                 strValue = cmbType->GetString(cmbType->GetSelection());
120                 // Setup Sound Type.
122                 if (strValue == _("Home")) {
123                 
124                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
125                 
126                 } else if (strValue == _("Work")) {
127                 
128                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
129                 
130                 } else {
131                 
132                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("")));
133                 
134                 }
135                 
136                 // Setup Organisation Priority.
137                 
138                 if (chkUsePref->IsChecked()){
139                 
140                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
141                 
142                 } else {
143                 
144                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
145                 
146                 }
147                 
148                 // Setup MIME Type.
149                 
150                 SoundListAudioTypePtr->insert(std::make_pair(SoundListIndex, wxSAudioMIMEType));
151                 
152                 // Setup Encoding Type.
153                 
154                 SoundListAudioEncTypePtr->insert(std::make_pair(SoundListIndex, wxT("base64")));
155                                 
156                 // Add to form.
157                 
158                 wxListItem coldata;
159                 
160                 coldata.SetId(SoundListIndex);
161                 coldata.SetData(SoundListIndex);
162                 coldata.SetText(_("Sound"));
163                 ListCtrlIndex = SoundListCtrlPtr->InsertItem(coldata);
164                 
165                 if (strValue == _("Home")) {
166                 
167                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Home"));
168                 
169                 } else if (strValue == _("Work")) {
170                 
171                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Work"));
172                 
173                 } else {
174                 
176                 
177                 }               
178                 
179                 if (chkUsePref->IsChecked()){
180                 
181                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
182                 
183                 }
184                 
185                 this->Close();
186                 
187         } else if (EditorMode == TRUE) {
188         
189                 // Do not touch the audio file but update the settings
190                 // associated with the audio file.
191         
192                 long longSelected = -1;
193                 wxString strValue;      
194                 
195                 // Update Category Type.
196                 
197                 SoundListTypePtr->erase(SoundListIndex);
198                 strValue = cmbType->GetString(cmbType->GetSelection());         
199                 
200                 if (strValue == _("Home")) {
201                 
202                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
203                 
204                 } else if (strValue == _("Work")) {
205                 
206                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
207                 
208                 }               
209                 
210                 // Update Category Priority.
211                 
212                 SoundListPrefPtr->erase(SoundListIndex);
213                 
214                 if (chkUsePref->IsChecked()){
215                 
216                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
217                 
218                 } else {
219                 
220                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
221                 
222                 }
223                 
224                 // Update form.
225                 
226                 longSelected = SoundListCtrlPtr->GetNextItem(longSelected, 
227                         wxLIST_NEXT_ALL,
228                         wxLIST_STATE_SELECTED);
229                         
230                 if (longSelected == -1){
231                         return;
232                 }               
233                 
234                 SoundListCtrlPtr->SetItem(longSelected, 0, wxT("Sound"));
235                 SoundListCtrlPtr->SetItem(longSelected, 1, strValue);
236                 
237                 if (chkUsePref->IsChecked()){
238                 
239                         SoundListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
240                 
241                 } else {
242                 
243                         SoundListCtrlPtr->SetItem(longSelected, 2, wxT(""));
244                 
245                 }
246                 
247                 this->Close();  
248         
249         }
252 void frmContactEditorSound::CloseWindow( wxCommandEvent& event )
254         
255         // Close this window.
256         
257         this->Close();
258         
261 void frmContactEditorSound::SetEditorMode(bool EditMode)
263         
264         // Set the editor mode.
265         
266         // Set if the editor is adding or editing an address.
267         // FALSE = Add
268         // TRUE = Edit
269         
270         if (EditMode == FALSE){
271         
272                 EditorMode = FALSE;
273                 btnAction->SetLabel(_("Add"));
274                 this->SetTitle(_("Add Sound"));
275         
276         } else if (EditMode == TRUE){
277         
278                 EditorMode = TRUE;
279                 btnAction->SetLabel(_("Modify"));
280                 this->SetTitle(_("Modify Sound"));
281                 fipSound->Disable();
282                 
283                 std::map<int,int>::iterator intiter;
284                 std::map<int,wxString>::iterator striter;               
285                 wxString strValue;
286                 
287                 // Load the data into the form. Get the website.
288                 
289                 striter = SoundListTypePtr->find(SoundListIndex);
290                  
291                 if (striter->first == SoundListIndex){
292                 
293                         strValue = striter->second;
294                 
295                 }
296                 
297                 if (strValue == wxT("home")){
298                 
299                         cmbType->SetSelection(1);
300                 
301                 } else if (strValue == wxT("work")){ 
302                 
303                         cmbType->SetSelection(2);
304                 
305                 } else {
306                 
307                         cmbType->SetSelection(0);
308                 
309                 }
311                 // Get the website priority.
312                 
313                 intiter = SoundListPrefPtr->find(SoundListIndex);
314                 
315                 if (intiter->first == SoundListIndex && intiter->second > 0 &&
316                         intiter != SoundListPrefPtr->end()){
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 )
342         
343         // Setup the pointers.
345         SoundListPtr = SoundList;
346         SoundListAltIDPtr = SoundListAltID;
347         SoundListPIDPtr = SoundListPID;
348         SoundListTypePtr = SoundListType;
349         SoundListAudioTypePtr = SoundListAudioType;
350         SoundListAudioEncTypePtr = SoundListAudioEncType;
351         SoundListTokensPtr = SoundListTokens;
352         SoundListMediatypePtr = SoundListMediatype;     
353         SoundListPrefPtr = SoundListPref;
354         SoundListCtrlPtr = SoundListCtrl;
355         SoundListIndex = SoundIndex;
356         
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