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