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