[Libreoffice-commits] core.git: dbaccess/source include/sfx2 offapi/com sfx2/source sw/PythonTest_sw_python.mk sw/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Dec 17 12:59:18 UTC 2018


 dbaccess/source/core/dataaccess/databasedocument.cxx |    6 +
 dbaccess/source/core/dataaccess/databasedocument.hxx |    1 
 include/sfx2/sfxbasemodel.hxx                        |    2 
 offapi/com/sun/star/frame/XModel2.idl                |   21 ++++++
 sfx2/source/doc/sfxbasemodel.cxx                     |   30 +++++++++
 sw/PythonTest_sw_python.mk                           |    1 
 sw/qa/python/check_xmodel.py                         |   59 +++++++++++++++++++
 7 files changed, 120 insertions(+)

New commits:
commit 43a63b725208bfa378355011ea56cb936afa4411
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Thu Dec 13 09:09:52 2018 +0100
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Mon Dec 17 13:58:56 2018 +0100

    Allow setting some MediaDescriptor properties during runtime
    
    Change-Id: Id6bb554c0e165c6d1f9c28c48fdbcd7156f42316
    Reviewed-on: https://gerrit.libreoffice.org/65256
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx
index e84af4dfe653..c20bb36c3566 100644
--- a/dbaccess/source/core/dataaccess/databasedocument.cxx
+++ b/dbaccess/source/core/dataaccess/databasedocument.cxx
@@ -44,6 +44,7 @@
 #include <com/sun/star/io/XSeekable.hpp>
 #include <com/sun/star/io/XOutputStream.hpp>
 #include <com/sun/star/io/XTruncate.hpp>
+#include <com/sun/star/lang/NoSupportException.hpp>
 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
 #include <com/sun/star/script/provider/theMasterScriptProviderFactory.hpp>
 #include <com/sun/star/sdb/DatabaseContext.hpp>
@@ -797,6 +798,11 @@ Sequence< PropertyValue > SAL_CALL ODatabaseDocument::getArgs(  )
     return m_pImpl->getMediaDescriptor().getPropertyValues();
 }
 
+void SAL_CALL ODatabaseDocument::setArgs(const Sequence<beans::PropertyValue>& /* aArgs */)
+{
+    throw NoSupportException();
+}
+
 void SAL_CALL ODatabaseDocument::connectController( const Reference< XController >& _xController )
 {
     DocumentGuard aGuard(*this, DocumentGuard::DefaultMethod);
diff --git a/dbaccess/source/core/dataaccess/databasedocument.hxx b/dbaccess/source/core/dataaccess/databasedocument.hxx
index df5765855df7..8a951d61d868 100644
--- a/dbaccess/source/core/dataaccess/databasedocument.hxx
+++ b/dbaccess/source/core/dataaccess/databasedocument.hxx
@@ -328,6 +328,7 @@ public:
     virtual css::uno::Sequence< OUString > SAL_CALL getAvailableViewControllerNames(  ) override ;
     virtual css::uno::Reference< css::frame::XController2 > SAL_CALL createDefaultViewController( const css::uno::Reference< css::frame::XFrame >& Frame ) override ;
     virtual css::uno::Reference< css::frame::XController2 > SAL_CALL createViewController( const OUString& ViewName, const css::uno::Sequence< css::beans::PropertyValue >& Arguments, const css::uno::Reference< css::frame::XFrame >& Frame ) override ;
+    virtual void SAL_CALL setArgs(const css::uno::Sequence<css::beans::PropertyValue>& aArgs) override;
 
     // XStorable
     virtual sal_Bool SAL_CALL hasLocation(  ) override ;
diff --git a/include/sfx2/sfxbasemodel.hxx b/include/sfx2/sfxbasemodel.hxx
index 8c513d515f3f..d885f1385333 100644
--- a/include/sfx2/sfxbasemodel.hxx
+++ b/include/sfx2/sfxbasemodel.hxx
@@ -336,6 +336,8 @@ public:
                                                                                           const css::uno::Sequence< css::beans::PropertyValue >& Arguments      ,
                                                                                           const css::uno::Reference< css::frame::XFrame >&       Frame          ) override;
 
+    virtual void SAL_CALL setArgs(const css::uno::Sequence<css::beans::PropertyValue>& aArgs) override;
+
 
     //  XModifiable2
 
diff --git a/offapi/com/sun/star/frame/XModel2.idl b/offapi/com/sun/star/frame/XModel2.idl
index 0a0e15f1b738..41d44512149a 100644
--- a/offapi/com/sun/star/frame/XModel2.idl
+++ b/offapi/com/sun/star/frame/XModel2.idl
@@ -24,6 +24,7 @@
 #include <com/sun/star/container/XEnumeration.idl>
 #include <com/sun/star/awt/XWindow.idl>
 #include <com/sun/star/lang/IllegalArgumentException.idl>
+#include <com/sun/star/util/InvalidStateException.idl>
 
 
  module com {  module sun {  module star {  module frame {
@@ -129,6 +130,26 @@ interface XModel2 : com::sun::star::frame::XModel
                                                               [in]  com::sun::star::frame::XFrame                    Frame          )
         raises (com::sun::star::lang::IllegalArgumentException,
                 com::sun::star::uno::Exception                );
+
+    /** Sets com::sun::star::document::MediaDescriptor properties
+        of the current model during runtime.
+
+        @since LibreOffice 6.3
+
+        @param Arguments
+            Properties which should be set
+            Supported properties:
+            <ul>
+                <li>com::sun::star::document::MediaDescriptor::SuggestedSaveAsDir</li>
+                <li>com::sun::star::document::MediaDescriptor::SuggestedSaveAsName</li>
+            </ul>
+
+        @throws com::sun::star::lang::IllegalArgumentException When trying to set an unsupported property
+        @throws com::sun::star::util::InvalidStateException When the document model can not be retrieved
+     */
+    void setArgs([in] sequence< com::sun::star::beans::PropertyValue > Arguments)
+        raises(com::sun::star::lang::IllegalArgumentException,
+               com::sun::star::util::InvalidStateException);
 };
 
 
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index 76be8c85d969..216bc94a8340 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -55,6 +55,7 @@
 #include <com/sun/star/ucb/ContentCreationException.hpp>
 #include <com/sun/star/ucb/CommandAbortedException.hpp>
 #include <com/sun/star/util/XCloneable.hpp>
+#include <com/sun/star/util/InvalidStateException.hpp>
 #include <comphelper/enumhelper.hxx>
 
 #include <cppuhelper/implbase.hxx>
@@ -1037,6 +1038,35 @@ Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getArgs()
     return m_pData->m_seqArguments;
 }
 
+void SAL_CALL SfxBaseModel::setArgs(const Sequence<beans::PropertyValue>& aArgs)
+{
+    SfxMedium* pMedium = m_pData->m_pObjectShell->GetMedium();
+    if (!pMedium)
+    {
+        throw util::InvalidStateException(
+            "Medium could not be retrieved, unable to execute setArgs");
+    }
+
+    for (int i = 0; i < aArgs.getLength(); i++)
+    {
+        OUString sValue;
+        aArgs[i].Value >>= sValue;
+
+        if (aArgs[i].Name == "SuggestedSaveAsName")
+        {
+            pMedium->GetItemSet()->Put(SfxStringItem(SID_SUGGESTEDSAVEASNAME, sValue));
+        }
+        else if (aArgs[i].Name == "SuggestedSaveAsDir")
+        {
+            pMedium->GetItemSet()->Put(SfxStringItem(SID_SUGGESTEDSAVEASDIR, sValue));
+        }
+        else
+        {
+            throw lang::IllegalArgumentException("Setting property not supported: " + aArgs[i].Name,
+                                                 comphelper::getProcessComponentContext(), 0);
+        }
+    }
+}
 
 //  frame::XModel
 
diff --git a/sw/PythonTest_sw_python.mk b/sw/PythonTest_sw_python.mk
index 4f97724d835c..8250da21dc6d 100644
--- a/sw/PythonTest_sw_python.mk
+++ b/sw/PythonTest_sw_python.mk
@@ -29,6 +29,7 @@ $(eval $(call gb_PythonTest_add_modules,sw_python,$(SRCDIR)/sw/qa/python,\
 	check_xautotextcontainer \
 	check_xautotextgroup \
 	check_xmodifiable2 \
+	check_xmodel \
 	check_xnamedgraph \
 	check_xrefreshable \
 	check_xtextrangecompare \
diff --git a/sw/qa/python/check_xmodel.py b/sw/qa/python/check_xmodel.py
new file mode 100644
index 000000000000..c5374c03c350
--- /dev/null
+++ b/sw/qa/python/check_xmodel.py
@@ -0,0 +1,59 @@
+#! /usr/bin/env python
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+import unittest
+import unohelper
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.lang import IllegalArgumentException
+from com.sun.star.beans import PropertyValue
+import uno
+
+
+class TestXModel(unittest.TestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls._uno = UnoInProcess()
+        cls._uno.setUp()
+
+    @classmethod
+    def tearDownClass(cls):
+        cls._uno.tearDown()
+
+    def test_setArgs_valid(self):
+        xDoc = self._uno.openEmptyWriterDoc()
+        self.assertIsNotNone(xDoc)
+
+        p1 = PropertyValue(Name="SuggestedSaveAsName", Value="prettyFileName")
+        p2 = PropertyValue(Name="SuggestedSaveAsDir", Value="/my/dir")
+        xDoc.setArgs([p1, p2])
+
+        # Make sure that all properties are returned with getArgs()
+        args = xDoc.getArgs()
+        self.assertTrue(p1 in args)
+        self.assertTrue(p2 in args)
+
+        xDoc.close(True)
+
+    def test_setArgs_invalid(self):
+        xDoc = self._uno.openEmptyWriterDoc()
+        self.assertIsNotNone(xDoc)
+
+        # IllegalArgumentException should be thrown when setting a non-existing property
+        p1 = PropertyValue(Name="PropertyNotExists", Value="doesntmatter")
+        with self.assertRaises(IllegalArgumentException):
+            xDoc.setArgs([p1])
+
+        xDoc.close(True)
+
+
+if __name__ == '__main__':
+    unittest.main()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:


More information about the Libreoffice-commits mailing list