X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fcontacteditor%2FfrmContactEditor-Logo.cpp;h=e4f7c966f8a2532cf9ded2fdc1512b2f6a94c29a;hb=bac054ea5eda94fe663d8b1a7c680ae80de8075c;hp=b749bd62e20feede62c126b40e7635c4ca724e8b;hpb=5b2b2bcea1ab1dfd2b74589573cd16ee9326c4b9;p=xestiaab%2F.git diff --git a/source/contacteditor/frmContactEditor-Logo.cpp b/source/contacteditor/frmContactEditor-Logo.cpp index b749bd6..e4f7c96 100644 --- a/source/contacteditor/frmContactEditor-Logo.cpp +++ b/source/contacteditor/frmContactEditor-Logo.cpp @@ -1,3 +1,21 @@ +// frmContactEditor-Logo.cpp - frmContactEditor Logo tab subroutines. +// +// (c) 2012-2016 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 "frmContactEditor.h" #include "frmContactEditorPicture.h" #include "../common/base64.h" @@ -5,114 +23,230 @@ void frmContactEditor::LoadLogo( wxListEvent& event ) { - long longSelected = -1; - int intSelectedData = 0; - - if (!GetSelectedItem(lboLogos, - &longSelected, - &intSelectedData)){ - return; - } - - std::string base64dec; + // Load the logo. + + long longSelected = -1; + int intSelectedData = 0; - std::map::iterator initier; + if (lboLogos->GetItemCount() == 0 || !GetSelectedItem(lboLogos, + &longSelected, + &intSelectedData)){ + return; + } - initier = LogosList.find(intSelectedData); + std::string base64dec; - base64dec = base64_decode(initier->second); + std::map::iterator initier; + std::map::iterator pictypeiter; + initier = ContactEditorData.LogosList.find(intSelectedData); + pictypeiter = ContactEditorData.LogosListPictureType.find(intSelectedData); - wxMemoryInputStream istream(base64dec.c_str(), (size_t)base64dec.size()); - wxImage photo; - //wxMemoryInputStream istream(base64dec, (size_t)base64dec.size()); + base64dec = base64_decode(initier->second); - if (!photo.LoadFile(istream, wxBITMAP_TYPE_ANY)){ + wxMemoryInputStream istream(base64dec.c_str(), (size_t)base64dec.size()); + wxImage photo; + + if (pictypeiter->second == wxT("image/jpeg")){ + + if (!photo.LoadFile(istream, wxBITMAP_TYPE_JPEG)){ + + return; - return; + } - } + } else if (pictypeiter->second == wxT("image/png")){ + + if (!photo.LoadFile(istream, wxBITMAP_TYPE_PNG)){ + + return; + + } + + } else if (pictypeiter->second == wxT("image/gif")){ + + if (!photo.LoadFile(istream, wxBITMAP_TYPE_GIF)){ + + return; + + } + + } else { + return; - LogoImage = (wxBitmap)photo; - imgLogo->SetBitmap(LogoImage); + } + + LogoImage = (wxBitmap)photo; + imgLogo->SetBitmap(LogoImage); } void frmContactEditor::AddLogo( wxCommandEvent& event ) { - int intResult = 0; - - frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this ); - frameCELogo->SetEditorMode(FALSE); - intResult = GetLastInt(&LogosList); - frameCELogo->SetupPointers(&LogosList, - &LogosListAltID, - &LogosListPID, - &LogosListType, - &LogosListPicEncType, - &LogosListPictureType, - &LogosListTokens, - &LogosListMediatype, - &LogosListPref, - lboLogos, - (intValueSeek)); - frameCELogo->ShowModal(); - delete frameCELogo; - frameCELogo = NULL; + + // Bring up the window to add a logo. + + frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this ); + frameCELogo->SetEditorMode(FALSE); + frameCELogo->SetupPointers(&ContactEditorData.LogosList, + &ContactEditorData.LogosListAltID, + &ContactEditorData.LogosListPID, + &ContactEditorData.LogosListType, + &ContactEditorData.LogosListPicEncType, + &ContactEditorData.LogosListPictureType, + &ContactEditorData.LogosListTokens, + &ContactEditorData.LogosListMediatype, + &ContactEditorData.LogosListPref, + lboLogos, + (intValueSeek), + FALSE); + frameCELogo->ShowModal(); + delete frameCELogo; + frameCELogo = NULL; + intValueSeek++; + } void frmContactEditor::ModifyLogo( wxCommandEvent& event ) { - long longSelected = -1; - int intSelectedData = 0; - - if (!GetSelectedItem(lboLogos, - &longSelected, - &intSelectedData)){ - return; - } - - frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this ); - frameCELogo->SetupPointers(&LogosList, - &LogosListAltID, - &LogosListPID, - &LogosListType, - &LogosListPicEncType, - &LogosListPictureType, - &LogosListTokens, - &LogosListMediatype, - &LogosListPref, - lboLogos, - intSelectedData); - frameCELogo->SetEditorMode(TRUE); - frameCELogo->ShowModal(); - delete frameCELogo; - frameCELogo = NULL; + + // Bring up the window to modify a logo. + + long longSelected = -1; + int intSelectedData = 0; + + if (lboLogos->GetItemCount() == 0 || !GetSelectedItem(lboLogos, + &longSelected, + &intSelectedData)){ + return; + } + + frmContactEditorPicture *frameCELogo = new frmContactEditorPicture ( this ); + frameCELogo->SetupPointers(&ContactEditorData.LogosList, + &ContactEditorData.LogosListAltID, + &ContactEditorData.LogosListPID, + &ContactEditorData.LogosListType, + &ContactEditorData.LogosListPicEncType, + &ContactEditorData.LogosListPictureType, + &ContactEditorData.LogosListTokens, + &ContactEditorData.LogosListMediatype, + &ContactEditorData.LogosListPref, + lboLogos, + intSelectedData, + FALSE); + frameCELogo->SetEditorMode(TRUE); + frameCELogo->ShowModal(); + delete frameCELogo; + frameCELogo = NULL; + } void frmContactEditor::DeleteLogo( wxCommandEvent& event ) { - long longSelected = -1; - int intSelectedData = 0; + + // Bring up a window to delete a logo. + + long longSelected = -1; + int intSelectedData = 0; + + if (lboLogos->GetItemCount() == 0 || !GetSelectedItem(lboLogos, + &longSelected, + &intSelectedData)){ + return; + } + + lboLogos->DeleteItem(longSelected); + + DeleteMapData(intSelectedData, + &ContactEditorData.LogosList, &ContactEditorData.LogosListAltID, &ContactEditorData.LogosListPID, &ContactEditorData.LogosListType, + &ContactEditorData.LogosListPicEncType, &ContactEditorData.LogosListPictureType, &ContactEditorData.LogosListTokens, + &ContactEditorData.LogosListMediatype, &ContactEditorData.LogosListPref); + + wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png)); + wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG); + LogoImage = (wxBitmap)misc_emptyimage_png; + + imgLogo->SetBitmap(LogoImage); + +} + +void frmContactEditor::SaveLogo( wxCommandEvent &event ) +{ + + // Save the logo to a file. + + long longSelected = -1; + int intSelectedData = 0; - if (!GetSelectedItem(lboLogos, + if (lboLogos->GetItemCount() == 0 || !GetSelectedItem(lboLogos, &longSelected, &intSelectedData)){ - return; - } - - lboLogos->DeleteItem(longSelected); - - DeleteMapData(intSelectedData, - &LogosList, &LogosListAltID, &LogosListPID, &LogosListType, - &LogosListPicEncType, &LogosListPictureType, &LogosListTokens, - &LogosListMediatype, &LogosListPref); - - wxMemoryInputStream istream(misc_emptyimage_png, sizeof(misc_emptyimage_png)); - wxImage misc_emptyimage_png(istream, wxBITMAP_TYPE_PNG); - LogoImage = (wxBitmap)misc_emptyimage_png; - - imgLogo->SetBitmap(LogoImage); -} + + return; + + } + + wxString FileTypes; + + wxString FinalFilename; + + std::map::iterator initier; + std::map::iterator logotypeiter; + + initier = ContactEditorData.LogosList.find(intSelectedData); + logotypeiter = ContactEditorData.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 = ContactEditorData.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