Blob Blame History Raw
From ea40b8b14d830f5025a3fe2e9da9163b83a843e5 Mon Sep 17 00:00:00 2001
From: Eike Rathke <erack@redhat.com>
Date: Wed, 27 Nov 2013 00:04:44 +0100
Subject: [PATCH 013/109] resolved fdo#53103 actually use the external data
 filter options

ScDocShell::ConvertFrom() queries the filter options from the SfxItemSet
at SfxMedium, which is fine when loading the data into the table
selector first, but the final load via ScAreaLink created a bare
SfxMedium without options set. Do so.

Additionally it may now even work that ScDocShell sets options at
SfxMedium, which the ScAreaLink code prepared for but previously the
SfxMedium did not have an SfxItemSet.

Change-Id: I45d6a24906dc3ba41654b8c0951dd84939d8af5e
(cherry picked from commit 513eadd422ff6a41cfe9a16f82cf32872d729652)
Reviewed-on: https://gerrit.libreoffice.org/6823
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
---
 sc/inc/tablink.hxx                 |  8 +++++++-
 sc/source/ui/docshell/arealink.cxx |  2 +-
 sc/source/ui/docshell/tablink.cxx  | 18 ++++++++++++------
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/sc/inc/tablink.hxx b/sc/inc/tablink.hxx
index 068d87f..49833af 100644
--- a/sc/inc/tablink.hxx
+++ b/sc/inc/tablink.hxx
@@ -72,6 +72,7 @@ public:
 
 class ScDocument;
 class SfxMedium;
+class SfxFilter;
 
 class SC_DLLPUBLIC ScDocumentLoader
 {
@@ -96,7 +97,12 @@ public:
 
     void                ReleaseDocRef();    // without calling DoClose
 
-    static OUString GetOptions( SfxMedium& rMedium );
+    /** Create SfxMedium for stream read with SfxFilter and filter options set
+        at the medium's SfxItemSet.
+     */
+    static SfxMedium*   CreateMedium( const OUString& rFileName, const SfxFilter* pFilter, const OUString& rOptions );
+
+    static OUString     GetOptions( SfxMedium& rMedium );
 
     /** Returns the filter name and options from a file name.
         @param bWithContent
diff --git a/sc/source/ui/docshell/arealink.cxx b/sc/source/ui/docshell/arealink.cxx
index 6409fbd..f80c80a 100644
--- a/sc/source/ui/docshell/arealink.cxx
+++ b/sc/source/ui/docshell/arealink.cxx
@@ -253,7 +253,7 @@ sal_Bool ScAreaLink::Refresh( const String& rNewFile, const String& rNewFilter,
     if ( rNewFilter != aFilterName )
         aOptions.Erase();
 
-    SfxMedium* pMed = new SfxMedium(aNewUrl, STREAM_STD_READ, pFilter);
+    SfxMedium* pMed = ScDocumentLoader::CreateMedium( aNewUrl, pFilter, aOptions);
 
     // aRef->DoClose() will be closed explicitly, but it is still more safe to use SfxObjectShellLock here
     ScDocShell* pSrcShell = new ScDocShell(SFX_CREATE_MODE_INTERNAL);
diff --git a/sc/source/ui/docshell/tablink.cxx b/sc/source/ui/docshell/tablink.cxx
index ba1ed72..0164e27 100644
--- a/sc/source/ui/docshell/tablink.cxx
+++ b/sc/source/ui/docshell/tablink.cxx
@@ -519,6 +519,17 @@ void ScDocumentLoader::RemoveAppPrefix( OUString& rFilterName )
         rFilterName = rFilterName.copy( aAppPrefix.getLength());
 }
 
+SfxMedium* ScDocumentLoader::CreateMedium( const OUString& rFileName, const SfxFilter* pFilter,
+        const OUString& rOptions )
+{
+    // Always create SfxItemSet so ScDocShell can set options.
+    SfxItemSet* pSet = new SfxAllItemSet( SFX_APP()->GetPool() );
+    if ( !rOptions.isEmpty() )
+        pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, rOptions ) );
+
+    return new SfxMedium( rFileName, STREAM_STD_READ, pFilter, pSet );
+}
+
 ScDocumentLoader::ScDocumentLoader( const OUString& rFileName,
                                     OUString& rFilterName, OUString& rOptions,
                                     sal_uInt32 nRekCnt, bool bWithInteraction ) :
@@ -530,12 +541,7 @@ ScDocumentLoader::ScDocumentLoader( const OUString& rFileName,
 
     const SfxFilter* pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( rFilterName );
 
-    //  ItemSet immer anlegen, damit die DocShell die Optionen setzen kann
-    SfxItemSet* pSet = new SfxAllItemSet( SFX_APP()->GetPool() );
-    if ( !rOptions.isEmpty() )
-        pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, rOptions ) );
-
-    pMedium = new SfxMedium( rFileName, STREAM_STD_READ, pFilter, pSet );
+    pMedium = CreateMedium( rFileName, pFilter, rOptions);
     if ( pMedium->GetError() != ERRCODE_NONE )
         return ;
 
-- 
1.8.4.2