Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added comments to describe functions in contacteditor/frmContactEditor-Logo.cpp
[xestiaab/.git] / source / contacteditor / frmContactEditor-Logo.cpp
1 // frmContactEditor-Logo.cpp - frmContactEditor Logo 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 "frmContactEditor.h"
20 #include "frmContactEditorPicture.h"
21 #include "../common/base64.h"
23 void frmContactEditor::LoadLogo( wxListEvent& event )
24 {
25     
26         // Load the logo.
27         
28         long longSelected = -1;
29         int intSelectedData = 0;
30     
31         if (!GetSelectedItem(lboLogos,
32                 &longSelected,
33                 &intSelectedData)){
34                 return;
35         }
36     
37         std::string base64dec;
38     
39         std::map<int,std::string>::iterator initier;
40         std::map<int,wxString>::iterator pictypeiter;
41     
42         initier = ContactEditorData.LogosList.find(intSelectedData);
43         pictypeiter = ContactEditorData.LogosListPictureType.find(intSelectedData);
44     
45         base64dec = base64_decode(initier->second);
46     
47         wxMemoryInputStream istream(base64dec.c_str(), (size_t)base64dec.size());
48         wxImage photo;
49         //wxMemoryInputStream istream(base64dec, (size_t)base64dec.size());
50     
51         if (pictypeiter->second == wxT("image/jpeg")){
52         
53                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_JPEG)){
54         
55                         return;
56         
57                 }
58         
59         } else if (pictypeiter->second == wxT("image/png")){
60         
61                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_PNG)){
62             
63                         return;
64             
65                 }
66         
67         } else if (pictypeiter->second == wxT("image/gif")){
68         
69                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_GIF)){
70             
71                         return;
72             
73                 }
74         
75         } else {
76     
77                 return;
78     
79         }
80     
81         LogoImage = (wxBitmap)photo;
82         imgLogo->SetBitmap(LogoImage);
83     
84 }
86 void frmContactEditor::AddLogo( wxCommandEvent& event )
87 {
88         
89         // Bring up the window to add a logo.
90         
91         int intResult = 0;
92     
93         frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
94         frameCELogo->SetEditorMode(FALSE);
95         intResult = GetLastInt(&ContactEditorData.LogosList);
96         frameCELogo->SetupPointers(&ContactEditorData.LogosList,
97                 &ContactEditorData.LogosListAltID,
98                 &ContactEditorData.LogosListPID,
99                 &ContactEditorData.LogosListType,
100                 &ContactEditorData.LogosListPicEncType,
101                 &ContactEditorData.LogosListPictureType,
102                 &ContactEditorData.LogosListTokens,
103                 &ContactEditorData.LogosListMediatype,
104                 &ContactEditorData.LogosListPref,
105                 lboLogos,
106                 (intValueSeek),
107                 FALSE);
108         frameCELogo->ShowModal();
109         delete frameCELogo;
110         frameCELogo = NULL;
111         
114 void frmContactEditor::ModifyLogo( wxCommandEvent& event )
116         
117         // Bring up the window to modify a logo.
118         
119         long longSelected = -1;
120         int intSelectedData = 0;
121     
122         if (!GetSelectedItem(lboLogos,
123                 &longSelected,
124                 &intSelectedData)){
125                 return;
126         }
127     
128         frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
129         frameCELogo->SetupPointers(&ContactEditorData.LogosList,
130                 &ContactEditorData.LogosListAltID,
131                 &ContactEditorData.LogosListPID,
132                 &ContactEditorData.LogosListType,
133                 &ContactEditorData.LogosListPicEncType,
134                 &ContactEditorData.LogosListPictureType,
135                 &ContactEditorData.LogosListTokens,
136                 &ContactEditorData.LogosListMediatype,
137                 &ContactEditorData.LogosListPref,
138                 lboLogos,
139                 intSelectedData,
140                 FALSE);
141         frameCELogo->SetEditorMode(TRUE);
142         frameCELogo->ShowModal();
143         delete frameCELogo;
144         frameCELogo = NULL;
145         
148 void frmContactEditor::DeleteLogo( wxCommandEvent& event )
150         
151         // Bring up a window to delete a logo.
152         
153         long longSelected = -1;
154         int intSelectedData = 0;
155     
156         if (!GetSelectedItem(lboLogos,
157                 &longSelected,
158                 &intSelectedData)){
159                 return;
160         }
161     
162         lboLogos->DeleteItem(longSelected);
163     
164         DeleteMapData(intSelectedData,
165                 &ContactEditorData.LogosList, &ContactEditorData.LogosListAltID, &ContactEditorData.LogosListPID, &ContactEditorData.LogosListType,
166                 &ContactEditorData.LogosListPicEncType, &ContactEditorData.LogosListPictureType, &ContactEditorData.LogosListTokens,
167                 &ContactEditorData.LogosListMediatype, &ContactEditorData.LogosListPref);
168     
169         wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png));
170         wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG);
171         LogoImage = (wxBitmap)misc_emptyimage_png;
172     
173         imgLogo->SetBitmap(LogoImage);
174         
177 void frmContactEditor::SaveLogo( wxCommandEvent &event )
179         
180         // Save the logo to a file.
181         
182         long longSelected = -1;
183         int intSelectedData = 0;
184     
185         if (!GetSelectedItem(lboLogos,
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 logotypeiter;
199     
200         initier = ContactEditorData.LogosList.find(intSelectedData);
201         logotypeiter = ContactEditorData.LogosListPictureType.find(intSelectedData);
202         
203         if (logotypeiter->second == wxT("image/jpeg")){
204     
205                 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
206         
207         } else if (logotypeiter->second == wxT("image/png")){
209                 FileTypes.Append("PNG Image (*.png)|*.png");        
210         
211         } else if (logotypeiter->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 Logo"), 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 LogoFile;
236         
237         if (LogoFile.Open(ExportDlg.GetPath(), wxFile::write)){
238         
239                 std::string base64dec;
240                 
241                 initier = ContactEditorData.LogosList.find(intSelectedData);
242                 base64dec = base64_decode(initier->second);
243                 
244                 LogoFile.Write(base64dec.c_str(), (size_t)base64dec.size());
246                 LogoFile.Close();
247         
248         } else {
249         
250                 wxMessageBox(_("An error occured whilst saving the logo. Check that you have free space and permissions to write the picture at this location."), _("Logo 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