Kaydet (Commit) 7bcf64c2 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Add isReadOnly() support to simplified configuration access

[API CHANGE]: extends the css.configuration.XReadWriteAccess in an incompatible
way, but that is unpublished, has been commented as "still unpublished and
unstable," and was specifically introduced for internal use by the simplified
configuration access, so should not affect 3rd party code.

Change-Id: I99ce045f5bd8c598e689d46fb0d3626dfaa6d0a0
üst f14e4cff
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <cassert> #include <cassert>
#include <memory> #include <memory>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/configuration/ReadOnlyAccess.hpp> #include <com/sun/star/configuration/ReadOnlyAccess.hpp>
#include <com/sun/star/configuration/ReadWriteAccess.hpp> #include <com/sun/star/configuration/ReadWriteAccess.hpp>
#include <com/sun/star/configuration/XReadWriteAccess.hpp> #include <com/sun/star/configuration/XReadWriteAccess.hpp>
...@@ -116,11 +117,21 @@ comphelper::detail::ConfigurationWrapper::get( ...@@ -116,11 +117,21 @@ comphelper::detail::ConfigurationWrapper::get(
comphelper::detail::ConfigurationWrapper::ConfigurationWrapper( comphelper::detail::ConfigurationWrapper::ConfigurationWrapper(
css::uno::Reference< css::uno::XComponentContext > const & context): css::uno::Reference< css::uno::XComponentContext > const & context):
context_(context), context_(context),
access_(css::configuration::ReadOnlyAccess::create(context, "*")) access_(css::configuration::ReadWriteAccess::create(context, "*"))
{} {}
comphelper::detail::ConfigurationWrapper::~ConfigurationWrapper() {} comphelper::detail::ConfigurationWrapper::~ConfigurationWrapper() {}
bool comphelper::detail::ConfigurationWrapper::isReadOnly(OUString const & path)
const
{
css::beans::Property SB(access_->getPropertyByHierarchicalName(path));
return
(access_->getPropertyByHierarchicalName(path).Attributes
& css::beans::PropertyAttribute::READONLY)
!= 0;
}
css::uno::Any comphelper::detail::ConfigurationWrapper::getPropertyValue( css::uno::Any comphelper::detail::ConfigurationWrapper::getPropertyValue(
OUString const & path) const OUString const & path) const
{ {
......
...@@ -104,6 +104,19 @@ private: ...@@ -104,6 +104,19 @@ private:
throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
{ return getRoot()->getPendingChanges(); } { return getRoot()->getPendingChanges(); }
css::beans::Property SAL_CALL getPropertyByHierarchicalName(
OUString const & aHierarchicalName)
throw (
css::beans::UnknownPropertyException, css::uno::RuntimeException,
std::exception)
SAL_OVERRIDE
{ return getRoot()->getPropertyByHierarchicalName(aHierarchicalName); }
sal_Bool SAL_CALL hasPropertyByHierarchicalName(
OUString const & aHierarchicalName)
throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
{ return getRoot()->hasPropertyByHierarchicalName(aHierarchicalName); }
rtl::Reference< RootAccess > getRoot(); rtl::Reference< RootAccess > getRoot();
css::uno::Reference< css::uno::XComponentContext > context_; css::uno::Reference< css::uno::XComponentContext > context_;
......
...@@ -93,6 +93,8 @@ public: ...@@ -93,6 +93,8 @@ public:
SAL_DLLPRIVATE ~ConfigurationWrapper(); SAL_DLLPRIVATE ~ConfigurationWrapper();
bool isReadOnly(OUString const & path) const;
com::sun::star::uno::Any getPropertyValue(OUString const & path) const; com::sun::star::uno::Any getPropertyValue(OUString const & path) const;
void setPropertyValue( void setPropertyValue(
...@@ -136,7 +138,11 @@ private: ...@@ -136,7 +138,11 @@ private:
context_; context_;
com::sun::star::uno::Reference< com::sun::star::uno::Reference<
com::sun::star::container::XHierarchicalNameAccess > access_; com::sun::star::configuration::XReadWriteAccess > access_;
// should really be an css.configuration.ReadOnlyAccess (with added
// css.beans.XHierarchicalPropertySetInfo), but then
// configmgr::Access::asProperty() would report all properties as
// READONLY, so isReadOnly() would not work
}; };
/// @internal /// @internal
...@@ -187,6 +193,15 @@ private: ...@@ -187,6 +193,15 @@ private:
/// each given configuration property. /// each given configuration property.
template< typename T, typename U > struct ConfigurationProperty template< typename T, typename U > struct ConfigurationProperty
{ {
/// Get the read-only status of the given (non-localized) configuration
/// property.
static bool isReadOnly(
css::uno::Reference<css::uno::XComponentContext> const & context
= comphelper::getProcessComponentContext())
{
return detail::ConfigurationWrapper::get(context).isReadOnly(T::path());
}
/// Get the value of the given (non-localized) configuration property. /// Get the value of the given (non-localized) configuration property.
/// ///
/// For nillable properties, U is of type boost::optional<U'>. /// For nillable properties, U is of type boost::optional<U'>.
...@@ -231,6 +246,14 @@ private: ...@@ -231,6 +246,14 @@ private:
/// to access each given localized configuration property. /// to access each given localized configuration property.
template< typename T, typename U > struct ConfigurationLocalizedProperty template< typename T, typename U > struct ConfigurationLocalizedProperty
{ {
/// Get the read-only status of the given localized configuration property.
static bool isReadOnly(
css::uno::Reference<css::uno::XComponentContext> const & context
= comphelper::getProcessComponentContext())
{
return detail::ConfigurationWrapper::get(context).isReadOnly(T::path());
}
/// Get the value of the given localized configuration property, for the /// Get the value of the given localized configuration property, for the
/// locale currently set at the /// locale currently set at the
/// com.sun.star.configuration.theDefaultProvider. /// com.sun.star.configuration.theDefaultProvider.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#ifndef _COM_SUN_STAR_CONFIGURATION_XREADWRITEACCESS_IDL #ifndef _COM_SUN_STAR_CONFIGURATION_XREADWRITEACCESS_IDL
#define _COM_SUN_STAR_CONFIGURATION_XREADWRITEACCESS_IDL #define _COM_SUN_STAR_CONFIGURATION_XREADWRITEACCESS_IDL
#include <com/sun/star/beans/XHierarchicalPropertySetInfo.idl>
#include <com/sun/star/container/XHierarchicalNameReplace.idl> #include <com/sun/star/container/XHierarchicalNameReplace.idl>
#include <com/sun/star/util/XChangesBatch.idl> #include <com/sun/star/util/XChangesBatch.idl>
...@@ -25,6 +26,9 @@ interface XReadWriteAccess { ...@@ -25,6 +26,9 @@ interface XReadWriteAccess {
interface com::sun::star::container::XHierarchicalNameReplace; interface com::sun::star::container::XHierarchicalNameReplace;
interface com::sun::star::util::XChangesBatch; interface com::sun::star::util::XChangesBatch;
// @since LibreOffice 4.5
interface com::sun::star::beans::XHierarchicalPropertySetInfo;
}; };
}; }; }; }; }; }; }; };
......
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