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