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