1 // frmContactEditor-Logo.cpp - frmContactEditor Logo tab subroutines.
3 // (c) 2012-2015 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 )
26 long longSelected = -1;
27 int intSelectedData = 0;
29 if (!GetSelectedItem(lboLogos,
35 std::string base64dec;
37 std::map<int,std::string>::iterator initier;
39 initier = LogosList.find(intSelectedData);
41 base64dec = base64_decode(initier->second);
44 wxMemoryInputStream istream(base64dec.c_str(), (size_t)base64dec.size());
46 //wxMemoryInputStream istream(base64dec, (size_t)base64dec.size());
48 if (!photo.LoadFile(istream, wxBITMAP_TYPE_ANY)){
55 LogoImage = (wxBitmap)photo;
56 imgLogo->SetBitmap(LogoImage);
60 void frmContactEditor::AddLogo( wxCommandEvent& event )
64 frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
65 frameCELogo->SetEditorMode(FALSE);
66 intResult = GetLastInt(&LogosList);
67 frameCELogo->SetupPointers(&LogosList,
72 &LogosListPictureType,
78 frameCELogo->ShowModal();
83 void frmContactEditor::ModifyLogo( wxCommandEvent& event )
85 long longSelected = -1;
86 int intSelectedData = 0;
88 if (!GetSelectedItem(lboLogos,
94 frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
95 frameCELogo->SetupPointers(&LogosList,
100 &LogosListPictureType,
106 frameCELogo->SetEditorMode(TRUE);
107 frameCELogo->ShowModal();
112 void frmContactEditor::DeleteLogo( wxCommandEvent& event )
114 long longSelected = -1;
115 int intSelectedData = 0;
117 if (!GetSelectedItem(lboLogos,
123 lboLogos->DeleteItem(longSelected);
125 DeleteMapData(intSelectedData,
126 &LogosList, &LogosListAltID, &LogosListPID, &LogosListType,
127 &LogosListPicEncType, &LogosListPictureType, &LogosListTokens,
128 &LogosListMediatype, &LogosListPref);
130 wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png));
131 wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG);
132 LogoImage = (wxBitmap)misc_emptyimage_png;
134 imgLogo->SetBitmap(LogoImage);
137 void frmContactEditor::SaveLogo( wxCommandEvent &event )
140 long longSelected = -1;
141 int intSelectedData = 0;
143 if (!GetSelectedItem(lboLogos,
153 wxString FinalFilename;
155 std::map<int,std::string>::iterator initier;
156 std::map<int,wxString>::iterator logotypeiter;
158 initier = LogosList.find(intSelectedData);
159 logotypeiter = LogosListPictureType.find(intSelectedData);
161 if (logotypeiter->second == wxT("image/jpeg")){
163 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
165 } else if (logotypeiter->second == wxT("image/png")){
167 FileTypes.Append("PNG Image (*.png)|*.png");
169 } else if (logotypeiter->second == wxT("image/gif")){
171 FileTypes.Append("GIF Image (*.gif)|*.gif");
175 wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this);
180 // Open up the dialog to save the picture.
182 wxFileDialog ExportDlg(this, wxT("Save Logo"), wxT(""), wxT(""),
183 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
185 if (ExportDlg.ShowModal() == wxID_CANCEL){
191 // Write out the picture to the file.
195 if (LogoFile.Open(ExportDlg.GetPath(), wxFile::write)){
197 std::string base64dec;
199 initier = LogosList.find(intSelectedData);
200 base64dec = base64_decode(initier->second);
202 LogoFile.Write(base64dec.c_str(), (size_t)base64dec.size());
208 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);