[Libreoffice-commits] core.git: include/sfx2 sfx2/qa sfx2/sdi sfx2/source

Miklos Vajna vmiklos at collabora.co.uk
Fri Jan 12 20:39:59 UTC 2018


 include/sfx2/sfxsids.hrc       |    3 ++-
 sfx2/qa/cppunit/misc/hello.odt |binary
 sfx2/qa/cppunit/test_misc.cxx  |   38 ++++++++++++++++++++++++++++++++++++++
 sfx2/sdi/sfx.sdi               |    2 +-
 sfx2/source/appl/appuno.cxx    |    1 +
 sfx2/source/doc/objstor.cxx    |   11 +++++++++++
 6 files changed, 53 insertions(+), 2 deletions(-)

New commits:
commit a746f20cae91a87b8263342fb558a12f2f0d50b2
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jan 12 14:32:21 2018 +0100

    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 <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc
index 81d4d45cbe9d..6fbdaa4f281e 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -244,8 +244,9 @@
 #define SID_TEMPLATE_MANAGER                (SID_SFX_START + 1727)
 #define SID_TOOLBAR_MODE                    (SID_SFX_START + 1728)
 #define SID_NO_FILE_SYNC                    (SID_SFX_START + 1729)
+#define SID_NO_THUMBNAIL                    (SID_SFX_START + 1730)
 
-//      SID_SFX_free_START                  (SID_SFX_START + 1730)
+//      SID_SFX_free_START                  (SID_SFX_START + 1731)
 //      SID_SFX_free_END                    (SID_SFX_START + 3999)
 
 #define SID_OPEN_NEW_VIEW                   (SID_SFX_START + 520)
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 <com/sun/star/beans/PropertyValue.hpp>
 #include <com/sun/star/document/DocumentProperties.hpp>
 #include <com/sun/star/packages/zip/ZipFileAccess.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
 
 #include <test/bootstrapfixture.hxx>
 #include <test/xmltesttools.hxx>
+#include <unotest/macros_test.hxx>
 
 #include <unotools/ucbstreamhelper.hxx>
+#include <comphelper/propertysequence.hxx>
+#include <comphelper/processfactory.hxx>
+#include <sfx2/app.hxx>
 
 
 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<document::XDocumentProperties> 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<lang::XComponent> 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<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xStorable.is());
+    utl::TempFile aTempFile;
+    uno::Sequence<beans::PropertyValue> aProperties(
+        comphelper::InitPropertySequence({ { "NoThumbnail", uno::makeAny(true) } }));
+    xStorable->storeToURL(aTempFile.GetURL(), aProperties);
+    uno::Reference<packages::zip::XZipFileAccess2> 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<SfxType*>(&aSfxInt16Item_Impl), "Version", SID_VERSION },
     { reinterpret_cast<SfxType*>(&aSfxBoolItem_Impl), "SaveACopy", SID_SAVEACOPYITEM },
     { reinterpret_cast<SfxType*>(&aSfxBoolItem_Impl), "NoFileSync", SID_NO_FILE_SYNC },
+    { reinterpret_cast<SfxType*>(&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 <basic/modsizeexceeded.hxx>
 #include <officecfg/Office/Common.hxx>
 #include <osl/file.hxx>
+#include <comphelper/scopeguard.hxx>
 
 #include <sfx2/signaturestate.hxx>
 #include <sfx2/app.hxx>
@@ -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<SfxBoolItem>(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 ) );


More information about the Libreoffice-commits mailing list