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 )
26 long longSelected = -1;
27 int intSelectedData = 0;
29 if (!GetSelectedItem(lboLogos,
35 std::string base64dec;
37 std::map<int,std::string>::iterator initier;
38 std::map<int,wxString>::iterator pictypeiter;
40 initier = ContactEditorData.LogosList.find(intSelectedData);
41 pictypeiter = ContactEditorData.LogosListPictureType.find(intSelectedData);
43 base64dec = base64_decode(initier->second);
45 wxMemoryInputStream istream(base64dec.c_str(), (size_t)base64dec.size());
47 //wxMemoryInputStream istream(base64dec, (size_t)base64dec.size());
49 if (pictypeiter->second == wxT("image/jpeg")){
51 if (!photo.LoadFile(istream, wxBITMAP_TYPE_JPEG)){
57 } else if (pictypeiter->second == wxT("image/png")){
59 if (!photo.LoadFile(istream, wxBITMAP_TYPE_PNG)){
65 } else if (pictypeiter->second == wxT("image/gif")){
67 if (!photo.LoadFile(istream, wxBITMAP_TYPE_GIF)){
79 LogoImage = (wxBitmap)photo;
80 imgLogo->SetBitmap(LogoImage);
84 void frmContactEditor::AddLogo( wxCommandEvent& event )
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,
103 frameCELogo->ShowModal();
108 void frmContactEditor::ModifyLogo( wxCommandEvent& event )
110 long longSelected = -1;
111 int intSelectedData = 0;
113 if (!GetSelectedItem(lboLogos,
119 frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this );
120 frameCELogo->SetupPointers(&ContactEditorData.LogosList,
121 &ContactEditorData.LogosListAltID,
122 &ContactEditorData.LogosListPID,
123 &ContactEditorData.LogosListType,
124 &ContactEditorData.LogosListPicEncType,
125 &ContactEditorData.LogosListPictureType,
126 &ContactEditorData.LogosListTokens,
127 &ContactEditorData.LogosListMediatype,
128 &ContactEditorData.LogosListPref,
132 frameCELogo->SetEditorMode(TRUE);
133 frameCELogo->ShowModal();
138 void frmContactEditor::DeleteLogo( wxCommandEvent& event )
140 long longSelected = -1;
141 int intSelectedData = 0;
143 if (!GetSelectedItem(lboLogos,
149 lboLogos->DeleteItem(longSelected);
151 DeleteMapData(intSelectedData,
152 &ContactEditorData.LogosList, &ContactEditorData.LogosListAltID, &ContactEditorData.LogosListPID, &ContactEditorData.LogosListType,
153 &ContactEditorData.LogosListPicEncType, &ContactEditorData.LogosListPictureType, &ContactEditorData.LogosListTokens,
154 &ContactEditorData.LogosListMediatype, &ContactEditorData.LogosListPref);
156 wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png));
157 wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG);
158 LogoImage = (wxBitmap)misc_emptyimage_png;
160 imgLogo->SetBitmap(LogoImage);
163 void frmContactEditor::SaveLogo( wxCommandEvent &event )
166 long longSelected = -1;
167 int intSelectedData = 0;
169 if (!GetSelectedItem(lboLogos,
179 wxString FinalFilename;
181 std::map<int,std::string>::iterator initier;
182 std::map<int,wxString>::iterator logotypeiter;
184 initier = ContactEditorData.LogosList.find(intSelectedData);
185 logotypeiter = ContactEditorData.LogosListPictureType.find(intSelectedData);
187 if (logotypeiter->second == wxT("image/jpeg")){
189 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
191 } else if (logotypeiter->second == wxT("image/png")){
193 FileTypes.Append("PNG Image (*.png)|*.png");
195 } else if (logotypeiter->second == wxT("image/gif")){
197 FileTypes.Append("GIF Image (*.gif)|*.gif");
201 wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this);
206 // Open up the dialog to save the picture.
208 wxFileDialog ExportDlg(this, wxT("Save Logo"), wxT(""), wxT(""),
209 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
211 if (ExportDlg.ShowModal() == wxID_CANCEL){
217 // Write out the picture to the file.
221 if (LogoFile.Open(ExportDlg.GetPath(), wxFile::write)){
223 std::string base64dec;
225 initier = ContactEditorData.LogosList.find(intSelectedData);
226 base64dec = base64_decode(initier->second);
228 LogoFile.Write(base64dec.c_str(), (size_t)base64dec.size());
234 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);