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