Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed commented out code from 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     
142         if (pictypeiter->second == wxT("image/jpeg")){
143         
144                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_JPEG)){
145         
146                         return;
147         
148                 }
149         
150         } else if (pictypeiter->second == wxT("image/png")){
151         
152                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_PNG)){
153             
154                         return;
155             
156                 }
157         
158         } else if (pictypeiter->second == wxT("image/gif")){
159         
160                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_GIF)){
161             
162                         return;
163             
164                 }
165         
166         } else {
167     
168                 return;
169     
170         }
171     
172         PictureImage = (wxBitmap)photo;
173         imgPicture->SetBitmap(PictureImage);
174     
177 void frmContactEditor::SavePicture( wxCommandEvent &event )
180         // Save the picture to a file.
181         
182         long longSelected = -1;
183         int intSelectedData = 0;
184     
185         if (!GetSelectedItem(lboPictures,
186                          &longSelected,
187                          &intSelectedData)){
188                 
189                 return;
190                 
191         }
192         
193         wxString FileTypes;
194         
195         wxString FinalFilename;
196         
197         std::map<int,std::string>::iterator initier;
198         std::map<int,wxString>::iterator pictypeiter;
199     
200         initier = ContactEditorData.PicturesList.find(intSelectedData);
201         pictypeiter = ContactEditorData.PicturesListPictureType.find(intSelectedData);
202         
203         if (pictypeiter->second == wxT("image/jpeg")){
204     
205                 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
206         
207         } else if (pictypeiter->second == wxT("image/png")){
209                 FileTypes.Append("PNG Image (*.png)|*.png");        
210         
211         } else if (pictypeiter->second == wxT("image/gif")){
212         
213                 FileTypes.Append("GIF Image (*.gif)|*.gif"); 
214         
215         } else {
217                 wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this);
218                 return;
220         }
221         
222         // Open up the dialog to save the picture.
223         
224         wxFileDialog ExportDlg(this, wxT("Save Picture"), wxT(""), wxT(""),
225                 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
226         
227         if (ExportDlg.ShowModal() == wxID_CANCEL){
228         
229                 return;
230         
231         }
232         
233         // Write out the picture to the file.
234         
235         wxFile PictureFile;
236         
237         if (PictureFile.Open(ExportDlg.GetPath(), wxFile::write)){
238         
239                 std::string base64dec;
240                 
241                 initier = ContactEditorData.PicturesList.find(intSelectedData);
242                 base64dec = base64_decode(initier->second);
243                 
244                 PictureFile.Write(base64dec.c_str(), (size_t)base64dec.size());
246                 PictureFile.Close();
247         
248         } else {
249         
250                 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);
251                 return;
252         
253         }
254                         
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