summaryrefslogtreecommitdiff
path: root/svx/source/gallery2
diff options
context:
space:
mode:
authorAditya <adityasahu1511@gmail.com>2020-07-17 13:55:11 +0530
committerTomaž Vajngerl <quikee@gmail.com>2020-07-23 22:07:32 +0200
commit2157185ce15d99f7a234abe46c50f3c6f83a2651 (patch)
treea9104b7c70a073f133727815d9fbb02fce11ef28 /svx/source/gallery2
parent09a3b52f883783a2047d77b058d085a3b14e4c9b (diff)
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@gmail.com>
Diffstat (limited to 'svx/source/gallery2')
-rw-r--r--svx/source/gallery2/galini.cxx6
-rw-r--r--svx/source/gallery2/gallery1.cxx56
-rw-r--r--svx/source/gallery2/gallerybinaryengine.cxx291
-rw-r--r--svx/source/gallery2/gallerybinaryengineentry.cxx131
-rw-r--r--svx/source/gallery2/gallerystoragelocations.cxx75
-rw-r--r--svx/source/gallery2/galtheme.cxx42
6 files changed, 322 insertions, 279 deletions
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 );