[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - 3 commits - desktop/source include/LibreOfficeKit

Jan Holesovsky kendy at collabora.com
Wed Feb 10 12:33:08 UTC 2016


 desktop/source/lib/init.cxx               |   42 ++++++++++++++++++++++++++----
 include/LibreOfficeKit/LibreOfficeKit.hxx |    5 +++
 2 files changed, 42 insertions(+), 5 deletions(-)

New commits:
commit 14aa9b0a818ca23efdf07a618ae493c7e7397752
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Feb 10 13:26:50 2016 +0100

    lok: Introduce a "TakeOwnership" filter option for saveAs().
    
    It is consumed by the saveAs() itself, and when provided, the document
    identity changes to the provided pUrl - meaning that '.uno:ModifiedStatus' is
    triggered as with the "Save As..." in the UI.
    
    This mode must not be used when saving to PNG or PDF.
    
    Change-Id: I11b5aa814476a8dcab9eac5202bd052828ebbd96

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 507e4f8..d5bec92 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -674,6 +674,30 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
 
         OUString aFilterOptions = getUString(pFilterOptions);
 
+        // 'TakeOwnership' == this is a 'real' SaveAs (that is, the document
+        // gets a new name).  When this is not provided, the meaning of
+        // saveAs() is more like save-a-copy, which allows saving to any
+        // random format like PDF or PNG.
+        // It is not a real filter option, so we have to filter it out.
+        bool bTakeOwnership = false;
+        int nIndex = -1;
+        if (aFilterOptions == "TakeOwnership")
+        {
+            bTakeOwnership = true;
+            aFilterOptions = "";
+        }
+        else if ((nIndex = aFilterOptions.indexOf(",TakeOwnership")) >= 0 || (nIndex = aFilterOptions.indexOf("TakeOwnership,")) >= 0)
+        {
+            OUString aFiltered;
+            if (nIndex > 0)
+                aFiltered = aFilterOptions.copy(0, nIndex);
+            if (nIndex + 14 < aFilterOptions.getLength())
+                aFiltered = aFiltered + aFilterOptions.copy(nIndex + 14);
+
+            bTakeOwnership = true;
+            aFilterOptions = aFiltered;
+        }
+
         MediaDescriptor aSaveMediaDescriptor;
         aSaveMediaDescriptor["Overwrite"] <<= sal_True;
         aSaveMediaDescriptor["FilterName"] <<= aFilterName;
@@ -691,7 +715,11 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
         }
 
         uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW);
-        xStorable->storeToURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList());
+
+        if (bTakeOwnership)
+            xStorable->storeAsURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList());
+        else
+            xStorable->storeToURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList());
 
         return true;
     }
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 1f2311a..84741e0 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -45,6 +45,11 @@ public:
      * @param pUrl the location where to store the document
      * @param pFormat the format to use while exporting, when omitted, then deducted from pURL's extension
      * @param pFilterOptions options for the export filter, e.g. SkipImages.
+     *        Another useful FilterOption is "TakeOwnership".  It is consumed
+     *        by the saveAs() itself, and when provided, the document identity
+     *        changes to the provided pUrl - meaning that '.uno:ModifiedStatus'
+     *        is triggered as with the "Save As..." in the UI.
+     *        "TakeOwnership" mode must not be used when saving to PNG or PDF.
      */
     inline bool saveAs(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL)
     {
commit 552ae012bd0321995a0b44501704e408f1d9d006
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Mon Feb 8 20:09:37 2016 +0100

    lok: Interaction handler for saveAs() too.
    
    The LOK does not have to be fully initialized, eg. during the unit tests.
    
    Change-Id: I11bb8db37c92b05e2c1ad06e1a6632db7fb0ea60

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index a3174fc..507e4f8 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -680,11 +680,15 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
         aSaveMediaDescriptor[MediaDescriptor::PROP_FILTEROPTIONS()] <<= aFilterOptions;
 
         // add interaction handler too
-        rtl::Reference<LOKInteractionHandler> const pInteraction(
-            new LOKInteractionHandler(::comphelper::getProcessComponentContext(), "saveas", gImpl, pDocument));
-        uno::Reference<task::XInteractionHandler2> const xInteraction(pInteraction.get());
+        if (gImpl)
+        {
+            // gImpl does not have to exist when running from a unit test
+            rtl::Reference<LOKInteractionHandler> const pInteraction(
+                    new LOKInteractionHandler(::comphelper::getProcessComponentContext(), "saveas", gImpl, pDocument));
+            uno::Reference<task::XInteractionHandler2> const xInteraction(pInteraction.get());
 
-        aSaveMediaDescriptor[MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= xInteraction;
+            aSaveMediaDescriptor[MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= xInteraction;
+        }
 
         uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW);
         xStorable->storeToURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList());
commit ac859e71e58329e52ba402ca69537778d196091f
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Feb 10 11:01:06 2016 +0100

    Revert "lok: Take over the identity of the document when performing saveAs()."
    
    This was not a good idea, breaks the export to pdf or png.
    
    This reverts commit 949664deadc04829087af1f6cf4d88b9a2d34114.

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index bd60e20..a3174fc 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -687,7 +687,7 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
         aSaveMediaDescriptor[MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= xInteraction;
 
         uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW);
-        xStorable->storeAsURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList());
+        xStorable->storeToURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList());
 
         return true;
     }


More information about the Libreoffice-commits mailing list