diff options
author | Aditya <adityasahu1511@gmail.com> | 2020-06-17 16:43:49 +0530 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-06-17 15:36:06 +0200 |
commit | f9383f75af46efbb319110921158dcd6b5e91913 (patch) | |
tree | c0463b347bf157df7cee36ddcef05c5220507606 /svx/source/gallery2 | |
parent | 27381dc1b76e4aee5459b3d85e6fc5919d2b8f98 (diff) |
svx: Refactor GalleryTheme class
Change-Id: I60ce3b5a9ca5a28e499015c3ac118d2f6a091f16
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96527
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx/source/gallery2')
-rw-r--r-- | svx/source/gallery2/gallery1.cxx | 18 | ||||
-rw-r--r-- | svx/source/gallery2/gallerybinaryengine.cxx | 43 | ||||
-rw-r--r-- | svx/source/gallery2/galtheme.cxx | 42 |
3 files changed, 57 insertions, 46 deletions
diff --git a/svx/source/gallery2/gallery1.cxx b/svx/source/gallery2/gallery1.cxx index a7c86c3ef9a3..3bd04dbeb527 100644 --- a/svx/source/gallery2/gallery1.cxx +++ b/svx/source/gallery2/gallery1.cxx @@ -121,15 +121,15 @@ GalleryThemeEntry::GalleryThemeEntry( bool bCreateUniqueURL, { GalleryBinaryEngine::CreateUniqueURL(rBaseURL,aURL); } - - maGalleryBinaryEngine.SetThmExtension(aURL); - maGalleryBinaryEngine.SetSdgExtension(aURL); - maGalleryBinaryEngine.SetSdvExtension(aURL); - maGalleryBinaryEngine.SetStrExtension(aURL); + mpGalleryBinaryEngine = createGalleryBinaryEngine(); + mpGalleryBinaryEngine->SetThmExtension(aURL); + mpGalleryBinaryEngine->SetSdgExtension(aURL); + mpGalleryBinaryEngine->SetSdvExtension(aURL); + mpGalleryBinaryEngine->SetStrExtension(aURL); SetModified( _bNewFile ); - aName = maGalleryBinaryEngine.ReadStrFromIni( "name" ); + aName = mpGalleryBinaryEngine->ReadStrFromIni( "name" ); // This is awful - we shouldn't use these resources if we // possibly can avoid them @@ -163,6 +163,12 @@ GalleryThemeEntry::GalleryThemeEntry( bool bCreateUniqueURL, aName = rName; } +std::unique_ptr<GalleryBinaryEngine> GalleryThemeEntry::createGalleryBinaryEngine() +{ + std::unique_ptr<GalleryBinaryEngine> pGalleryBinaryEngine = std::make_unique<GalleryBinaryEngine>(); + return pGalleryBinaryEngine; +} + 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 0e08359909c2..c5d2f018e1d4 100644 --- a/svx/source/gallery2/gallerybinaryengine.cxx +++ b/svx/source/gallery2/gallerybinaryengine.cxx @@ -19,7 +19,9 @@ #include <svx/gallerybinaryengine.hxx> #include <svx/galmisc.hxx> +#include <galobj.hxx> +#include <unotools/ucbstreamhelper.hxx> #include <tools/urlobj.hxx> static bool FileExists(const INetURLObject& rURL, const OUString& rExt) @@ -85,3 +87,44 @@ void GalleryBinaryEngine::SetStrExtension(INetURLObject aURL) aURL.setExtension("str"); aStrURL = ImplGetURLIgnoreCase(aURL); } + +bool GalleryBinaryEngine::ImplWriteSgaObject( + const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry, OUString& aDestDir, + ::std::vector<std::unique_ptr<GalleryObject>>& aObjectList) +{ + std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( + GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE)); + bool bRet = false; + + if (pOStm) + { + const sal_uInt32 nOffset = pOStm->Seek(STREAM_SEEK_TO_END); + + rObj.WriteData(*pOStm, aDestDir); + + if (!pOStm->GetError()) + { + GalleryObject* pEntry; + + if (!pExistentEntry) + { + pEntry = new GalleryObject; + if (nPos < aObjectList.size()) + { + aObjectList.emplace(aObjectList.begin() + nPos, pEntry); + } + else + aObjectList.emplace_back(pEntry); + } + else + pEntry = pExistentEntry; + + pEntry->aURL = rObj.GetURL(); + pEntry->nOffset = nOffset; + pEntry->eObjKind = rObj.GetObjKind(); + bRet = true; + } + } + + return bRet; +} diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx index a5b60f572817..e849542e4ef2 100644 --- a/svx/source/gallery2/galtheme.cxx +++ b/svx/source/gallery2/galtheme.cxx @@ -103,44 +103,6 @@ void GalleryTheme::ImplCreateSvDrawStorage() } } -bool GalleryTheme::ImplWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry) -{ - std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE )); - bool bRet = false; - - if( pOStm ) - { - const sal_uInt32 nOffset = pOStm->Seek( STREAM_SEEK_TO_END ); - - rObj.WriteData( *pOStm, m_aDestDir ); - - if( !pOStm->GetError() ) - { - GalleryObject* pEntry; - - if( !pExistentEntry ) - { - pEntry = new GalleryObject; - if ( nPos < aObjectList.size() ) - { - aObjectList.emplace( aObjectList.begin() + nPos, pEntry ); - } - else - aObjectList.emplace_back( pEntry ); - } - else - pEntry = pExistentEntry; - - pEntry->aURL = rObj.GetURL(); - pEntry->nOffset = nOffset; - pEntry->eObjKind = rObj.GetObjKind(); - bRet = true; - } - } - - return bRet; -} - std::unique_ptr<SgaObject> GalleryTheme::ImplReadSgaObject( GalleryObject const * pEntry ) { std::unique_ptr<SgaObject> pSgaObj; @@ -390,11 +352,11 @@ bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos) else if (rObj.GetTitle() == "__<empty>__") const_cast<SgaObject&>(rObj).SetTitle(""); - ImplWriteSgaObject(rObj, nInsertPos, &aNewEntry); + pThm->getGalleryBinaryEngine()->ImplWriteSgaObject(rObj, nInsertPos, &aNewEntry, m_aDestDir, aObjectList); pFoundEntry->nOffset = aNewEntry.nOffset; } else - ImplWriteSgaObject(rObj, nInsertPos, nullptr); + pThm->getGalleryBinaryEngine()->ImplWriteSgaObject(rObj, nInsertPos, nullptr, m_aDestDir, aObjectList); ImplSetModified(true); ImplBroadcast(pFoundEntry? iFoundPos: nInsertPos); |