Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed references to the boost library in remaining source and header files.
[xestiaab/.git] / source / contacteditor / frmContactEditorPicture.cpp
1 // frmContactEditorPicture.cpp - frmContactEditorPicture 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 "frmContactEditorPicture.h"
21 #include <wx/wx.h>
22 #include <wx/tokenzr.h>
23 #include <wx/icon.h>
24 #include <wx/mstream.h>
25 #include <wx/fs_mem.h>
26 #include <SFML/Audio.hpp>
28 #include "../common/textprocessing.h"
29 #include "../common/base64.h"
30 #include "../common/mime.h"
33 frmContactEditorPicture::frmContactEditorPicture( wxWindow* parent )
34 :
35 frmContactEditorPictureADT( parent )
36 {
37         EditorMode = FALSE;
38         sliPriority->Disable();
39         
40         cmbType->Append(wxT(""));
41         cmbType->Append(_("Home"));
42         cmbType->Append(_("Work"));
43 }
45 void frmContactEditorPicture::EnablePriority( wxCommandEvent& event )
46 {
47         if (chkUsePref->IsChecked()){
48                 sliPriority->Enable();
49         } else {
50                 sliPriority->Disable();
51         }
52 }
54 void frmContactEditorPicture::ProcessData( wxCommandEvent& event )
55 {
56         long ListCtrlIndex;
57         
58         if (EditorMode == FALSE){
60                 // Load the file into memory.
61                 
62                 wxFile PictureFile;
63                 wxString wxSPictureFilename;
64                 wxString wxSPictureMIMEType;
65                 size_t len;
66                 std::string b64enc;             
67                 
68                 wxSPictureFilename = fipPicture->GetPath();
70 /*              
71 #if wxABI_VERSION < 20900
72                 if (AudioFile.Open(wxSAudioFilename.c_str(), wxT("rb"))){
73 #else
74                 if (AudioFile.Open(wxSAudioFilename, wxT("rb"))){
75 #endif
77 */
78                 if (PictureFile.Open(wxSPictureFilename, wxFile::read)){
79                         size_t flen;
80                         len = PictureFile.Length();
81                         
82                         unsigned char* PictureFileData = new unsigned char[len];
83                         flen = PictureFile.Read(PictureFileData, len);                  
84                         
85                         // Check to make sure it is an audio file.
86                         
87                         wxMemoryInputStream istream(PictureFileData, flen);
88                         wxImage photo;                  
89                         
90                         //wxBitmap (bigimgs_contactpersonicon48i, -1);
91                         
92                         //Get MIME data.
93                         
94                         /*const char *MIMEType;
95                         magic_t MagicCookie = magic_open(MAGIC_MIME);                   
96                         magic_setflags(MagicCookie, MAGIC_MIME_TYPE);
97                         
98                         if (!MagicCookie){
100                                 wxMessageBox(_("An error occured with the support library for getting the picture type."), _("Error opening picture file"), wxICON_ERROR);                      
101                                 return;
102                                 
103                         }
104                         
105                         if (magic_load(MagicCookie, NULL) != 0) {
106                         
107                                 wxMessageBox(_("An error occured whilst determining the picture type."), _("Error opening picture file"), wxICON_ERROR);
108                                 return;
109                         
110                         }
111                         
112                         MIMEType = magic_file(MagicCookie, wxSPictureFilename.mb_str());
113                         wxSPictureMIMEType = wxString::FromUTF8(MIMEType);
114                         magic_close(MagicCookie);*/
115                         
116                         wxSPictureMIMEType = GetMIME(wxSPictureFilename);
117                         
118                         if (!photo.LoadFile(istream, wxBITMAP_TYPE_ANY)){
120                                 wxMessageBox(_("This file is in an picture format that is unsupported or is not a picture file."), _("Error opening picture file"), wxICON_ERROR);
121                                 return;                 
122                                                         
123                         
124                         }
125                         
126                         // Covert the file into base64.
127                 
128                         b64enc = base64_encode(PictureFileData, (int)len);                      
129                         
130                         delete[] PictureFileData;
131         
132                 } else {
133         
134                         wxMessageBox(_("There was an error opening the audio file!"), _("Error opening audio file"), wxICON_ERROR);
135         
136                         return;
137         
138                 }               
140                 PictureListPtr->insert(std::make_pair(PictureListIndex, b64enc));
142                 wxString strValue;              
143                 strValue.Clear();
144                 
145                 strValue = cmbType->GetString(cmbType->GetSelection());
147                 // Setup Picture Type.
149                 if (strValue == _("Home")) {
150                 
151                         PictureListTypePtr->insert(std::make_pair(PictureListIndex, wxT("home")));
152                 
153                 } else if (strValue == _("Work")) {
154                 
155                         PictureListTypePtr->insert(std::make_pair(PictureListIndex, wxT("work")));
156                 
157                 } else {
158                 
159                         PictureListTypePtr->insert(std::make_pair(PictureListIndex, wxT("")));
160                 
161                 }
162                 
163                 // Setup Organisation Priority.
164                 
165                 if (chkUsePref->IsChecked()){
166                 
167                         PictureListPrefPtr->insert(std::make_pair(PictureListIndex, sliPriority->GetValue()));
168                 
169                 } else {
170                 
171                         PictureListPrefPtr->insert(std::make_pair(PictureListIndex, 0));
172                 
173                 }
174                 
175                 // Setup MIME Type.
176                 
177                 PictureListPictureTypePtr->insert(std::make_pair(PictureListIndex, wxSPictureMIMEType));
178                 
179                 // Setup encoding type.
180                 
181                 PictureListPicEncTypePtr->insert(std::make_pair(PictureListIndex, wxT("base64")));
182                 
183                 // Add to form.
184                 
185                 wxListItem coldata;
186                 
187                 coldata.SetId(PictureListIndex);
188                 coldata.SetData(PictureListIndex);
189                 coldata.SetText(_("Picture"));
190                 ListCtrlIndex = PictureListCtrlPtr->InsertItem(coldata);
191                 
192                 if (strValue == _("Home")) {
193                 
194                         PictureListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Home"));
195                 
196                 } else if (strValue == _("Work")) {
197                 
198                         PictureListCtrlPtr->SetItem(ListCtrlIndex, 1, _("Work"));
199                 
200                 } else {
201                 
203                 
204                 }               
205                 
206                 if (chkUsePref->IsChecked()){
207                 
208                         PictureListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
209                 
210                 }
211                 
212                 this->Close();
213                 
214         } else if (EditorMode == TRUE) {
215         
216                 // Do not touch the audio file but update the settings
217                 // associated with the audio file.
218         
219                 long longSelected = -1;
220                 wxString strValue;      
221                 
222                 // Update Picture Type.
223                 
224                 PictureListTypePtr->erase(PictureListIndex);
225                 strValue = cmbType->GetString(cmbType->GetSelection());         
226                 
227                 if (strValue == _("Home")) {
228                 
229                         PictureListTypePtr->insert(std::make_pair(PictureListIndex, wxT("home")));
230                 
231                 } else if (strValue == _("Work")) {
232                 
233                         PictureListTypePtr->insert(std::make_pair(PictureListIndex, wxT("work")));
234                 
235                 }               
236                 
237                 // Update Category Priority.
238                 
239                 PictureListPrefPtr->erase(PictureListIndex);
240                 
241                 if (chkUsePref->IsChecked()){
242                 
243                         PictureListPrefPtr->insert(std::make_pair(PictureListIndex, sliPriority->GetValue()));
244                 
245                 } else {
246                 
247                         PictureListPrefPtr->insert(std::make_pair(PictureListIndex, 0));
248                 
249                 }
250                 
251                 // Update form.
252                 
253                 longSelected = PictureListCtrlPtr->GetNextItem(longSelected, 
254                         wxLIST_NEXT_ALL,
255                         wxLIST_STATE_SELECTED);
256                         
257                 if (longSelected == -1){
258                         return;
259                 }               
260                 
261                 PictureListCtrlPtr->SetItem(longSelected, 0, wxT("Picture"));
262                 PictureListCtrlPtr->SetItem(longSelected, 1, strValue);
263                 
264                 if (chkUsePref->IsChecked()){
265                 
266                         PictureListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
267                 
268                 } else {
269                 
270                         PictureListCtrlPtr->SetItem(longSelected, 2, wxT(""));
271                 
272                 }
273                 
274                 this->Close();  
275         
276         }
279 void frmContactEditorPicture::CloseWindow( wxCommandEvent& event )
281         this->Close();
284 void frmContactEditorPicture::SetEditorMode(bool EditMode)
286         // Set if the editor is adding or editing an address.
287         // FALSE = Add
288         // TRUE = Edit
289         
290         if (EditMode == FALSE){
291         
292                 EditorMode = FALSE;
293                 btnAction->SetLabel(_("Add"));
294                 this->SetTitle(_("Add Picture"));
295         
296         } else if (EditMode == TRUE){
297         
298                 EditorMode = TRUE;
299                 btnAction->SetLabel(_("Modify"));
300                 this->SetTitle(_("Modify Picture"));
301                 fipPicture->Disable();
302                 
303                 std::map<int,int>::iterator intiter;
304                 std::map<int,wxString>::iterator striter;               
305                 wxString strValue;
306                 
307                 // Load the data into the form. Get the website.
308                 
309                 striter = PictureListTypePtr->find(PictureListIndex);
310                  
311                 if (striter->first == PictureListIndex){
312                 
313                         strValue = striter->second;
314                 
315                 }
316                 
317                 if (strValue == wxT("home")){
318                 
319                         cmbType->SetSelection(1);
320                 
321                 } else if (strValue == wxT("work")){ 
322                 
323                         cmbType->SetSelection(2);
324                 
325                 } else {
326                 
327                         cmbType->SetSelection(0);
328                 
329                 }
330                 
331                 //strValue.Clear();
332                 
333                 // Get the website priority.
334                 
335                 intiter = PictureListPrefPtr->find(PictureListIndex);
336                 
337                 if (intiter->first == PictureListIndex && intiter->second > 0){
338                 
339                         sliPriority->SetValue(intiter->second);
340                         sliPriority->Enable();
341                         chkUsePref->SetValue(TRUE);
342                 
343                 }       
344                 
345         }
346                 
349 void frmContactEditorPicture::SetupPointers(std::map<int, std::string> *PictureList,                    
350         std::map<int, wxString> *PictureListAltID,
351         std::map<int, wxString> *PictureListPID,
352         std::map<int, wxString> *PictureListType,
353         std::map<int, wxString> *PictureListPicEncType, 
354         std::map<int, wxString> *PictureListPictureType,        
355         std::map<int, wxString> *PictureListTokens,
356         std::map<int, wxString> *PictureListMediatype,  
357         std::map<int, int> *PictureListPref,
358         wxListCtrl *PictureListCtrl,
359         int PictureIndex )
362         PictureListPtr = PictureList;
363         PictureListAltIDPtr = PictureListAltID;
364         PictureListPIDPtr = PictureListPID;
365         PictureListPicEncTypePtr = PictureListPicEncType;       
366         PictureListPictureTypePtr = PictureListPictureType;
367         PictureListTypePtr = PictureListType;
368         PictureListTokensPtr = PictureListTokens;
369         PictureListMediatypePtr = PictureListMediatype; 
370         PictureListPrefPtr = PictureListPref;
371         PictureListCtrlPtr = PictureListCtrl;
372         PictureListIndex = PictureIndex;
373         
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