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