Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmPreferences: Removed std::cout printing contact background colour
[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         
27         // Bring up window for adding a picture.
28             
29         frmContactEditorPicture *frameCEPicture = new frmContactEditorPicture ( this );
30         frameCEPicture->SetEditorMode(FALSE);
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         
47 }
49 void frmContactEditor::ModifyPicture( wxCommandEvent& event )
50 {
51         
52         // Bring up window for modifying a picture.
53         
54         long longSelected = -1;
55         int intSelectedData = 0;
56     
57         if (!GetSelectedItem(lboPictures,
58                 &longSelected,
59                 &intSelectedData)){
60                 return;
61         }
62     
63         frmContactEditorPicture *frameCEPicture = new frmContactEditorPicture ( this );
64         frameCEPicture->SetupPointers(&ContactEditorData.PicturesList,
65                 &ContactEditorData.PicturesListAltID,
66                 &ContactEditorData.PicturesListPID,
67                 &ContactEditorData.PicturesListType,
68                 &ContactEditorData.PicturesListPicEncType,
69                 &ContactEditorData.PicturesListPictureType,
70                 &ContactEditorData.PicturesListTokens,
71                 &ContactEditorData.PicturesListMediatype,
72                 &ContactEditorData.PicturesListPref,
73                 lboPictures,
74                 intSelectedData,
75                 TRUE);
76         frameCEPicture->SetEditorMode(TRUE);
77         frameCEPicture->ShowModal();
78         delete frameCEPicture;
79         frameCEPicture = NULL;
80     
81 }
83 void frmContactEditor::DeletePicture( wxCommandEvent& event )
84 {
85         
86         // Bring up window for deleting a picture.
87         
88         long longSelected = -1;
89         int intSelectedData = 0;
90     
91         if (!GetSelectedItem(lboPictures,
92                 &longSelected,
93                 &intSelectedData)){
94                 return;
95         }
96     
97         lboPictures->DeleteItem(longSelected);
98     
99         DeleteMapData(intSelectedData,
100                 &ContactEditorData.PicturesList, &ContactEditorData.PicturesListAltID, &ContactEditorData.PicturesListPID, &ContactEditorData.PicturesListType,
101                 &ContactEditorData.PicturesListPicEncType, &ContactEditorData.PicturesListPictureType, &ContactEditorData.PicturesListTokens,
102                 &ContactEditorData.PicturesListMediatype, &ContactEditorData.PicturesListPref);
103     
104         wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png));
105         wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG);
106         PictureImage = (wxBitmap)misc_emptyimage_png;
107     
108         imgPicture->SetBitmap(PictureImage);
109         
112 void frmContactEditor::LoadPicture( wxListEvent& event )
114     
115         // Load the picture.
116         
117         long longSelected = -1;
118         int intSelectedData = 0;
119     
120         if (!GetSelectedItem(lboPictures,
121                 &longSelected,
122                 &intSelectedData)){
123                 return;
124         }
125     
126         std::string base64dec;
128         std::map<int,std::string>::iterator initier;
129         std::map<int,wxString>::iterator pictypeiter;
130     
131         initier = ContactEditorData.PicturesList.find(intSelectedData);
132         pictypeiter = ContactEditorData.PicturesListPictureType.find(intSelectedData);
133     
134         base64dec = base64_decode(initier->second);
135     
136         wxMemoryInputStream istream(base64dec.c_str(), (size_t)base64dec.size());
137         wxImage photo;
138     
139         if (pictypeiter->second == wxT("image/jpeg")){
140         
141                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_JPEG)){
142         
143                         return;
144         
145                 }
146         
147         } else if (pictypeiter->second == wxT("image/png")){
148         
149                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_PNG)){
150             
151                         return;
152             
153                 }
154         
155         } else if (pictypeiter->second == wxT("image/gif")){
156         
157                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_GIF)){
158             
159                         return;
160             
161                 }
162         
163         } else {
164     
165                 return;
166     
167         }
168     
169         PictureImage = (wxBitmap)photo;
170         imgPicture->SetBitmap(PictureImage);
171     
174 void frmContactEditor::SavePicture( wxCommandEvent &event )
177         // Save the picture to a file.
178         
179         long longSelected = -1;
180         int intSelectedData = 0;
181     
182         if (!GetSelectedItem(lboPictures,
183                          &longSelected,
184                          &intSelectedData)){
185                 
186                 return;
187                 
188         }
189         
190         wxString FileTypes;
191         
192         wxString FinalFilename;
193         
194         std::map<int,std::string>::iterator initier;
195         std::map<int,wxString>::iterator pictypeiter;
196     
197         initier = ContactEditorData.PicturesList.find(intSelectedData);
198         pictypeiter = ContactEditorData.PicturesListPictureType.find(intSelectedData);
199         
200         if (pictypeiter->second == wxT("image/jpeg")){
201     
202                 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
203         
204         } else if (pictypeiter->second == wxT("image/png")){
206                 FileTypes.Append("PNG Image (*.png)|*.png");        
207         
208         } else if (pictypeiter->second == wxT("image/gif")){
209         
210                 FileTypes.Append("GIF Image (*.gif)|*.gif"); 
211         
212         } else {
214                 wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this);
215                 return;
217         }
218         
219         // Open up the dialog to save the picture.
220         
221         wxFileDialog ExportDlg(this, wxT("Save Picture"), wxT(""), wxT(""),
222                 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
223         
224         if (ExportDlg.ShowModal() == wxID_CANCEL){
225         
226                 return;
227         
228         }
229         
230         // Write out the picture to the file.
231         
232         wxFile PictureFile;
233         
234         if (PictureFile.Open(ExportDlg.GetPath(), wxFile::write)){
235         
236                 std::string base64dec;
237                 
238                 initier = ContactEditorData.PicturesList.find(intSelectedData);
239                 base64dec = base64_decode(initier->second);
240                 
241                 PictureFile.Write(base64dec.c_str(), (size_t)base64dec.size());
243                 PictureFile.Close();
244         
245         } else {
246         
247                 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);
248                 return;
249         
250         }
251                         
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