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