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 (lboLogos->GetItemCount() == 0 || !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();
111 void frmContactEditor::ModifyLogo( wxCommandEvent& event )
114 // Bring up the window to modify a logo.
116 long longSelected = -1;
117 int intSelectedData = 0;
119 if (lboLogos->GetItemCount() == 0 || !GetSelectedItem(lboLogos,
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,
138 frameCELogo->SetEditorMode(TRUE);
139 frameCELogo->ShowModal();
145 void frmContactEditor::DeleteLogo( wxCommandEvent& event )
148 // Bring up a window to delete a logo.
150 long longSelected = -1;
151 int intSelectedData = 0;
153 if (lboLogos->GetItemCount() == 0 || !GetSelectedItem(lboLogos,
159 lboLogos->DeleteItem(longSelected);
161 DeleteMapData(intSelectedData,
162 &ContactEditorData.LogosList, &ContactEditorData.LogosListAltID, &ContactEditorData.LogosListPID, &ContactEditorData.LogosListType,
163 &ContactEditorData.LogosListPicEncType, &ContactEditorData.LogosListPictureType, &ContactEditorData.LogosListTokens,
164 &ContactEditorData.LogosListMediatype, &ContactEditorData.LogosListPref);
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;
170 imgLogo->SetBitmap(LogoImage);
174 void frmContactEditor::SaveLogo( wxCommandEvent &event )
177 // Save the logo to a file.
179 long longSelected = -1;
180 int intSelectedData = 0;
182 if (lboLogos->GetItemCount() == 0 || !GetSelectedItem(lboLogos,
192 wxString FinalFilename;
194 std::map<int,std::string>::iterator initier;
195 std::map<int,wxString>::iterator logotypeiter;
197 initier = ContactEditorData.LogosList.find(intSelectedData);
198 logotypeiter = ContactEditorData.LogosListPictureType.find(intSelectedData);
200 if (logotypeiter->second == wxT("image/jpeg")){
202 FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg");
204 } else if (logotypeiter->second == wxT("image/png")){
206 FileTypes.Append("PNG Image (*.png)|*.png");
208 } else if (logotypeiter->second == wxT("image/gif")){
210 FileTypes.Append("GIF Image (*.gif)|*.gif");
214 wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this);
219 // Open up the dialog to save the picture.
221 wxFileDialog ExportDlg(this, wxT("Save Logo"), wxT(""), wxT(""),
222 FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
224 if (ExportDlg.ShowModal() == wxID_CANCEL){
230 // Write out the picture to the file.
234 if (LogoFile.Open(ExportDlg.GetPath(), wxFile::write)){
236 std::string base64dec;
238 initier = ContactEditorData.LogosList.find(intSelectedData);
239 base64dec = base64_decode(initier->second);
241 LogoFile.Write(base64dec.c_str(), (size_t)base64dec.size());
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);