summaryrefslogtreecommitdiff
path: root/sw/source/ui/app
diff options
context:
space:
mode:
authorMatteo Casalin <matteo.casalin@yahoo.com>2013-08-15 13:39:11 +0200
committerPetr Mladek <pmladek@suse.cz>2013-08-16 15:50:59 +0000
commitad3188b5faf6db2ccab07a7a8901518e80e3ad25 (patch)
tree6683d04dd07f393d9a15c170b50dfd4542a96db9 /sw/source/ui/app
parent462b28770e4fa3dfa6fe4af71a6776cceb4c4640 (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/source/ui/app')
-rw-r--r--sw/source/ui/app/docsh2.cxx98
1 files changed, 98 insertions, 0 deletions
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: */