1 // frmContactEditor-Logo.cpp - frmContactEditor Logo tab subroutines.
3 // (c) 2012-2016 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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 )
28 long longSelected = -1;
29 int intSelectedData = 0;
31 if (!GetSelectedItem(lboLogos,
37 std::string base64dec;
39 std::map<int,std::string>::iterator initier;
40 std::map<int,wxString>::iterator pictypeiter;
42 initier = ContactEditorData.LogosList.find(intSelectedData);
43 pictypeiter = ContactEditorData.LogosListPictureType.find(intSelectedData);
45 base64dec = base64_decode(initier->second);
47 wxMemoryInputStream istream(base64dec.c_str(), (size_t)base64dec.size());
50 if (pictypeiter->second == wxT("image/jpeg")){
52 if (!photo.LoadFile(istream, wxBITMAP_TYPE_JPEG)){
58 } else if (pictypeiter->second == wxT("image/png")){
60 if (!photo.LoadFile(istream, wxBITMAP_TYPE_PNG)){
66 } else if (pictypeiter->second == wxT("image/gif")){
68 if (!photo.LoadFile(istream, wxBITMAP_TYPE_GIF)){
80 LogoImage = (wxBitmap)photo;
81 imgLogo->SetBitmap(LogoImage);
85 void frmContactEditor::AddLogo( wxCommandEvent& event )
88 // Bring up the window to add a logo.
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,
107 frameCELogo->ShowModal();
113 void frmContactEditor::ModifyLogo( wxCommandEvent& event )
116 // Bring up the window to modify a logo.
118 long longSelected = -1;
119 int intSelectedData = 0;
121 if (!GetSelectedItem(lboLogos,
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,
140 frameCELogo->SetEditorMode(TRUE);
141 frameCELogo->ShowModal();
147 void frmContactEditor::DeleteLogo( wxCommandEvent& event )
150 // Bring up a window to delete a logo.
152 long longSelected = -1;
153 int intSelectedData = 0;
155 if (!GetSelectedItem(lboLogos,
161 lboLogos->DeleteItem(longSelected);
163 DeleteMapData(intSelectedData,
164 &ContactEditorData.LogosList, &ContactEditorData.LogosListAltID, &ContactEditorData.LogosListPID, &ContactEditorData.LogosListType,
165 &ContactEditorData.LogosListPicEncType, &ContactEditorData.LogosListPictureType, &ContactEditorData.LogosListTokens,
166 &ContactEditorData.LogosListMediatype, &ContactEditorData.LogosListPref);
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;
172 imgLogo->SetBitmap(LogoImage);
176 void frmContactEditor::SaveLogo( wxCommandEvent &event )
179 // Save the logo to a file.
181 long longSelected = -1;
182 int intSelectedData = 0;
184 if (!GetSelectedItem(lboLogos,
194 wxString FinalFilename;
196 std::map<int,std::string>::iterator initier;
197 std::map<int,wxString>::iterator logotypeiter;
199 initier = ContactEditorData.LogosList.find(intSelectedData);
200 logotypeiter = ContactEditorData.LogosListPictureType.find(intSelectedData);
202 if (logotypeiter->second == wxT("image/jpeg")){
204 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
206 } else if (logotypeiter->second == wxT("image/png")){
208 FileTypes.Append("PNG Image (*.png)|*.png");
210 } else if (logotypeiter->second == wxT("image/gif")){
212 FileTypes.Append("GIF Image (*.gif)|*.gif");
216 wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this);
221 // Open up the dialog to save the picture.
223 wxFileDialog ExportDlg(this, wxT("Save Logo"), wxT(""), wxT(""),
224 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
226 if (ExportDlg.ShowModal() == wxID_CANCEL){
232 // Write out the picture to the file.
236 if (LogoFile.Open(ExportDlg.GetPath(), wxFile::write)){
238 std::string base64dec;
240 initier = ContactEditorData.LogosList.find(intSelectedData);
241 base64dec = base64_decode(initier->second);
243 LogoFile.Write(base64dec.c_str(), (size_t)base64dec.size());
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);