diff options
author | Aditya <adityasahu1511@gmail.com> | 2020-09-01 14:56:51 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-09-02 09:25:21 +0200 |
commit | c640f745e8023660e89bca3e97308c0d53834b77 (patch) | |
tree | 775064a2038ed0696d6b1712e83bccad662fb856 /svx/source | |
parent | 4824218c896ae2dfec8a5ca21a116dcc8f44ceee (diff) |
svx: Refactor GalleryObject member aURL
The member aURL does not belong here and needs to be refactored,
the reason is that there can be two type of URLs - XML and binary
URL.
Change-Id: Ieb4e57a6f144070f95282a7fd02d08bda6d11f3a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101084
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx/source')
-rw-r--r-- | svx/source/gallery2/gallerybinaryengine.cxx | 36 | ||||
-rw-r--r-- | svx/source/gallery2/galleryobjectbinarystorage.cxx | 25 | ||||
-rw-r--r-- | svx/source/gallery2/galleryobjectcollection.cxx | 16 | ||||
-rw-r--r-- | svx/source/gallery2/galleryobjectstorage.cxx | 24 | ||||
-rw-r--r-- | svx/source/gallery2/galleryobjectxmlstorage.cxx | 25 | ||||
-rw-r--r-- | svx/source/gallery2/galmisc.cxx | 2 | ||||
-rw-r--r-- | svx/source/gallery2/galtheme.cxx | 21 | ||||
-rw-r--r-- | svx/source/unogallery/unogalitem.cxx | 2 |
8 files changed, 122 insertions, 29 deletions
diff --git a/svx/source/gallery2/gallerybinaryengine.cxx b/svx/source/gallery2/gallerybinaryengine.cxx index 64e23a480781..07cd79150eb8 100644 --- a/svx/source/gallery2/gallerybinaryengine.cxx +++ b/svx/source/gallery2/gallerybinaryengine.cxx @@ -23,6 +23,7 @@ #include <svx/gallerybinaryengine.hxx> #include <svx/galleryobjectcollection.hxx> #include <svx/gallery1.hxx> +#include <svx/galleryobjectbinarystorage.hxx> #include <osl/thread.hxx> #include "codec.hxx" #include "gallerydrawmodel.hxx" @@ -160,7 +161,8 @@ void GalleryBinaryEngine::removeObject(std::unique_ptr<GalleryObject>& pEntry) KillFile(GetSdgURL()); if (SgaObjKind::SvDraw == pEntry->eObjKind) - GetSvDrawStorage()->Remove(pEntry->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)); + GetSvDrawStorage()->Remove( + pEntry->getURL().GetMainURL(INetURLObject::DecodeMechanism::NONE)); } std::unique_ptr<SgaObject> GalleryBinaryEngine::implReadSgaObject(GalleryObject const* pEntry) @@ -209,7 +211,7 @@ std::unique_ptr<SgaObject> GalleryBinaryEngine::implReadSgaObject(GalleryObject if (pSgaObj) { ReadSgaObject(*pIStm, *pSgaObj); - pSgaObj->ImplUpdateURL(pEntry->aURL); + pSgaObj->ImplUpdateURL(pEntry->getURL()); } } } @@ -249,7 +251,9 @@ bool GalleryBinaryEngine::implWriteSgaObject(const SgaObject& rObj, sal_uInt32 n else pEntry = pExistentEntry; - pEntry->aURL = rObj.GetURL(); + pEntry->m_pGalleryObjectStorage = std::make_unique<GalleryObjectBinaryStorage>(); + pEntry->m_pGalleryObjectStorage->setURL(rObj.GetURL()); + pEntry->nOffset = nOffset; pEntry->eObjKind = rObj.GetObjKind(); bRet = true; @@ -447,12 +451,14 @@ INetURLObject GalleryBinaryEngine::implCreateUniqueURL(SgaObjKind eObjKind, bExists = false; - for (auto const& p : mrGalleryObjectCollection.getObjectList()) - if (p->aURL == aNewURL) + for (auto const& pObject : mrGalleryObjectCollection.getObjectList()) + { + if (pObject->getURL() == aNewURL) { bExists = true; break; } + } } else { @@ -526,7 +532,7 @@ SgaObjectSvDraw GalleryBinaryEngine::updateSvDrawObject(GalleryObject* pEntry) { if (GetSvDrawStorage().is()) { - const OUString aStmName(GetSvDrawStreamNameFromURL(pEntry->aURL)); + const OUString aStmName(GetSvDrawStreamNameFromURL(pEntry->getURL())); tools::SvRef<SotStorageStream> pIStm = GetSvDrawStorage()->OpenSotStream(aStmName, StreamMode::READ); @@ -534,7 +540,7 @@ SgaObjectSvDraw GalleryBinaryEngine::updateSvDrawObject(GalleryObject* pEntry) { pIStm->SetBufferSize(16384); - SgaObjectSvDraw aNewObj(*pIStm, pEntry->aURL); + SgaObjectSvDraw aNewObj(*pIStm, pEntry->getURL()); pIStm->SetBufferSize(0); @@ -699,29 +705,29 @@ SvStream& GalleryBinaryEngine::writeGalleryTheme(SvStream& rOStm, const GalleryT if (SgaObjKind::SvDraw == pObj->eObjKind) { - aPath = GetSvDrawStreamNameFromURL(pObj->aURL); + aPath = GetSvDrawStreamNameFromURL(pObj->getURL()); bRel = false; } else { - aPath = pObj->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); + aPath = pObj->getURL().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() + && (pObj->getURL().GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() > (rRelURL1.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + 1))) { - aPath = pObj->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); + aPath = pObj->getURL().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 = pObj->getURL().GetMainURL(INetURLObject::DecodeMechanism::NONE); aPath = aPath.copy( 0, std::min(rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength(), @@ -729,17 +735,17 @@ SvStream& GalleryBinaryEngine::writeGalleryTheme(SvStream& rOStm, const GalleryT bRel = aPath == rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE); if (bRel - && (pObj->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + && (pObj->getURL().GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() > (rRelURL2.GetMainURL(INetURLObject::DecodeMechanism::NONE).getLength() + 1))) { - aPath = pObj->aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); + aPath = pObj->getURL().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); + aPath = pObj->getURL().GetMainURL(INetURLObject::DecodeMechanism::NONE); } } diff --git a/svx/source/gallery2/galleryobjectbinarystorage.cxx b/svx/source/gallery2/galleryobjectbinarystorage.cxx new file mode 100644 index 000000000000..c18ed6441df1 --- /dev/null +++ b/svx/source/gallery2/galleryobjectbinarystorage.cxx @@ -0,0 +1,25 @@ +/* -*- 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/galleryobjectbinarystorage.hxx> +#include <tools/urlobj.hxx> + +void GalleryObjectBinaryStorage::setURL(INetURLObject aURL) { m_aURL = aURL; } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/gallery2/galleryobjectcollection.cxx b/svx/source/gallery2/galleryobjectcollection.cxx index 5080ed334916..c5667eea2dca 100644 --- a/svx/source/gallery2/galleryobjectcollection.cxx +++ b/svx/source/gallery2/galleryobjectcollection.cxx @@ -26,9 +26,11 @@ void GalleryObjectCollection::clear() { m_aObjectList.clear(); } const GalleryObject* GalleryObjectCollection::searchObjectWithURL(const INetURLObject& rURL) { - for (auto const& i : m_aObjectList) - if (i->aURL == rURL) - return i.get(); + for (auto const& pObject : m_aObjectList) + { + if (pObject->getURL() == rURL) + return pObject.get(); + } return nullptr; } @@ -47,4 +49,12 @@ const GalleryObject* GalleryObjectCollection::getForPosition(sal_uInt32 nPos) co return nullptr; } +const INetURLObject& GalleryObjectCollection::getURLForPosition(sal_uInt32 nPos) const +{ + if (nPos < size()) + return get(nPos)->getURL(); + INetURLObject* aInvalidURL = new INetURLObject(); + return *aInvalidURL; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/gallery2/galleryobjectstorage.cxx b/svx/source/gallery2/galleryobjectstorage.cxx new file mode 100644 index 000000000000..2d324b3d0eb2 --- /dev/null +++ b/svx/source/gallery2/galleryobjectstorage.cxx @@ -0,0 +1,24 @@ +/* -*- 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/galleryobjectstorage.hxx> + +GalleryObjectStorage::~GalleryObjectStorage() = default; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/gallery2/galleryobjectxmlstorage.cxx b/svx/source/gallery2/galleryobjectxmlstorage.cxx new file mode 100644 index 000000000000..cadd94c03439 --- /dev/null +++ b/svx/source/gallery2/galleryobjectxmlstorage.cxx @@ -0,0 +1,25 @@ +/* -*- 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/galleryobjectxmlstorage.hxx> +#include <tools/urlobj.hxx> + +void GalleryObjectXMLStorage::setURL(INetURLObject aURL) { m_aURL = aURL; } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/gallery2/galmisc.cxx b/svx/source/gallery2/galmisc.cxx index 8a5c7ac50ebf..946543e9082d 100644 --- a/svx/source/gallery2/galmisc.cxx +++ b/svx/source/gallery2/galmisc.cxx @@ -556,7 +556,7 @@ INetURLObject ImplGetURL(const GalleryObject* pObject) INetURLObject aURL; if (pObject) - aURL = pObject->aURL; + aURL = pObject->getURL(); return aURL; } diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx index c10041ee8471..476ad79f27e6 100644 --- a/svx/source/gallery2/galtheme.cxx +++ b/svx/source/gallery2/galtheme.cxx @@ -141,7 +141,7 @@ bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos) sal_uInt32 iFoundPos = 0; for (sal_uInt32 n = maGalleryObjectCollection.size(); iFoundPos < n; ++iFoundPos) { - if (maGalleryObjectCollection.get(iFoundPos)->aURL == rObj.GetURL()) + if (maGalleryObjectCollection.get(iFoundPos)->getURL() == rObj.GetURL()) { pFoundEntry = maGalleryObjectCollection.get(iFoundPos).get(); break; @@ -240,7 +240,7 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize GalleryObject* pEntry = maGalleryObjectCollection.get(i).get(); - const INetURLObject aURL( pEntry->aURL ); + const INetURLObject aURL( pEntry->getURL()); rActualizeLink.Call( aURL ); @@ -695,6 +695,9 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm ) aFileName = OStringToOUString(aTempFileName, osl_getThreadTextEncoding()); + pObj->m_pGalleryObjectStorage.reset(); + pObj->m_pGalleryObjectStorage = std::make_unique<GalleryObjectBinaryStorage>(); + if( bRel ) { aFileName = aFileName.replaceAll( "\\", "/" ); @@ -705,9 +708,9 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm ) aPath += aFileName; - pObj->aURL = INetURLObject( aPath ); + pObj->m_pGalleryObjectStorage->setURL(INetURLObject(aPath)); - if( !FileExists( pObj->aURL ) ) + if (!FileExists(pObj->getURL())) { aPath = aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE ); @@ -717,7 +720,7 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm ) aPath += aFileName; // assign this URL, even in the case it is not valid (#94482) - pObj->aURL = INetURLObject( aPath ); + pObj->m_pGalleryObjectStorage->setURL(INetURLObject(aPath)); } } else @@ -725,18 +728,18 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm ) if( SgaObjKind::SvDraw == pObj->eObjKind ) { OUString aDummyURL = "gallery/svdraw/" + aFileName; - pObj->aURL = INetURLObject( aDummyURL, INetProtocol::PrivSoffice ); + pObj->m_pGalleryObjectStorage->setURL(INetURLObject(aDummyURL, INetProtocol::PrivSoffice)); } else { OUString aLocalURL; - pObj->aURL = INetURLObject( aFileName ); + pObj->m_pGalleryObjectStorage->setURL(INetURLObject(aFileName)); - if( ( pObj->aURL.GetProtocol() == INetProtocol::NotValid ) && + if( ( pObj->getURL().GetProtocol() == INetProtocol::NotValid ) && osl::FileBase::getFileURLFromSystemPath( aFileName, aLocalURL ) == osl::FileBase::E_None ) { - pObj->aURL = INetURLObject( aLocalURL ); + pObj->m_pGalleryObjectStorage->setURL(INetURLObject(aLocalURL)); } } } diff --git a/svx/source/unogallery/unogalitem.cxx b/svx/source/unogallery/unogalitem.cxx index 0749dfdd2f44..5c04c26cedb9 100644 --- a/svx/source/unogallery/unogalitem.cxx +++ b/svx/source/unogallery/unogalitem.cxx @@ -258,7 +258,7 @@ void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEnt ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr ); if( pGalTheme ) - *pValue <<= implGetObject()->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ); + *pValue <<= implGetObject()->getURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ); } break; |