X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;ds=sidebyside;f=source%2Fcontacteditor%2FfrmContactEditor-Picture.cpp;h=68aa2cbf22be17f4ed1cc568a4523e93b515672a;hb=ad76a9933d9cfcee0abe970c996a944b56e3caf8;hp=5412b99308d0f7eccc99be7c78e0ddeb8851be7b;hpb=5b2b2bcea1ab1dfd2b74589573cd16ee9326c4b9;p=xestiaab%2F.git
diff --git a/source/contacteditor/frmContactEditor-Picture.cpp b/source/contacteditor/frmContactEditor-Picture.cpp
index 5412b99..68aa2cb 100644
--- a/source/contacteditor/frmContactEditor-Picture.cpp
+++ b/source/contacteditor/frmContactEditor-Picture.cpp
@@ -1,3 +1,22 @@
+// frmContactEditor-Picture.cpp - frmContactEditor Picture tab subroutines.
+//
+// (c) 2012-2015 Xestia Software Development.
+//
+// This file is part of Xestia Address Book.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// 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"
@@ -140,3 +159,81 @@ void frmContactEditor::LoadPicture( wxListEvent& event )
imgPicture->SetBitmap(PictureImage);
}
+
+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 {
+
+ 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