From a746f20cae91a87b8263342fb558a12f2f0d50b2 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 12 Jan 2018 14:32:21 +0100 Subject: sfx2 store: add API to allow disabling thumbnails only for a single save This is similar to the officecfg::Office::Common::Save::Document::GenerateThumbnail config setting, but here we allow configuring this at a per-save basis, not persistently. Change-Id: Ieb5bd57f1d8fc9e211011f2647276d985cf53131 Reviewed-on: https://gerrit.libreoffice.org/47812 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sfx2/qa/cppunit/misc/hello.odt | Bin 0 -> 8159 bytes sfx2/qa/cppunit/test_misc.cxx | 38 ++++++++++++++++++++++++++++++++++++++ sfx2/sdi/sfx.sdi | 2 +- sfx2/source/appl/appuno.cxx | 1 + sfx2/source/doc/objstor.cxx | 11 +++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 sfx2/qa/cppunit/misc/hello.odt (limited to 'sfx2') diff --git a/sfx2/qa/cppunit/misc/hello.odt b/sfx2/qa/cppunit/misc/hello.odt new file mode 100644 index 000000000000..23ce6a4db9af Binary files /dev/null and b/sfx2/qa/cppunit/misc/hello.odt differ diff --git a/sfx2/qa/cppunit/test_misc.cxx b/sfx2/qa/cppunit/test_misc.cxx index e3cbd8d4748c..5f36b438f089 100644 --- a/sfx2/qa/cppunit/test_misc.cxx +++ b/sfx2/qa/cppunit/test_misc.cxx @@ -20,11 +20,17 @@ #include #include #include +#include +#include #include #include +#include #include +#include +#include +#include using namespace ::com::sun::star; @@ -34,10 +40,13 @@ namespace { class MiscTest : public test::BootstrapFixture + , public unotest::MacrosTest , public XmlTestTools { public: + virtual void setUp() override; void testODFCustomMetadata(); + void testNoThumbnail(); virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override { @@ -52,11 +61,19 @@ public: CPPUNIT_TEST_SUITE(MiscTest); CPPUNIT_TEST(testODFCustomMetadata); + CPPUNIT_TEST(testNoThumbnail); CPPUNIT_TEST_SUITE_END(); private: }; +void MiscTest::setUp() +{ + m_xContext = comphelper::getProcessComponentContext(); + mxDesktop.set(frame::Desktop::create(m_xContext)); + SfxApplication::GetOrCreate(); +} + void MiscTest::testODFCustomMetadata() { uno::Reference const xProps( @@ -86,6 +103,27 @@ void MiscTest::testODFCustomMetadata() aTempFile.EnableKillingFile(); } +void MiscTest::testNoThumbnail() +{ + // Load a document. + const OUString aURL(m_directories.getURLFromSrc("/sfx2/qa/cppunit/misc/hello.odt")); + uno::Reference xComponent + = loadFromDesktop(aURL, "com.sun.star.text.TextDocument"); + CPPUNIT_ASSERT(xComponent.is()); + + // Save it with the NoThumbnail option and assert that it has no thumbnail. + uno::Reference xStorable(xComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xStorable.is()); + utl::TempFile aTempFile; + uno::Sequence aProperties( + comphelper::InitPropertySequence({ { "NoThumbnail", uno::makeAny(true) } })); + xStorable->storeToURL(aTempFile.GetURL(), aProperties); + uno::Reference xZipFile + = packages::zip::ZipFileAccess::createWithURL(m_xContext, aTempFile.GetURL()); + CPPUNIT_ASSERT(!xZipFile->hasByName("Thumbnails/thumbnail.png")); + + xComponent->dispose(); +} CPPUNIT_TEST_SUITE_REGISTRATION(MiscTest); diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi index a366a271edb5..0ddf3653c3c0 100644 --- a/sfx2/sdi/sfx.sdi +++ b/sfx2/sdi/sfx.sdi @@ -3557,7 +3557,7 @@ SfxVoidItem SaveAll SID_SAVEDOCS SfxStringItem SaveAs SID_SAVEASDOC -(SfxStringItem URL SID_FILE_NAME,SfxStringItem FilterName SID_FILTER_NAME,SfxStringItem Password SID_PASSWORD,SfxBoolItem PasswordInteraction SID_PASSWORDINTERACTION,SfxStringItem FilterOptions SID_FILE_FILTEROPTIONS,SfxStringItem VersionComment SID_DOCINFO_COMMENTS,SfxStringItem VersionAuthor SID_DOCINFO_AUTHOR,SfxBoolItem Overwrite SID_OVERWRITE,SfxBoolItem Unpacked SID_UNPACK,SfxBoolItem SaveTo SID_SAVETO,SfxBoolItem NoFileSync SID_NO_FILE_SYNC) +(SfxStringItem URL SID_FILE_NAME,SfxStringItem FilterName SID_FILTER_NAME,SfxStringItem Password SID_PASSWORD,SfxBoolItem PasswordInteraction SID_PASSWORDINTERACTION,SfxStringItem FilterOptions SID_FILE_FILTEROPTIONS,SfxStringItem VersionComment SID_DOCINFO_COMMENTS,SfxStringItem VersionAuthor SID_DOCINFO_AUTHOR,SfxBoolItem Overwrite SID_OVERWRITE,SfxBoolItem Unpacked SID_UNPACK,SfxBoolItem SaveTo SID_SAVETO,SfxBoolItem NoFileSync SID_NO_FILE_SYNC,SfxBoolItem NoThumbnail SID_NO_THUMBNAIL) [ AutoUpdate = FALSE, FastCall = FALSE, diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index 8b3d0792f70d..5b50b2e7a145 100644 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -106,6 +106,7 @@ SfxFormalArgument const aFormalArgs[] = { { reinterpret_cast(&aSfxInt16Item_Impl), "Version", SID_VERSION }, { reinterpret_cast(&aSfxBoolItem_Impl), "SaveACopy", SID_SAVEACOPYITEM }, { reinterpret_cast(&aSfxBoolItem_Impl), "NoFileSync", SID_NO_FILE_SYNC }, + { reinterpret_cast(&aSfxBoolItem_Impl), "NoThumbnail", SID_NO_THUMBNAIL }, }; static sal_uInt16 nMediaArgsCount = SAL_N_ELEMENTS(aFormalArgs); diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index b470d8f60177..44f6f1556f75 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -100,6 +100,7 @@ #include #include #include +#include #include #include @@ -2743,6 +2744,16 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString& if (pNoFileSync && pNoFileSync->GetValue()) pNewFile->DisableFileSync(true); + bool bUseThumbnailSave = IsUseThumbnailSave(); + comphelper::ScopeGuard aThumbnailGuard( + [this, bUseThumbnailSave] { this->SetUseThumbnailSave(bUseThumbnailSave); }); + const SfxBoolItem* pNoThumbnail = pMergedParams->GetItem(SID_NO_THUMBNAIL, false); + if (pNoThumbnail) + // Thumbnail generation should be avoided just for this save. + SetUseThumbnailSave(!pNoThumbnail->GetValue()); + else + aThumbnailGuard.dismiss(); + // set filter; if no filter is given, take the default filter of the factory if ( !aFilterName.isEmpty() ) pNewFile->SetFilter( GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName ) ); -- cgit