summaryrefslogtreecommitdiff
path: root/svx/source/gallery2
diff options
context:
space:
mode:
authorAditya <adityasahu1511@gmail.com>2020-06-29 15:39:19 +0530
committerTomaž Vajngerl <quikee@gmail.com>2020-07-10 09:07:40 +0200
commitdd4c68b02578618d861a2df687823eaaa8ab35f8 (patch)
tree73633d84d5b596ea1eb0fca818d9842d24e6367a /svx/source/gallery2
parentf2cb874d6de86dfffe13fe6f051b1ea84d8e628a (diff)
svx:Refactoring of GalleryTheme members to GalleryBinaryEngine
Moving of aSvDrawStorageRef into the binary engine and consequent changes Change-Id: I7262c77ec8730fbbe516f9fb205c25c4e1f15ff5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96764 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx/source/gallery2')
-rw-r--r--svx/source/gallery2/gallery1.cxx5
-rw-r--r--svx/source/gallery2/gallerybinaryengine.cxx38
-rw-r--r--svx/source/gallery2/galtheme.cxx49
3 files changed, 57 insertions, 35 deletions
diff --git a/svx/source/gallery2/gallery1.cxx b/svx/source/gallery2/gallery1.cxx
index 7f0c524fda65..73b623a1ce1f 100644
--- a/svx/source/gallery2/gallery1.cxx
+++ b/svx/source/gallery2/gallery1.cxx
@@ -169,6 +169,11 @@ std::unique_ptr<GalleryBinaryEngine> GalleryThemeEntry::createGalleryBinaryEngin
return pGalleryBinaryEngine;
}
+void GalleryThemeEntry::callGalleryThemeInit()
+{
+ getGalleryBinaryEngine()->galleryThemeInit(IsReadOnly());
+}
+
void GalleryTheme::InsertAllThemes(weld::ComboBox& rListBox)
{
for (size_t i = 0; i < SAL_N_ELEMENTS(aUnlocalized); ++i)
diff --git a/svx/source/gallery2/gallerybinaryengine.cxx b/svx/source/gallery2/gallerybinaryengine.cxx
index f72247ba038b..57ebc07feff8 100644
--- a/svx/source/gallery2/gallerybinaryengine.cxx
+++ b/svx/source/gallery2/gallerybinaryengine.cxx
@@ -22,9 +22,13 @@
#include <vcl/salctype.hxx>
#include <galobj.hxx>
+#include <sal/log.hxx>
+
#include <unotools/ucbstreamhelper.hxx>
+#include <com/sun/star/ucb/ContentCreationException.hpp>
#include <tools/urlobj.hxx>
#include <tools/vcompat.hxx>
+#include <tools/diagnose_ex.h>
static bool FileExists(const INetURLObject& rURL, const OUString& rExt)
{
@@ -33,6 +37,14 @@ static bool FileExists(const INetURLObject& rURL, const OUString& rExt)
return FileExists(aURL);
}
+void GalleryBinaryEngine::galleryThemeInit(bool bReadOnly)
+{
+ SAL_WARN_IF(aSvDrawStorageRef.is(), "svx", "SotStorage is already initialized");
+ ImplCreateSvDrawStorage(bReadOnly);
+}
+
+void GalleryBinaryEngine::galleryThemeDestroy() { aSvDrawStorageRef.clear(); }
+
INetURLObject GalleryBinaryEngine::ImplGetURLIgnoreCase(const INetURLObject& rURL)
{
INetURLObject aURL(rURL);
@@ -333,6 +345,32 @@ GalleryBinaryEngine::implCreateUniqueURL(SgaObjKind eObjKind, const INetURLObjec
return aNewURL;
}
+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;
+}
+
SvStream& WriteGalleryTheme(SvStream& rOut, const GalleryTheme& rTheme)
{
return rTheme.WriteData(rOut);
diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx
index ec52c09b56e5..d53d59d424b0 100644
--- a/svx/source/gallery2/galtheme.cxx
+++ b/svx/source/gallery2/galtheme.cxx
@@ -70,7 +70,7 @@ GalleryTheme::GalleryTheme( Gallery* pGallery, GalleryThemeEntry* pThemeEntry )
, bDragging(false)
, bAbortActualize(false)
{
- ImplCreateSvDrawStorage();
+ pThm->callGalleryThemeInit();
}
GalleryTheme::~GalleryTheme()
@@ -85,24 +85,7 @@ GalleryTheme::~GalleryTheme()
pEntry.reset();
}
aObjectList.clear();
-
-}
-
-void GalleryTheme::ImplCreateSvDrawStorage()
-{
- try
- {
- aSvDrawStorageRef = new SotStorage( false, GetSdvURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ), pThm->IsReadOnly() ? 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 ) && !pThm->IsReadOnly() )
- 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");
- }
+ pThm->getGalleryBinaryEngine()->galleryThemeDestroy();
}
const GalleryObject* GalleryTheme::ImplGetGalleryObject( const INetURLObject& rURL )
@@ -237,7 +220,7 @@ void GalleryTheme::RemoveObject(sal_uInt32 nPos)
KillFile( GetSdgURL() );
if( SgaObjKind::SvDraw == pEntry->eObjKind )
- aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
+ pThm->getGalleryBinaryEngine()->GetSvDrawStorage()->Remove( pEntry->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry.get() ) );
pEntry.reset();
@@ -330,10 +313,10 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
}
else
{
- if ( aSvDrawStorageRef.is() )
+ if ( pThm->getGalleryBinaryEngine()->GetSvDrawStorage().is() )
{
const OUString aStmName( GetSvDrawStreamNameFromURL( pEntry->aURL ) );
- tools::SvRef<SotStorageStream> pIStm = aSvDrawStorageRef->OpenSotStream( aStmName, StreamMode::READ );
+ tools::SvRef<SotStorageStream> pIStm = pThm->getGalleryBinaryEngine()->GetSvDrawStorage()->OpenSotStream( aStmName, StreamMode::READ );
if( pIStm.is() && !pIStm->GetError() )
{
@@ -417,8 +400,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 ) );
- aSvDrawStorageRef->CopyTo( aTempStorageRef.get() );
- nStorErr = aSvDrawStorageRef->GetError();
+ pThm->getGalleryBinaryEngine()->GetSvDrawStorage()->CopyTo( aTempStorageRef.get() );
+ nStorErr = pThm->getGalleryBinaryEngine()->GetSvDrawStorage()->GetError();
}
catch (const css::ucb::ContentCreationException&)
{
@@ -430,9 +413,10 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize
if( nStorErr == ERRCODE_NONE )
{
- aSvDrawStorageRef.clear();
+ auto aSvDrawStorage = pThm->getGalleryBinaryEngine()->GetSvDrawStorage();
+ aSvDrawStorage.clear();
CopyFile( aTmpURL, GetSdvURL() );
- ImplCreateSvDrawStorage();
+ pThm->callGalleryThemeInit();
}
KillFile( aTmpURL );
@@ -688,7 +672,7 @@ bool GalleryTheme::GetModel(sal_uInt32 nPos, SdrModel& rModel)
if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
{
const INetURLObject aURL( ImplGetURL( pObject ) );
- tools::SvRef<SotStorage> xStor( GetSvDrawStorage() );
+ tools::SvRef<SotStorage> xStor( pThm->getGalleryBinaryEngine()->GetSvDrawStorage() );
if( xStor.is() )
{
@@ -710,7 +694,7 @@ bool GalleryTheme::GetModel(sal_uInt32 nPos, SdrModel& rModel)
bool GalleryTheme::InsertModel(const FmFormModel& rModel, sal_uInt32 nInsertPos)
{
INetURLObject aURL( GalleryBinaryEngine::implCreateUniqueURL( SgaObjKind::SvDraw, GetParent()->GetUserURL(), aObjectList) );
- tools::SvRef<SotStorage> xStor( GetSvDrawStorage() );
+ tools::SvRef<SotStorage> xStor(pThm->getGalleryBinaryEngine()->GetSvDrawStorage() );
bool bRet = false;
if( xStor.is() )
@@ -760,7 +744,7 @@ bool GalleryTheme::GetModelStream(sal_uInt32 nPos, tools::SvRef<SotStorageStream
if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
{
const INetURLObject aURL( ImplGetURL( pObject ) );
- tools::SvRef<SotStorage> xStor( GetSvDrawStorage() );
+ tools::SvRef<SotStorage> xStor( pThm->getGalleryBinaryEngine()->GetSvDrawStorage() );
if( xStor.is() )
{
@@ -806,7 +790,7 @@ bool GalleryTheme::GetModelStream(sal_uInt32 nPos, tools::SvRef<SotStorageStream
bool GalleryTheme::InsertModelStream(const tools::SvRef<SotStorageStream>& rxModelStream, sal_uInt32 nInsertPos)
{
INetURLObject aURL( GalleryBinaryEngine::implCreateUniqueURL( SgaObjKind::SvDraw, GetParent()->GetUserURL(), aObjectList ) );
- tools::SvRef<SotStorage> xStor( GetSvDrawStorage() );
+ tools::SvRef<SotStorage> xStor( pThm->getGalleryBinaryEngine()->GetSvDrawStorage() );
bool bRet = false;
if( xStor.is() )
@@ -1255,11 +1239,6 @@ void GalleryTheme::SetId( sal_uInt32 nNewId, bool bResetThemeName ) { pThm->SetI
bool GalleryTheme::IsReadOnly() const { return pThm->IsReadOnly(); }
bool GalleryTheme::IsDefault() const { return pThm->IsDefault(); }
-const tools::SvRef<SotStorage>& GalleryTheme::GetSvDrawStorage() const
-{
- return aSvDrawStorageRef;
-}
-
const OUString& GalleryTheme::GetName() const { return pThm->GetThemeName(); }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */