Kaydet (Commit) d9c476bf authored tarafından Maxim Monastirsky's avatar Maxim Monastirsky

tdf#92431 Keep thumbnail for modified but unsaved doc

A regression of 1166966e.

We need to consider 2 use-cases:

1. Protecting an existing document with a password (by overwriting
   the original file). In this case we don't want to generate a
   thumbnail from the now encrypted file, but we do want to erase
   the stored thumbnail and show a generic icon instead.

2. Closing a modified document without saving the changes. Here we
   don't want to generate a thumbnail either, because it may
   contain the unsaved changes, but either we don't want to replace
   the stored thumbnail, because most likely it correctly represents
   the last saved state of the document.

Change-Id: Ia7b1f3dbc9fbbc2ef1d87442c1dee25306f65826
Reviewed-on: https://gerrit.libreoffice.org/16659Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMaxim Monastirsky <momonasmon@gmail.com>
üst ff4b8d39
...@@ -399,7 +399,7 @@ void SAL_CALL OApplicationController::disposing() ...@@ -399,7 +399,7 @@ void SAL_CALL OApplicationController::disposing()
aFilter, aFilter,
getStrippedDatabaseName(), getStrippedDatabaseName(),
OUString(), OUString(),
OUString()); boost::none);
// add to recent document list // add to recent document list
if ( aURL.GetProtocol() == INetProtocol::File ) if ( aURL.GetProtocol() == INetProtocol::File )
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#ifndef INCLUDED_UNOTOOLS_HISTORYOPTIONS_HXX #ifndef INCLUDED_UNOTOOLS_HISTORYOPTIONS_HXX
#define INCLUDED_UNOTOOLS_HISTORYOPTIONS_HXX #define INCLUDED_UNOTOOLS_HISTORYOPTIONS_HXX
#include <boost/optional.hpp>
#include <unotools/unotoolsdllapi.h> #include <unotools/unotoolsdllapi.h>
#include <sal/types.h> #include <sal/types.h>
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
...@@ -94,7 +95,7 @@ public: ...@@ -94,7 +95,7 @@ public:
*/ */
void AppendItem(EHistoryType eHistory, void AppendItem(EHistoryType eHistory,
const OUString& sURL, const OUString& sFilter, const OUString& sTitle, const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
const OUString& sPassword, const OUString& sThumbnail); const OUString& sPassword, const boost::optional<OUString>& sThumbnail);
/** Delete item from the specified list. /** Delete item from the specified list.
*/ */
......
...@@ -1198,7 +1198,7 @@ void BookmarksBox_Impl::dispose() ...@@ -1198,7 +1198,7 @@ void BookmarksBox_Impl::dispose()
{ {
OUString aTitle = GetEntry(i); OUString aTitle = GetEntry(i);
OUString* pURL = static_cast<OUString*>(GetEntryData(i)); OUString* pURL = static_cast<OUString*>(GetEntryData(i));
aHistOpt.AppendItem(eHELPBOOKMARKS, *pURL, sEmpty, aTitle, sEmpty, sEmpty); aHistOpt.AppendItem(eHELPBOOKMARKS, *pURL, sEmpty, aTitle, sEmpty, boost::none);
delete pURL; delete pURL;
} }
ListBox::dispose(); ListBox::dispose();
......
...@@ -194,26 +194,33 @@ void SfxPickList::AddDocumentToPickList( SfxObjectShell* pDocSh ) ...@@ -194,26 +194,33 @@ void SfxPickList::AddDocumentToPickList( SfxObjectShell* pDocSh )
aFilter = pFilter->GetFilterName(); aFilter = pFilter->GetFilterName();
// generate a thumbnail // generate a thumbnail
OUString aThumbnail; boost::optional<OUString> aThumbnail;
// don't generate thumbnail when in headless mode, or on non-desktop (?) // don't generate thumbnail when in headless mode, or on non-desktop (?)
#if HAVE_FEATURE_DESKTOP #if HAVE_FEATURE_DESKTOP
SFX_ITEMSET_ARG( pMed->GetItemSet(), pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, false ); if (!pDocSh->IsModified() && !Application::IsHeadlessModeEnabled())
if (!pDocSh->IsModified() && !pEncryptionDataItem && !Application::IsHeadlessModeEnabled())
{ {
// not modified => the document matches what is in the shell // not modified => the document matches what is in the shell
std::shared_ptr<GDIMetaFile> xMetaFile = pDocSh->GetPreviewMetaFile(); SFX_ITEMSET_ARG( pMed->GetItemSet(), pEncryptionDataItem, SfxUnoAnyItem, SID_ENCRYPTIONDATA, false );
BitmapEx aResultBitmap; if ( pEncryptionDataItem )
if (xMetaFile->CreateThumbnail(aResultBitmap)) {
// encrypted document, will show a generic document icon instead
aThumbnail = OUString();
}
else
{ {
SvMemoryStream aStream(65535, 65535); std::shared_ptr<GDIMetaFile> xMetaFile = pDocSh->GetPreviewMetaFile();
vcl::PNGWriter aWriter(aResultBitmap); BitmapEx aResultBitmap;
if (aWriter.Write(aStream)) if (xMetaFile->CreateThumbnail(aResultBitmap))
{ {
Sequence<sal_Int8> aSequence(static_cast<const sal_Int8*>(aStream.GetData()), aStream.Tell()); SvMemoryStream aStream(65535, 65535);
OUStringBuffer aBuffer; vcl::PNGWriter aWriter(aResultBitmap);
::sax::Converter::encodeBase64(aBuffer, aSequence); if (aWriter.Write(aStream))
aThumbnail = aBuffer.makeStringAndClear(); {
Sequence<sal_Int8> aSequence(static_cast<const sal_Int8*>(aStream.GetData()), aStream.Tell());
OUStringBuffer aBuffer;
::sax::Converter::encodeBase64(aBuffer, aSequence);
aThumbnail = aBuffer.makeStringAndClear();
}
} }
} }
} }
......
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
void AppendItem(EHistoryType eHistory, void AppendItem(EHistoryType eHistory,
const OUString& sURL, const OUString& sFilter, const OUString& sTitle, const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
const OUString& sPassword, const OUString& sThumbnail); const OUString& sPassword, const boost::optional<OUString>& sThumbnail);
void DeleteItem(EHistoryType eHistory, const OUString& sURL); void DeleteItem(EHistoryType eHistory, const OUString& sURL);
...@@ -352,7 +352,7 @@ Sequence< Sequence<PropertyValue> > SvtHistoryOptions_Impl::GetList(EHistoryType ...@@ -352,7 +352,7 @@ Sequence< Sequence<PropertyValue> > SvtHistoryOptions_Impl::GetList(EHistoryType
void SvtHistoryOptions_Impl::AppendItem(EHistoryType eHistory, void SvtHistoryOptions_Impl::AppendItem(EHistoryType eHistory,
const OUString& sURL, const OUString& sFilter, const OUString& sTitle, const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
const OUString& sPassword, const OUString& sThumbnail) const OUString& sPassword, const boost::optional<OUString>& sThumbnail)
{ {
uno::Reference<container::XNameAccess> xListAccess(GetListAccess(eHistory)); uno::Reference<container::XNameAccess> xListAccess(GetListAccess(eHistory));
if (!xListAccess.is()) if (!xListAccess.is())
...@@ -377,9 +377,12 @@ void SvtHistoryOptions_Impl::AppendItem(EHistoryType eHistory, ...@@ -377,9 +377,12 @@ void SvtHistoryOptions_Impl::AppendItem(EHistoryType eHistory,
// The item to be appended already exists // The item to be appended already exists
if (xItemList->hasByName(sURL)) if (xItemList->hasByName(sURL))
{ {
// update the thumbnail if (sThumbnail)
xItemList->getByName(sURL) >>= xSet; {
xSet->setPropertyValue(s_sThumbnail, uno::makeAny(sThumbnail)); // update the thumbnail
xItemList->getByName(sURL) >>= xSet;
xSet->setPropertyValue(s_sThumbnail, uno::makeAny(*sThumbnail));
}
for (sal_Int32 i=0; i<nLength; ++i) for (sal_Int32 i=0; i<nLength; ++i)
{ {
...@@ -466,7 +469,7 @@ void SvtHistoryOptions_Impl::AppendItem(EHistoryType eHistory, ...@@ -466,7 +469,7 @@ void SvtHistoryOptions_Impl::AppendItem(EHistoryType eHistory,
xSet->setPropertyValue(s_sFilter, uno::makeAny(sFilter)); xSet->setPropertyValue(s_sFilter, uno::makeAny(sFilter));
xSet->setPropertyValue(s_sTitle, uno::makeAny(sTitle)); xSet->setPropertyValue(s_sTitle, uno::makeAny(sTitle));
xSet->setPropertyValue(s_sPassword, uno::makeAny(sPassword)); xSet->setPropertyValue(s_sPassword, uno::makeAny(sPassword));
xSet->setPropertyValue(s_sThumbnail, uno::makeAny(sThumbnail)); xSet->setPropertyValue(s_sThumbnail, uno::makeAny(sThumbnail.get_value_or(OUString())));
::comphelper::ConfigurationHelper::flush(m_xCfg); ::comphelper::ConfigurationHelper::flush(m_xCfg);
} }
...@@ -605,7 +608,7 @@ Sequence< Sequence< PropertyValue > > SvtHistoryOptions::GetList( EHistoryType e ...@@ -605,7 +608,7 @@ Sequence< Sequence< PropertyValue > > SvtHistoryOptions::GetList( EHistoryType e
void SvtHistoryOptions::AppendItem(EHistoryType eHistory, void SvtHistoryOptions::AppendItem(EHistoryType eHistory,
const OUString& sURL, const OUString& sFilter, const OUString& sTitle, const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
const OUString& sPassword, const OUString& sThumbnail) const OUString& sPassword, const boost::optional<OUString>& sThumbnail)
{ {
MutexGuard aGuard(theHistoryOptionsMutex::get()); MutexGuard aGuard(theHistoryOptionsMutex::get());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment