diff options
author | Matteo Casalin <matteo.casalin@yahoo.com> | 2013-08-15 13:39:11 +0200 |
---|---|---|
committer | Petr Mladek <pmladek@suse.cz> | 2013-08-16 15:50:59 +0000 |
commit | ad3188b5faf6db2ccab07a7a8901518e80e3ad25 (patch) | |
tree | 6683d04dd07f393d9a15c170b50dfd4542a96db9 /sw | |
parent | 462b28770e4fa3dfa6fe4af71a6776cceb4c4640 (diff) |
sw_FindDocShell(): better place and name + String to OUString
Change-Id: I345a2802b4428c607297cbe6972c5b7aebc5de0b
Reviewed-on: https://gerrit.libreoffice.org/5439
Reviewed-by: Petr Mladek <pmladek@suse.cz>
Tested-by: Petr Mladek <pmladek@suse.cz>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/docsh.hxx | 15 | ||||
-rw-r--r-- | sw/source/core/docnode/section.cxx | 108 | ||||
-rw-r--r-- | sw/source/ui/app/docsh2.cxx | 98 | ||||
-rw-r--r-- | sw/source/ui/uiview/view2.cxx | 11 |
4 files changed, 117 insertions, 115 deletions
diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx index e060cb7cd04e..efa659b47024 100644 --- a/sw/inc/docsh.hxx +++ b/sw/inc/docsh.hxx @@ -305,6 +305,21 @@ class Graphic; /// implemented in source/ui/docvw/romenu.cxx String ExportGraphic( const Graphic &rGraphic, const String &rGrfName ); +/** Find the right DocShell and create a new one: + The return value specifies what should happen to the Shell + 0 - Error, could not find the DocShell + 1 - DocShell is an existing Document + 2 - DocShell was created anew, thus it needs to be closed again + (will be assigned to xLockRef additionally) +*/ +int SwFindDocShell( SfxObjectShellRef& xDocSh, + SfxObjectShellLock& xLockRef, + const OUString& rFileName, + const OUString& rPasswd, + const OUString& rFilter, + sal_Int16 nVersion, + SwDocShell* pDestSh ); + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx index d243448c098a..6f607e7740b9 100644 --- a/sw/source/core/docnode/section.cxx +++ b/sw/source/core/docnode/section.cxx @@ -1175,112 +1175,6 @@ static void lcl_UpdateLinksInSect( SwBaseLink& rUpdLnk, SwSectionNode& rSectNd ) } -// Find the right DocShell and create a new one: -// The return value specifies what should happen to the Shell -// 0 - Error, could not find the DocShell -// 1 - DocShell is an existing Document -// 2 - DocShell was created anew, thus it needs to be closed again -// (will be assigned to xLockRef additionally) -int sw_FindDocShell( SfxObjectShellRef& xDocSh, - SfxObjectShellLock& xLockRef, - const String& rFileName, - const String& rPasswd, - String& rFilter, - sal_Int16 nVersion, - SwDocShell* pDestSh ) -{ - if( !rFileName.Len() ) - return 0; - - // 1. Does the file already exist in the list of all Documents? - INetURLObject aTmpObj( rFileName ); - aTmpObj.SetMark( aEmptyStr ); - - // Iterate over the DocShell and get the ones with the name - TypeId aType( TYPE(SwDocShell) ); - - SfxObjectShell* pShell = pDestSh; - bool bFirst = 0 != pShell; - - if( !bFirst ) - // No DocShell passed, starting with the first from the DocShell list - pShell = SfxObjectShell::GetFirst( &aType ); - - while( pShell ) - { - // We want this one - SfxMedium* pMed = pShell->GetMedium(); - if( pMed && pMed->GetURLObject() == aTmpObj ) - { - const SfxPoolItem* pItem; - if( ( SFX_ITEM_SET == pMed->GetItemSet()->GetItemState( - SID_VERSION, sal_False, &pItem ) ) - ? (nVersion == ((SfxInt16Item*)pItem)->GetValue()) - : !nVersion ) - { - // Found, thus return - xDocSh = pShell; - return 1; - } - } - - if( bFirst ) - { - bFirst = false; - pShell = SfxObjectShell::GetFirst( &aType ); - } - else - pShell = SfxObjectShell::GetNext( *pShell, &aType ); - } - - // 2. Open the file ourselves - SfxMedium* pMed = new SfxMedium( aTmpObj.GetMainURL( - INetURLObject::NO_DECODE ), STREAM_READ ); - if( INET_PROT_FILE == aTmpObj.GetProtocol() ) - pMed->DownLoad(); // Touch the medium (download it) - - const SfxFilter* pSfxFlt = 0; - if( !pMed->GetError() ) - { - String sFactory(OUString::createFromAscii(SwDocShell::Factory().GetShortName())); - SfxFilterMatcher aMatcher( sFactory ); - - // No Filter, so search for it. Else test if the one passed is a valid one - if( rFilter.Len() ) - { - pSfxFlt = aMatcher.GetFilter4FilterName( rFilter ); - } - - if( nVersion ) - pMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion )); - - if( rPasswd.Len() ) - pMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd )); - - if( !pSfxFlt ) - aMatcher.DetectFilter( *pMed, &pSfxFlt, sal_False, sal_False ); - - if( pSfxFlt ) - { - // We cannot do anything without a Filter - pMed->SetFilter( pSfxFlt ); - - // If the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure - xLockRef = new SwDocShell( SFX_CREATE_MODE_INTERNAL ); - xDocSh = (SfxObjectShell*)xLockRef; - if( xDocSh->DoLoad( pMed ) ) - return 2; - } - } - - if( !xDocSh.Is() ) // Medium still needs to be deleted - delete pMed; - - return 0; -} - - - ::sfx2::SvBaseLink::UpdateResult SwIntrnlSectRefLink::DataChanged( const String& rMimeType, const uno::Any & rValue ) { @@ -1373,7 +1267,7 @@ int sw_FindDocShell( SfxObjectShellRef& xDocSh, } else { - nRet = sw_FindDocShell( xDocSh, xLockRef, sFileName, + nRet = SwFindDocShell( xDocSh, xLockRef, sFileName, rSection.GetLinkFilePassword(), sFilter, 0, pDoc->GetDocShell() ); if( nRet ) diff --git a/sw/source/ui/app/docsh2.cxx b/sw/source/ui/app/docsh2.cxx index ab2781bcbd6f..c13402764d34 100644 --- a/sw/source/ui/app/docsh2.cxx +++ b/sw/source/ui/app/docsh2.cxx @@ -1494,4 +1494,102 @@ SfxInPlaceClient* SwDocShell::GetIPClient( const ::svt::EmbeddedObjectRef& xObjR return pResult; } + +int SwFindDocShell( SfxObjectShellRef& xDocSh, + SfxObjectShellLock& xLockRef, + const OUString& rFileName, + const OUString& rPasswd, + const OUString& rFilter, + sal_Int16 nVersion, + SwDocShell* pDestSh ) +{ + if ( rFileName.isEmpty() ) + return 0; + + // 1. Does the file already exist in the list of all Documents? + INetURLObject aTmpObj( rFileName ); + aTmpObj.SetMark( OUString() ); + + // Iterate over the DocShell and get the ones with the name + TypeId aType( TYPE(SwDocShell) ); + + SfxObjectShell* pShell = pDestSh; + bool bFirst = 0 != pShell; + + if( !bFirst ) + // No DocShell passed, starting with the first from the DocShell list + pShell = SfxObjectShell::GetFirst( &aType ); + + while( pShell ) + { + // We want this one + SfxMedium* pMed = pShell->GetMedium(); + if( pMed && pMed->GetURLObject() == aTmpObj ) + { + const SfxPoolItem* pItem; + if( ( SFX_ITEM_SET == pMed->GetItemSet()->GetItemState( + SID_VERSION, sal_False, &pItem ) ) + ? (nVersion == ((SfxInt16Item*)pItem)->GetValue()) + : !nVersion ) + { + // Found, thus return + xDocSh = pShell; + return 1; + } + } + + if( bFirst ) + { + bFirst = false; + pShell = SfxObjectShell::GetFirst( &aType ); + } + else + pShell = SfxObjectShell::GetNext( *pShell, &aType ); + } + + // 2. Open the file ourselves + SfxMedium* pMed = new SfxMedium( aTmpObj.GetMainURL( + INetURLObject::NO_DECODE ), STREAM_READ ); + if( INET_PROT_FILE == aTmpObj.GetProtocol() ) + pMed->DownLoad(); // Touch the medium (download it) + + const SfxFilter* pSfxFlt = 0; + if( !pMed->GetError() ) + { + SfxFilterMatcher aMatcher( OUString::createFromAscii(SwDocShell::Factory().GetShortName()) ); + + // No Filter, so search for it. Else test if the one passed is a valid one + if( !rFilter.isEmpty() ) + { + pSfxFlt = aMatcher.GetFilter4FilterName( rFilter ); + } + + if( nVersion ) + pMed->GetItemSet()->Put( SfxInt16Item( SID_VERSION, nVersion )); + + if( !rPasswd.isEmpty() ) + pMed->GetItemSet()->Put( SfxStringItem( SID_PASSWORD, rPasswd )); + + if( !pSfxFlt ) + aMatcher.DetectFilter( *pMed, &pSfxFlt, sal_False, sal_False ); + + if( pSfxFlt ) + { + // We cannot do anything without a Filter + pMed->SetFilter( pSfxFlt ); + + // If the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure + xLockRef = new SwDocShell( SFX_CREATE_MODE_INTERNAL ); + xDocSh = (SfxObjectShell*)xLockRef; + if( xDocSh->DoLoad( pMed ) ) + return 2; + } + } + + if( !xDocSh.Is() ) // Medium still needs to be deleted + delete pMed; + + return 0; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/uiview/view2.cxx b/sw/source/ui/uiview/view2.cxx index c68f6163b4b9..04ae139e18c3 100644 --- a/sw/source/ui/uiview/view2.cxx +++ b/sw/source/ui/uiview/view2.cxx @@ -2177,13 +2177,8 @@ long SwView::InsertMedium( sal_uInt16 nSlotId, SfxMedium* pMedium, sal_Int16 nVe SfxObjectShellRef xDocSh; SfxObjectShellLock xLockRef; - extern int sw_FindDocShell( SfxObjectShellRef& xDocSh, SfxObjectShellLock& xLockRef, - const String& rFileName, const String& rPasswd, - String& rFilter, sal_Int16 nVersion, - SwDocShell* pDestSh ); - String sFltNm; - int nRet = sw_FindDocShell( xDocSh, xLockRef, pMedium->GetName(), aEmptyStr, + const int nRet = SwFindDocShell( xDocSh, xLockRef, pMedium->GetName(), OUString(), sFltNm, nVersion, pDocSh ); if( nRet ) { @@ -2204,9 +2199,9 @@ long SwView::InsertMedium( sal_uInt16 nSlotId, SfxMedium* pMedium, sal_Int16 nVe Window* pWin = &GetEditWin(); InfoBox(pWin, SW_RES(MSG_NO_MERGE_ENTRY)).Execute(); } + if( nRet==2 && xDocSh.Is() ) + xDocSh->DoClose(); } - if( 2 == nRet && xDocSh.Is() ) - xDocSh->DoClose(); } delete pMedium; |