[Libreoffice-commits] core.git: 2 commits - sw/inc sw/source
Michael Stahl
mstahl at redhat.com
Wed Oct 15 14:51:22 PDT 2014
sw/inc/iodetect.hxx | 4 -
sw/source/filter/basflt/iodetect.cxx | 80 ++++++++---------------------------
sw/source/uibase/dbui/dbmgr.cxx | 2
sw/source/uibase/dochdl/swdtflvr.cxx | 3 -
4 files changed, 22 insertions(+), 67 deletions(-)
New commits:
commit 40e043ca9e23098e198f78254223701466fe1e71
Author: Michael Stahl <mstahl at redhat.com>
Date: Wed Oct 15 22:33:58 2014 +0200
sw: remove more dead code from SwIoSystem::GetFileFilter()
Change-Id: I53cadf01246faf3c4b54ee360db19bde2dcb98cc
diff --git a/sw/inc/iodetect.hxx b/sw/inc/iodetect.hxx
index fca893e..3754434 100644
--- a/sw/inc/iodetect.hxx
+++ b/sw/inc/iodetect.hxx
@@ -102,8 +102,6 @@ public:
static bool IsDetectableText( const sal_Char* pBuf, sal_uLong &rLen,
rtl_TextEncoding *pCharSet=0, bool *pSwap=0, LineEnd *pLineEnd=0, bool bEncodedFilter = false );
- static const SfxFilter* GetTextFilter( const sal_Char* pBuf, sal_uLong nLen );
-
static const OUString GetSubStorageName( const SfxFilter& rFltr );
};
diff --git a/sw/source/filter/basflt/iodetect.cxx b/sw/source/filter/basflt/iodetect.cxx
index 9c60782..66f5c6e 100644
--- a/sw/source/filter/basflt/iodetect.cxx
+++ b/sw/source/filter/basflt/iodetect.cxx
@@ -25,6 +25,9 @@
#include <tools/urlobj.hxx>
#include <unotools/moduleoptions.hxx>
+
+using namespace ::com::sun::star;
+
static bool IsDocShellRegistered()
{
return SvtModuleOptions().IsWriter();
@@ -210,7 +213,6 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName)
if ( !pFilter )
return 0;
- ::boost::scoped_ptr<SfxMedium> pMedium;
if (SotStorage::IsStorageFile(rFileName))
{
// package storage or OLEStorage based format
@@ -218,25 +220,24 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName)
INetURLObject aObj;
aObj.SetSmartProtocol( INET_PROT_FILE );
aObj.SetSmartURL( rFileName );
- pMedium.reset(new SfxMedium(aObj.GetMainURL(INetURLObject::NO_DECODE), STREAM_STD_READ));
+ SfxMedium aMedium(aObj.GetMainURL(INetURLObject::NO_DECODE), STREAM_STD_READ);
// templates should not get precedence over "normal" filters (#i35508, #i33168)
const SfxFilter* pTemplateFilter = 0;
- const SfxFilter* pOldFilter = pFCntnr->GetFilter4FilterName("");
- assert(!pOldFilter);
- bool bLookForTemplate = pOldFilter && pOldFilter->IsOwnTemplateFormat();
- if ( pMedium->IsStorage() )
+ if (aMedium.IsStorage())
{
- com::sun::star::uno::Reference < com::sun::star::embed::XStorage > xStor = pMedium->GetStorage();
+ uno::Reference<embed::XStorage> const xStor = aMedium.GetStorage();
if ( xStor.is() )
{
while ( pFilter )
{
if( 'C' == pFilter->GetUserData()[0] && IsValidStgFilter( xStor, *pFilter ) )
{
- if ( pFilter->IsOwnTemplateFormat() && !bLookForTemplate )
+ if (pFilter->IsOwnTemplateFormat())
+ {
// found template filter; maybe there's a "normal" one also
pTemplateFilter = pFilter;
+ }
else
return pFilter;
}
@@ -253,7 +254,7 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName)
{
try
{
- SvStream* pStream = pMedium->GetInStream();
+ SvStream *const pStream = aMedium.GetInStream();
if ( pStream && SotStorage::IsStorageFile(pStream) )
xStg = new SotStorage( pStream, false );
}
@@ -267,9 +268,11 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName)
{
if( 'C' == pFilter->GetUserData()[0] && IsValidStgFilter( *xStg, *pFilter ) )
{
- if ( pFilter->IsOwnTemplateFormat() && !bLookForTemplate )
+ if (pFilter->IsOwnTemplateFormat())
+ {
// found template filter; maybe there's a "normal" one also
pTemplateFilter = pFilter;
+ }
else
return pFilter;
}
@@ -287,42 +290,7 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName)
return pFilter;
}
- sal_Char aBuffer[4098];
- const sal_uLong nMaxRead = sizeof(aBuffer) - 2;
- sal_uLong nBytesRead = 0;
- if (pMedium)
- {
- SvStream* pIStrm = pMedium->GetInStream();
- if( !pIStrm || SVSTREAM_OK != pIStrm->GetError() )
- return 0;
- sal_uLong nCurrPos = pIStrm->Tell();
- nBytesRead = pIStrm->Read(aBuffer, nMaxRead);
- pIStrm->Seek( nCurrPos );
- }
-
- TerminateBuffer(aBuffer, nBytesRead, sizeof(aBuffer));
-
- {
- for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
- {
- OUString sNm(aFilterDetect[n].IsReader(aBuffer, nBytesRead));
- const SfxFilter* pFilterTmp =
- sNm.isEmpty() ? 0 : SwIoSystem::GetFilterOfFormat(sNm, pFCntnr);
- if (pFilterTmp)
- {
- return pFilterTmp;
- }
- }
- }
-
- // no filter recognized so far; thus check "WORD 4 WORD" Filter
- if( !rFileName.isEmpty() )
- {
- if( pMedium )
- pMedium->CloseInStream();
-
- }
- return SwIoSystem::GetTextFilter( aBuffer, nBytesRead);
+ return SwIoSystem::GetFilterOfFormat(OUString::createFromAscii(FILTER_TEXT), 0);
}
bool SwIoSystem::IsDetectableText(const sal_Char* pBuf, sal_uLong &rLen,
@@ -464,11 +432,4 @@ bool SwIoSystem::IsDetectableText(const sal_Char* pBuf, sal_uLong &rLen,
return bEncodedFilter || (!bIsBareUnicode && eSysLE == eLineEnd);
}
-const SfxFilter* SwIoSystem::GetTextFilter( const sal_Char* pBuf, sal_uLong nLen)
-{
- bool bAuto = IsDetectableText(pBuf, nLen);
- const sal_Char* pNm = bAuto ? FILTER_TEXT : FILTER_TEXT_DLG;
- return SwIoSystem::GetFilterOfFormat( OUString::createFromAscii(pNm), 0 );
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 3ec25899e05035ac882971637dfc9b6fa84437c9
Author: Michael Stahl <mstahl at redhat.com>
Date: Wed Oct 15 21:35:06 2014 +0200
sw: fix temp file leak in SwIoSystem::GetFileFilter()
Change-Id: Id483d58a9de27a247880aedfe6bb3fe1d410129c
diff --git a/sw/inc/iodetect.hxx b/sw/inc/iodetect.hxx
index c3ed1e2..fca893e 100644
--- a/sw/inc/iodetect.hxx
+++ b/sw/inc/iodetect.hxx
@@ -94,7 +94,7 @@ public:
/** Detect for the given file which filter should be used. The filter name
is returned. If no filter could be found, the name of the ASCII filter
is returned! */
- static const SfxFilter* GetFileFilter( const OUString& rFileName, const OUString& rPrefFltName, SfxMedium* pMedium = 0 );
+ static const SfxFilter* GetFileFilter(const OUString& rFileName);
static bool IsValidStgFilter( SotStorage& , const SfxFilter& );
static bool IsValidStgFilter( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rStg, const SfxFilter& rFilter);
diff --git a/sw/source/filter/basflt/iodetect.cxx b/sw/source/filter/basflt/iodetect.cxx
index c6fdded..9c60782 100644
--- a/sw/source/filter/basflt/iodetect.cxx
+++ b/sw/source/filter/basflt/iodetect.cxx
@@ -198,9 +198,7 @@ void TerminateBuffer(sal_Char *pBuffer, sal_uLong nBytesRead, sal_uLong nBufferL
// Check the type of the stream (file) by searching for corresponding set of bytes.
// If no known type is found, return ASCII for now!
// Returns the internal FilterName.
-// rPrefFltName is the internal FilterName that was chosen by the user in the Open Dlg.
-const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName,
- const OUString& rPrefFltName, SfxMedium* pMedium)
+const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName)
{
SfxFilterContainer aCntSw( OUString(sSWRITER) );
SfxFilterContainer aCntSwWeb( OUString(sSWRITERWEB) );
@@ -212,21 +210,20 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName,
if ( !pFilter )
return 0;
- if( pMedium ? ( pMedium->IsStorage() || SotStorage::IsStorageFile( pMedium->GetInStream() ) ) : SotStorage::IsStorageFile( rFileName ) )
+ ::boost::scoped_ptr<SfxMedium> pMedium;
+ if (SotStorage::IsStorageFile(rFileName))
{
// package storage or OLEStorage based format
SotStorageRef xStg;
- if (!pMedium )
- {
- INetURLObject aObj;
- aObj.SetSmartProtocol( INET_PROT_FILE );
- aObj.SetSmartURL( rFileName );
- pMedium = new SfxMedium( aObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ );
- }
+ INetURLObject aObj;
+ aObj.SetSmartProtocol( INET_PROT_FILE );
+ aObj.SetSmartURL( rFileName );
+ pMedium.reset(new SfxMedium(aObj.GetMainURL(INetURLObject::NO_DECODE), STREAM_STD_READ));
// templates should not get precedence over "normal" filters (#i35508, #i33168)
const SfxFilter* pTemplateFilter = 0;
- const SfxFilter* pOldFilter = pFCntnr->GetFilter4FilterName( rPrefFltName );
+ const SfxFilter* pOldFilter = pFCntnr->GetFilter4FilterName("");
+ assert(!pOldFilter);
bool bLookForTemplate = pOldFilter && pOldFilter->IsOwnTemplateFormat();
if ( pMedium->IsStorage() )
{
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index a39ad54..141f9a2 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -867,7 +867,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
if( bMergeShell || !pSourceDocSh->IsModified() )
{
const SfxFilter* pStoreToFilter = SwIoSystem::GetFileFilter(
- pSourceDocSh->GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), ::aEmptyOUStr );
+ pSourceDocSh->GetMedium()->GetURLObject().GetMainURL(INetURLObject::NO_DECODE));
SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
const OUString* pStoreToFilterOptions = 0;
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index 18f79a5..14ce7d6 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -2570,8 +2570,7 @@ bool SwTransferable::_PasteFileName( TransferableDataHelper& rData,
//Own FileFormat? --> insert, not for StarWriter/Web
OUString sFileURL = URIHelper::SmartRel2Abs(INetURLObject(), sFile, Link(), false );
const SfxFilter* pFlt = SW_PASTESDR_SETATTR == nAction
- ? 0 : SwIoSystem::GetFileFilter(
- sFileURL, aEmptyOUStr );
+ ? 0 : SwIoSystem::GetFileFilter(sFileURL);
if( pFlt && !rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
{
// and then pull up the insert-region-dialog by PostUser event
More information about the Libreoffice-commits
mailing list