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