Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Version 0.19 release
[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;
50         if (pictypeiter->second == wxT("image/jpeg")){
51         
52                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_JPEG)){
53         
54                         return;
55         
56                 }
57         
58         } else if (pictypeiter->second == wxT("image/png")){
59         
60                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_PNG)){
61             
62                         return;
63             
64                 }
65         
66         } else if (pictypeiter->second == wxT("image/gif")){
67         
68                 if (!photo.LoadFile(istream, wxBITMAP_TYPE_GIF)){
69             
70                         return;
71             
72                 }
73         
74         } else {
75     
76                 return;
77     
78         }
79     
80         LogoImage = (wxBitmap)photo;
81         imgLogo->SetBitmap(LogoImage);
82     
83 }
85 void frmContactEditor::AddLogo( wxCommandEvent& event )
86 {
87         
88         // Bring up the window to add a logo.
89             
90         frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
91         frameCELogo->SetEditorMode(FALSE);
92         frameCELogo->SetupPointers(&ContactEditorData.LogosList,
93                 &ContactEditorData.LogosListAltID,
94                 &ContactEditorData.LogosListPID,
95                 &ContactEditorData.LogosListType,
96                 &ContactEditorData.LogosListPicEncType,
97                 &ContactEditorData.LogosListPictureType,
98                 &ContactEditorData.LogosListTokens,
99                 &ContactEditorData.LogosListMediatype,
100                 &ContactEditorData.LogosListPref,
101                 lboLogos,
102                 (intValueSeek),
103                 FALSE);
104         frameCELogo->ShowModal();
105         delete frameCELogo;
106         frameCELogo = NULL;
107         
110 void frmContactEditor::ModifyLogo( wxCommandEvent& event )
112         
113         // Bring up the window to modify a logo.
114         
115         long longSelected = -1;
116         int intSelectedData = 0;
117     
118         if (!GetSelectedItem(lboLogos,
119                 &longSelected,
120                 &intSelectedData)){
121                 return;
122         }
123     
124         frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
125         frameCELogo->SetupPointers(&ContactEditorData.LogosList,
126                 &ContactEditorData.LogosListAltID,
127                 &ContactEditorData.LogosListPID,
128                 &ContactEditorData.LogosListType,
129                 &ContactEditorData.LogosListPicEncType,
130                 &ContactEditorData.LogosListPictureType,
131                 &ContactEditorData.LogosListTokens,
132                 &ContactEditorData.LogosListMediatype,
133                 &ContactEditorData.LogosListPref,
134                 lboLogos,
135                 intSelectedData,
136                 FALSE);
137         frameCELogo->SetEditorMode(TRUE);
138         frameCELogo->ShowModal();
139         delete frameCELogo;
140         frameCELogo = NULL;
141         
144 void frmContactEditor::DeleteLogo( wxCommandEvent& event )
146         
147         // Bring up a window to delete a logo.
148         
149         long longSelected = -1;
150         int intSelectedData = 0;
151     
152         if (!GetSelectedItem(lboLogos,
153                 &longSelected,
154                 &intSelectedData)){
155                 return;
156         }
157     
158         lboLogos->DeleteItem(longSelected);
159     
160         DeleteMapData(intSelectedData,
161                 &ContactEditorData.LogosList, &ContactEditorData.LogosListAltID, &ContactEditorData.LogosListPID, &ContactEditorData.LogosListType,
162                 &ContactEditorData.LogosListPicEncType, &ContactEditorData.LogosListPictureType, &ContactEditorData.LogosListTokens,
163                 &ContactEditorData.LogosListMediatype, &ContactEditorData.LogosListPref);
164     
165         wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png));
166         wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG);
167         LogoImage = (wxBitmap)misc_emptyimage_png;
168     
169         imgLogo->SetBitmap(LogoImage);
170         
173 void frmContactEditor::SaveLogo( wxCommandEvent &event )
175         
176         // Save the logo to a file.
177         
178         long longSelected = -1;
179         int intSelectedData = 0;
180     
181         if (!GetSelectedItem(lboLogos,
182                          &longSelected,
183                          &intSelectedData)){
184                 
185                 return;
186                 
187         }
188         
189         wxString FileTypes;
190         
191         wxString FinalFilename;
192         
193         std::map<int,std::string>::iterator initier;
194         std::map<int,wxString>::iterator logotypeiter;
195     
196         initier = ContactEditorData.LogosList.find(intSelectedData);
197         logotypeiter = ContactEditorData.LogosListPictureType.find(intSelectedData);
198         
199         if (logotypeiter->second == wxT("image/jpeg")){
200     
201                 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
202         
203         } else if (logotypeiter->second == wxT("image/png")){
205                 FileTypes.Append("PNG Image (*.png)|*.png");        
206         
207         } else if (logotypeiter->second == wxT("image/gif")){
208         
209                 FileTypes.Append("GIF Image (*.gif)|*.gif"); 
210         
211         } else {
213                 wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this);
214                 return;
216         }
217         
218         // Open up the dialog to save the picture.
219         
220         wxFileDialog ExportDlg(this, wxT("Save Logo"), wxT(""), wxT(""),
221                 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
222         
223         if (ExportDlg.ShowModal() == wxID_CANCEL){
224         
225                 return;
226         
227         }
228         
229         // Write out the picture to the file.
230         
231         wxFile LogoFile;
232         
233         if (LogoFile.Open(ExportDlg.GetPath(), wxFile::write)){
234         
235                 std::string base64dec;
236                 
237                 initier = ContactEditorData.LogosList.find(intSelectedData);
238                 base64dec = base64_decode(initier->second);
239                 
240                 LogoFile.Write(base64dec.c_str(), (size_t)base64dec.size());
242                 LogoFile.Close();
243         
244         } else {
245         
246                 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);
247                 return;
248         
249         }
250         
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