Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Removed commented out code from 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;
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         int intResult = 0;
91     
92         frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
93         frameCELogo->SetEditorMode(FALSE);
94         intResult = GetLastInt(&ContactEditorData.LogosList);
95         frameCELogo->SetupPointers(&ContactEditorData.LogosList,
96                 &ContactEditorData.LogosListAltID,
97                 &ContactEditorData.LogosListPID,
98                 &ContactEditorData.LogosListType,
99                 &ContactEditorData.LogosListPicEncType,
100                 &ContactEditorData.LogosListPictureType,
101                 &ContactEditorData.LogosListTokens,
102                 &ContactEditorData.LogosListMediatype,
103                 &ContactEditorData.LogosListPref,
104                 lboLogos,
105                 (intValueSeek),
106                 FALSE);
107         frameCELogo->ShowModal();
108         delete frameCELogo;
109         frameCELogo = NULL;
110         
113 void frmContactEditor::ModifyLogo( wxCommandEvent& event )
115         
116         // Bring up the window to modify a logo.
117         
118         long longSelected = -1;
119         int intSelectedData = 0;
120     
121         if (!GetSelectedItem(lboLogos,
122                 &longSelected,
123                 &intSelectedData)){
124                 return;
125         }
126     
127         frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
128         frameCELogo->SetupPointers(&ContactEditorData.LogosList,
129                 &ContactEditorData.LogosListAltID,
130                 &ContactEditorData.LogosListPID,
131                 &ContactEditorData.LogosListType,
132                 &ContactEditorData.LogosListPicEncType,
133                 &ContactEditorData.LogosListPictureType,
134                 &ContactEditorData.LogosListTokens,
135                 &ContactEditorData.LogosListMediatype,
136                 &ContactEditorData.LogosListPref,
137                 lboLogos,
138                 intSelectedData,
139                 FALSE);
140         frameCELogo->SetEditorMode(TRUE);
141         frameCELogo->ShowModal();
142         delete frameCELogo;
143         frameCELogo = NULL;
144         
147 void frmContactEditor::DeleteLogo( wxCommandEvent& event )
149         
150         // Bring up a window to delete a logo.
151         
152         long longSelected = -1;
153         int intSelectedData = 0;
154     
155         if (!GetSelectedItem(lboLogos,
156                 &longSelected,
157                 &intSelectedData)){
158                 return;
159         }
160     
161         lboLogos->DeleteItem(longSelected);
162     
163         DeleteMapData(intSelectedData,
164                 &ContactEditorData.LogosList, &ContactEditorData.LogosListAltID, &ContactEditorData.LogosListPID, &ContactEditorData.LogosListType,
165                 &ContactEditorData.LogosListPicEncType, &ContactEditorData.LogosListPictureType, &ContactEditorData.LogosListTokens,
166                 &ContactEditorData.LogosListMediatype, &ContactEditorData.LogosListPref);
167     
168         wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png));
169         wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG);
170         LogoImage = (wxBitmap)misc_emptyimage_png;
171     
172         imgLogo->SetBitmap(LogoImage);
173         
176 void frmContactEditor::SaveLogo( wxCommandEvent &event )
178         
179         // Save the logo to a file.
180         
181         long longSelected = -1;
182         int intSelectedData = 0;
183     
184         if (!GetSelectedItem(lboLogos,
185                          &longSelected,
186                          &intSelectedData)){
187                 
188                 return;
189                 
190         }
191         
192         wxString FileTypes;
193         
194         wxString FinalFilename;
195         
196         std::map<int,std::string>::iterator initier;
197         std::map<int,wxString>::iterator logotypeiter;
198     
199         initier = ContactEditorData.LogosList.find(intSelectedData);
200         logotypeiter = ContactEditorData.LogosListPictureType.find(intSelectedData);
201         
202         if (logotypeiter->second == wxT("image/jpeg")){
203     
204                 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
205         
206         } else if (logotypeiter->second == wxT("image/png")){
208                 FileTypes.Append("PNG Image (*.png)|*.png");        
209         
210         } else if (logotypeiter->second == wxT("image/gif")){
211         
212                 FileTypes.Append("GIF Image (*.gif)|*.gif"); 
213         
214         } else {
216                 wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this);
217                 return;
219         }
220         
221         // Open up the dialog to save the picture.
222         
223         wxFileDialog ExportDlg(this, wxT("Save Logo"), wxT(""), wxT(""),
224                 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
225         
226         if (ExportDlg.ShowModal() == wxID_CANCEL){
227         
228                 return;
229         
230         }
231         
232         // Write out the picture to the file.
233         
234         wxFile LogoFile;
235         
236         if (LogoFile.Open(ExportDlg.GetPath(), wxFile::write)){
237         
238                 std::string base64dec;
239                 
240                 initier = ContactEditorData.LogosList.find(intSelectedData);
241                 base64dec = base64_decode(initier->second);
242                 
243                 LogoFile.Write(base64dec.c_str(), (size_t)base64dec.size());
245                 LogoFile.Close();
246         
247         } else {
248         
249                 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);
250                 return;
251         
252         }
253         
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