Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
402f67245e5bd2e4fad106843766f4d34160b23c
[xestiaab/.git] / frmContactEditor-Picture.cpp
1 // frmContactEditor-Picture.cpp - frmContactEditor Picture tab subroutines.
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 <wx/file.h>
20 #include "frmContactEditor.h"
21 #include "frmContactEditorPicture.h"
22 #include "../common/base64.h"
24 void frmContactEditor::AddPicture( wxCommandEvent& event )
25 {
26     int intResult = 0;
27     
28     frmContactEditorPicture *frameCEPicture = new frmContactEditorPicture ( this );
29     frameCEPicture->SetEditorMode(FALSE);
30     intResult = GetLastInt(&PicturesList);
31     frameCEPicture->SetupPointers(&PicturesList,
32                                   &PicturesListAltID,
33                                   &PicturesListPID,
34                                   &PicturesListType,
35                                   &PicturesListPicEncType,
36                                   &PicturesListPictureType,
37                                   &PicturesListTokens,
38                                   &PicturesListMediatype,
39                                   &PicturesListPref,
40                                   lboPictures,
41                                   (intValueSeek));
42     frameCEPicture->ShowModal();
43     delete frameCEPicture;
44     frameCEPicture = NULL;
45 }
47 void frmContactEditor::ModifyPicture( wxCommandEvent& event )
48 {
49     long longSelected = -1;
50     int intSelectedData = 0;
51     
52     if (!GetSelectedItem(lboPictures,
53                          &longSelected,
54                          &intSelectedData)){
55         return;
56     }
57     
58     frmContactEditorPicture *frameCEPicture = new frmContactEditorPicture ( this );
59     frameCEPicture->SetupPointers(&PicturesList,
60                                   &PicturesListAltID,
61                                   &PicturesListPID,
62                                   &PicturesListType,
63                                   &PicturesListPicEncType,
64                                   &PicturesListPictureType,
65                                   &PicturesListTokens,
66                                   &PicturesListMediatype,
67                                   &PicturesListPref,
68                                   lboPictures,
69                                   intSelectedData);
70     frameCEPicture->SetEditorMode(TRUE);
71     frameCEPicture->ShowModal();
72     delete frameCEPicture;
73     frameCEPicture = NULL;
74     
75 }
77 void frmContactEditor::DeletePicture( wxCommandEvent& event )
78 {
79     long longSelected = -1;
80     int intSelectedData = 0;
81     
82     if (!GetSelectedItem(lboPictures,
83                          &longSelected,
84                          &intSelectedData)){
85         return;
86     }
87     
88     lboPictures->DeleteItem(longSelected);
89     
90     DeleteMapData(intSelectedData,
91                   &PicturesList, &PicturesListAltID, &PicturesListPID, &PicturesListType,
92                   &PicturesListPicEncType, &PicturesListPictureType, &PicturesListTokens,
93                   &PicturesListMediatype, &PicturesListPref);
94     
95     wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png));
96     wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG);
97     PictureImage = (wxBitmap)misc_emptyimage_png;
98     
99     imgPicture->SetBitmap(PictureImage);
102 void frmContactEditor::LoadPicture( wxListEvent& event )
104     
105     long longSelected = -1;
106     int intSelectedData = 0;
107     
108     if (!GetSelectedItem(lboPictures,
109                          &longSelected,
110                          &intSelectedData)){
111         return;
112     }
113     
114     std::string base64dec;
115     
116     std::map<int,std::string>::iterator initier;
117     std::map<int,wxString>::iterator pictypeiter;
118     
119     initier = ContactEditorData.PicturesList.find(intSelectedData);
120     pictypeiter = ContactEditorData.PicturesListPictureType.find(intSelectedData);
121     
122     base64dec = base64_decode(initier->second);
123     
124     wxMemoryInputStream istream(base64dec.c_str(), (size_t)base64dec.size());
125     wxImage photo;
126     //wxMemoryInputStream istream(base64dec, (size_t)base64dec.size());
127     
128     if (pictypeiter->second == wxT("image/jpeg")){
129         
130         if (!photo.LoadFile(istream, wxBITMAP_TYPE_JPEG)){
131         
132             return;
133         
134         }
135         
136     } else if (pictypeiter->second == wxT("image/png")){
137         
138         if (!photo.LoadFile(istream, wxBITMAP_TYPE_PNG)){
139             
140             return;
141             
142         }
143         
144     } else if (pictypeiter->second == wxT("image/gif")){
145         
146         if (!photo.LoadFile(istream, wxBITMAP_TYPE_GIF)){
147             
148             return;
149             
150         }
151         
152     } else {
153     
154         return;
155     
156     }
157     
158     PictureImage = (wxBitmap)photo;
159     imgPicture->SetBitmap(PictureImage);
160     
163 void frmContactEditor::SavePicture( wxCommandEvent &event )
166         long longSelected = -1;
167         int intSelectedData = 0;
168     
169         if (!GetSelectedItem(lboPictures,
170                          &longSelected,
171                          &intSelectedData)){
172                 
173                 return;
174                 
175         }
176         
177         wxString FileTypes;
178         
179         wxString FinalFilename;
180         
181         std::map<int,std::string>::iterator initier;
182         std::map<int,wxString>::iterator pictypeiter;
183     
184         initier = ContactEditorData.PicturesList.find(intSelectedData);
185         pictypeiter = ContactEditorData.PicturesListPictureType.find(intSelectedData);
186         
187         if (pictypeiter->second == wxT("image/jpeg")){
188     
189                 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
190         
191         } else if (pictypeiter->second == wxT("image/png")){
193                 FileTypes.Append("PNG Image (*.png)|*.png");        
194         
195         } else if (pictypeiter->second == wxT("image/gif")){
196         
197                 FileTypes.Append("GIF Image (*.gif)|*.gif"); 
198         
199         } else {
201                 wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this);
202                 return;
204         }
205         
206         // Open up the dialog to save the picture.
207         
208         wxFileDialog ExportDlg(this, wxT("Save Picture"), wxT(""), wxT(""),
209                 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
210         
211         if (ExportDlg.ShowModal() == wxID_CANCEL){
212         
213                 return;
214         
215         }
216         
217         // Write out the picture to the file.
218         
219         wxFile PictureFile;
220         
221         if (PictureFile.Open(ExportDlg.GetPath(), wxFile::write)){
222         
223                 std::string base64dec;
224                 
225                 initier = ContactEditorData.PicturesList.find(intSelectedData);
226                 base64dec = base64_decode(initier->second);
227                 
228                 PictureFile.Write(base64dec.c_str(), (size_t)base64dec.size());
230                 PictureFile.Close();
231         
232         } else {
233         
234                 wxMessageBox(_("An error occured whilst saving the picture. Check that you have free space and permissions to write the picture at this location."), _("Picture save error"), wxOK, this);
235                 return;
236         
237         }
238                         
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