[Libreoffice-commits] core.git: include/svx svx/Library_svxcore.mk svx/source

Aditya (via logerrit) logerrit at kemper.freedesktop.org
Thu Jul 23 20:08:20 UTC 2020


 include/svx/gallery1.hxx                         |   31 --
 include/svx/gallerybinaryengine.hxx              |   59 ++--
 include/svx/gallerybinaryengineentry.hxx         |   50 +++
 include/svx/gallerystoragelocations.hxx          |   49 +++
 include/svx/galtheme.hxx                         |    7 
 svx/Library_svxcore.mk                           |    2 
 svx/source/gallery2/galini.cxx                   |    6 
 svx/source/gallery2/gallery1.cxx                 |   56 ----
 svx/source/gallery2/gallerybinaryengine.cxx      |  291 ++++++-----------------
 svx/source/gallery2/gallerybinaryengineentry.cxx |  131 ++++++++++
 svx/source/gallery2/gallerystoragelocations.cxx  |   75 +++++
 svx/source/gallery2/galtheme.cxx                 |   42 +--
 svx/source/unogallery/unogalitem.cxx             |    2 
 13 files changed, 469 insertions(+), 332 deletions(-)

New commits:
commit 2157185ce15d99f7a234abe46c50f3c6f83a2651
Author:     Aditya <adityasahu1511 at gmail.com>
AuthorDate: Fri Jul 17 13:55:11 2020 +0530
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Jul 23 22:07:32 2020 +0200

    svx:Introduce GalleryBinaryEngineEntry and GalleryStorageLocations
    
    Change GalleryBinaryEngine to GalleryBinaryEngineEntry and create
     GalleryBinaryEngine class that is instantiated at when GalleryEngine is
     instantiated.
    Implement GalleryStorageLocations, a shared class which contains locations
     to binary files like aThmURL, aSdgURL, aSdvURL and aStrURL. The class shares
     the members between GalleryBinaryEngine and GalleryBinaryEngineEntry.
    
    Change-Id: I22da487fbc2a500252196f9ff8dcfa9c4df6abbf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98979
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/svx/gallery1.hxx b/include/svx/gallery1.hxx
index 013245d91da0..28ba3fe72eb4 100644
--- a/include/svx/gallery1.hxx
+++ b/include/svx/gallery1.hxx
@@ -24,21 +24,23 @@
 #include <svl/SfxBroadcaster.hxx>
 #include <svx/svxdllapi.h>
 #include <tools/urlobj.hxx>
+#include <svx/gallerybinaryengineentry.hxx>
 #include <svx/gallerybinaryengine.hxx>
 
 #include <cstdio>
 #include <memory>
 #include <vector>
 
-class SgaObjectSvDraw;
 struct GalleryObject;
-class GalleryBinaryEngine;
+class GalleryBinaryEngineEntry;
+class GalleryStorageLocations;
 
 class GalleryThemeEntry
 {
 private:
 
-    std::unique_ptr<GalleryBinaryEngine>     mpGalleryBinaryEngine;
+    std::unique_ptr<GalleryBinaryEngineEntry>     mpGalleryBinaryEngineEntry;
+    GalleryStorageLocations maGalleryStorageLocations;
     OUString                aName;
     sal_uInt32              nId;
     bool                    bReadOnly;
@@ -52,26 +54,17 @@ public:
                                                bool bReadOnly, bool bNewFile,
                                                sal_uInt32 nId, bool bThemeNameFromResource );
 
-    static std::unique_ptr<GalleryBinaryEngine> createGalleryBinaryEngine();
-    const std::unique_ptr<GalleryBinaryEngine>& getGalleryBinaryEngine() const { return mpGalleryBinaryEngine; }
+    std::unique_ptr<GalleryBinaryEngineEntry> createGalleryBinaryEngineEntry();
+    const std::unique_ptr<GalleryBinaryEngineEntry>& getGalleryBinaryEngineEntry() const { return mpGalleryBinaryEngineEntry; }
 
-    void callGalleryThemeInit();
-
-    bool readModel(const GalleryObject* pObject, SdrModel& rModel);
-    bool insertModel(const FmFormModel& rModel, INetURLObject& aURL);
-
-    bool readModelStream(const GalleryObject* pObject, tools::SvRef<SotStorageStream> const& rxModelStream);
-    SgaObjectSvDraw insertModelStream(const tools::SvRef<SotStorageStream>& rxModelStream, INetURLObject& rURL);
-
-    void insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry, OUString& rDestDir,
-        ::std::vector<std::unique_ptr<GalleryObject>>& rObjectList, sal_uInt32& rInsertPos);
+    const GalleryStorageLocations& getGalleryStorageLocations() const { return maGalleryStorageLocations; }
 
     const OUString&         GetThemeName() const { return aName; }
 
-    const INetURLObject&    GetThmURL() const { return mpGalleryBinaryEngine->GetThmURL(); }
-    const INetURLObject&    GetSdgURL() const { return mpGalleryBinaryEngine->GetSdgURL(); }
-    const INetURLObject&    GetSdvURL() const { return mpGalleryBinaryEngine->GetSdvURL(); }
-    const INetURLObject&    GetStrURL() const { return mpGalleryBinaryEngine->GetStrURL(); }
+    const INetURLObject&    GetThmURL() const { return mpGalleryBinaryEngineEntry->GetThmURL(); }
+    const INetURLObject&    GetSdgURL() const { return mpGalleryBinaryEngineEntry->GetSdgURL(); }
+    const INetURLObject&    GetSdvURL() const { return mpGalleryBinaryEngineEntry->GetSdvURL(); }
+    const INetURLObject&    GetStrURL() const { return mpGalleryBinaryEngineEntry->GetStrURL(); }
 
     bool                    IsReadOnly() const { return bReadOnly; }
     bool                    IsDefault() const;
diff --git a/include/svx/gallerybinaryengine.hxx b/include/svx/gallerybinaryengine.hxx
index 4582bd1d4b8d..b40f9c2b11bb 100644
--- a/include/svx/gallerybinaryengine.hxx
+++ b/include/svx/gallerybinaryengine.hxx
@@ -19,52 +19,54 @@
 
 #pragma once
 
-#include <tools/urlobj.hxx>
-#include <svx/svxdllapi.h>
 #include <svx/galtheme.hxx>
+#include <svx/gallerybinaryengine.hxx>
+#include <svx/gallerystoragelocations.hxx>
+#include <svx/svxdllapi.h>
+#include <svx/fmmodel.hxx>
+#include <tools/urlobj.hxx>
 #include <sot/storage.hxx>
 
+#include <cstdio>
+#include <memory>
+#include <vector>
+
+class GalleryStorageLocations;
 class SgaObjectSvDraw;
+class SgaObject;
 class SotStorage;
 struct GalleryObject;
+class FmFormModel;
+class GalleryTheme;
 
 class SVXCORE_DLLPUBLIC GalleryBinaryEngine
 {
 private:
-    INetURLObject aThmURL;
-    INetURLObject aSdgURL;
-    INetURLObject aSdvURL;
-    INetURLObject aStrURL;
-    tools::SvRef<SotStorage> aSvDrawStorageRef;
-
-    static INetURLObject ImplGetURLIgnoreCase(const INetURLObject& rURL);
+    tools::SvRef<SotStorage> m_aSvDrawStorageRef;
+    const GalleryStorageLocations& maGalleryStorageLocations;
 
 public:
-    void galleryThemeInit(bool bReadOnly);
-    void galleryThemeDestroy();
+    GalleryBinaryEngine(const GalleryStorageLocations& rGalleryStorageLocations);
+    void clearSotStorage();
 
-    static void CreateUniqueURL(const INetURLObject& rBaseURL, INetURLObject& aURL);
-
-    OUString ReadStrFromIni(const OUString& aKeyName);
+    SAL_DLLPRIVATE void ImplCreateSvDrawStorage(bool bReadOnly);
+    SAL_DLLPRIVATE const tools::SvRef<SotStorage>& GetSvDrawStorage() const;
 
-    void SetThmExtension(INetURLObject aURL);
-    void SetSdgExtension(INetURLObject aURL);
-    void SetSdvExtension(INetURLObject aURL);
-    void SetStrExtension(INetURLObject aURL);
+    const INetURLObject& GetThmURL() const { return maGalleryStorageLocations.GetThmURL(); }
+    const INetURLObject& GetSdgURL() const { return maGalleryStorageLocations.GetSdgURL(); }
+    const INetURLObject& GetSdvURL() const { return maGalleryStorageLocations.GetSdvURL(); }
+    const INetURLObject& GetStrURL() const { return maGalleryStorageLocations.GetStrURL(); }
 
-    const INetURLObject& GetThmURL() const { return aThmURL; }
-    const INetURLObject& GetSdgURL() const { return aSdgURL; }
-    const INetURLObject& GetSdvURL() const { return aSdvURL; }
-    const INetURLObject& GetStrURL() const { return aStrURL; }
+    SAL_DLLPRIVATE bool implWrite(const GalleryTheme& rTheme);
 
-    SAL_DLLPRIVATE void ImplCreateSvDrawStorage(bool bReadOnly);
-    SAL_DLLPRIVATE const tools::SvRef<SotStorage>& GetSvDrawStorage() const;
+    void insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry, OUString& rDestDir,
+                      ::std::vector<std::unique_ptr<GalleryObject>>& rObjectList,
+                      sal_uInt32& rInsertPos);
 
     std::unique_ptr<SgaObject> implReadSgaObject(GalleryObject const* pEntry);
     bool implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry,
                             OUString& aDestDir,
                             ::std::vector<std::unique_ptr<GalleryObject>>& aObjectList);
-    SAL_DLLPRIVATE bool implWrite(const GalleryTheme& rTheme);
 
     bool readModel(const GalleryObject* pObject, SdrModel& rModel);
     bool insertModel(const FmFormModel& rModel, INetURLObject& rURL);
@@ -73,13 +75,6 @@ public:
                          tools::SvRef<SotStorageStream> const& rxModelStream);
     SgaObjectSvDraw insertModelStream(const tools::SvRef<SotStorageStream>& rxModelStream,
                                       INetURLObject& rURL);
-
-    void insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry, OUString& rDestDir,
-                      ::std::vector<std::unique_ptr<GalleryObject>>& rObjectList,
-                      sal_uInt32& rInsertPos);
-
-    SAL_DLLPRIVATE static GalleryThemeEntry* CreateThemeEntry(const INetURLObject& rURL,
-                                                              bool bReadOnly);
 };
 
 SvStream& WriteGalleryTheme(SvStream& rOut, const GalleryTheme& rTheme);
diff --git a/include/svx/gallerybinaryengineentry.hxx b/include/svx/gallerybinaryengineentry.hxx
new file mode 100644
index 000000000000..a310f085df03
--- /dev/null
+++ b/include/svx/gallerybinaryengineentry.hxx
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <tools/urlobj.hxx>
+#include <svx/svxdllapi.h>
+#include <svx/galtheme.hxx>
+#include <svx/gallerybinaryengine.hxx>
+#include <svx/gallerystoragelocations.hxx>
+
+class GalleryStorageLocations;
+
+class SVXCORE_DLLPUBLIC GalleryBinaryEngineEntry
+{
+private:
+    GalleryStorageLocations& maGalleryStorageLocations;
+
+public:
+    GalleryBinaryEngineEntry(GalleryStorageLocations& rGalleryStorageLocations);
+    static void CreateUniqueURL(const INetURLObject& rBaseURL, INetURLObject& aURL);
+
+    OUString ReadStrFromIni(const OUString& aKeyName);
+
+    const INetURLObject& GetThmURL() const { return maGalleryStorageLocations.GetThmURL(); }
+    const INetURLObject& GetSdgURL() const { return maGalleryStorageLocations.GetSdgURL(); }
+    const INetURLObject& GetSdvURL() const { return maGalleryStorageLocations.GetSdvURL(); }
+    const INetURLObject& GetStrURL() const { return maGalleryStorageLocations.GetStrURL(); }
+
+    SAL_DLLPRIVATE static GalleryThemeEntry* CreateThemeEntry(const INetURLObject& rURL,
+                                                              bool bReadOnly);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/gallerystoragelocations.hxx b/include/svx/gallerystoragelocations.hxx
new file mode 100644
index 000000000000..77ce6b69c232
--- /dev/null
+++ b/include/svx/gallerystoragelocations.hxx
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <tools/urlobj.hxx>
+#include <svx/svxdllapi.h>
+
+class SVXCORE_DLLPUBLIC GalleryStorageLocations
+{
+private:
+    INetURLObject maThmURL;
+    INetURLObject maSdgURL;
+    INetURLObject maSdvURL;
+    INetURLObject maStrURL;
+
+public:
+    static INetURLObject ImplGetURLIgnoreCase(const INetURLObject& rURL);
+
+    const INetURLObject& GetThmURL() const { return maThmURL; }
+    const INetURLObject& GetSdgURL() const { return maSdgURL; }
+    const INetURLObject& GetSdvURL() const { return maSdvURL; }
+    const INetURLObject& GetStrURL() const { return maStrURL; }
+
+    void SetThmExtension(INetURLObject& aURL);
+    void SetSdgExtension(INetURLObject& aURL);
+    void SetSdvExtension(INetURLObject& aURL);
+    void SetStrExtension(INetURLObject& aURL);
+
+    void SetStorageLocations(INetURLObject& aURL);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/galtheme.hxx b/include/svx/galtheme.hxx
index 7d67fe6f3488..1da9eac44a7a 100644
--- a/include/svx/galtheme.hxx
+++ b/include/svx/galtheme.hxx
@@ -21,6 +21,7 @@
 #define INCLUDED_SVX_GALTHEME_HXX
 
 #include <svx/svxdllapi.h>
+#include <svx/gallerybinaryengine.hxx>
 
 #include <tools/debug.hxx>
 #include <tools/urlobj.hxx>
@@ -34,7 +35,6 @@ namespace weld { class ComboBox; }
 
 class SotStorageStream;
 
-
 struct GalleryObject
 {
     INetURLObject   aURL;
@@ -62,6 +62,7 @@ namespace unogallery
     class GalleryItem;
 }
 
+class GalleryBinaryEngine;
 
 class SVXCORE_DLLPUBLIC GalleryTheme : public SfxBroadcaster
 {
@@ -72,6 +73,7 @@ class SVXCORE_DLLPUBLIC GalleryTheme : public SfxBroadcaster
 
 private:
 
+    std::unique_ptr<GalleryBinaryEngine>     mpGalleryBinaryEngine;
     ::std::vector< std::unique_ptr<GalleryObject> > aObjectList;
     OUString                    m_aDestDir;
     bool                        m_bDestDirRelative;
@@ -83,6 +85,9 @@ private:
     bool                        bDragging;
     bool                        bAbortActualize;
 
+    std::unique_ptr<GalleryBinaryEngine> createGalleryBinaryEngine();
+    const std::unique_ptr<GalleryBinaryEngine>& getGalleryBinaryEngine() const { return mpGalleryBinaryEngine; }
+
     SAL_DLLPRIVATE const GalleryObject* ImplGetGalleryObject(sal_uInt32 nPos) const
     {
         if (nPos < aObjectList.size())
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 73d22cafee6c..37f135fced87 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -153,6 +153,8 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
     svx/source/gallery2/galtheme \
     svx/source/gallery2/GalleryControl \
     svx/source/gallery2/gallerybinaryengine \
+    svx/source/gallery2/gallerybinaryengineentry \
+    svx/source/gallery2/gallerystoragelocations \
     svx/source/items/chrtitem \
     svx/source/items/clipfmtitem \
     svx/source/items/customshapeitem \
diff --git a/svx/source/gallery2/galini.cxx b/svx/source/gallery2/galini.cxx
index 22f3aaff515c..161b1ec6e24c 100644
--- a/svx/source/gallery2/galini.cxx
+++ b/svx/source/gallery2/galini.cxx
@@ -17,16 +17,16 @@
 #include <sal/log.hxx>
 
 #include <unotools/ucbstreamhelper.hxx>
-#include <svx/gallerybinaryengine.hxx>
+#include <svx/gallerybinaryengineentry.hxx>
 #include <i18nlangtag/languagetag.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/settings.hxx>
 #include <memory>
 
-OUString GalleryBinaryEngine::ReadStrFromIni(const OUString &aKeyName )
+OUString GalleryBinaryEngineEntry::ReadStrFromIni(const OUString &aKeyName )
 {
     std::unique_ptr<SvStream> pStrm(::utl::UcbStreamHelper::CreateStream(
-                                GetStrURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ),
+        GetStrURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ),
                                 StreamMode::READ ));
 
     const LanguageTag &rLangTag = Application::GetSettings().GetUILanguageTag();
diff --git a/svx/source/gallery2/gallery1.cxx b/svx/source/gallery2/gallery1.cxx
index 848b593e60f5..79533c4f0891 100644
--- a/svx/source/gallery2/gallery1.cxx
+++ b/svx/source/gallery2/gallery1.cxx
@@ -41,7 +41,7 @@
 #include <svx/galmisc.hxx>
 #include <svx/galtheme.hxx>
 #include <svx/gallery1.hxx>
-#include <svx/gallerybinaryengine.hxx>
+#include <svx/gallerybinaryengineentry.hxx>
 #include <galobj.hxx>
 #include <vcl/weld.hxx>
 #include <com/sun/star/sdbc/XResultSet.hpp>
@@ -120,17 +120,14 @@ GalleryThemeEntry::GalleryThemeEntry( bool bCreateUniqueURL,
 
     if (bCreateUniqueURL)
     {
-        GalleryBinaryEngine::CreateUniqueURL(rBaseURL,aURL);
+        GalleryBinaryEngineEntry::CreateUniqueURL(rBaseURL,aURL);
     }
-    mpGalleryBinaryEngine = createGalleryBinaryEngine();
-    mpGalleryBinaryEngine->SetThmExtension(aURL);
-    mpGalleryBinaryEngine->SetSdgExtension(aURL);
-    mpGalleryBinaryEngine->SetSdvExtension(aURL);
-    mpGalleryBinaryEngine->SetStrExtension(aURL);
+    mpGalleryBinaryEngineEntry = createGalleryBinaryEngineEntry();
+    maGalleryStorageLocations.SetStorageLocations(aURL);
 
     SetModified( _bNewFile );
 
-    aName = mpGalleryBinaryEngine->ReadStrFromIni( "name" );
+    aName = mpGalleryBinaryEngineEntry->ReadStrFromIni( "name" );
 
     // This is awful - we shouldn't use these resources if we
     // possibly can avoid them
@@ -164,43 +161,10 @@ GalleryThemeEntry::GalleryThemeEntry( bool bCreateUniqueURL,
         aName = rName;
 }
 
-std::unique_ptr<GalleryBinaryEngine> GalleryThemeEntry::createGalleryBinaryEngine()
+std::unique_ptr<GalleryBinaryEngineEntry> GalleryThemeEntry::createGalleryBinaryEngineEntry()
 {
-    std::unique_ptr<GalleryBinaryEngine> pGalleryBinaryEngine = std::make_unique<GalleryBinaryEngine>();
-    return pGalleryBinaryEngine;
-}
-
-void GalleryThemeEntry::callGalleryThemeInit()
-{
-    getGalleryBinaryEngine()->galleryThemeInit(IsReadOnly());
-}
-
-bool GalleryThemeEntry::readModel(const GalleryObject* pObject, SdrModel& rModel)
-{
-    return mpGalleryBinaryEngine->readModel(pObject, rModel);
-}
-
-bool GalleryThemeEntry::insertModel(const FmFormModel& rModel, INetURLObject& aURL)
-{
-    return mpGalleryBinaryEngine->insertModel(rModel, aURL);
-}
-
-bool GalleryThemeEntry::readModelStream(const GalleryObject* pObject, tools::SvRef<SotStorageStream> const& rxModelStream)
-{
-    return mpGalleryBinaryEngine->readModelStream(pObject, rxModelStream);
-}
-
-SgaObjectSvDraw
-GalleryThemeEntry::insertModelStream(const tools::SvRef<SotStorageStream>& rxModelStream,
-    INetURLObject& rURL)
-{
-    return mpGalleryBinaryEngine->insertModelStream(rxModelStream, rURL);
-}
-
-void GalleryThemeEntry::insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry, OUString& rDestDir,
-    ::std::vector<std::unique_ptr<GalleryObject>>& rObjectList, sal_uInt32& rInsertPos)
-{
-    mpGalleryBinaryEngine->insertObject(rObj, pFoundEntry, rDestDir, rObjectList, rInsertPos);
+    std::unique_ptr<GalleryBinaryEngineEntry> pGalleryBinaryEngineEntry = std::make_unique<GalleryBinaryEngineEntry>(maGalleryStorageLocations);
+    return pGalleryBinaryEngineEntry;
 }
 
 void GalleryTheme::InsertAllThemes(weld::ComboBox& rListBox)
@@ -466,7 +430,7 @@ void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, bool& rbDirIsReadO
                                     }
                                 }
 
-                                GalleryThemeEntry* pEntry = GalleryBinaryEngine::CreateThemeEntry( aThmURL, rbDirIsReadOnly || bReadOnly );
+                                GalleryThemeEntry* pEntry = GalleryBinaryEngineEntry::CreateThemeEntry( aThmURL, rbDirIsReadOnly || bReadOnly );
 
                                 if( pEntry )
                                     aThemeList.emplace_back( pEntry );
@@ -628,7 +592,7 @@ void Gallery::RenameTheme( const OUString& rOldName, const OUString& rNewName )
         {
             pThemeEntry->SetName( rNewName );
             if (pThm->pThm->IsModified())
-                if (!pThm->pThm->getGalleryBinaryEngine()->implWrite(*pThm))
+                if (!pThm->mpGalleryBinaryEngine->implWrite(*pThm))
                     pThm->ImplSetModified(false);
 
             Broadcast( GalleryHint( GalleryHintType::THEME_RENAMED, rOldName, pThm->GetName() ) );
diff --git a/svx/source/gallery2/gallerybinaryengine.cxx b/svx/source/gallery2/gallerybinaryengine.cxx
index 494c385908c7..3078a76eca71 100644
--- a/svx/source/gallery2/gallerybinaryengine.cxx
+++ b/svx/source/gallery2/gallerybinaryengine.cxx
@@ -17,96 +17,119 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include <svx/gallerybinaryengine.hxx>
-#include <svx/galmisc.hxx>
 #include <svx/unomodel.hxx>
 #include <svx/fmmodel.hxx>
-#include <svx/gallery1.hxx>
 #include <galobj.hxx>
+#include <svx/gallerybinaryengine.hxx>
 #include "codec.hxx"
 #include "gallerydrawmodel.hxx"
+#include <vcl/cvtgrf.hxx>
 
 #include <sal/log.hxx>
 
+#include <com/sun/star/ucb/ContentCreationException.hpp>
+#include <tools/urlobj.hxx>
+#include <tools/diagnose_ex.h>
 #include <unotools/ucbstreamhelper.hxx>
 #include <unotools/streamwrap.hxx>
-#include <com/sun/star/ucb/ContentCreationException.hpp>
 #include <tools/urlobj.hxx>
 #include <tools/vcompat.hxx>
-#include <tools/diagnose_ex.h>
 
 using namespace ::com::sun::star;
 
-static bool FileExists(const INetURLObject& rURL, const OUString& rExt)
+GalleryBinaryEngine::GalleryBinaryEngine(const GalleryStorageLocations& rGalleryStorageLocations)
+    : maGalleryStorageLocations(rGalleryStorageLocations)
 {
-    INetURLObject aURL(rURL);
-    aURL.setExtension(rExt);
-    return FileExists(aURL);
 }
 
-void GalleryBinaryEngine::galleryThemeInit(bool bReadOnly)
+void GalleryBinaryEngine::clearSotStorage() { m_aSvDrawStorageRef.clear(); }
+
+void GalleryBinaryEngine::ImplCreateSvDrawStorage(bool bReadOnly)
 {
-    SAL_WARN_IF(aSvDrawStorageRef.is(), "svx", "SotStorage is already initialized");
-    ImplCreateSvDrawStorage(bReadOnly);
+    try
+    {
+        m_aSvDrawStorageRef
+            = new SotStorage(false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
+                             bReadOnly ? StreamMode::READ : StreamMode::STD_READWRITE);
+        // #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
+        if ((m_aSvDrawStorageRef->GetError() != ERRCODE_NONE) && !bReadOnly)
+            m_aSvDrawStorageRef = new SotStorage(
+                false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
+                StreamMode::READ);
+    }
+    catch (const css::ucb::ContentCreationException&)
+    {
+        TOOLS_WARN_EXCEPTION("svx", "failed to open: " << GetSdvURL().GetMainURL(
+                                                              INetURLObject::DecodeMechanism::NONE)
+                                                       << "due to");
+    }
 }
 
-void GalleryBinaryEngine::galleryThemeDestroy() { aSvDrawStorageRef.clear(); }
+const tools::SvRef<SotStorage>& GalleryBinaryEngine::GetSvDrawStorage() const
+{
+    return m_aSvDrawStorageRef;
+}
 
-INetURLObject GalleryBinaryEngine::ImplGetURLIgnoreCase(const INetURLObject& rURL)
+bool GalleryBinaryEngine::implWrite(const GalleryTheme& rTheme)
 {
-    INetURLObject aURL(rURL);
+    INetURLObject aPathURL(GetThmURL());
 
-    // check original file name
-    if (!FileExists(aURL))
+    aPathURL.removeSegment();
+    aPathURL.removeFinalSlash();
+
+    DBG_ASSERT(aPathURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
+
+    if (FileExists(aPathURL) || CreateDir(aPathURL))
     {
-        // check upper case file name
-        aURL.setName(aURL.getName().toAsciiUpperCase());
+#ifdef UNX
+        std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
+            GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
+            StreamMode::WRITE | StreamMode::COPY_ON_SYMLINK | StreamMode::TRUNC));
+#else
+        std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
+            GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
+            StreamMode::WRITE | StreamMode::TRUNC));
+#endif
 
-        if (!FileExists(aURL))
+        if (pOStm)
         {
-            // check lower case file name
-            aURL.setName(aURL.getName().toAsciiLowerCase());
+            WriteGalleryTheme(*pOStm, rTheme);
+            pOStm.reset();
+            return true;
         }
-    }
-
-    return aURL;
-}
 
-void GalleryBinaryEngine::CreateUniqueURL(const INetURLObject& rBaseURL, INetURLObject& aURL)
-{
-    INetURLObject aBaseNoCase(ImplGetURLIgnoreCase(rBaseURL));
-    aURL = aBaseNoCase;
-    static sal_Int32 nIdx = 0;
-    while (FileExists(aURL, "thm"))
-    { // create new URLs
-        nIdx++;
-        aURL = aBaseNoCase;
-        aURL.setName(aURL.getName() + OUString::number(nIdx));
+        return false;
     }
+    return true;
 }
 
-void GalleryBinaryEngine::SetThmExtension(INetURLObject aURL)
+void GalleryBinaryEngine::insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry,
+                                       OUString& rDestDir,
+                                       ::std::vector<std::unique_ptr<GalleryObject>>& rObjectList,
+                                       sal_uInt32& rInsertPos)
 {
-    aURL.setExtension("thm");
-    aThmURL = ImplGetURLIgnoreCase(aURL);
-}
+    if (pFoundEntry)
+    {
+        GalleryObject aNewEntry;
 
-void GalleryBinaryEngine::SetSdgExtension(INetURLObject aURL)
-{
-    aURL.setExtension("sdg");
-    aSdgURL = ImplGetURLIgnoreCase(aURL);
-}
+        // update title of new object if necessary
+        if (rObj.GetTitle().isEmpty())
+        {
+            std::unique_ptr<SgaObject> pOldObj(implReadSgaObject(pFoundEntry));
 
-void GalleryBinaryEngine::SetSdvExtension(INetURLObject aURL)
-{
-    aURL.setExtension("sdv");
-    aSdvURL = ImplGetURLIgnoreCase(aURL);
-}
+            if (pOldObj)
+            {
+                const_cast<SgaObject&>(rObj).SetTitle(pOldObj->GetTitle());
+            }
+        }
+        else if (rObj.GetTitle() == "__<empty>__")
+            const_cast<SgaObject&>(rObj).SetTitle("");
 
-void GalleryBinaryEngine::SetStrExtension(INetURLObject aURL)
-{
-    aURL.setExtension("str");
-    aStrURL = ImplGetURLIgnoreCase(aURL);
+        implWriteSgaObject(rObj, rInsertPos, &aNewEntry, rDestDir, rObjectList);
+        pFoundEntry->nOffset = aNewEntry.nOffset;
+    }
+    else
+        implWriteSgaObject(rObj, rInsertPos, nullptr, rDestDir, rObjectList);
 }
 
 std::unique_ptr<SgaObject> GalleryBinaryEngine::implReadSgaObject(GalleryObject const* pEntry)
@@ -205,65 +228,6 @@ bool GalleryBinaryEngine::implWriteSgaObject(
     return bRet;
 }
 
-bool GalleryBinaryEngine::implWrite(const GalleryTheme& rTheme)
-{
-    INetURLObject aPathURL(GetThmURL());
-
-    aPathURL.removeSegment();
-    aPathURL.removeFinalSlash();
-
-    DBG_ASSERT(aPathURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
-
-    if (FileExists(aPathURL) || CreateDir(aPathURL))
-    {
-#ifdef UNX
-        std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
-            GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
-            StreamMode::WRITE | StreamMode::COPY_ON_SYMLINK | StreamMode::TRUNC));
-#else
-        std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream(
-            GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
-            StreamMode::WRITE | StreamMode::TRUNC));
-#endif
-
-        if (pOStm)
-        {
-            WriteGalleryTheme(*pOStm, rTheme);
-            pOStm.reset();
-            return true;
-        }
-
-        return false;
-    }
-    return true;
-}
-
-void GalleryBinaryEngine::ImplCreateSvDrawStorage(bool bReadOnly)
-{
-    try
-    {
-        aSvDrawStorageRef
-            = new SotStorage(false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
-                             bReadOnly ? StreamMode::READ : StreamMode::STD_READWRITE);
-        // #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
-        if ((aSvDrawStorageRef->GetError() != ERRCODE_NONE) && !bReadOnly)
-            aSvDrawStorageRef = new SotStorage(
-                false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE),
-                StreamMode::READ);
-    }
-    catch (const css::ucb::ContentCreationException&)
-    {
-        TOOLS_WARN_EXCEPTION("svx", "failed to open: " << GetSdvURL().GetMainURL(
-                                                              INetURLObject::DecodeMechanism::NONE)
-                                                       << "due to");
-    }
-}
-
-const tools::SvRef<SotStorage>& GalleryBinaryEngine::GetSvDrawStorage() const
-{
-    return aSvDrawStorageRef;
-}
-
 bool GalleryBinaryEngine::readModel(const GalleryObject* pObject, SdrModel& rModel)
 {
     tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
@@ -285,7 +249,6 @@ bool GalleryBinaryEngine::readModel(const GalleryObject* pObject, SdrModel& rMod
     }
     return bRet;
 }
-
 bool GalleryBinaryEngine::insertModel(const FmFormModel& rModel, INetURLObject& rURL)
 {
     tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage());
@@ -404,105 +367,9 @@ GalleryBinaryEngine::insertModelStream(const tools::SvRef<SotStorageStream>& rxM
     return SgaObjectSvDraw();
 }
 
-void GalleryBinaryEngine::insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry,
-                                       OUString& rDestDir,
-                                       ::std::vector<std::unique_ptr<GalleryObject>>& rObjectList,
-                                       sal_uInt32& rInsertPos)
-{
-    if (pFoundEntry)
-    {
-        GalleryObject aNewEntry;
-
-        // update title of new object if necessary
-        if (rObj.GetTitle().isEmpty())
-        {
-            std::unique_ptr<SgaObject> pOldObj(implReadSgaObject(pFoundEntry));
-
-            if (pOldObj)
-            {
-                const_cast<SgaObject&>(rObj).SetTitle(pOldObj->GetTitle());
-            }
-        }
-        else if (rObj.GetTitle() == "__<empty>__")
-            const_cast<SgaObject&>(rObj).SetTitle("");
-
-        implWriteSgaObject(rObj, rInsertPos, &aNewEntry, rDestDir, rObjectList);
-        pFoundEntry->nOffset = aNewEntry.nOffset;
-    }
-    else
-        implWriteSgaObject(rObj, rInsertPos, nullptr, rDestDir, rObjectList);
-}
-
-GalleryThemeEntry* GalleryBinaryEngine::CreateThemeEntry(const INetURLObject& rURL, bool bReadOnly)
-{
-    DBG_ASSERT(rURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
-
-    GalleryThemeEntry* pRet = nullptr;
-
-    if (FileExists(rURL))
-    {
-        std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
-            rURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
-
-        if (pIStm)
-        {
-            OUString aThemeName;
-            sal_uInt16 nVersion;
-
-            pIStm->ReadUInt16(nVersion);
-
-            if (nVersion <= 0x00ff)
-            {
-                bool bThemeNameFromResource = false;
-                sal_uInt32 nThemeId = 0;
-
-                OString aTmpStr = read_uInt16_lenPrefixed_uInt8s_ToOString(*pIStm);
-                aThemeName = OStringToOUString(aTmpStr, RTL_TEXTENCODING_UTF8);
-
-                // execute a character conversion
-                if (nVersion >= 0x0004)
-                {
-                    sal_uInt32 nCount;
-                    sal_uInt16 nTemp16;
-
-                    pIStm->ReadUInt32(nCount).ReadUInt16(nTemp16);
-                    pIStm->Seek(STREAM_SEEK_TO_END);
-
-                    // check whether there is a newer version;
-                    // therefore jump back by 520Bytes (8 bytes ID + 512Bytes reserve buffer)
-                    // if this is at all possible.
-                    if (pIStm->Tell() >= 520)
-                    {
-                        sal_uInt32 nId1, nId2;
-
-                        pIStm->SeekRel(-520);
-                        pIStm->ReadUInt32(nId1).ReadUInt32(nId2);
-
-                        if (nId1 == COMPAT_FORMAT('G', 'A', 'L', 'R')
-                            && nId2 == COMPAT_FORMAT('E', 'S', 'R', 'V'))
-                        {
-                            VersionCompat aCompat(*pIStm, StreamMode::READ);
-
-                            pIStm->ReadUInt32(nThemeId);
-
-                            if (aCompat.GetVersion() >= 2)
-                            {
-                                pIStm->ReadCharAsBool(bThemeNameFromResource);
-                            }
-                        }
-                    }
-                }
-
-                pRet = new GalleryThemeEntry(false, rURL, aThemeName, bReadOnly, false, nThemeId,
-                                             bThemeNameFromResource);
-            }
-        }
-    }
-
-    return pRet;
-}
-
 SvStream& WriteGalleryTheme(SvStream& rOut, const GalleryTheme& rTheme)
 {
     return rTheme.WriteData(rOut);
 }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/gallerybinaryengineentry.cxx b/svx/source/gallery2/gallerybinaryengineentry.cxx
new file mode 100644
index 000000000000..67f5c556ce51
--- /dev/null
+++ b/svx/source/gallery2/gallerybinaryengineentry.cxx
@@ -0,0 +1,131 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <svx/gallerybinaryengineentry.hxx>
+#include <svx/galmisc.hxx>
+#include <svx/unomodel.hxx>
+#include <svx/fmmodel.hxx>
+#include <svx/gallery1.hxx>
+#include "codec.hxx"
+#include "gallerydrawmodel.hxx"
+
+#include <sal/log.hxx>
+
+#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/streamwrap.hxx>
+#include <tools/urlobj.hxx>
+#include <tools/vcompat.hxx>
+
+static bool FileExists(const INetURLObject& rURL, const OUString& rExt)
+{
+    INetURLObject aURL(rURL);
+    aURL.setExtension(rExt);
+    return FileExists(aURL);
+}
+
+GalleryBinaryEngineEntry::GalleryBinaryEngineEntry(
+    GalleryStorageLocations& rGalleryStorageLocations)
+    : maGalleryStorageLocations(rGalleryStorageLocations)
+{
+}
+
+void GalleryBinaryEngineEntry::CreateUniqueURL(const INetURLObject& rBaseURL, INetURLObject& aURL)
+{
+    INetURLObject aBaseNoCase(GalleryStorageLocations::ImplGetURLIgnoreCase(rBaseURL));
+    aURL = aBaseNoCase;
+    static sal_Int32 nIdx = 0;
+    while (FileExists(aURL, "thm"))
+    { // create new URLs
+        nIdx++;
+        aURL = aBaseNoCase;
+        aURL.setName(aURL.getName() + OUString::number(nIdx));
+    }
+}
+
+GalleryThemeEntry* GalleryBinaryEngineEntry::CreateThemeEntry(const INetURLObject& rURL,
+                                                              bool bReadOnly)
+{
+    DBG_ASSERT(rURL.GetProtocol() != INetProtocol::NotValid, "invalid URL");
+
+    GalleryThemeEntry* pRet = nullptr;
+
+    if (FileExists(rURL))
+    {
+        std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream(
+            rURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ));
+
+        if (pIStm)
+        {
+            OUString aThemeName;
+            sal_uInt16 nVersion;
+
+            pIStm->ReadUInt16(nVersion);
+
+            if (nVersion <= 0x00ff)
+            {
+                bool bThemeNameFromResource = false;
+                sal_uInt32 nThemeId = 0;
+
+                OString aTmpStr = read_uInt16_lenPrefixed_uInt8s_ToOString(*pIStm);
+                aThemeName = OStringToOUString(aTmpStr, RTL_TEXTENCODING_UTF8);
+
+                // execute a character conversion
+                if (nVersion >= 0x0004)
+                {
+                    sal_uInt32 nCount;
+                    sal_uInt16 nTemp16;
+
+                    pIStm->ReadUInt32(nCount).ReadUInt16(nTemp16);
+                    pIStm->Seek(STREAM_SEEK_TO_END);
+
+                    // check whether there is a newer version;
+                    // therefore jump back by 520Bytes (8 bytes ID + 512Bytes reserve buffer)
+                    // if this is at all possible.
+                    if (pIStm->Tell() >= 520)
+                    {
+                        sal_uInt32 nId1, nId2;
+
+                        pIStm->SeekRel(-520);
+                        pIStm->ReadUInt32(nId1).ReadUInt32(nId2);
+
+                        if (nId1 == COMPAT_FORMAT('G', 'A', 'L', 'R')
+                            && nId2 == COMPAT_FORMAT('E', 'S', 'R', 'V'))
+                        {
+                            VersionCompat aCompat(*pIStm, StreamMode::READ);
+
+                            pIStm->ReadUInt32(nThemeId);
+
+                            if (aCompat.GetVersion() >= 2)
+                            {
+                                pIStm->ReadCharAsBool(bThemeNameFromResource);
+                            }
+                        }
+                    }
+                }
+
+                pRet = new GalleryThemeEntry(false, rURL, aThemeName, bReadOnly, false, nThemeId,
+                                             bThemeNameFromResource);
+            }
+        }
+    }
+
+    return pRet;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/gallerystoragelocations.cxx b/svx/source/gallery2/gallerystoragelocations.cxx
new file mode 100644
index 000000000000..cc427c8d16b4
--- /dev/null
+++ b/svx/source/gallery2/gallerystoragelocations.cxx
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <svx/gallerystoragelocations.hxx>
+#include <svx/galmisc.hxx>
+
+INetURLObject GalleryStorageLocations::ImplGetURLIgnoreCase(const INetURLObject& rURL)
+{
+    INetURLObject aURL(rURL);
+
+    // check original file name
+    if (!FileExists(aURL))
+    {
+        // check upper case file name
+        aURL.setName(aURL.getName().toAsciiUpperCase());
+
+        if (!FileExists(aURL))
+        {
+            // check lower case file name
+            aURL.setName(aURL.getName().toAsciiLowerCase());
+        }
+    }
+
+    return aURL;
+}
+
+void GalleryStorageLocations::SetThmExtension(INetURLObject& aURL)
+{
+    aURL.setExtension("thm");
+    maThmURL = ImplGetURLIgnoreCase(aURL);
+}
+
+void GalleryStorageLocations::SetSdgExtension(INetURLObject& aURL)
+{
+    aURL.setExtension("sdg");
+    maSdgURL = ImplGetURLIgnoreCase(aURL);
+}
+
+void GalleryStorageLocations::SetSdvExtension(INetURLObject& aURL)
+{
+    aURL.setExtension("sdv");
+    maSdvURL = ImplGetURLIgnoreCase(aURL);
+}
+
+void GalleryStorageLocations::SetStrExtension(INetURLObject& aURL)
+{
+    aURL.setExtension("str");
+    maStrURL = ImplGetURLIgnoreCase(aURL);
+}
+
+void GalleryStorageLocations::SetStorageLocations(INetURLObject& aURL)
+{
+    SetThmExtension(aURL);
+    SetSdgExtension(aURL);
+    SetSdvExtension(aURL);
+    SetStrExtension(aURL);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx
index 61c6077eb5b6..2d1951d691c3 100644
--- a/svx/source/gallery2/galtheme.cxx
+++ b/svx/source/gallery2/galtheme.cxx
@@ -69,13 +69,14 @@ GalleryTheme::GalleryTheme( Gallery* pGallery, GalleryThemeEntry* pThemeEntry )
     , bDragging(false)
     , bAbortActualize(false)
 {
-    pThm->callGalleryThemeInit();
+    mpGalleryBinaryEngine = createGalleryBinaryEngine();
+    mpGalleryBinaryEngine->ImplCreateSvDrawStorage(IsReadOnly());
 }
 
 GalleryTheme::~GalleryTheme()
 {
     if(pThm->IsModified())
-        if(!pThm->getGalleryBinaryEngine()->implWrite(*this))
+        if(!mpGalleryBinaryEngine->implWrite(*this))
             ImplSetModified(false);
 
     for (auto & pEntry : aObjectList)
@@ -84,7 +85,13 @@ GalleryTheme::~GalleryTheme()
         pEntry.reset();
     }
     aObjectList.clear();
-    pThm->getGalleryBinaryEngine()->galleryThemeDestroy();
+    mpGalleryBinaryEngine->clearSotStorage();
+}
+
+std::unique_ptr<GalleryBinaryEngine> GalleryTheme::createGalleryBinaryEngine()
+{
+    std::unique_ptr<GalleryBinaryEngine> pGalleryBinaryEngine = std::make_unique<GalleryBinaryEngine>(pThm->getGalleryStorageLocations());
+    return pGalleryBinaryEngine;
 }
 
 const GalleryObject* GalleryTheme::ImplGetGalleryObject( const INetURLObject& rURL )
@@ -256,7 +263,7 @@ bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos)
         }
     }
 
-    pThm->insertObject(rObj, pFoundEntry, m_aDestDir, aObjectList, nInsertPos);
+    mpGalleryBinaryEngine->insertObject(rObj, pFoundEntry, m_aDestDir, aObjectList, nInsertPos);
 
     ImplSetModified(true);
     ImplBroadcast(pFoundEntry? iFoundPos: nInsertPos);
@@ -266,7 +273,7 @@ bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos)
 
 std::unique_ptr<SgaObject> GalleryTheme::AcquireObject(sal_uInt32 nPos)
 {
-    return pThm->getGalleryBinaryEngine()->implReadSgaObject(ImplGetGalleryObject(nPos));
+    return mpGalleryBinaryEngine->implReadSgaObject(ImplGetGalleryObject(nPos));
 }
 
 void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx& rBitmapEx, Size& rSize, OUString& rTitle, OUString& rPath) const
@@ -299,7 +306,7 @@ void GalleryTheme::RemoveObject(sal_uInt32 nPos)
         KillFile( GetSdgURL() );
 
     if( SgaObjKind::SvDraw == pEntry->eObjKind )
-        pThm->getGalleryBinaryEngine()->GetSvDrawStorage()->Remove( pEntry->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
+        mpGalleryBinaryEngine->GetSvDrawStorage()->Remove( pEntry->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
 
     Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry.get() ) );
     pEntry.reset();
@@ -392,10 +399,10 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
         }
         else
         {
-            if ( pThm->getGalleryBinaryEngine()->GetSvDrawStorage().is() )
+            if ( mpGalleryBinaryEngine->GetSvDrawStorage().is() )
             {
                 const OUString        aStmName( GetSvDrawStreamNameFromURL( pEntry->aURL ) );
-                tools::SvRef<SotStorageStream>  pIStm = pThm->getGalleryBinaryEngine()->GetSvDrawStorage()->OpenSotStream( aStmName, StreamMode::READ );
+                tools::SvRef<SotStorageStream>  pIStm = mpGalleryBinaryEngine->GetSvDrawStorage()->OpenSotStream( aStmName, StreamMode::READ );
 
                 if( pIStm.is() && !pIStm->GetError() )
                 {
@@ -479,8 +486,8 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
     try
     {
         tools::SvRef<SotStorage> aTempStorageRef( new SotStorage( false, aTmpURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::STD_READWRITE ) );
-        pThm->getGalleryBinaryEngine()->GetSvDrawStorage()->CopyTo( aTempStorageRef.get() );
-        nStorErr = pThm->getGalleryBinaryEngine()->GetSvDrawStorage()->GetError();
+        mpGalleryBinaryEngine->GetSvDrawStorage()->CopyTo( aTempStorageRef.get() );
+        nStorErr = mpGalleryBinaryEngine->GetSvDrawStorage()->GetError();
     }
     catch (const css::ucb::ContentCreationException&)
     {
@@ -492,16 +499,15 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
 
     if( nStorErr == ERRCODE_NONE )
     {
-        auto aSvDrawStorage = pThm->getGalleryBinaryEngine()->GetSvDrawStorage();
-        aSvDrawStorage.clear();
+        mpGalleryBinaryEngine->clearSotStorage();
         CopyFile( aTmpURL, GetSdvURL() );
-        pThm->callGalleryThemeInit();
+        mpGalleryBinaryEngine->ImplCreateSvDrawStorage(IsReadOnly());
     }
 
     KillFile( aTmpURL );
     ImplSetModified( true );
     if (pThm->IsModified())
-        if (!pThm->getGalleryBinaryEngine()->implWrite(*this))
+        if (!mpGalleryBinaryEngine->implWrite(*this))
             ImplSetModified(false);
     UnlockBroadcaster();
 }
@@ -681,7 +687,7 @@ bool GalleryTheme::GetModel(sal_uInt32 nPos, SdrModel& rModel)
 
     if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
     {
-        bRet = pThm->readModel(pObject, rModel);
+        bRet = mpGalleryBinaryEngine->readModel(pObject, rModel);
     }
 
     return bRet;
@@ -692,7 +698,7 @@ bool GalleryTheme::InsertModel(const FmFormModel& rModel, sal_uInt32 nInsertPos)
     INetURLObject   aURL( implCreateUniqueURL( SgaObjKind::SvDraw ) );
     bool bRet = false;
 
-    if(pThm->insertModel(rModel, aURL))
+    if(mpGalleryBinaryEngine->insertModel(rModel, aURL))
     {
         SgaObjectSvDraw aObjSvDraw(rModel, aURL);
         bRet = InsertObject( aObjSvDraw, nInsertPos );
@@ -707,7 +713,7 @@ bool GalleryTheme::GetModelStream(sal_uInt32 nPos, tools::SvRef<SotStorageStream
 
     if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
     {
-        bRet = pThm->readModelStream(pObject, rxModelStream);
+        bRet = mpGalleryBinaryEngine->readModelStream(pObject, rxModelStream);
     }
 
     return bRet;
@@ -718,7 +724,7 @@ bool GalleryTheme::InsertModelStream(const tools::SvRef<SotStorageStream>& rxMod
     INetURLObject   aURL( implCreateUniqueURL( SgaObjKind::SvDraw ) );
     bool            bRet = false;
 
-    const SgaObjectSvDraw aObjSvDraw = pThm->insertModelStream(rxModelStream, aURL);
+    const SgaObjectSvDraw aObjSvDraw = mpGalleryBinaryEngine->insertModelStream(rxModelStream, aURL);
     if(aObjSvDraw.IsValid())
         bRet = InsertObject( aObjSvDraw, nInsertPos );
 
diff --git a/svx/source/unogallery/unogalitem.cxx b/svx/source/unogallery/unogalitem.cxx
index b94ec657561f..48fb9e0da18c 100644
--- a/svx/source/unogallery/unogalitem.cxx
+++ b/svx/source/unogallery/unogalitem.cxx
@@ -220,7 +220,7 @@ void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry** ppEnt
 
             if( pGalTheme )
             {
-                std::unique_ptr<SgaObject> pObj(pGalTheme->pThm->getGalleryBinaryEngine()->implReadSgaObject( implGetObject() ));
+                std::unique_ptr<SgaObject> pObj(pGalTheme->getGalleryBinaryEngine()->implReadSgaObject( implGetObject() ));
 
                 if( pObj )
                 {


More information about the Libreoffice-commits mailing list