LibreOffice Module comphelper (master) 1
configurationlistener.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#ifndef INCLUDED_COMPHELPER_CONFIGURATIONLISTENER_HXX
11#define INCLUDED_COMPHELPER_CONFIGURATIONLISTENER_HXX
12
13#include <vector>
15#include <com/sun/star/beans/XPropertySet.hpp>
16#include <com/sun/star/beans/XPropertyChangeListener.hpp>
17#include <rtl/ref.hxx>
21
22namespace com::sun::star::beans { struct PropertyChangeEvent; }
23namespace com::sun::star::uno { class XComponentContext; }
24
25namespace comphelper {
26
27class ConfigurationListener;
28
30public:
31 OUString maName;
33
35 virtual void setProperty(const css::uno::Any &aProperty) = 0;
36 void dispose() { mxListener.clear(); }
37};
38
40template< typename uno_type > class ConfigurationListenerProperty : public ConfigurationListenerPropertyBase
41{
42 uno_type maValue;
43protected:
44 virtual void setProperty(const css::uno::Any &aProperty) override
45 {
46 aProperty >>= maValue;
47 }
48public:
55 const OUString &rProp );
56
57 virtual inline ~ConfigurationListenerProperty() override;
58
59 uno_type get() const { return maValue; }
60};
61
62// workaround for incremental linking bugs in MSVC2019
63class SAL_DLLPUBLIC_TEMPLATE ConfigurationListener_Base : public cppu::WeakImplHelper< css::beans::XPropertyChangeListener > {};
65{
66 css::uno::Reference< css::beans::XPropertySet > mxConfig;
67 std::vector< ConfigurationListenerPropertyBase * > maListeners;
69public:
71 ConfigurationListener(const OUString &rPath,
72 css::uno::Reference< css::uno::XComponentContext >
73 const & xContext = comphelper::getProcessComponentContext())
74 : mxConfig( ConfigurationHelper::openConfig( xContext, rPath, EConfigurationModes::ReadOnly ),
75 css::uno::UNO_QUERY_THROW )
76 , mbDisposed(false)
77 { }
78
79 virtual ~ConfigurationListener() override
80 {
81 dispose();
82 }
83
86
89
91 void dispose();
92
93 // XPropertyChangeListener implementation
94 virtual void SAL_CALL disposing(css::lang::EventObject const &) override;
95
97 virtual void SAL_CALL propertyChange(
98 css::beans::PropertyChangeEvent const &rEvt ) override;
99
100 bool isDisposed() const { return mbDisposed; }
101};
102
104 : maValue()
105{
106 maName = rProp;
107 mxListener = xListener;
108 mxListener->addListener(this);
109}
110
112{
113 if (mxListener.is())
114 mxListener->removeListener(this);
115}
116
117} // namespace comphelper
118
119#endif // INCLUDED_COMPHELPER_CONFIGURATIONLISTENER_HXX
120
121/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< ConfigurationListener > mxListener
virtual void setProperty(const css::uno::Any &aProperty)=0
Access to this class must be protected by the SolarMutex.
ConfigurationListenerProperty(const rtl::Reference< ConfigurationListener > &xListener, const OUString &rProp)
Provide a mirror of the configmgr's version of this property for the lifecycle of this property.
virtual void setProperty(const css::uno::Any &aProperty) override
css::uno::Reference< css::beans::XPropertySet > mxConfig
std::vector< ConfigurationListenerPropertyBase * > maListeners
ConfigurationListener(const OUString &rPath, css::uno::Reference< css::uno::XComponentContext > const &xContext=comphelper::getProcessComponentContext())
Public health warning, you -must- dispose this if you use it.
#define COMPHELPER_DLLPUBLIC
Reference< script::XScriptListener > mxListener
double maValue
void addListener(const InterfaceRef &xObject, const css::uno::Reference< css::lang::XEventListener > &xListener)
void removeListener(const InterfaceRef &xObject, const css::uno::Reference< css::lang::XEventListener > &xListener)
Reference< XComponentContext > getProcessComponentContext()
This function gets the process service factory's default component context.
EConfigurationModes
specify all possible modes, which can be used to open a configuration access.
void dispose()