Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
6e77c686ecb8d61b0eeefff83e9182c781be6a28
[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 frmContactEditorSound::frmContactEditorSound( wxWindow* parent )
22 :
23 frmContactEditorSoundADT( parent )
24 {
25         
26         // Setup the window.
27         
28         EditorMode = FALSE;
29         sliPriority->Disable();
30         
31         cmbType->Append(wxT(""));
32         cmbType->Append(_("Home"));
33         cmbType->Append(_("Work"));     
34         
35 }
37 void frmContactEditorSound::EnablePriority( wxCommandEvent& event )
38 {
39         
40         // Enable/disable the priority setting.
41         
42         if (chkUsePref->IsChecked()){
43                 sliPriority->Enable();
44         } else {
45                 sliPriority->Disable();
46         }
47         
48 }
50 void frmContactEditorSound::ProcessData( wxCommandEvent& event )
51 {
52         
53         // Process audio data.
54         
55         long ListCtrlIndex;
56         
57         if (EditorMode == FALSE){
59                 // Load the file into memory.
60                 
61                 wxFile AudioFile;
62                 wxString wxSAudioString;
63                 wxString wxSAudioFilename;
64                 wxString wxSAudioMIMEType;
65                 sf::SoundBuffer AudioBuffer;
66                 wxFileOffset len;
67                 std::string b64enc;             
68                 
69                 wxSAudioFilename = fipSound->GetPath();
71                 if (AudioFile.Open(wxSAudioFilename, wxFile::read)){
72                         
73                         len = AudioFile.Length();
74                         
75                         unsigned char* AudioFileData = new unsigned char[len];
76                         
77                         wxSAudioMIMEType = GetMIME(wxSAudioFilename);
79                         // Check to make sure it is an audio file.
80                         
81                         if (!AudioBuffer.loadFromMemory(AudioFileData, (size_t)len)){
82                 
83                                 // Can't load file. We must flee...
84                                 // Also show an error message too.
85                         
86                                 wxMessageBox(_("This file is in an audio format that is unsupported or is not an audio file."), _("Error opening audio file"), wxICON_ERROR);                   
87                         
88                                 return;
89                 
90                         }
91                         
92                         // Covert the file into base64.
93                 
94                         b64enc = base64_encode(AudioFileData, (int)len);                        
95                         
96                         delete[] AudioFileData;
97         
98                 } else {
99         
100                         wxMessageBox(_("There was an error opening the audio file!"), _("Error opening audio file"), wxICON_ERROR);
101         
102                         return;
103         
104                 }               
106                 SoundListPtr->insert(std::make_pair(SoundListIndex, b64enc));           
108                 wxString strValue;              
109                 strValue.Clear();
110                 strValue = cmbType->GetString(cmbType->GetSelection());
112                 // Setup Sound Type.
114                 if (strValue == _("Home")) {
115                 
116                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
117                 
118                 } else if (strValue == _("Work")) {
119                 
120                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
121                 
122                 } else {
123                 
124                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("")));
125                 
126                 }
127                 
128                 // Setup Organisation Priority.
129                 
130                 if (chkUsePref->IsChecked()){
131                 
132                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
133                 
134                 } else {
135                 
136                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
137                 
138                 }
139                 
140                 // Setup MIME Type.
141                 
142                 SoundListAudioTypePtr->insert(std::make_pair(SoundListIndex, wxSAudioMIMEType));
143                 
144                 // Setup Encoding Type.
145                 
146                 SoundListAudioEncTypePtr->insert(std::make_pair(SoundListIndex, wxT("base64")));
147                                 
148                 // Add to form.
149                 
150                 wxListItem coldata;
151                 
152                 coldata.SetId(SoundListIndex);
153                 coldata.SetData(SoundListIndex);
154                 coldata.SetText(_("Sound"));
155                 ListCtrlIndex = SoundListCtrlPtr->InsertItem(coldata);
156                 
157                 if (strValue == _("Home")) {
158                 
159                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Home"));
160                 
161                 } else if (strValue == _("Work")) {
162                 
163                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Work"));
164                 
165                 } else {
166                 
168                 
169                 }               
170                 
171                 if (chkUsePref->IsChecked()){
172                 
173                         SoundListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
174                 
175                 }
176                 
177                 this->Close();
178                 
179         } else if (EditorMode == TRUE) {
180         
181                 // Do not touch the audio file but update the settings
182                 // associated with the audio file.
183         
184                 long longSelected = -1;
185                 wxString strValue;      
186                 
187                 // Update Category Type.
188                 
189                 SoundListTypePtr->erase(SoundListIndex);
190                 strValue = cmbType->GetString(cmbType->GetSelection());         
191                 
192                 if (strValue == _("Home")) {
193                 
194                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("home")));
195                 
196                 } else if (strValue == _("Work")) {
197                 
198                         SoundListTypePtr->insert(std::make_pair(SoundListIndex, wxT("work")));
199                 
200                 }               
201                 
202                 // Update Category Priority.
203                 
204                 SoundListPrefPtr->erase(SoundListIndex);
205                 
206                 if (chkUsePref->IsChecked()){
207                 
208                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, sliPriority->GetValue()));
209                 
210                 } else {
211                 
212                         SoundListPrefPtr->insert(std::make_pair(SoundListIndex, 0));
213                 
214                 }
215                 
216                 // Update form.
217                 
218                 longSelected = SoundListCtrlPtr->GetNextItem(longSelected, 
219                         wxLIST_NEXT_ALL,
220                         wxLIST_STATE_SELECTED);
221                         
222                 if (longSelected == -1){
223                         return;
224                 }               
225                 
226                 SoundListCtrlPtr->SetItem(longSelected, 0, wxT("Sound"));
227                 SoundListCtrlPtr->SetItem(longSelected, 1, strValue);
228                 
229                 if (chkUsePref->IsChecked()){
230                 
231                         SoundListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
232                 
233                 } else {
234                 
235                         SoundListCtrlPtr->SetItem(longSelected, 2, wxT(""));
236                 
237                 }
238                 
239                 this->Close();  
240         
241         }
244 void frmContactEditorSound::CloseWindow( wxCommandEvent& event )
246         
247         // Close this window.
248         
249         this->Close();
250         
253 void frmContactEditorSound::SetEditorMode(bool EditMode)
255         
256         // Set the editor mode.
257         
258         // Set if the editor is adding or editing an address.
259         // FALSE = Add
260         // TRUE = Edit
261         
262         if (EditMode == FALSE){
263         
264                 EditorMode = FALSE;
265                 btnAction->SetLabel(_("Add"));
266                 this->SetTitle(_("Add Sound"));
267         
268         } else if (EditMode == TRUE){
269         
270                 EditorMode = TRUE;
271                 btnAction->SetLabel(_("Modify"));
272                 this->SetTitle(_("Modify Sound"));
273                 fipSound->Disable();
274                 
275                 std::map<int,int>::iterator intiter;
276                 std::map<int,wxString>::iterator striter;               
277                 wxString strValue;
278                 
279                 // Load the data into the form. Get the website.
280                 
281                 striter = SoundListTypePtr->find(SoundListIndex);
282                  
283                 if (striter->first == SoundListIndex){
284                 
285                         strValue = striter->second;
286                 
287                 }
288                 
289                 if (strValue == wxT("home")){
290                 
291                         cmbType->SetSelection(1);
292                 
293                 } else if (strValue == wxT("work")){ 
294                 
295                         cmbType->SetSelection(2);
296                 
297                 } else {
298                 
299                         cmbType->SetSelection(0);
300                 
301                 }
303                 // Get the website priority.
304                 
305                 intiter = SoundListPrefPtr->find(SoundListIndex);
306                 
307                 if (intiter->first == SoundListIndex && intiter->second > 0 &&
308                         intiter != SoundListPrefPtr->end()){
310                         sliPriority->SetValue(intiter->second);
311                         sliPriority->Enable();
312                         chkUsePref->SetValue(TRUE);
313                 
314                 }       
315                 
316         }
317         
318         
319                 
322 void frmContactEditorSound::SetupPointers(std::map<int, std::string> *SoundList,                        
323         std::map<int, wxString> *SoundListAltID,
324         std::map<int, wxString> *SoundListPID,
325         std::map<int, wxString> *SoundListType,
326         std::map<int, wxString> *SoundListAudioType,    
327         std::map<int, wxString> *SoundListAudioEncType,
328         std::map<int, wxString> *SoundListTokens,
329         std::map<int, wxString> *SoundListMediatype,    
330         std::map<int, int> *SoundListPref,
331         wxListCtrl *SoundListCtrl,
332         int SoundIndex )
334         
335         // Setup the pointers.
337         SoundListPtr = SoundList;
338         SoundListAltIDPtr = SoundListAltID;
339         SoundListPIDPtr = SoundListPID;
340         SoundListTypePtr = SoundListType;
341         SoundListAudioTypePtr = SoundListAudioType;
342         SoundListAudioEncTypePtr = SoundListAudioEncType;
343         SoundListTokensPtr = SoundListTokens;
344         SoundListMediatypePtr = SoundListMediatype;     
345         SoundListPrefPtr = SoundListPref;
346         SoundListCtrlPtr = SoundListCtrl;
347         SoundListIndex = SoundIndex;
348         
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