diff options
author | Aditya <adityasahu1511@gmail.com> | 2020-07-20 17:13:13 +0530 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-07-30 07:30:05 +0200 |
commit | 104f7027ea3bea45849cb5d88a1893e69bf3606c (patch) | |
tree | fd81f655d3748852b2b4c279aabee32d7eff6ed3 /svx | |
parent | 1486f96317aa6eac34ddb7ef4e1c64824bb269b4 (diff) |
svx: GalleryObjectCollection shared class and related refactoring work
Add GalleryObjectCollection, a shared class primarily owned by GalleryTheme
which contains object list to be used by GalleryTheme and GalleryBinaryEngine.
Refactor ImplCreateUniqueURL, InsertGraphic()
Implement comphelper::GraphicMimeTypeHelper::GetExtensionForConvertDataFormat()
Refactor Actualize(), implement updateSvDrawObject(), updateTheme()
Move ImplCreateSvDrawStorage into constructor instead of calling in directly.
Change-Id: I6a8c552268628b4e192f45112ac9e8789c6e1609
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99035
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/Library_svxcore.mk | 1 | ||||
-rw-r--r-- | svx/source/gallery2/gallerybinaryengine.cxx | 290 | ||||
-rw-r--r-- | svx/source/gallery2/gallerybinaryengineentry.cxx | 2 | ||||
-rw-r--r-- | svx/source/gallery2/galleryobjectcollection.cxx | 25 | ||||
-rw-r--r-- | svx/source/gallery2/galtheme.cxx | 313 |
5 files changed, 339 insertions, 292 deletions
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index 37f135fced87..4898c073764d 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -155,6 +155,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\ svx/source/gallery2/gallerybinaryengine \ svx/source/gallery2/gallerybinaryengineentry \ svx/source/gallery2/gallerystoragelocations \ + svx/source/gallery2/galleryobjectcollection \ svx/source/items/chrtitem \ svx/source/items/clipfmtitem \ svx/source/items/customshapeitem \ diff --git a/svx/source/gallery2/gallerybinaryengine.cxx b/svx/source/gallery2/gallerybinaryengine.cxx index 5f7d806d59e3..9a3cc550198a 100644 --- a/svx/source/gallery2/gallerybinaryengine.cxx +++ b/svx/source/gallery2/gallerybinaryengine.cxx @@ -21,37 +21,50 @@ #include <svx/fmmodel.hxx> #include <galobj.hxx> #include <svx/gallerybinaryengine.hxx> +#include <svx/galleryobjectcollection.hxx> #include "codec.hxx" #include "gallerydrawmodel.hxx" #include <vcl/cvtgrf.hxx> +#include <sot/formats.hxx> #include <sal/log.hxx> #include <com/sun/star/ucb/ContentCreationException.hpp> +#include <comphelper/fileformat.h> +#include <comphelper/graphicmimetype.hxx> #include <tools/urlobj.hxx> #include <tools/diagnose_ex.h> #include <unotools/ucbstreamhelper.hxx> #include <unotools/streamwrap.hxx> +#include <unotools/tempfile.hxx> +#include <tools/urlobj.hxx> #include <tools/vcompat.hxx> using namespace ::com::sun::star; -GalleryBinaryEngine::GalleryBinaryEngine(const GalleryStorageLocations& rGalleryStorageLocations) +GalleryBinaryEngine::GalleryBinaryEngine(const GalleryStorageLocations& rGalleryStorageLocations, + GalleryObjectCollection& rGalleryObjectCollection, + bool bReadOnly) : maGalleryStorageLocations(rGalleryStorageLocations) + , mrGalleryObjectCollection(rGalleryObjectCollection) + , mbReadOnly(bReadOnly) { + ImplCreateSvDrawStorage(); } +GalleryBinaryEngine::~GalleryBinaryEngine() { clearSotStorage(); } + void GalleryBinaryEngine::clearSotStorage() { m_aSvDrawStorageRef.clear(); } -void GalleryBinaryEngine::ImplCreateSvDrawStorage(bool bReadOnly) +void GalleryBinaryEngine::ImplCreateSvDrawStorage() { try { m_aSvDrawStorageRef = new SotStorage(false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), - bReadOnly ? StreamMode::READ : StreamMode::STD_READWRITE); + mbReadOnly ? 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) + if ((m_aSvDrawStorageRef->GetError() != ERRCODE_NONE) && !mbReadOnly) m_aSvDrawStorageRef = new SotStorage( false, GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ); @@ -103,9 +116,7 @@ bool GalleryBinaryEngine::implWrite(const GalleryTheme& rTheme) } void GalleryBinaryEngine::insertObject(const SgaObject& rObj, GalleryObject* pFoundEntry, - OUString& rDestDir, - ::std::vector<std::unique_ptr<GalleryObject>>& rObjectList, - sal_uInt32& rInsertPos) + OUString& rDestDir, sal_uInt32& rInsertPos) { if (pFoundEntry) { @@ -124,11 +135,11 @@ void GalleryBinaryEngine::insertObject(const SgaObject& rObj, GalleryObject* pFo else if (rObj.GetTitle() == "__<empty>__") const_cast<SgaObject&>(rObj).SetTitle(""); - implWriteSgaObject(rObj, rInsertPos, &aNewEntry, rDestDir, rObjectList); + implWriteSgaObject(rObj, rInsertPos, &aNewEntry, rDestDir); pFoundEntry->nOffset = aNewEntry.nOffset; } else - implWriteSgaObject(rObj, rInsertPos, nullptr, rDestDir, rObjectList); + implWriteSgaObject(rObj, rInsertPos, nullptr, rDestDir); } std::unique_ptr<SgaObject> GalleryBinaryEngine::implReadSgaObject(GalleryObject const* pEntry) @@ -186,9 +197,8 @@ std::unique_ptr<SgaObject> GalleryBinaryEngine::implReadSgaObject(GalleryObject return pSgaObj; } -bool GalleryBinaryEngine::implWriteSgaObject( - const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry, OUString& aDestDir, - ::std::vector<std::unique_ptr<GalleryObject>>& rObjectList) +bool GalleryBinaryEngine::implWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, + GalleryObject* pExistentEntry, OUString& aDestDir) { std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE)); @@ -207,12 +217,13 @@ bool GalleryBinaryEngine::implWriteSgaObject( if (!pExistentEntry) { pEntry = new GalleryObject; - if (nPos < rObjectList.size()) + if (nPos < mrGalleryObjectCollection.size()) { - rObjectList.emplace(rObjectList.begin() + nPos, pEntry); + mrGalleryObjectCollection.getObjectList().emplace( + mrGalleryObjectCollection.getObjectList().begin() + nPos, pEntry); } else - rObjectList.emplace_back(pEntry); + mrGalleryObjectCollection.getObjectList().emplace_back(pEntry); } else pEntry = pExistentEntry; @@ -248,14 +259,16 @@ bool GalleryBinaryEngine::readModel(const GalleryObject* pObject, SdrModel& rMod } return bRet; } -bool GalleryBinaryEngine::insertModel(const FmFormModel& rModel, INetURLObject& rURL) +SgaObjectSvDraw GalleryBinaryEngine::insertModel(const FmFormModel& rModel, + const INetURLObject& rUserURL) { + INetURLObject aURL(implCreateUniqueURL(SgaObjKind::SvDraw, rUserURL)); tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage()); bool bRet = false; if (xSotStorage.is()) { - const OUString aStreamName(GetSvDrawStreamNameFromURL(rURL)); + const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL)); tools::SvRef<SotStorageStream> xOutputStream( xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC)); @@ -285,7 +298,12 @@ bool GalleryBinaryEngine::insertModel(const FmFormModel& rModel, INetURLObject& bRet = !xOutputStream->GetError(); } } - return bRet; + if (bRet) + { + SgaObjectSvDraw aObjSvDraw(rModel, aURL); + return aObjSvDraw; + } + return SgaObjectSvDraw(); } bool GalleryBinaryEngine::readModelStream(const GalleryObject* pObject, @@ -338,13 +356,14 @@ bool GalleryBinaryEngine::readModelStream(const GalleryObject* pObject, SgaObjectSvDraw GalleryBinaryEngine::insertModelStream(const tools::SvRef<SotStorageStream>& rxModelStream, - INetURLObject& rURL) + const INetURLObject& rUserURL) { + INetURLObject aURL(implCreateUniqueURL(SgaObjKind::SvDraw, rUserURL)); tools::SvRef<SotStorage> xSotStorage(GetSvDrawStorage()); if (xSotStorage.is()) { - const OUString aStreamName(GetSvDrawStreamNameFromURL(rURL)); + const OUString aStreamName(GetSvDrawStreamNameFromURL(aURL)); tools::SvRef<SotStorageStream> xOutputStream( xSotStorage->OpenSotStream(aStreamName, StreamMode::WRITE | StreamMode::TRUNC)); @@ -358,7 +377,7 @@ GalleryBinaryEngine::insertModelStream(const tools::SvRef<SotStorageStream>& rxM if (!xOutputStream->GetError()) { xOutputStream->Seek(0); - SgaObjectSvDraw aObjSvDraw(*xOutputStream, rURL); + SgaObjectSvDraw aObjSvDraw(*xOutputStream, aURL); return aObjSvDraw; } } @@ -366,6 +385,235 @@ GalleryBinaryEngine::insertModelStream(const tools::SvRef<SotStorageStream>& rxM return SgaObjectSvDraw(); } +INetURLObject GalleryBinaryEngine::implCreateUniqueURL(SgaObjKind eObjKind, + const INetURLObject& rUserURL, + ConvertDataFormat nFormat) +{ + INetURLObject aDir(rUserURL); + INetURLObject aInfoFileURL(rUserURL); + INetURLObject aNewURL; + sal_uInt32 nNextNumber = 1999; + char const* pExt = nullptr; + bool bExists; + + aDir.Append("dragdrop"); + CreateDir(aDir); + + aInfoFileURL.Append("sdddndx1"); + + // read next possible number + if (FileExists(aInfoFileURL)) + { + std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( + aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ)); + + if (pIStm) + { + pIStm->ReadUInt32(nNextNumber); + } + } + + pExt = comphelper::GraphicMimeTypeHelper::GetExtensionForConvertDataFormat(nFormat); + + do + { + // get URL + if (SgaObjKind::SvDraw == eObjKind) + { + OUString aFileName = "gallery/svdraw/dd" + OUString::number(++nNextNumber % 99999999); + aNewURL = INetURLObject(aFileName, INetProtocol::PrivSoffice); + + bExists = false; + + for (auto const& p : mrGalleryObjectCollection.getObjectList()) + if (p->aURL == aNewURL) + { + bExists = true; + break; + } + } + else + { + OUString aFileName = "dd" + OUString::number(++nNextNumber % 999999); + + if (pExt) + aFileName += OUString(pExt, strlen(pExt), RTL_TEXTENCODING_ASCII_US); + + aNewURL = aDir; + aNewURL.Append(aFileName); + + bExists = FileExists(aNewURL); + } + } while (bExists); + + // write updated number + std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( + aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE)); + + if (pOStm) + { + pOStm->WriteUInt32(nNextNumber); + } + + return aNewURL; +} + +SgaObjectBmp GalleryBinaryEngine::insertGraphic(const Graphic& rGraphic, const GfxLink& aGfxLink, + ConvertDataFormat& nExportFormat, + const INetURLObject& rUserURL) +{ + const INetURLObject aURL(implCreateUniqueURL(SgaObjKind::Bitmap, rUserURL, nExportFormat)); + std::unique_ptr<SvStream> pOStm( + ::utl::UcbStreamHelper::CreateStream(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), + StreamMode::WRITE | StreamMode::TRUNC)); + bool bRet = false; + + if (pOStm) + { + pOStm->SetVersion(SOFFICE_FILEFORMAT_50); + + if (ConvertDataFormat::SVM == nExportFormat) + { + GDIMetaFile aMtf(rGraphic.GetGDIMetaFile()); + + aMtf.Write(*pOStm); + bRet = (pOStm->GetError() == ERRCODE_NONE); + } + else + { + if (aGfxLink.GetDataSize() && aGfxLink.GetData()) + { + pOStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize()); + bRet = (pOStm->GetError() == ERRCODE_NONE); + } + else + bRet = (GraphicConverter::Export(*pOStm, rGraphic, nExportFormat) == ERRCODE_NONE); + } + + pOStm.reset(); + } + if (bRet) + { + const SgaObjectBmp aObjBmp(aURL); + return aObjBmp; + } + return SgaObjectBmp(); +} + +SgaObjectSvDraw GalleryBinaryEngine::updateSvDrawObject(GalleryObject* pEntry) +{ + if (GetSvDrawStorage().is()) + { + const OUString aStmName(GetSvDrawStreamNameFromURL(pEntry->aURL)); + tools::SvRef<SotStorageStream> pIStm + = GetSvDrawStorage()->OpenSotStream(aStmName, StreamMode::READ); + + if (pIStm.is() && !pIStm->GetError()) + { + pIStm->SetBufferSize(16384); + + SgaObjectSvDraw aNewObj(*pIStm, pEntry->aURL); + + pIStm->SetBufferSize(0); + + return aNewObj; + } + } + return SgaObjectSvDraw(); +} + +void GalleryBinaryEngine::updateTheme() +{ + ::utl::TempFile aTmp; + INetURLObject aInURL(GetSdgURL()); + INetURLObject aTmpURL(aTmp.GetURL()); + + DBG_ASSERT(aInURL.GetProtocol() != INetProtocol::NotValid, "invalid URL"); + DBG_ASSERT(aTmpURL.GetProtocol() != INetProtocol::NotValid, "invalid URL"); + + std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( + aInURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ)); + std::unique_ptr<SvStream> pTmpStm(::utl::UcbStreamHelper::CreateStream( + aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), + StreamMode::WRITE | StreamMode::TRUNC)); + + if (pIStm && pTmpStm) + { + for (const auto& i : mrGalleryObjectCollection.getObjectList()) + { + GalleryObject* pEntry = i.get(); + std::unique_ptr<SgaObject> pObj; + + switch (pEntry->eObjKind) + { + case SgaObjKind::Bitmap: + pObj.reset(new SgaObjectBmp()); + break; + case SgaObjKind::Animation: + pObj.reset(new SgaObjectAnim()); + break; + case SgaObjKind::Inet: + pObj.reset(new SgaObjectINet()); + break; + case SgaObjKind::SvDraw: + pObj.reset(new SgaObjectSvDraw()); + break; + case SgaObjKind::Sound: + pObj.reset(new SgaObjectSound()); + break; + + default: + break; + } + + if (pObj) + { + pIStm->Seek(pEntry->nOffset); + ReadSgaObject(*pIStm, *pObj); + pEntry->nOffset = pTmpStm->Tell(); + WriteSgaObject(*pTmpStm, *pObj); + } + } + } + else + { + OSL_FAIL("File(s) could not be opened"); + } + + pIStm.reset(); + pTmpStm.reset(); + + CopyFile(aTmpURL, aInURL); + KillFile(aTmpURL); + + ErrCode nStorErr = ERRCODE_NONE; + + try + { + tools::SvRef<SotStorage> aTempStorageRef( + new SotStorage(false, aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), + StreamMode::STD_READWRITE)); + GetSvDrawStorage()->CopyTo(aTempStorageRef.get()); + nStorErr = GetSvDrawStorage()->GetError(); + } + catch (const css::ucb::ContentCreationException&) + { + TOOLS_WARN_EXCEPTION("svx", "failed to open: " + << aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE) + << "due to"); + nStorErr = ERRCODE_IO_GENERAL; + } + + if (nStorErr == ERRCODE_NONE) + { + clearSotStorage(); + CopyFile(aTmpURL, GetSdvURL()); + ImplCreateSvDrawStorage(); + } + + KillFile(aTmpURL); +} + SvStream& WriteGalleryTheme(SvStream& rOut, const GalleryTheme& rTheme) { return rTheme.WriteData(rOut); diff --git a/svx/source/gallery2/gallerybinaryengineentry.cxx b/svx/source/gallery2/gallerybinaryengineentry.cxx index 67f5c556ce51..ee67b2a255b7 100644 --- a/svx/source/gallery2/gallerybinaryengineentry.cxx +++ b/svx/source/gallery2/gallerybinaryengineentry.cxx @@ -41,7 +41,7 @@ static bool FileExists(const INetURLObject& rURL, const OUString& rExt) GalleryBinaryEngineEntry::GalleryBinaryEngineEntry( GalleryStorageLocations& rGalleryStorageLocations) - : maGalleryStorageLocations(rGalleryStorageLocations) + : m_rGalleryStorageLocations(rGalleryStorageLocations) { } diff --git a/svx/source/gallery2/galleryobjectcollection.cxx b/svx/source/gallery2/galleryobjectcollection.cxx new file mode 100644 index 000000000000..0ab69de1a0a4 --- /dev/null +++ b/svx/source/gallery2/galleryobjectcollection.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 <galobj.hxx> +#include <svx/galleryobjectcollection.hxx> + +void GalleryObjectCollection::clear() { m_aObjectList.clear(); } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx index 2d1951d691c3..557fbca1406a 100644 --- a/svx/source/gallery2/galtheme.cxx +++ b/svx/source/gallery2/galtheme.cxx @@ -50,6 +50,7 @@ #include <svx/galmisc.hxx> #include <svx/galtheme.hxx> #include <svx/svdpage.hxx> +#include <svx/galleryobjectcollection.hxx> #include <com/sun/star/sdbc/XResultSet.hpp> #include <com/sun/star/ucb/XContentAccess.hpp> #include <galobj.hxx> @@ -69,8 +70,7 @@ GalleryTheme::GalleryTheme( Gallery* pGallery, GalleryThemeEntry* pThemeEntry ) , bDragging(false) , bAbortActualize(false) { - mpGalleryBinaryEngine = createGalleryBinaryEngine(); - mpGalleryBinaryEngine->ImplCreateSvDrawStorage(IsReadOnly()); + mpGalleryBinaryEngine = createGalleryBinaryEngine(IsReadOnly()); } GalleryTheme::~GalleryTheme() @@ -79,140 +79,29 @@ GalleryTheme::~GalleryTheme() if(!mpGalleryBinaryEngine->implWrite(*this)) ImplSetModified(false); - for (auto & pEntry : aObjectList) + for (auto & pEntry : maGalleryObjectCollection.getObjectList()) { Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry.get() ) ); pEntry.reset(); } - aObjectList.clear(); + maGalleryObjectCollection.clear(); mpGalleryBinaryEngine->clearSotStorage(); } -std::unique_ptr<GalleryBinaryEngine> GalleryTheme::createGalleryBinaryEngine() +std::unique_ptr<GalleryBinaryEngine> GalleryTheme::createGalleryBinaryEngine(bool bReadOnly) { - std::unique_ptr<GalleryBinaryEngine> pGalleryBinaryEngine = std::make_unique<GalleryBinaryEngine>(pThm->getGalleryStorageLocations()); + std::unique_ptr<GalleryBinaryEngine> pGalleryBinaryEngine = std::make_unique<GalleryBinaryEngine>(pThm->getGalleryStorageLocations(), maGalleryObjectCollection, bReadOnly); return pGalleryBinaryEngine; } -const GalleryObject* GalleryTheme::ImplGetGalleryObject( const INetURLObject& rURL ) +const GalleryObject* GalleryTheme::ImplGetGalleryObject(const INetURLObject& rURL) { - for (auto const & i : aObjectList) - if ( i->aURL == rURL ) + for (auto const& i : maGalleryObjectCollection.getObjectList()) + if (i->aURL == rURL) return i.get(); return nullptr; } -INetURLObject GalleryTheme::implCreateUniqueURL(SgaObjKind eObjKind, ConvertDataFormat nFormat) -{ - INetURLObject aDir(GetParent()->GetUserURL()); - INetURLObject aInfoFileURL(GetParent()->GetUserURL()); - INetURLObject aNewURL; - sal_uInt32 nNextNumber = 1999; - char const* pExt = nullptr; - bool bExists; - - aDir.Append("dragdrop"); - CreateDir(aDir); - - aInfoFileURL.Append("sdddndx1"); - - // read next possible number - if (FileExists(aInfoFileURL)) - { - std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( - aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ)); - - if (pIStm) - { - pIStm->ReadUInt32(nNextNumber); - } - } - - // create extension - if (nFormat != ConvertDataFormat::Unknown) - { - switch (nFormat) - { - case ConvertDataFormat::BMP: - pExt = ".bmp"; - break; - case ConvertDataFormat::GIF: - pExt = ".gif"; - break; - case ConvertDataFormat::JPG: - pExt = ".jpg"; - break; - case ConvertDataFormat::MET: - pExt = ".met"; - break; - case ConvertDataFormat::PCT: - pExt = ".pct"; - break; - case ConvertDataFormat::PNG: - pExt = ".png"; - break; - case ConvertDataFormat::SVM: - pExt = ".svm"; - break; - case ConvertDataFormat::TIF: - pExt = ".tif"; - break; - case ConvertDataFormat::WMF: - pExt = ".wmf"; - break; - case ConvertDataFormat::EMF: - pExt = ".emf"; - break; - - default: - pExt = ".grf"; - break; - } - } - - do - { - // get URL - if (SgaObjKind::SvDraw == eObjKind) - { - OUString aFileName = "gallery/svdraw/dd" + OUString::number(++nNextNumber % 99999999); - aNewURL = INetURLObject(aFileName, INetProtocol::PrivSoffice); - - bExists = false; - - for (auto const& p : aObjectList) - if (p->aURL == aNewURL) - { - bExists = true; - break; - } - } - else - { - OUString aFileName = "dd" + OUString::number(++nNextNumber % 999999); - - if (pExt) - aFileName += OUString(pExt, strlen(pExt), RTL_TEXTENCODING_ASCII_US); - - aNewURL = aDir; - aNewURL.Append(aFileName); - - bExists = FileExists(aNewURL); - } - } while (bExists); - - // write updated number - std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( - aInfoFileURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE)); - - if (pOStm) - { - pOStm->WriteUInt32(nNextNumber); - } - - return aNewURL; -} - void GalleryTheme::ImplBroadcast(sal_uInt32 nUpdatePos) { if( !IsBroadcasterLocked() ) @@ -254,16 +143,16 @@ bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos) GalleryObject* pFoundEntry = nullptr; sal_uInt32 iFoundPos = 0; - for (sal_uInt32 n = aObjectList.size(); iFoundPos < n; ++iFoundPos) + for (sal_uInt32 n = maGalleryObjectCollection.size(); iFoundPos < n; ++iFoundPos) { - if (aObjectList[ iFoundPos ]->aURL == rObj.GetURL()) + if (maGalleryObjectCollection.get(iFoundPos)->aURL == rObj.GetURL()) { - pFoundEntry = aObjectList[ iFoundPos ].get(); + pFoundEntry = maGalleryObjectCollection.get(iFoundPos).get(); break; } } - mpGalleryBinaryEngine->insertObject(rObj, pFoundEntry, m_aDestDir, aObjectList, nInsertPos); + mpGalleryBinaryEngine->insertObject(rObj, pFoundEntry, m_aDestDir, nInsertPos); ImplSetModified(true); ImplBroadcast(pFoundEntry? iFoundPos: nInsertPos); @@ -276,9 +165,9 @@ std::unique_ptr<SgaObject> GalleryTheme::AcquireObject(sal_uInt32 nPos) return mpGalleryBinaryEngine->implReadSgaObject(ImplGetGalleryObject(nPos)); } -void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx& rBitmapEx, Size& rSize, OUString& rTitle, OUString& rPath) const +void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx& rBitmapEx, Size& rSize, OUString& rTitle, OUString& rPath) { - const GalleryObject* pGalleryObject = aObjectList[ nPos ].get(); + const GalleryObject* pGalleryObject = maGalleryObjectCollection.get(nPos).get(); rBitmapEx = pGalleryObject->maPreviewBitmapEx; rSize = pGalleryObject->maPreparedSize; @@ -288,7 +177,7 @@ void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx& rBitm void GalleryTheme::SetPreviewBitmapExAndStrings(sal_uInt32 nPos, const BitmapEx& rBitmapEx, const Size& rSize, const OUString& rTitle, const OUString& rPath) { - GalleryObject* pGalleryObject = aObjectList[ nPos ].get(); + GalleryObject* pGalleryObject = maGalleryObjectCollection.get(nPos).get(); pGalleryObject->maPreviewBitmapEx = rBitmapEx; pGalleryObject->maPreparedSize = rSize; @@ -298,11 +187,11 @@ void GalleryTheme::SetPreviewBitmapExAndStrings(sal_uInt32 nPos, const BitmapEx& void GalleryTheme::RemoveObject(sal_uInt32 nPos) { - auto it = aObjectList.begin() + nPos; + auto it = maGalleryObjectCollection.getObjectList().begin() + nPos; std::unique_ptr<GalleryObject> pEntry = std::move(*it); - aObjectList.erase( it ); + maGalleryObjectCollection.getObjectList().erase( it ); - if( aObjectList.empty() ) + if( maGalleryObjectCollection.getObjectList().empty() ) KillFile( GetSdgURL() ); if( SgaObjKind::SvDraw == pEntry->eObjKind ) @@ -317,18 +206,18 @@ void GalleryTheme::RemoveObject(sal_uInt32 nPos) bool GalleryTheme::ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos) { - if (nOldPos == nNewPos || nOldPos >= aObjectList.size()) + if (nOldPos == nNewPos || nOldPos >= maGalleryObjectCollection.size()) return false; - std::unique_ptr<GalleryObject> pEntry = std::move(aObjectList[nOldPos]); + std::unique_ptr<GalleryObject> pEntry = std::move(maGalleryObjectCollection.get(nOldPos)); - aObjectList.insert(aObjectList.begin() + nNewPos, std::move(pEntry)); + maGalleryObjectCollection.getObjectList().insert(maGalleryObjectCollection.getObjectList().begin() + nNewPos, std::move(pEntry)); if (nNewPos < nOldPos) nOldPos++; - auto it = aObjectList.begin() + nOldPos; - aObjectList.erase(it); + auto it = maGalleryObjectCollection.getObjectList().begin() + nOldPos; + maGalleryObjectCollection.getObjectList().erase(it); ImplSetModified(true); ImplBroadcast((nNewPos < nOldPos)? nNewPos: (nNewPos - 1)); @@ -343,21 +232,21 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize Graphic aGraphic; OUString aFormat; - const sal_uInt32 nCount = aObjectList.size(); + const sal_uInt32 nCount = maGalleryObjectCollection.size(); LockBroadcaster(); bAbortActualize = false; // reset delete flag for (sal_uInt32 i = 0; i < nCount; i++) - aObjectList[ i ]->mbDelete = false; + maGalleryObjectCollection.get(i)->mbDelete = false; for (sal_uInt32 i = 0; ( i < nCount ) && !bAbortActualize; i++) { if( pProgress ) pProgress->Update( i, nCount - 1 ); - GalleryObject* pEntry = aObjectList[ i ].get(); + GalleryObject* pEntry = maGalleryObjectCollection.get(i).get(); const INetURLObject aURL( pEntry->aURL ); @@ -399,112 +288,30 @@ void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualize } else { + //update SvDraw object if ( mpGalleryBinaryEngine->GetSvDrawStorage().is() ) { - const OUString aStmName( GetSvDrawStreamNameFromURL( pEntry->aURL ) ); - tools::SvRef<SotStorageStream> pIStm = mpGalleryBinaryEngine->GetSvDrawStorage()->OpenSotStream( aStmName, StreamMode::READ ); - - if( pIStm.is() && !pIStm->GetError() ) - { - pIStm->SetBufferSize( 16384 ); - - SgaObjectSvDraw aNewObj( *pIStm, pEntry->aURL ); - - if( !InsertObject( aNewObj ) ) - pEntry->mbDelete = true; - - pIStm->SetBufferSize( 0 ); - } + SgaObjectSvDraw aNewObj = mpGalleryBinaryEngine->updateSvDrawObject(pEntry); + if (aNewObj.IsValid() && !InsertObject(aNewObj)) + pEntry->mbDelete = true; } } } // remove all entries with set flag - for ( auto it = aObjectList.begin(); it != aObjectList.end(); /* increment is in the body of loop */) + for ( auto it = maGalleryObjectCollection.getObjectList().begin(); it != maGalleryObjectCollection.getObjectList().end(); /* increment is in the body of loop */) { if( (*it)->mbDelete ) { Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), it->get() ) ); - it = aObjectList.erase( it ); + it = maGalleryObjectCollection.getObjectList().erase( it ); } else ++it; } // update theme - ::utl::TempFile aTmp; - INetURLObject aInURL( GetSdgURL() ); - INetURLObject aTmpURL( aTmp.GetURL() ); - - DBG_ASSERT( aInURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" ); - DBG_ASSERT( aTmpURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" ); - - std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aInURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ )); - std::unique_ptr<SvStream> pTmpStm(::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE | StreamMode::TRUNC )); - - if( pIStm && pTmpStm ) - { - for (const auto & i : aObjectList) - { - GalleryObject* pEntry = i.get(); - std::unique_ptr<SgaObject> pObj; - - switch( pEntry->eObjKind ) - { - case SgaObjKind::Bitmap: pObj.reset(new SgaObjectBmp()); break; - case SgaObjKind::Animation: pObj.reset(new SgaObjectAnim()); break; - case SgaObjKind::Inet: pObj.reset(new SgaObjectINet()); break; - case SgaObjKind::SvDraw: pObj.reset(new SgaObjectSvDraw()); break; - case SgaObjKind::Sound: pObj.reset(new SgaObjectSound()); break; - - default: - break; - } - - if( pObj ) - { - pIStm->Seek( pEntry->nOffset ); - ReadSgaObject( *pIStm, *pObj); - pEntry->nOffset = pTmpStm->Tell(); - WriteSgaObject( *pTmpStm, *pObj ); - } - } - } - else - { - OSL_FAIL( "File(s) could not be opened" ); - } - - pIStm.reset(); - pTmpStm.reset(); - - CopyFile( aTmpURL, aInURL ); - KillFile( aTmpURL ); - - ErrCode nStorErr = ERRCODE_NONE; - - try - { - tools::SvRef<SotStorage> aTempStorageRef( new SotStorage( false, aTmpURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::STD_READWRITE ) ); - mpGalleryBinaryEngine->GetSvDrawStorage()->CopyTo( aTempStorageRef.get() ); - nStorErr = mpGalleryBinaryEngine->GetSvDrawStorage()->GetError(); - } - catch (const css::ucb::ContentCreationException&) - { - TOOLS_WARN_EXCEPTION("svx", "failed to open: " - << aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE) - << "due to"); - nStorErr = ERRCODE_IO_GENERAL; - } - - if( nStorErr == ERRCODE_NONE ) - { - mpGalleryBinaryEngine->clearSotStorage(); - CopyFile( aTmpURL, GetSdvURL() ); - mpGalleryBinaryEngine->ImplCreateSvDrawStorage(IsReadOnly()); - } - - KillFile( aTmpURL ); + mpGalleryBinaryEngine->updateTheme(); ImplSetModified( true ); if (pThm->IsModified()) if (!mpGalleryBinaryEngine->implWrite(*this)) @@ -642,39 +449,10 @@ bool GalleryTheme::InsertGraphic(const Graphic& rGraphic, sal_uInt32 nInsertPos) nExportFormat = ConvertDataFormat::SVM; } - const INetURLObject aURL( implCreateUniqueURL( SgaObjKind::Bitmap, nExportFormat ) ); - std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE | StreamMode::TRUNC )); - - if( pOStm ) - { - pOStm->SetVersion( SOFFICE_FILEFORMAT_50 ); - - if( ConvertDataFormat::SVM == nExportFormat ) - { - GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() ); - - aMtf.Write( *pOStm ); - bRet = ( pOStm->GetError() == ERRCODE_NONE ); - } - else - { - if( aGfxLink.GetDataSize() && aGfxLink.GetData() ) - { - pOStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize()); - bRet = ( pOStm->GetError() == ERRCODE_NONE ); - } - else - bRet = ( GraphicConverter::Export( *pOStm, rGraphic, nExportFormat ) == ERRCODE_NONE ); - } - - pOStm.reset(); - } + const SgaObjectBmp aObjBmp = mpGalleryBinaryEngine->insertGraphic(rGraphic, aGfxLink, nExportFormat, GetParent()->GetUserURL()); - if( bRet ) - { - const SgaObjectBmp aObjBmp( aURL ); - InsertObject( aObjBmp, nInsertPos ); - } + if (aObjBmp.IsValid()) + bRet = InsertObject(aObjBmp, nInsertPos); } return bRet; @@ -695,14 +473,10 @@ bool GalleryTheme::GetModel(sal_uInt32 nPos, SdrModel& rModel) bool GalleryTheme::InsertModel(const FmFormModel& rModel, sal_uInt32 nInsertPos) { - INetURLObject aURL( implCreateUniqueURL( SgaObjKind::SvDraw ) ); bool bRet = false; - - if(mpGalleryBinaryEngine->insertModel(rModel, aURL)) - { - SgaObjectSvDraw aObjSvDraw(rModel, aURL); + SgaObjectSvDraw aObjSvDraw = mpGalleryBinaryEngine->insertModel(rModel, GetParent()->GetUserURL()); + if(aObjSvDraw.IsValid()) bRet = InsertObject( aObjSvDraw, nInsertPos ); - } return bRet; } @@ -721,10 +495,9 @@ bool GalleryTheme::GetModelStream(sal_uInt32 nPos, tools::SvRef<SotStorageStream bool GalleryTheme::InsertModelStream(const tools::SvRef<SotStorageStream>& rxModelStream, sal_uInt32 nInsertPos) { - INetURLObject aURL( implCreateUniqueURL( SgaObjKind::SvDraw ) ); bool bRet = false; - const SgaObjectSvDraw aObjSvDraw = mpGalleryBinaryEngine->insertModelStream(rxModelStream, aURL); + const SgaObjectSvDraw aObjSvDraw = mpGalleryBinaryEngine->insertModelStream(rxModelStream, GetParent()->GetUserURL()); if(aObjSvDraw.IsValid()) bRet = InsertObject( aObjSvDraw, nInsertPos ); @@ -1029,13 +802,13 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm ) sal_uInt32 nId1, nId2; bool bRel; - for(auto & i : aObjectList) + for(auto & i : maGalleryObjectCollection.getObjectList()) { GalleryObject* pObj = i.get(); Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pObj ) ); i.reset(); } - aObjectList.clear(); + maGalleryObjectCollection.clear(); for( sal_uInt32 i = 0; i < nCount; i++ ) { @@ -1097,7 +870,7 @@ SvStream& GalleryTheme::ReadData( SvStream& rIStm ) } } } - aObjectList.push_back( std::move(pObj) ); + maGalleryObjectCollection.getObjectList().push_back( std::move(pObj) ); } rIStm.ReadUInt32( nId1 ).ReadUInt32( nId2 ); |