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.
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,
104 frameCELogo->ShowModal();
110 void frmContactEditor::ModifyLogo( wxCommandEvent& event )
113 // Bring up the window to modify a logo.
115 long longSelected = -1;
116 int intSelectedData = 0;
118 if (!GetSelectedItem(lboLogos,
124 frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
125 frameCELogo->SetupPointers(&ContactEditorData.LogosList,
126 &ContactEditorData.LogosListAltID,
127 &ContactEditorData.LogosListPID,
128 &ContactEditorData.LogosListType,
129 &ContactEditorData.LogosListPicEncType,
130 &ContactEditorData.LogosListPictureType,
131 &ContactEditorData.LogosListTokens,
132 &ContactEditorData.LogosListMediatype,
133 &ContactEditorData.LogosListPref,
137 frameCELogo->SetEditorMode(TRUE);
138 frameCELogo->ShowModal();
144 void frmContactEditor::DeleteLogo( wxCommandEvent& event )
147 // Bring up a window to delete a logo.
149 long longSelected = -1;
150 int intSelectedData = 0;
152 if (!GetSelectedItem(lboLogos,
158 lboLogos->DeleteItem(longSelected);
160 DeleteMapData(intSelectedData,
161 &ContactEditorData.LogosList, &ContactEditorData.LogosListAltID, &ContactEditorData.LogosListPID, &ContactEditorData.LogosListType,
162 &ContactEditorData.LogosListPicEncType, &ContactEditorData.LogosListPictureType, &ContactEditorData.LogosListTokens,
163 &ContactEditorData.LogosListMediatype, &ContactEditorData.LogosListPref);
165 wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png));
166 wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG);
167 LogoImage = (wxBitmap)misc_emptyimage_png;
169 imgLogo->SetBitmap(LogoImage);
173 void frmContactEditor::SaveLogo( wxCommandEvent &event )
176 // Save the logo to a file.
178 long longSelected = -1;
179 int intSelectedData = 0;
181 if (!GetSelectedItem(lboLogos,
191 wxString FinalFilename;
193 std::map<int,std::string>::iterator initier;
194 std::map<int,wxString>::iterator logotypeiter;
196 initier = ContactEditorData.LogosList.find(intSelectedData);
197 logotypeiter = ContactEditorData.LogosListPictureType.find(intSelectedData);
199 if (logotypeiter->second == wxT("image/jpeg")){
201 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
203 } else if (logotypeiter->second == wxT("image/png")){
205 FileTypes.Append("PNG Image (*.png)|*.png");
207 } else if (logotypeiter->second == wxT("image/gif")){
209 FileTypes.Append("GIF Image (*.gif)|*.gif");
213 wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this);
218 // Open up the dialog to save the picture.
220 wxFileDialog ExportDlg(this, wxT("Save Logo"), wxT(""), wxT(""),
221 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
223 if (ExportDlg.ShowModal() == wxID_CANCEL){
229 // Write out the picture to the file.
233 if (LogoFile.Open(ExportDlg.GetPath(), wxFile::write)){
235 std::string base64dec;
237 initier = ContactEditorData.LogosList.find(intSelectedData);
238 base64dec = base64_decode(initier->second);
240 LogoFile.Write(base64dec.c_str(), (size_t)base64dec.size());
246 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);