diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2011-12-13 12:37:00 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2011-12-13 12:50:34 +0100 |
commit | bcdea3b379637a98e5bbc304078149ca6c2b6e03 (patch) | |
tree | a3803df980a54ab1a03c740c3114a54ca7d12f27 /svl | |
parent | ddf1cf333174777e7923aa0d6126daf2c8645fed (diff) |
Simplified, type-safe C++ configuration access.
* New offapi com.sun.star.configuration entities to access the complete
configuration read-only or read/write...
* ...configmgr adapted to support those new services/singletons...
* ...new unotools/configuration.hxx is the type-safe C++ plumbing on top of
that...
* ...officecfg now generates C++ headers to access all the properties and sets
given in the .xcs files...
* ...and svl's asiancfg.cxx exemplarily makes use of the new
officecfg/Office/Common.hxx to access the configuration.
* There is still TODOs: For one, see those listed in
officecfg/registry/cppheader.xsl. For another, at least a notification
mechanism for the new read-only configuration access and the C++ wrapper is
missing.
Diffstat (limited to 'svl')
-rw-r--r-- | svl/inc/svl/asiancfg.hxx | 2 | ||||
-rw-r--r-- | svl/source/config/asiancfg.cxx | 99 |
2 files changed, 28 insertions, 73 deletions
diff --git a/svl/inc/svl/asiancfg.hxx b/svl/inc/svl/asiancfg.hxx index 733aea6a3bc0..350a2372efac 100644 --- a/svl/inc/svl/asiancfg.hxx +++ b/svl/inc/svl/asiancfg.hxx @@ -70,7 +70,7 @@ public: rtl::OUString const * startChars, rtl::OUString const * endChars); private: - class Impl; + struct Impl; boost::scoped_ptr< Impl > impl_; }; diff --git a/svl/source/config/asiancfg.cxx b/svl/source/config/asiancfg.cxx index 697e74d89bd8..51c20858148b 100644 --- a/svl/source/config/asiancfg.cxx +++ b/svl/source/config/asiancfg.cxx @@ -31,19 +31,18 @@ #include <cassert> #include "boost/noncopyable.hpp" -#include "com/sun/star/beans/NamedValue.hpp" #include "com/sun/star/beans/XPropertySet.hpp" #include "com/sun/star/container/ElementExistException.hpp" #include "com/sun/star/container/NoSuchElementException.hpp" +#include "com/sun/star/container/XNameAccess.hpp" #include "com/sun/star/container/XNameContainer.hpp" #include "com/sun/star/lang/Locale.hpp" -#include "com/sun/star/lang/XMultiServiceFactory.hpp" #include "com/sun/star/lang/XSingleServiceFactory.hpp" #include "com/sun/star/uno/Any.hxx" #include "com/sun/star/uno/Reference.hxx" #include "com/sun/star/uno/Sequence.hxx" -#include "com/sun/star/util/XChangesBatch.hpp" #include "comphelper/processfactory.hxx" +#include "officecfg/Office/Common.hxx" #include "rtl/oustringostreaminserter.hxx" #include "rtl/ustrbuf.hxx" #include "rtl/ustring.h" @@ -51,38 +50,12 @@ #include "sal/log.hxx" #include "sal/types.h" #include "svl/asiancfg.hxx" +#include "unotools/configuration.hxx" namespace { namespace css = com::sun::star; -css::uno::Reference< css::beans::XPropertySet > -obtainPropertySet() { - css::uno::Sequence< css::uno::Any > args(1); - args[0] <<= css::beans::NamedValue( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")), - css::uno::makeAny( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "/org.openoffice.Office.Common/AsianLayout")))); - return css::uno::Reference< css::beans::XPropertySet >( - (css::uno::Reference< css::lang::XMultiServiceFactory >( - (css::uno::Reference< css::lang::XMultiServiceFactory >( - comphelper::getProcessServiceFactory(), - css::uno::UNO_SET_THROW)-> - createInstance( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.configuration.ConfigurationProvider")))), - css::uno::UNO_QUERY_THROW)-> - createInstanceWithArguments( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.configuration.ConfigurationUpdateAccess")), - args)), - css::uno::UNO_QUERY_THROW); -} - rtl::OUString toString(css::lang::Locale const & locale) { SAL_WARN_IF( locale.Language.indexOf('-') != -1, "svl", @@ -108,74 +81,54 @@ rtl::OUString toString(css::lang::Locale const & locale) { } -class SvxAsianConfig::Impl: private boost::noncopyable { -public: - Impl(): propertySet_(obtainPropertySet()) {} +struct SvxAsianConfig::Impl: private boost::noncopyable { + Impl(): + context(comphelper::getProcessComponentContext()), + batch(unotools::ConfigurationChanges::create(context)) + {} - css::uno::Reference< css::beans::XPropertySet > getPropertySet() const - { return propertySet_; } + css::uno::Reference< css::uno::XComponentContext > context; - css::uno::Reference< css::container::XNameContainer > - getStartEndCharacters() const; - -private: - css::uno::Reference< css::beans::XPropertySet > propertySet_; + boost::shared_ptr< unotools::ConfigurationChanges > batch; }; -css::uno::Reference< css::container::XNameContainer > -SvxAsianConfig::Impl::getStartEndCharacters() const { - return - css::uno::Reference< css::container::XNameContainer >( - (propertySet_->getPropertyValue( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM("StartEndCharacters"))). - get< css::uno::Reference< css::container::XNameContainer > >()), - css::uno::UNO_SET_THROW); -} - SvxAsianConfig::SvxAsianConfig(): impl_(new Impl) {} SvxAsianConfig::~SvxAsianConfig() {} void SvxAsianConfig::Commit() { - css::uno::Reference< css::util::XChangesBatch >( - impl_->getPropertySet(), css::uno::UNO_QUERY_THROW)->commitChanges(); + impl_->batch->commit(); } bool SvxAsianConfig::IsKerningWesternTextOnly() const { return - impl_->getPropertySet()->getPropertyValue( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM("IsKerningWesternTextOnly"))). - get< bool >(); + officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::get( + impl_->context); } void SvxAsianConfig::SetKerningWesternTextOnly(bool value) { - impl_->getPropertySet()->setPropertyValue( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsKerningWesternTextOnly")), - css::uno::makeAny(value)); + officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::set( + impl_->context, impl_->batch, value); } sal_Int16 SvxAsianConfig::GetCharDistanceCompression() const { return - impl_->getPropertySet()->getPropertyValue( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM("CompressCharacterDistance"))). - get< sal_Int16 >(); + officecfg::Office::Common::AsianLayout::CompressCharacterDistance::get( + impl_->context); } void SvxAsianConfig::SetCharDistanceCompression(sal_Int16 value) { - assert(value >= 0 && value <= 2); - impl_->getPropertySet()->setPropertyValue( - rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CompressCharacterDistance")), - css::uno::makeAny(value)); + officecfg::Office::Common::AsianLayout::CompressCharacterDistance::set( + impl_->context, impl_->batch, value); } css::uno::Sequence< css::lang::Locale > SvxAsianConfig::GetStartEndCharLocales() const { css::uno::Sequence< rtl::OUString > ns( - impl_->getStartEndCharacters()->getElementNames()); + officecfg::Office::Common::AsianLayout::StartEndCharacters::get( + impl_->context)-> + getElementNames()); css::uno::Sequence< css::lang::Locale > ls(ns.getLength()); for (sal_Int32 i = 0; i < ns.getLength(); ++i) { sal_Int32 n = 0; @@ -190,8 +143,9 @@ bool SvxAsianConfig::GetStartEndChars( css::lang::Locale const & locale, rtl::OUString & startChars, rtl::OUString & endChars) const { - css::uno::Reference< css::container::XNameContainer > set( - impl_->getStartEndCharacters()); + css::uno::Reference< css::container::XNameAccess > set( + officecfg::Office::Common::AsianLayout::StartEndCharacters::get( + impl_->context)); css::uno::Any v; try { v = set->getByName(toString(locale)); @@ -218,7 +172,8 @@ void SvxAsianConfig::SetStartEndChars( { assert((startChars == 0) == (endChars == 0)); css::uno::Reference< css::container::XNameContainer > set( - impl_->getStartEndCharacters()); + officecfg::Office::Common::AsianLayout::StartEndCharacters::get( + impl_->context, impl_->batch)); rtl::OUString name(toString(locale)); if (startChars == 0) { try { |