loplugin:useuniqueptr in SfxApplication::LoadTemplate and SfxMedium

pass SfxItemSet around by std::unique_ptr

Change-Id: I54da96d8df224f7c4f2fb9ebf06ed32d479298e7
Reviewed-on: https://gerrit.libreoffice.org/58649
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2018-08-08 09:31:02 +02:00
parent 1444bd7200
commit 6a6774cc4b
13 changed files with 36 additions and 39 deletions
+1 -1
View File
@@ -151,7 +151,7 @@ public:
/**
* @param pArgs Takes ownership
*/
ErrCode LoadTemplate( SfxObjectShellLock& xDoc, const OUString& rFileName, SfxItemSet* pArgs );
ErrCode LoadTemplate( SfxObjectShellLock& xDoc, const OUString& rFileName, std::unique_ptr<SfxItemSet> pArgs );
vcl::Window* GetTopWindow() const;
// members
+3 -3
View File
@@ -43,6 +43,7 @@
#include <cppuhelper/weak.hxx>
#include <rtl/ustring.hxx>
#include <svl/lstner.hxx>
#include <svl/itemset.hxx>
#include <tools/link.hxx>
#include <tools/stream.hxx>
#include <ucbhelper/content.hxx>
@@ -55,7 +56,6 @@ class INetURLObject;
class SfxObjectShell;
class SfxFrame;
class Timer;
class SfxItemSet;
class DateTime;
class SFX2_DLLPUBLIC SfxMedium : public SvRefBase
@@ -78,7 +78,7 @@ public:
SfxMedium( const OUString &rName,
StreamMode nOpenMode,
std::shared_ptr<const SfxFilter> pFilter = nullptr,
SfxItemSet *pSet = nullptr );
std::unique_ptr<SfxItemSet> pSet = nullptr );
/**
* @param pSet Takes ownership
*/
@@ -86,7 +86,7 @@ public:
const OUString &rReferer,
StreamMode nOpenMode,
std::shared_ptr<const SfxFilter> pFilter = nullptr,
SfxItemSet *pSet = nullptr );
std::unique_ptr<SfxItemSet> pSet = nullptr );
/**
* @param pSet does NOT take ownership
+2 -2
View File
@@ -750,12 +750,12 @@ void ScDocShell::Execute( SfxRequest& rReq )
ScDocumentLoader::RemoveAppPrefix( aFilterName );
std::shared_ptr<const SfxFilter> pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
SfxItemSet* pSet = new SfxAllItemSet( pApp->GetPool() );
std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet( pApp->GetPool() ));
if (!aOptions.isEmpty())
pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) );
if ( nVersion != 0 )
pSet->Put( SfxInt16Item( SID_VERSION, nVersion ) );
pMed = new SfxMedium( aFileName, StreamMode::STD_READ, pFilter, pSet );
pMed = new SfxMedium( aFileName, StreamMode::STD_READ, pFilter, std::move(pSet) );
}
else
{
+2 -2
View File
@@ -2502,7 +2502,7 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
setRelativeFileName(nFileId, aStr);
}
SfxItemSet* pSet = new SfxAllItemSet(SfxGetpApp()->GetPool());
std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet(SfxGetpApp()->GetPool()));
if (!aOptions.isEmpty())
pSet->Put(SfxStringItem(SID_FILE_FILTEROPTIONS, aOptions));
@@ -2524,7 +2524,7 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
}
}
unique_ptr<SfxMedium> pMedium(new SfxMedium(aFile, StreamMode::STD_READ, pFilter, pSet));
unique_ptr<SfxMedium> pMedium(new SfxMedium(aFile, StreamMode::STD_READ, pFilter, std::move(pSet)));
if (pMedium->GetError() != ERRCODE_NONE)
return nullptr;
+4 -4
View File
@@ -187,11 +187,11 @@ bool ScTableLink::Refresh(const OUString& rNewFile, const OUString& rNewFilter,
aOptions = *pNewOptions;
// always create ItemSet, so that DocShell can set the options
SfxItemSet* pSet = new SfxAllItemSet( SfxGetpApp()->GetPool() );
std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet( SfxGetpApp()->GetPool() ));
if (!aOptions.isEmpty())
pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) );
SfxMedium* pMed = new SfxMedium(aNewUrl, StreamMode::STD_READ, pFilter, pSet);
SfxMedium* pMed = new SfxMedium(aNewUrl, StreamMode::STD_READ, pFilter, std::move(pSet));
if ( bInEdit ) // only if using the edit dialog,
pMed->UseInteractionHandler(true); // enable the filter options dialog
@@ -496,7 +496,7 @@ SfxMedium* ScDocumentLoader::CreateMedium( const OUString& rFileName, std::share
const OUString& rOptions, weld::Window* pInteractionParent )
{
// Always create SfxItemSet so ScDocShell can set options.
SfxItemSet* pSet = new SfxAllItemSet( SfxGetpApp()->GetPool() );
std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet( SfxGetpApp()->GetPool() ));
if ( !rOptions.isEmpty() )
pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, rOptions ) );
@@ -508,7 +508,7 @@ SfxMedium* ScDocumentLoader::CreateMedium( const OUString& rFileName, std::share
pSet->Put(SfxUnoAnyItem(SID_INTERACTIONHANDLER, makeAny(xIHdl)));
}
SfxMedium *pRet = new SfxMedium( rFileName, StreamMode::STD_READ, pFilter, pSet );
SfxMedium *pRet = new SfxMedium( rFileName, StreamMode::STD_READ, pFilter, std::move(pSet) );
if (pInteractionParent)
pRet->UseInteractionHandler(true); // to enable the filter options dialog
return pRet;
+2 -2
View File
@@ -123,7 +123,7 @@ public:
protected:
/// Load the document.
sd::DrawDocShellRef loadURL( const OUString &rURL, sal_Int32 nFormat, SfxAllItemSet *pParams = nullptr )
sd::DrawDocShellRef loadURL( const OUString &rURL, sal_Int32 nFormat, std::unique_ptr<SfxAllItemSet> pParams = nullptr )
{
FileFormat *pFmt = getFormat(nFormat);
CPPUNIT_ASSERT_MESSAGE( "missing filter info", pFmt->pName != nullptr );
@@ -142,7 +142,7 @@ protected:
std::shared_ptr<const SfxFilter> pFilt(pFilter);
::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false, DocumentType::Impress);
SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ, pFilt, pParams);
SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ, pFilt, std::move(pParams));
if ( !xDocShRef->DoLoad(pSrcMed) || !xDocShRef.is() )
{
if (xDocShRef.is())
+2 -2
View File
@@ -431,10 +431,10 @@ SfxFrame* SdModule::CreateFromTemplate( const OUString& rTemplatePath, const Ref
SfxObjectShellLock xDocShell;
SfxItemSet* pSet = new SfxAllItemSet( SfxGetpApp()->GetPool() );
std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet( SfxGetpApp()->GetPool() ));
pSet->Put( SfxBoolItem( SID_TEMPLATE, true ) );
ErrCode lErr = SfxGetpApp()->LoadTemplate( xDocShell, rTemplatePath, pSet );
ErrCode lErr = SfxGetpApp()->LoadTemplate( xDocShell, rTemplatePath, std::move(pSet) );
SfxObjectShell* pDocShell = xDocShell;
@@ -141,10 +141,10 @@ SdPage* TemplatePageObjectProvider::operator() (SdDrawDocument*)
::sd::DrawDocShell* TemplatePageObjectProvider::LoadDocument (const OUString& sFileName)
{
SfxApplication* pSfxApp = SfxGetpApp();
SfxItemSet* pSet = new SfxAllItemSet (pSfxApp->GetPool());
std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet (pSfxApp->GetPool()));
pSet->Put (SfxBoolItem (SID_TEMPLATE, true));
pSet->Put (SfxBoolItem (SID_PREVIEW, true));
if (pSfxApp->LoadTemplate (mxDocumentShell, sFileName, pSet))
if (pSfxApp->LoadTemplate (mxDocumentShell, sFileName, std::move(pSet)))
{
mxDocumentShell = nullptr;
}
+2 -6
View File
@@ -281,7 +281,7 @@ ErrCode CheckPasswd_Impl
}
ErrCode SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const OUString &rFileName, SfxItemSet* pSet )
ErrCode SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const OUString &rFileName, std::unique_ptr<SfxItemSet> pSet )
{
std::shared_ptr<const SfxFilter> pFilter;
SfxMedium aMedium( rFileName, ( StreamMode::READ | StreamMode::SHARE_DENYNONE ) );
@@ -291,7 +291,6 @@ ErrCode SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const OUString &
if ( aMedium.GetError() )
{
delete pSet;
return aMedium.GetErrorCode();
}
@@ -299,20 +298,17 @@ ErrCode SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const OUString &
ErrCode nErr = GetFilterMatcher().GuessFilter( aMedium, pFilter, SfxFilterFlags::TEMPLATE, SfxFilterFlags::NONE );
if ( ERRCODE_NONE != nErr)
{
delete pSet;
return ERRCODE_SFX_NOTATEMPLATE;
}
if( !pFilter || !pFilter->IsAllowedAsTemplate() )
{
delete pSet;
return ERRCODE_SFX_NOTATEMPLATE;
}
if ( pFilter->GetFilterFlags() & SfxFilterFlags::STARONEFILTER )
{
DBG_ASSERT( !xDoc.Is(), "Sorry, not implemented!" );
delete pSet;
SfxStringItem aName( SID_FILE_NAME, rFileName );
SfxStringItem aReferer( SID_REFERER, OUString("private:user") );
SfxStringItem aFlags( SID_OPTIONS, OUString("T") );
@@ -343,7 +339,7 @@ ErrCode SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const OUString &
xDoc = SfxObjectShell::CreateObject( pFilter->GetServiceName() );
//pMedium takes ownership of pSet
SfxMedium *pMedium = new SfxMedium( rFileName, StreamMode::STD_READ, pFilter, pSet );
SfxMedium *pMedium = new SfxMedium( rFileName, StreamMode::STD_READ, pFilter, std::move(pSet) );
if(!xDoc->DoLoad(pMedium))
{
ErrCode nErrCode = xDoc->GetErrorCode();
+4 -4
View File
@@ -3081,20 +3081,20 @@ void SfxMedium::CompleteReOpen()
pImpl->bUseInteractionHandler = bUseInteractionHandler;
}
SfxMedium::SfxMedium(const OUString &rName, StreamMode nOpenMode, std::shared_ptr<const SfxFilter> pFilter, SfxItemSet *pInSet) :
SfxMedium::SfxMedium(const OUString &rName, StreamMode nOpenMode, std::shared_ptr<const SfxFilter> pFilter, std::unique_ptr<SfxItemSet> pInSet) :
pImpl(new SfxMedium_Impl)
{
pImpl->m_pSet.reset( pInSet );
pImpl->m_pSet = std::move( pInSet );
pImpl->m_pFilter = std::move(pFilter);
pImpl->m_aLogicName = rName;
pImpl->m_nStorOpenMode = nOpenMode;
Init_Impl();
}
SfxMedium::SfxMedium(const OUString &rName, const OUString &rReferer, StreamMode nOpenMode, std::shared_ptr<const SfxFilter> pFilter, SfxItemSet *pInSet) :
SfxMedium::SfxMedium(const OUString &rName, const OUString &rReferer, StreamMode nOpenMode, std::shared_ptr<const SfxFilter> pFilter, std::unique_ptr<SfxItemSet> pInSet) :
pImpl(new SfxMedium_Impl)
{
pImpl->m_pSet.reset( pInSet );
pImpl->m_pSet = std::move(pInSet);
SfxItemSet * s = GetItemSet();
if (s->GetItem(SID_REFERER) == nullptr) {
s->Put(SfxStringItem(SID_REFERER, rReferer));
+2 -2
View File
@@ -108,7 +108,7 @@ SfxMedium* DocumentInserter::CreateMedium(char const*const pFallbackHack)
DBG_ASSERT( m_pURLList.size() == 1, "DocumentInserter::CreateMedium(): invalid URL list count" );
pMedium.reset(new SfxMedium(
m_pURLList[0], SFX_STREAM_READONLY,
SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), m_pItemSet ));
SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), std::unique_ptr<SfxItemSet>(m_pItemSet) ));
pMedium->UseInteractionHandler( true );
std::unique_ptr<SfxFilterMatcher> pMatcher;
if ( !m_sDocFactory.isEmpty() )
@@ -145,7 +145,7 @@ SfxMediumList* DocumentInserter::CreateMediumList()
{
SfxMedium* pMedium = new SfxMedium(
url, SFX_STREAM_READONLY,
SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), m_pItemSet );
SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), std::unique_ptr<SfxItemSet>(m_pItemSet) );
pMedium->UseInteractionHandler( true );
+2 -2
View File
@@ -147,10 +147,10 @@ IMPL_LINK_NOARG(SfxNewFileDialog, Update, Timer*, void)
{
SfxErrorContext eEC(ERRCTX_SFX_LOADTEMPLATE, m_xDialog.get());
SfxApplication *pSfxApp = SfxGetpApp();
SfxItemSet* pSet = new SfxAllItemSet(pSfxApp->GetPool());
std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet(pSfxApp->GetPool()));
pSet->Put(SfxBoolItem(SID_TEMPLATE, true));
pSet->Put(SfxBoolItem(SID_PREVIEW, true));
ErrCode lErr = pSfxApp->LoadTemplate(m_xDocShell, aFileName, pSet);
ErrCode lErr = pSfxApp->LoadTemplate(m_xDocShell, aFileName, std::move(pSet));
if (lErr)
ErrorHandler::HandleError(lErr);
if (!m_xDocShell.Is())
+8 -7
View File
@@ -2512,7 +2512,7 @@ bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs )
// copy the original itemset, but remove the "version" item, because pMediumTmp
// is a new medium "from scratch", so no version should be stored into it
SfxItemSet* pSet = new SfxAllItemSet(*pRetrMedium->GetItemSet());
std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet(*pRetrMedium->GetItemSet()));
pSet->ClearItem( SID_VERSION );
pSet->ClearItem( SID_DOC_BASEURL );
@@ -2531,7 +2531,7 @@ bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs )
// create a medium as a copy; this medium is only for writing, because it
// uses the same name as the original one writing is done through a copy,
// that will be transferred to the target (of course after calling HandsOff)
SfxMedium* pMediumTmp = new SfxMedium( pRetrMedium->GetName(), pRetrMedium->GetOpenMode(), pFilter, pSet );
SfxMedium* pMediumTmp = new SfxMedium( pRetrMedium->GetName(), pRetrMedium->GetOpenMode(), pFilter, std::move(pSet) );
pMediumTmp->SetInCheckIn( pRetrMedium->IsInCheckIn( ) );
pMediumTmp->SetLongName( pRetrMedium->GetLongName() );
if ( pMediumTmp->GetErrorCode() != ERRCODE_NONE )
@@ -2771,7 +2771,7 @@ bool SfxObjectShell::CommonSaveAs_Impl(const INetURLObject& aURL, const OUString
bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString& aFilterName, SfxItemSet const & rItemSet)
{
// copy all items stored in the itemset of the current medium
SfxAllItemSet* pMergedParams = new SfxAllItemSet( *pMedium->GetItemSet() );
std::unique_ptr<SfxAllItemSet> pMergedParams(new SfxAllItemSet( *pMedium->GetItemSet() ));
// in "SaveAs" title and password will be cleared ( maybe the new itemset contains new values, otherwise they will be empty )
pMergedParams->ClearItem( SID_ENCRYPTIONDATA );
@@ -2803,16 +2803,17 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString&
pMergedParams->ClearItem( SID_DOC_SALVAGE );
// create a medium for the target URL
SfxMedium *pNewFile = new SfxMedium( rFileName, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC, nullptr, pMergedParams );
auto pMergedParamsTmp = pMergedParams.get();
SfxMedium *pNewFile = new SfxMedium( rFileName, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC, nullptr, std::move(pMergedParams) );
const SfxBoolItem* pNoFileSync = pMergedParams->GetItem<SfxBoolItem>(SID_NO_FILE_SYNC, false);
const SfxBoolItem* pNoFileSync = pMergedParamsTmp->GetItem<SfxBoolItem>(SID_NO_FILE_SYNC, false);
if (pNoFileSync && pNoFileSync->GetValue())
pNewFile->DisableFileSync(true);
bool bUseThumbnailSave = IsUseThumbnailSave();
comphelper::ScopeGuard aThumbnailGuard(
[this, bUseThumbnailSave] { this->SetUseThumbnailSave(bUseThumbnailSave); });
const SfxBoolItem* pNoThumbnail = pMergedParams->GetItem<SfxBoolItem>(SID_NO_THUMBNAIL, false);
const SfxBoolItem* pNoThumbnail = pMergedParamsTmp->GetItem<SfxBoolItem>(SID_NO_THUMBNAIL, false);
if (pNoThumbnail)
// Thumbnail generation should be avoided just for this save.
SetUseThumbnailSave(!pNoThumbnail->GetValue());
@@ -2834,7 +2835,7 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString&
}
// check if a "SaveTo" is wanted, no "SaveAs"
const SfxBoolItem* pSaveToItem = pMergedParams->GetItem<SfxBoolItem>(SID_SAVETO, false);
const SfxBoolItem* pSaveToItem = pMergedParamsTmp->GetItem<SfxBoolItem>(SID_SAVETO, false);
bool bCopyTo = GetCreateMode() == SfxObjectCreateMode::EMBEDDED || (pSaveToItem && pSaveToItem->GetValue());
// distinguish between "Save" and "SaveAs"