include/svx/gallerybinaryengine.hxx | 18 ++- include/svx/galtheme.hxx | 7 - svx/source/gallery2/gallery1.cxx | 2 svx/source/gallery2/gallerybinaryengine.cxx | 129 ++++++++++++++++++++++++++-- svx/source/gallery2/galtheme.cxx | 102 +--------------------- 5 files changed, 142 insertions(+), 116 deletions(-)
New commits: commit 9a7ab3527adef056291ec56c031ebbe3f471af66 Author: Aditya <adityasahu1...@gmail.com> AuthorDate: Sat Aug 1 18:58:06 2020 +0530 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Aug 31 20:10:01 2020 +0200 svx:Refactor WriteData() and move m_aDestDir member out of GalleryTheme Move m_aDestDir out of GalleryTheme because only GalleryBinaryEngine seems to be using it. Use SetDestDir() to delegate the member value to GalleryBinaryEngine. Refactor WriteData() so that it's called writeGalleryTheme() Change-Id: I5f6b6f0857695adeb102342e617ad341553abd14 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99940 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/svx/gallerybinaryengine.hxx b/include/svx/gallerybinaryengine.hxx index cf56b98c8c47..eb9e0b291de1 100644 --- a/include/svx/gallerybinaryengine.hxx +++ b/include/svx/gallerybinaryengine.hxx @@ -38,6 +38,7 @@ class SotStorage; struct GalleryObject; class FmFormModel; class GalleryTheme; +class GalleryThemeEntry; class SVXCORE_DLLPUBLIC GalleryBinaryEngine { @@ -46,6 +47,8 @@ private: const GalleryStorageLocations& maGalleryStorageLocations; GalleryObjectCollection& mrGalleryObjectCollection; bool mbReadOnly; + OUString m_aDestDir; + bool m_bDestDirRelative; public: GalleryBinaryEngine(const GalleryStorageLocations& rGalleryStorageLocations, @@ -54,6 +57,8 @@ public: void clearSotStorage(); + void setDestDir(const OUString& rDestDir, bool bRelative); + SAL_DLLPRIVATE void ImplCreateSvDrawStorage(); SAL_DLLPRIVATE const tools::SvRef<SotStorage>& GetSvDrawStorage() const; @@ -62,14 +67,12 @@ public: const INetURLObject& GetSdvURL() const { return maGalleryStorageLocations.GetSdvURL(); } const INetURLObject& GetStrURL() const { return maGalleryStorageLocations.GetStrURL(); } - SAL_DLLPRIVATE bool implWrite(const GalleryTheme& rTheme); + SAL_DLLPRIVATE bool implWrite(const GalleryTheme& rTheme, const GalleryThemeEntry* pThm); - void insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry, OUString& rDestDir, - sal_uInt32& rInsertPos); + void insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry, sal_uInt32& rInsertPos); std::unique_ptr<SgaObject> implReadSgaObject(GalleryObject const* pEntry); - bool implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry, - OUString& aDestDir); + bool implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry); bool readModel(const GalleryObject* pObject, SdrModel& rModel); SgaObjectSvDraw insertModel(const FmFormModel& rModel, const INetURLObject& rUserURL); @@ -90,8 +93,9 @@ public: void updateTheme(); static void insertFileOrDirURL(const INetURLObject& rFileOrDirURL, std::vector<INetURLObject>& rURLVector); -}; -SvStream& WriteGalleryTheme(SvStream& rOut, const GalleryTheme& rTheme); + SvStream& writeGalleryTheme(SvStream& rOStm, const GalleryTheme& rTheme, + const GalleryThemeEntry* pThm); +}; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/svx/galtheme.hxx b/include/svx/galtheme.hxx index 4c3748c7b145..97da3322044f 100644 --- a/include/svx/galtheme.hxx +++ b/include/svx/galtheme.hxx @@ -22,7 +22,6 @@ #include <svx/svxdllapi.h> #include <svx/galleryobjectcollection.hxx> -#include <svx/gallerybinaryengine.hxx> #include <tools/debug.hxx> #include <tools/urlobj.hxx> @@ -76,8 +75,6 @@ private: std::unique_ptr<GalleryBinaryEngine> mpGalleryBinaryEngine; GalleryObjectCollection maGalleryObjectCollection; - OUString m_aDestDir; - bool m_bDestDirRelative; Gallery* pParent; GalleryThemeEntry* pThm; sal_uInt32 mnThemeLockCount; @@ -112,8 +109,7 @@ public: const OUString& GetName() const; // used for building gallery themes during compilation: - SAL_DLLPRIVATE void SetDestDir(const OUString& rDestDir, bool bRelative) - { m_aDestDir = rDestDir; m_bDestDirRelative = bRelative; } + void SetDestDir(const OUString& rDestDir, bool bRelative); SAL_DLLPRIVATE const INetURLObject& GetThmURL() const; const INetURLObject& GetSdgURL() const; @@ -180,7 +176,6 @@ public: public: - SAL_DLLPRIVATE SvStream& WriteData( SvStream& rOut ) const; SAL_DLLPRIVATE SvStream& ReadData( SvStream& rIn ); static void InsertAllThemes(weld::ComboBox& rListBox); diff --git a/svx/source/gallery2/gallery1.cxx b/svx/source/gallery2/gallery1.cxx index a7dc2bd4823f..600b8cc01c95 100644 --- a/svx/source/gallery2/gallery1.cxx +++ b/svx/source/gallery2/gallery1.cxx @@ -593,7 +593,7 @@ void Gallery::RenameTheme( const OUString& rOldName, const OUString& rNewName ) { pThemeEntry->SetName( rNewName ); if (pThm->pThm->IsModified()) - if (!pThm->mpGalleryBinaryEngine->implWrite(*pThm)) + if (!pThm->mpGalleryBinaryEngine->implWrite(*pThm, pThm->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 987a0ffb22e7..6831608d9506 100644 --- a/svx/source/gallery2/gallerybinaryengine.cxx +++ b/svx/source/gallery2/gallerybinaryengine.cxx @@ -22,6 +22,8 @@ #include <galobj.hxx> #include <svx/gallerybinaryengine.hxx> #include <svx/galleryobjectcollection.hxx> +#include <svx/gallery1.hxx> +#include <osl/thread.hxx> #include "codec.hxx" #include "gallerydrawmodel.hxx" #include <vcl/cvtgrf.hxx> @@ -51,12 +53,19 @@ GalleryBinaryEngine::GalleryBinaryEngine(const GalleryStorageLocations& rGallery : maGalleryStorageLocations(rGalleryStorageLocations) , mrGalleryObjectCollection(rGalleryObjectCollection) , mbReadOnly(bReadOnly) + , m_bDestDirRelative(false) { ImplCreateSvDrawStorage(); } GalleryBinaryEngine::~GalleryBinaryEngine() { clearSotStorage(); } +void GalleryBinaryEngine::setDestDir(const OUString& rDestDir, bool bRelative) +{ + m_aDestDir = rDestDir; + m_bDestDirRelative = bRelative; +} + void GalleryBinaryEngine::clearSotStorage() { m_aSvDrawStorageRef.clear(); } void GalleryBinaryEngine::ImplCreateSvDrawStorage() @@ -85,7 +94,7 @@ const tools::SvRef<SotStorage>& GalleryBinaryEngine::GetSvDrawStorage() const return m_aSvDrawStorageRef; } -bool GalleryBinaryEngine::implWrite(const GalleryTheme& rTheme) +bool GalleryBinaryEngine::implWrite(const GalleryTheme& rTheme, const GalleryThemeEntry* pThm) { INetURLObject aPathURL(GetThmURL()); @@ -108,7 +117,7 @@ bool GalleryBinaryEngine::implWrite(const GalleryTheme& rTheme) if (pOStm) { - WriteGalleryTheme(*pOStm, rTheme); + writeGalleryTheme(*pOStm, rTheme, pThm); pOStm.reset(); return true; } @@ -119,7 +128,7 @@ bool GalleryBinaryEngine::implWrite(const GalleryTheme& rTheme) } void GalleryBinaryEngine::insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry, - OUString& rDestDir, sal_uInt32& rInsertPos) + sal_uInt32& rInsertPos) { if (pFoundEntry) { @@ -138,11 +147,11 @@ void GalleryBinaryEngine::insertObject(const SgaObject& rObj, GalleryObject* pFo else if (rObj.GetTitle() == "__<empty>__") const_cast<SgaObject&>(rObj).SetTitle(""); - implWriteSgaObject(rObj, rInsertPos, &aNewEntry, rDestDir); + implWriteSgaObject(rObj, rInsertPos, &aNewEntry); pFoundEntry->nOffset = aNewEntry.nOffset; } else - implWriteSgaObject(rObj, rInsertPos, nullptr, rDestDir); + implWriteSgaObject(rObj, rInsertPos, nullptr); } std::unique_ptr<SgaObject> GalleryBinaryEngine::implReadSgaObject(GalleryObject const* pEntry) @@ -201,7 +210,7 @@ std::unique_ptr<SgaObject> GalleryBinaryEngine::implReadSgaObject(GalleryObject } bool GalleryBinaryEngine::implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, - GalleryObject* pExistentEntry, OUString& aDestDir) + GalleryObject* pExistentEntry) { std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE)); @@ -211,7 +220,7 @@ bool GalleryBinaryEngine::implWriteSgaObject(const SgaObject& rObj, sal_uInt32 n { const sal_uInt32 nOffset = pOStm->Seek(STREAM_SEEK_TO_END); - rObj.WriteData(*pOStm, aDestDir); + rObj.WriteData(*pOStm, m_aDestDir); if (!pOStm->GetError()) { @@ -262,6 +271,7 @@ bool GalleryBinaryEngine::readModel(const GalleryObject* pObject, SdrModel& rMod } return bRet; } + SgaObjectSvDraw GalleryBinaryEngine::insertModel(const FmFormModel& rModel, const INetURLObject& rUserURL) { @@ -659,9 +669,110 @@ void GalleryBinaryEngine::insertFileOrDirURL(const INetURLObject& rFileOrDirURL, } } -SvStream& WriteGalleryTheme(SvStream& rOut, const GalleryTheme& rTheme) +SvStream& GalleryBinaryEngine::writeGalleryTheme(SvStream& rOStm, const GalleryTheme& rTheme, + const GalleryThemeEntry* pThm) { - return rTheme.WriteData(rOut); + const INetURLObject rRelURL1 = rTheme.GetParent()->GetRelativeURL(); + const INetURLObject rRelURL2 = rTheme.GetParent()->GetUserURL(); + const sal_uInt32 rId = rTheme.GetId(); + sal_uInt32 nCount = mrGalleryObjectCollection.size(); + bool bRel; + + rOStm.WriteUInt16(0x0004); + write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, pThm->GetThemeName(), + RTL_TEXTENCODING_UTF8); + rOStm.WriteUInt32(nCount).WriteUInt16(osl_getThreadTextEncoding()); + + for (sal_uInt32 i = 0; i < nCount; i++) + { + const GalleryObject* pObj = mrGalleryObjectCollection.getForPosition(i); + OUString aPath; + + if (SgaObjKind::SvDraw == pObj->eObjKind) + { + aPath = GetSvDrawStreamNameFromURL(pObj->aURL); + bRel = false; + } + else + { + aPath = pObj->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); + aPath = aPath.copy( + 0, std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(), + aPath.getLength())); + bRel = aPath == rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE); + + if (bRel + && (pObj->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + > (rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + 1))) + { + aPath = pObj->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); + aPath = aPath.copy( + std::min(rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(), + aPath.getLength())); + } + else + { + aPath = pObj->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); + aPath = aPath.copy( + 0, + std::min(rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(), + aPath.getLength())); + bRel = aPath == rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE); + + if (bRel + && (pObj->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + > (rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + + 1))) + { + aPath = pObj->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); + aPath = aPath.copy(std::min( + rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(), + aPath.getLength())); + } + else + aPath = pObj->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); + } + } + + if (!m_aDestDir.isEmpty()) + { + bool aFound = aPath.indexOf(m_aDestDir) != -1; + aPath = aPath.replaceFirst(m_aDestDir, ""); + if (aFound) + bRel = m_bDestDirRelative; + else + SAL_WARN("svx", "failed to replace destdir of '" << m_aDestDir << "' in '" << aPath + << "'"); + } + + rOStm.WriteBool(bRel); + write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aPath, RTL_TEXTENCODING_UTF8); + rOStm.WriteUInt32(pObj->nOffset).WriteUInt16(static_cast<sal_uInt16>(pObj->eObjKind)); + } + + // more recently, a 512-byte reserve buffer is written, + // to recognize them two sal_uInt32-Ids will be written. + rOStm.WriteUInt32(COMPAT_FORMAT('G', 'A', 'L', 'R')) + .WriteUInt32(COMPAT_FORMAT('E', 'S', 'R', 'V')); + + const long nReservePos = rOStm.Tell(); + std::unique_ptr<VersionCompat> pCompat(new VersionCompat(rOStm, StreamMode::WRITE, 2)); + + rOStm.WriteUInt32(rId).WriteBool(pThm->IsNameFromResource()); // From version 2 and up + + pCompat.reset(); + + // Fill the rest of the buffer. + const long nRest = std::max(512L - (static_cast<long>(rOStm.Tell()) - nReservePos), 0L); + + if (nRest) + { + std::unique_ptr<char[]> pReserve(new char[nRest]); + memset(pReserve.get(), 0, nRest); + rOStm.WriteBytes(pReserve.get(), nRest); + } + + return rOStm; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx index 2bb71540cf29..1de5ff849b8e 100644 --- a/svx/source/gallery2/galtheme.cxx +++ b/svx/source/gallery2/galtheme.cxx @@ -61,8 +61,7 @@ using namespace ::com::sun::star; GalleryTheme::GalleryTheme( Gallery* pGallery, GalleryThemeEntry* pThemeEntry ) - : m_bDestDirRelative(false) - , pParent(pGallery) + : pParent(pGallery) , pThm(pThemeEntry) , mnThemeLockCount(0) , mnBroadcasterLockCount(0) @@ -76,7 +75,7 @@ GalleryTheme::GalleryTheme( Gallery* pGallery, GalleryThemeEntry* pThemeEntry ) GalleryTheme::~GalleryTheme() { if(pThm->IsModified()) - if(!mpGalleryBinaryEngine->implWrite(*this)) + if(!mpGalleryBinaryEngine->implWrite(*this, pThm)) ImplSetModified(false); for (auto & pEntry : maGalleryObjectCollection.getObjectList()) @@ -88,6 +87,11 @@ GalleryTheme::~GalleryTheme() mpGalleryBinaryEngine->clearSotStorage(); } +void GalleryTheme::SetDestDir(const OUString& rDestDir, bool bRelative) +{ + mpGalleryBinaryEngine->setDestDir(rDestDir, bRelative); +} + std::unique_ptr<GalleryBinaryEngine> GalleryTheme::createGalleryBinaryEngine(bool bReadOnly) { std::unique_ptr<GalleryBinaryEngine> pGalleryBinaryEngine = std::make_unique<GalleryBinaryEngine>(pThm->getGalleryStorageLocations(), maGalleryObjectCollection, bReadOnly); @@ -144,7 +148,7 @@ bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos) } } - mpGalleryBinaryEngine->insertObject(rObj, pFoundEntry, m_aDestDir, nInsertPos); + mpGalleryBinaryEngine->insertObject(rObj, pFoundEntry, nInsertPos); ImplSetModified(true); ImplBroadcast(pFoundEntry? iFoundPos: nInsertPos); @@ -306,7 +310,7 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize mpGalleryBinaryEngine->updateTheme(); ImplSetModified( true ); if (pThm->IsModified()) - if (!mpGalleryBinaryEngine->implWrite(*this)) + if (!mpGalleryBinaryEngine->implWrite(*this, pThm)) ImplSetModified(false); UnlockBroadcaster(); } @@ -650,94 +654,6 @@ void GalleryTheme::CopyToClipboard(sal_uInt32 nPos) pTransferable->CopyToClipboard(GetSystemClipboard()); } -SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const -{ - const INetURLObject aRelURL1( GetParent()->GetRelativeURL() ); - const INetURLObject aRelURL2( GetParent()->GetUserURL() ); - sal_uInt32 nCount = GetObjectCount(); - bool bRel; - - rOStm.WriteUInt16( 0x0004 ); - write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, pThm->GetThemeName(), RTL_TEXTENCODING_UTF8); - rOStm.WriteUInt32( nCount ).WriteUInt16( osl_getThreadTextEncoding() ); - - for( sal_uInt32 i = 0; i < nCount; i++ ) - { - const GalleryObject* pObj = maGalleryObjectCollection.getForPosition( i ); - OUString aPath; - - if( SgaObjKind::SvDraw == pObj->eObjKind ) - { - aPath = GetSvDrawStreamNameFromURL( pObj->aURL ); - bRel = false; - } - else - { - aPath = pObj->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); - aPath = aPath.copy( 0, std::min(aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) ); - bRel = aPath == aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE ); - - if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() > ( aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() + 1 ) ) ) - { - aPath = pObj->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); - aPath = aPath.copy( std::min(aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) ); - } - else - { - aPath = pObj->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); - aPath = aPath.copy( 0, std::min(aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) ); - bRel = aPath == aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE ); - - if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() > ( aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() + 1 ) ) ) - { - aPath = pObj->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); - aPath = aPath.copy( std::min(aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) ); - } - else - aPath = pObj->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); - } - } - - if ( !m_aDestDir.isEmpty() ) - { - bool aFound = aPath.indexOf(m_aDestDir) != -1; - aPath = aPath.replaceFirst(m_aDestDir, ""); - if ( aFound ) - bRel = m_bDestDirRelative; - else - SAL_WARN( "svx", "failed to replace destdir of '" - << m_aDestDir << "' in '" << aPath << "'"); - } - - rOStm.WriteBool( bRel ); - write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aPath, RTL_TEXTENCODING_UTF8); - rOStm.WriteUInt32( pObj->nOffset ).WriteUInt16( static_cast<sal_uInt16>(pObj->eObjKind) ); - } - - // more recently, a 512-byte reserve buffer is written, - // to recognize them two sal_uInt32-Ids will be written. - rOStm.WriteUInt32( COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) ).WriteUInt32( COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) ); - - const long nReservePos = rOStm.Tell(); - std::unique_ptr<VersionCompat> pCompat(new VersionCompat( rOStm, StreamMode::WRITE, 2 )); - - rOStm.WriteUInt32( GetId() ).WriteBool( pThm->IsNameFromResource() ); // From version 2 and up - - pCompat.reset(); - - // Fill the rest of the buffer. - const long nRest = std::max( 512L - ( static_cast<long>(rOStm.Tell()) - nReservePos ), 0L ); - - if( nRest ) - { - std::unique_ptr<char[]> pReserve(new char[ nRest ]); - memset( pReserve.get(), 0, nRest ); - rOStm.WriteBytes(pReserve.get(), nRest); - } - - return rOStm; -} - SvStream& GalleryTheme::ReadData( SvStream& rIStm ) { sal_uInt32 nCount; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits