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