diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2015-10-05 18:08:02 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-10-09 08:42:49 +0000 |
commit | ccf8bdcf929e842ef42ae968e4f0532282357277 (patch) | |
tree | f267454624fc8ceb12d1fd90fc826da4cf8e8c59 /comphelper | |
parent | 18b934af9979522c8cff1ff76504ce19c3e6916d (diff) |
Create a wrapper to make listening for configmgr changes easy.
Change-Id: Ib58d04f9e046e604b24e0e338796a7a60aa1d6fd
Reviewed-on: https://gerrit.libreoffice.org/19253
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/misc/configuration.cxx | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/comphelper/source/misc/configuration.cxx b/comphelper/source/misc/configuration.cxx index 6280fdc84ac2..e5bf8b84d2d2 100644 --- a/comphelper/source/misc/configuration.cxx +++ b/comphelper/source/misc/configuration.cxx @@ -27,6 +27,7 @@ #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/XComponentContext.hpp> #include <comphelper/configuration.hxx> +#include <comphelper/configurationlistener.hxx> #include <rtl/instance.hxx> #include <rtl/ustrbuf.hxx> #include <rtl/ustring.hxx> @@ -209,4 +210,54 @@ comphelper::detail::ConfigurationWrapper::createChanges() const { new ConfigurationChanges(context_)); } +void comphelper::ConfigurationListener::addListener(ConfigurationListenerPropertyBase *pListener) +{ + maListeners.push_back( pListener ); + mxConfig->addPropertyChangeListener( pListener->maName, this ); + pListener->setProperty( mxConfig->getPropertyValue( pListener->maName ) ); +} + +void comphelper::ConfigurationListener::removeListener(ConfigurationListenerPropertyBase *pListener) +{ + auto it = maListeners.begin(); + it = std::find( maListeners.begin(), maListeners.end(), pListener ); + if ( it != maListeners.end() ) + { + maListeners.erase( it ); + mxConfig->removePropertyChangeListener( pListener->maName, this ); + } +} + +void comphelper::ConfigurationListener::dispose() +{ + for (auto it = maListeners.begin(); it != maListeners.end(); ++it) + { + mxConfig->removePropertyChangeListener( (*it)->maName, this ); + (*it)->dispose(); + } + maListeners.clear(); +} + +void SAL_CALL comphelper::ConfigurationListener::disposing(css::lang::EventObject const &) + throw (css::uno::RuntimeException, std::exception) +{ + dispose(); +} + +void SAL_CALL comphelper::ConfigurationListener::propertyChange( + css::beans::PropertyChangeEvent const &rEvt ) + throw (css::uno::RuntimeException, std::exception) +{ + assert( rEvt.Source == mxConfig ); + for ( auto it = maListeners.begin(); it != maListeners.end(); ++it ) + { + if ( (*it)->maName == rEvt.PropertyName ) + { + // ignore rEvt.NewValue - in theory it could be stale => not set. + css::uno::Any aValue = mxConfig->getPropertyValue( (*it)->maName ); + (*it)->setProperty( aValue ); + } + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |