1 // frmContactEditor-Picture.cpp - frmContactEditor Picture tab subroutines.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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 "frmContactEditor.h"
20 #include "frmContactEditorPicture.h"
21 #include "../common/base64.h"
23 void frmContactEditor::AddPicture( wxCommandEvent& event )
27 frmContactEditorPicture *frameCEPicture = new frmContactEditorPicture ( this );
28 frameCEPicture->SetEditorMode(FALSE);
29 intResult = GetLastInt(&PicturesList);
30 frameCEPicture->SetupPointers(&PicturesList,
34 &PicturesListPicEncType,
35 &PicturesListPictureType,
37 &PicturesListMediatype,
41 frameCEPicture->ShowModal();
42 delete frameCEPicture;
43 frameCEPicture = NULL;
46 void frmContactEditor::ModifyPicture( wxCommandEvent& event )
48 long longSelected = -1;
49 int intSelectedData = 0;
51 if (!GetSelectedItem(lboPictures,
57 frmContactEditorPicture *frameCEPicture = new frmContactEditorPicture ( this );
58 frameCEPicture->SetupPointers(&PicturesList,
62 &PicturesListPicEncType,
63 &PicturesListPictureType,
65 &PicturesListMediatype,
69 frameCEPicture->SetEditorMode(TRUE);
70 frameCEPicture->ShowModal();
71 delete frameCEPicture;
72 frameCEPicture = NULL;
76 void frmContactEditor::DeletePicture( wxCommandEvent& event )
78 long longSelected = -1;
79 int intSelectedData = 0;
81 if (!GetSelectedItem(lboPictures,
87 lboPictures->DeleteItem(longSelected);
89 DeleteMapData(intSelectedData,
90 &PicturesList, &PicturesListAltID, &PicturesListPID, &PicturesListType,
91 &PicturesListPicEncType, &PicturesListPictureType, &PicturesListTokens,
92 &PicturesListMediatype, &PicturesListPref);
94 wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png));
95 wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG);
96 PictureImage = (wxBitmap)misc_emptyimage_png;
98 imgPicture->SetBitmap(PictureImage);
101 void frmContactEditor::LoadPicture( wxListEvent& event )
104 long longSelected = -1;
105 int intSelectedData = 0;
107 if (!GetSelectedItem(lboPictures,
113 std::string base64dec;
115 std::map<int,std::string>::iterator initier;
116 std::map<int,wxString>::iterator pictypeiter;
118 initier = PicturesList.find(intSelectedData);
119 pictypeiter = PicturesListPictureType.find(intSelectedData);
121 base64dec = base64_decode(initier->second);
123 wxMemoryInputStream istream(base64dec.c_str(), (size_t)base64dec.size());
125 //wxMemoryInputStream istream(base64dec, (size_t)base64dec.size());
127 if (pictypeiter->second == wxT("image/jpeg")){
129 if (!photo.LoadFile(istream, wxBITMAP_TYPE_JPEG)){
135 } else if (pictypeiter->second == wxT("image/png")){
137 if (!photo.LoadFile(istream, wxBITMAP_TYPE_PNG)){
143 } else if (pictypeiter->second == wxT("image/gif")){
145 if (!photo.LoadFile(istream, wxBITMAP_TYPE_GIF)){
157 PictureImage = (wxBitmap)photo;
158 imgPicture->SetBitmap(PictureImage);
162 void frmContactEditor::SavePicture( wxCommandEvent &event )