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