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