nss: upgrade to release 3.73
[LibreOffice.git] / include / comphelper / configurationlistener.hxx
blob29a2b578b588357ca24b0d4c0fb77134a8428392
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_COMPHELPER_CONFIGURATIONLISTENER_HXX
11 #define INCLUDED_COMPHELPER_CONFIGURATIONLISTENER_HXX
13 #include <vector>
14 #include <comphelper/comphelperdllapi.h>
15 #include <com/sun/star/beans/XPropertySet.hpp>
16 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
17 #include <rtl/ref.hxx>
18 #include <cppuhelper/implbase.hxx>
19 #include <comphelper/processfactory.hxx>
20 #include <comphelper/configurationhelper.hxx>
22 namespace com::sun::star::beans { struct PropertyChangeEvent; }
23 namespace com::sun::star::uno { class XComponentContext; }
25 namespace comphelper {
27 class ConfigurationListener;
29 class COMPHELPER_DLLPUBLIC ConfigurationListenerPropertyBase {
30 public:
31 OUString maName;
32 rtl::Reference<ConfigurationListener> mxListener;
34 virtual ~ConfigurationListenerPropertyBase() {}
35 virtual void setProperty(const css::uno::Any &aProperty) = 0;
36 void dispose() { mxListener.clear(); }
39 /// Access to this class must be protected by the SolarMutex
40 template< typename uno_type > class ConfigurationListenerProperty : public ConfigurationListenerPropertyBase
42 uno_type maValue;
43 protected:
44 virtual void setProperty(const css::uno::Any &aProperty) override
46 aProperty >>= maValue;
48 public:
49 /**
50 * Provide a mirror of the configmgr's version of this property
51 * for the lifecycle of this property. The property value tracks
52 * the same value in the configuration.
54 inline ConfigurationListenerProperty(const rtl::Reference< ConfigurationListener > &xListener,
55 const OUString &rProp );
57 virtual inline ~ConfigurationListenerProperty() override;
59 uno_type get() const { return maValue; }
62 class COMPHELPER_DLLPUBLIC ConfigurationListener :
63 public cppu::WeakImplHelper< css::beans::XPropertyChangeListener >
65 css::uno::Reference< css::beans::XPropertySet > mxConfig;
66 std::vector< ConfigurationListenerPropertyBase * > maListeners;
67 public:
68 /// Public health warning, you -must- dispose this if you use it.
69 ConfigurationListener(const OUString &rPath,
70 css::uno::Reference< css::uno::XComponentContext >
71 const & xContext = comphelper::getProcessComponentContext())
72 : mxConfig( ConfigurationHelper::openConfig( xContext, rPath, EConfigurationModes::ReadOnly ),
73 css::uno::UNO_QUERY_THROW )
74 { }
76 virtual ~ConfigurationListener() override
78 dispose();
81 /// Listen for the specific property denoted by the listener
82 void addListener(ConfigurationListenerPropertyBase *pListener);
84 /// Stop listening.
85 void removeListener(ConfigurationListenerPropertyBase *pListener);
87 /// Release various circular references
88 void dispose();
90 // XPropertyChangeListener implementation
91 virtual void SAL_CALL disposing(css::lang::EventObject const &) override;
93 /// Notify of the property change
94 virtual void SAL_CALL propertyChange(
95 css::beans::PropertyChangeEvent const &rEvt ) override;
98 template< typename uno_type > ConfigurationListenerProperty< uno_type >::ConfigurationListenerProperty(const rtl::Reference< ConfigurationListener > &xListener, const OUString &rProp )
99 : maValue()
101 maName = rProp;
102 mxListener = xListener;
103 mxListener->addListener(this);
106 template< typename uno_type > ConfigurationListenerProperty< uno_type >::~ConfigurationListenerProperty()
108 if (mxListener.is())
109 mxListener->removeListener(this);
112 } // namespace comphelper
114 #endif // INCLUDED_COMPHELPER_CONFIGURATIONLISTENER_HXX
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */