From d06d0b1d631e7a48c34738397e98651f541d4000 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Mon, 30 Nov 2015 00:23:13 +0000 Subject: [PATCH] Implemented option to save photos, logos and sounds. --- .../contacteditor/frmContactEditor-Load.cpp | 1 - .../contacteditor/frmContactEditor-Logo.cpp | 73 +++++++++++++++++- .../frmContactEditor-Picture.cpp | 74 ++++++++++++++++++- .../contacteditor/frmContactEditor-Sound.cpp | 54 +++++++++++++- 4 files changed, 198 insertions(+), 4 deletions(-) diff --git a/source/contacteditor/frmContactEditor-Load.cpp b/source/contacteditor/frmContactEditor-Load.cpp index 77514d9..6b97937 100644 --- a/source/contacteditor/frmContactEditor-Load.cpp +++ b/source/contacteditor/frmContactEditor-Load.cpp @@ -225,7 +225,6 @@ bool frmContactEditor::LoadContact(wxString Filename){ // Check if version is 4.0, otherwise don't // load. - wxPuts(wxSPropertySeg2); if (wxSPropertySeg2 != wxT("4.0")){ wxMessageBox(_("This file is not a vCard 4.0 contact and is not supported under Xestia Address Book."), _("Contact not supported"), wxICON_ERROR); diff --git a/source/contacteditor/frmContactEditor-Logo.cpp b/source/contacteditor/frmContactEditor-Logo.cpp index 94280d2..5f0eba8 100644 --- a/source/contacteditor/frmContactEditor-Logo.cpp +++ b/source/contacteditor/frmContactEditor-Logo.cpp @@ -137,6 +137,77 @@ void frmContactEditor::DeleteLogo( wxCommandEvent& event ) void frmContactEditor::SaveLogo( wxCommandEvent &event ) { - return; + long longSelected = -1; + int intSelectedData = 0; + + if (!GetSelectedItem(lboLogos, + &longSelected, + &intSelectedData)){ + + return; + + } + + wxString FileTypes; + + wxString FinalFilename; + + std::map::iterator initier; + std::map::iterator logotypeiter; + + initier = LogosList.find(intSelectedData); + logotypeiter = LogosListPictureType.find(intSelectedData); + + if (logotypeiter->second == wxT("image/jpeg")){ + + FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg"); + + } else if (logotypeiter->second == wxT("image/png")){ + + FileTypes.Append("PNG Image (*.png)|*.png"); + + } else if (logotypeiter->second == wxT("image/gif")){ + + FileTypes.Append("GIF Image (*.gif)|*.gif"); + + } else { + + wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this); + return; + + } + + // Open up the dialog to save the picture. + + wxFileDialog ExportDlg(this, wxT("Save Logo"), wxT(""), wxT(""), + FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT); + + if (ExportDlg.ShowModal() == wxID_CANCEL){ + + return; + + } + + // Write out the picture to the file. + + wxFile LogoFile; + + if (LogoFile.Open(ExportDlg.GetPath(), wxFile::write)){ + + std::string base64dec; + + initier = LogosList.find(intSelectedData); + base64dec = base64_decode(initier->second); + + LogoFile.Write(base64dec.c_str(), (size_t)base64dec.size()); + + LogoFile.Close(); + + } else { + + 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); + return; + + } } \ No newline at end of file diff --git a/source/contacteditor/frmContactEditor-Picture.cpp b/source/contacteditor/frmContactEditor-Picture.cpp index 64585df..68aa2cb 100644 --- a/source/contacteditor/frmContactEditor-Picture.cpp +++ b/source/contacteditor/frmContactEditor-Picture.cpp @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License along // with Xestia Address Book. If not, see +#include #include "frmContactEditor.h" #include "frmContactEditorPicture.h" #include "../common/base64.h" @@ -161,7 +162,78 @@ void frmContactEditor::LoadPicture( wxListEvent& event ) void frmContactEditor::SavePicture( wxCommandEvent &event ) { + + long longSelected = -1; + int intSelectedData = 0; + + if (!GetSelectedItem(lboPictures, + &longSelected, + &intSelectedData)){ + + return; + + } + + wxString FileTypes; + + wxString FinalFilename; + + std::map::iterator initier; + std::map::iterator pictypeiter; + + initier = PicturesList.find(intSelectedData); + pictypeiter = PicturesListPictureType.find(intSelectedData); + + if (pictypeiter->second == wxT("image/jpeg")){ + + FileTypes.Append("JPEG Image (*.jpeg)|*.jpeg"); + + } else if (pictypeiter->second == wxT("image/png")){ + + FileTypes.Append("PNG Image (*.png)|*.png"); + + } else if (pictypeiter->second == wxT("image/gif")){ + + FileTypes.Append("GIF Image (*.gif)|*.gif"); + + } else { + + wxMessageBox(_("Picture format for saving is not supported."), _("Picture format unsupported"), wxOK, this); + return; + + } + + // Open up the dialog to save the picture. + + wxFileDialog ExportDlg(this, wxT("Save Picture"), wxT(""), wxT(""), + FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT); + + if (ExportDlg.ShowModal() == wxID_CANCEL){ + + return; + + } + + // Write out the picture to the file. + + wxFile PictureFile; + + if (PictureFile.Open(ExportDlg.GetPath(), wxFile::write)){ + + std::string base64dec; + + initier = PicturesList.find(intSelectedData); + base64dec = base64_decode(initier->second); + + PictureFile.Write(base64dec.c_str(), (size_t)base64dec.size()); + + PictureFile.Close(); + + } else { - return; + wxMessageBox(_("An error occured whilst saving the picture. Check that you have free space and permissions to write the picture at this location."), _("Picture save error"), wxOK, this); + return; + } + } \ No newline at end of file diff --git a/source/contacteditor/frmContactEditor-Sound.cpp b/source/contacteditor/frmContactEditor-Sound.cpp index 1626626..c19b947 100644 --- a/source/contacteditor/frmContactEditor-Sound.cpp +++ b/source/contacteditor/frmContactEditor-Sound.cpp @@ -200,7 +200,59 @@ void frmContactEditor::StopSound( wxCommandEvent& event ) void frmContactEditor::SaveSound( wxCommandEvent &event ) { + + long longSelected = -1; + int intSelectedData = 0; + + if (!GetSelectedItem(lboSounds, + &longSelected, + &intSelectedData)){ + + return; + + } + + wxString FileTypes; + + wxString FinalFilename; + + std::map::iterator initier; + std::map::iterator soundtypeiter; + + initier = SoundsList.find(intSelectedData); + soundtypeiter = SoundsListAudioType.find(intSelectedData); + + // Open up the dialog to save the picture. + + wxFileDialog ExportDlg(this, wxT("Save Sound"), wxT(""), wxT(""), + FileTypes, wxFD_SAVE|wxFD_OVERWRITE_PROMPT); + + if (ExportDlg.ShowModal() == wxID_CANCEL){ + + return; + + } + + // Write out the picture to the file. + + wxFile SoundFile; + + if (SoundFile.Open(ExportDlg.GetPath(), wxFile::write)){ + + std::string base64dec; + + initier = SoundsList.find(intSelectedData); + base64dec = base64_decode(initier->second); + + SoundFile.Write(base64dec.c_str(), (size_t)base64dec.size()); + + SoundFile.Close(); + + } else { + + wxMessageBox(_("An error occured whilst saving the sound. Check that you have free space and permissions to write the picture at this location."), _("Sound save error"), wxOK, this); + return; - return; + } } \ No newline at end of file -- 2.39.2