summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2012-01-25 18:17:08 +0100
committerStephan Bergmann <sbergman@redhat.com>2012-01-25 18:18:52 +0100
commitd70aa23c2d3af951c8846b4aea83c87c06a37a35 (patch)
tree4669966eef4aef87b3da1d818884cd0d7f04c4f9
parent866df124ee89a9d7b1f2b7803892f02c1010a9be (diff)
Add configuration wrappers for groups, too (to add listeners etc.).
-rw-r--r--officecfg/registry/cppheader.xsl24
-rw-r--r--unotools/inc/unotools/configuration.hxx48
-rw-r--r--unotools/source/config/configuration.cxx25
3 files changed, 93 insertions, 4 deletions
diff --git a/officecfg/registry/cppheader.xsl b/officecfg/registry/cppheader.xsl
index df891c29e6e2..2522aca68d5d 100644
--- a/officecfg/registry/cppheader.xsl
+++ b/officecfg/registry/cppheader.xsl
@@ -141,9 +141,18 @@
<xsl:template match="group">
<xsl:param name="path"/>
<xsl:if test=".//prop or .//set">
- <xsl:text>namespace </xsl:text>
- <xsl:value-of select="translate(@oor:name, '-.', '__')"/>
- <xsl:text> {&#xA;</xsl:text>
+ <xsl:variable name="name" select="translate(@oor:name, '-.', '__')"/>
+ <xsl:text>struct </xsl:text>
+ <xsl:value-of select="$name"/>
+ <xsl:text>: public unotools::ConfigurationGroup&lt; </xsl:text>
+ <xsl:value-of select="$name"/>
+ <xsl:text>&gt; {&#xA;</xsl:text>
+ <xsl:text> static rtl::OUString path() { return rtl::OUString(<!--
+ -->RTL_CONSTASCII_USTRINGPARAM("</xsl:text>
+ <xsl:value-of select="$path"/>
+ <xsl:text>/</xsl:text>
+ <xsl:value-of select="@oor:name"/>
+ <xsl:text>")); }&#xA;</xsl:text>
<xsl:text>&#xA;</xsl:text>
<xsl:apply-templates select="group|set|prop">
<xsl:with-param name="path">
@@ -152,7 +161,14 @@
<xsl:value-of select="@oor:name"/>
</xsl:with-param>
</xsl:apply-templates>
- <xsl:text>}&#xA;</xsl:text>
+ <xsl:text>private:&#xA;</xsl:text>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="$name"/>
+ <xsl:text>(); // not defined&#xA;</xsl:text>
+ <xsl:text> ~</xsl:text>
+ <xsl:value-of select="$name"/>
+ <xsl:text>(); // not defined&#xA;</xsl:text>
+ <xsl:text>};&#xA;</xsl:text>
<xsl:text>&#xA;</xsl:text>
</xsl:if>
</xsl:template>
diff --git a/unotools/inc/unotools/configuration.hxx b/unotools/inc/unotools/configuration.hxx
index c9969c8a024f..cfcc7e776404 100644
--- a/unotools/inc/unotools/configuration.hxx
+++ b/unotools/inc/unotools/configuration.hxx
@@ -43,6 +43,7 @@ namespace com { namespace sun { namespace star {
namespace configuration { class XReadWriteAccess; }
namespace container {
class XHierarchicalNameAccess;
+ class XHierarchicalNameReplace;
class XNameAccess;
class XNameContainer;
}
@@ -80,6 +81,10 @@ private:
rtl::OUString const & path, com::sun::star::uno::Any const & value)
const;
+ SAL_DLLPRIVATE com::sun::star::uno::Reference<
+ com::sun::star::container::XHierarchicalNameReplace >
+ getGroup(rtl::OUString const & path) const;
+
SAL_DLLPRIVATE
com::sun::star::uno::Reference< com::sun::star::container::XNameContainer >
getSet(rtl::OUString const & path) const;
@@ -120,6 +125,16 @@ public:
rtl::OUString const & path, com::sun::star::uno::Any const & value)
const;
+ com::sun::star::uno::Reference<
+ com::sun::star::container::XHierarchicalNameAccess >
+ getGroupReadOnly(rtl::OUString const & path) const;
+
+ com::sun::star::uno::Reference<
+ com::sun::star::container::XHierarchicalNameReplace >
+ getGroupReadWrite(
+ boost::shared_ptr< ConfigurationChanges > const & batch,
+ rtl::OUString const & path) const;
+
com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >
getSetReadOnly(rtl::OUString const & path) const;
@@ -230,6 +245,39 @@ private:
~ConfigurationLocalizedProperty(); // not defined
};
+/// A type-safe wrapper around a configuration group.
+///
+/// Automatically generated headers for the various configuration groups derive
+/// from this template and make available its member functions to access each
+/// given configuration group.
+template< typename T > struct ConfigurationGroup: private boost::noncopyable {
+ /// Get read-only access to the given configuration group.
+ static com::sun::star::uno::Reference<
+ com::sun::star::container::XHierarchicalNameAccess >
+ get(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
+ const & context)
+ {
+ return detail::ConfigurationWrapper::get(context).getGroupReadOnly(
+ T::path());
+ }
+
+ /// Get read/write access to the given configuration group, storing any
+ /// modifications via the given changes batch.
+ static com::sun::star::uno::Reference<
+ com::sun::star::container::XHierarchicalNameReplace >
+ get(com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
+ const & context,
+ boost::shared_ptr< ConfigurationChanges > const & batch)
+ {
+ return detail::ConfigurationWrapper::get(context).getGroupReadWrite(
+ batch, T::path());
+ }
+
+private:
+ ConfigurationGroup(); // not defined
+ ~ConfigurationGroup(); // not defined
+};
+
/// A type-safe wrapper around a configuration set.
///
/// Automatically generated headers for the various configuration sets derive
diff --git a/unotools/source/config/configuration.cxx b/unotools/source/config/configuration.cxx
index a4b30ed360fa..a8c818c124dd 100644
--- a/unotools/source/config/configuration.cxx
+++ b/unotools/source/config/configuration.cxx
@@ -37,6 +37,7 @@
#include "com/sun/star/configuration/XReadWriteAccess.hpp"
#include "com/sun/star/configuration/theDefaultProvider.hpp"
#include "com/sun/star/container/XHierarchicalNameAccess.hpp"
+#include "com/sun/star/container/XHierarchicalNameReplace.hpp"
#include "com/sun/star/container/XNameAccess.hpp"
#include "com/sun/star/container/XNameContainer.hpp"
#include "com/sun/star/lang/Locale.hpp"
@@ -90,6 +91,13 @@ void unotools::ConfigurationChanges::setPropertyValue(
access_->replaceByHierarchicalName(path, value);
}
+css::uno::Reference< css::container::XHierarchicalNameReplace >
+unotools::ConfigurationChanges::getGroup(rtl::OUString const & path) const
+{
+ return css::uno::Reference< css::container::XHierarchicalNameReplace >(
+ access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW);
+}
+
css::uno::Reference< css::container::XNameContainer >
unotools::ConfigurationChanges::getSet(rtl::OUString const & path) const
{
@@ -139,6 +147,23 @@ void unotools::detail::ConfigurationWrapper::setLocalizedPropertyValue(
batch->setPropertyValue(extendLocalizedPath(path), value);
}
+css::uno::Reference< css::container::XHierarchicalNameAccess >
+unotools::detail::ConfigurationWrapper::getGroupReadOnly(
+ rtl::OUString const & path) const
+{
+ return css::uno::Reference< css::container::XHierarchicalNameAccess >(
+ access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW);
+}
+
+css::uno::Reference< css::container::XHierarchicalNameReplace >
+unotools::detail::ConfigurationWrapper::getGroupReadWrite(
+ boost::shared_ptr< ConfigurationChanges > const & batch,
+ rtl::OUString const & path) const
+{
+ assert(batch.get() != 0);
+ return batch->getGroup(path);
+}
+
css::uno::Reference< css::container::XNameAccess >
unotools::detail::ConfigurationWrapper::getSetReadOnly(
rtl::OUString const & path) const