Kaydet (Commit) 43a63b72 authored tarafından Samuel Mehrbrodt's avatar Samuel Mehrbrodt

Allow setting some MediaDescriptor properties during runtime

Change-Id: Id6bb554c0e165c6d1f9c28c48fdbcd7156f42316
Reviewed-on: https://gerrit.libreoffice.org/65256Reviewed-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Tested-by: 's avatarSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
üst 397195cd
......@@ -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);
......
......@@ -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 ;
......
......@@ -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
......
......@@ -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);
};
......
......@@ -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
......
......@@ -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 \
......
#! /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:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment