14#include <com/sun/star/beans/NamedValue.hpp>
15#include <com/sun/star/beans/PropertyAttribute.hpp>
16#include <com/sun/star/configuration/ReadOnlyAccess.hpp>
17#include <com/sun/star/configuration/ReadWriteAccess.hpp>
18#include <com/sun/star/configuration/XReadWriteAccess.hpp>
19#include <com/sun/star/configuration/theDefaultProvider.hpp>
20#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
21#include <com/sun/star/container/XHierarchicalNameReplace.hpp>
22#include <com/sun/star/container/XNameAccess.hpp>
23#include <com/sun/star/container/XNameContainer.hpp>
24#include <com/sun/star/util/XChangesListener.hpp>
25#include <com/sun/star/util/XChangesNotifier.hpp>
26#include <com/sun/star/lang/DisposedException.hpp>
27#include <com/sun/star/lang/XLocalizable.hpp>
28#include <com/sun/star/uno/Any.hxx>
29#include <com/sun/star/uno/Reference.hxx>
34#include <rtl/ustring.hxx>
42OUString getDefaultLocale(
43 css::uno::Reference< css::uno::XComponentContext >
const & context)
46 css::uno::Reference< css::lang::XLocalizable >(
47 css::configuration::theDefaultProvider::get(context),
48 css::uno::UNO_QUERY_THROW)->
52OUString extendLocalizedPath(std::u16string_view path, OUString
const & locale) {
54 locale.match(
"*"),
"comphelper",
55 "Locale \"" << locale <<
"\" starts with \"*\"");
56 assert(locale.indexOf(
'&') == -1);
57 assert(locale.indexOf(
'"') == -1);
58 assert(locale.indexOf(
'\'') == -1);
59 return OUString::Concat(path) +
"/['*" + locale +
"']";
64std::shared_ptr< comphelper::ConfigurationChanges >
77 css::uno::Reference< css::uno::XComponentContext >
const & context):
79 css::configuration::ReadWriteAccess::
create(
80 context, getDefaultLocale(context)))
84 OUString
const & path, css::uno::Any
const & value)
const
89css::uno::Reference< css::container::XHierarchicalNameReplace >
92 return css::uno::Reference< css::container::XHierarchicalNameReplace >(
93 access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW);
96css::uno::Reference< css::container::XNameContainer >
99 return css::uno::Reference< css::container::XNameContainer >(
100 access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW);
111 :
public ::cppu::WeakImplHelper<css::util::XChangesListener>
124 virtual void SAL_CALL
disposing(
const css::lang::EventObject&)
override
142 css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider(
143 css::configuration::theDefaultProvider::get(
context_ ) );
146 css::uno::Sequence< css::uno::Any > params {
147 css::uno::Any( css::beans::NamedValue{
"nodepath", css::uno::Any( OUString(
"/"))} ),
148 css::uno::Any( css::beans::NamedValue{
"locale", css::uno::Any( OUString(
"*"))} ) };
150 css::uno::Reference< css::uno::XInterface > xCfg
151 = xConfigProvider->createInstanceWithArguments(
u"com.sun.star.configuration.ConfigurationAccess",
154 maNotifier = css::uno::Reference< css::util::XChangesNotifier >(xCfg, css::uno::UNO_QUERY);
159 catch(
const css::uno::Exception&)
167 maPropertyCache.clear();
176 (
access_->getPropertyByHierarchicalName(path).Attributes
177 & css::beans::PropertyAttribute::READONLY)
183 std::scoped_lock aGuard(
maMutex);
185 throw css::lang::DisposedException();
187 auto it = maPropertyCache.find(path);
188 if( it != maPropertyCache.end())
191 sal_Int32
idx = path.lastIndexOf(
"/");
193 OUString parentPath = path.copy(0,
idx);
194 OUString childName = path.copy(
idx+1);
196 css::uno::Reference<css::container::XNameAccess> access(
197 access_->getByHierarchicalName(parentPath), css::uno::UNO_QUERY_THROW);
198 css::uno::Any
property = access->getByName(childName);
199 maPropertyCache.emplace(path,
property);
204 std::shared_ptr< ConfigurationChanges >
const & batch,
205 OUString
const & path, css::uno::Any
const & value)
208 batch->setPropertyValue(path,
value);
213 std::u16string_view path)
const
215 return access_->getByHierarchicalName(
216 extendLocalizedPath(path, getDefaultLocale(
context_)));
220 std::shared_ptr< ConfigurationChanges >
const & batch,
221 OUString
const & path, css::uno::Any
const & value)
224 batch->setPropertyValue(path,
value);
227css::uno::Reference< css::container::XHierarchicalNameAccess >
229 OUString
const & path)
const
231 return css::uno::Reference< css::container::XHierarchicalNameAccess >(
232 (css::configuration::ReadOnlyAccess::create(
234 getByHierarchicalName(path)),
235 css::uno::UNO_QUERY_THROW);
238css::uno::Reference< css::container::XHierarchicalNameReplace >
240 std::shared_ptr< ConfigurationChanges >
const & batch,
241 OUString
const & path)
244 return batch->getGroup(path);
247css::uno::Reference< css::container::XNameAccess >
249 OUString
const & path)
const
251 return css::uno::Reference< css::container::XNameAccess >(
252 (css::configuration::ReadOnlyAccess::create(
254 getByHierarchicalName(path)),
255 css::uno::UNO_QUERY_THROW);
258css::uno::Reference< css::container::XNameContainer >
260 std::shared_ptr< ConfigurationChanges >
const & batch,
261 OUString
const & path)
264 return batch->getSet(path);
267std::shared_ptr< comphelper::ConfigurationChanges >
269 return std::shared_ptr< ConfigurationChanges >(
275 maListeners.push_back( pListener );
276 mxConfig->addPropertyChangeListener( pListener->
maName,
this );
282 auto it =
std::find( maListeners.begin(), maListeners.end(), pListener );
283 if ( it != maListeners.end() )
285 maListeners.erase( it );
286 mxConfig->removePropertyChangeListener( pListener->
maName,
this );
292 for (
auto const& listener : maListeners)
294 mxConfig->removePropertyChangeListener( listener->maName,
this );
307 css::beans::PropertyChangeEvent
const &rEvt )
318 assert( rEvt.Source == mxConfig );
319 for (
auto const& listener : maListeners)
321 if ( listener->maName == rEvt.PropertyName )
324 css::uno::Any aValue = mxConfig->getPropertyValue( listener->maName );
325 listener->setProperty( aValue );
const OUString & getBcp47(bool bResolveSystem=true) const
A batch of configuration changes that is committed as a whole.
SAL_DLLPRIVATE css::uno::Reference< css::container::XHierarchicalNameReplace > getGroup(OUString const &path) const
static std::shared_ptr< ConfigurationChanges > create()
SAL_DLLPRIVATE void setPropertyValue(OUString const &path, css::uno::Any const &value) const
ConfigurationChanges(const ConfigurationChanges &)=delete
SAL_DLLPRIVATE css::uno::Reference< css::container::XNameContainer > getSet(OUString const &path) const
virtual void setProperty(const css::uno::Any &aProperty)=0
void removeListener(ConfigurationListenerPropertyBase *pListener)
Stop listening.
virtual void SAL_CALL propertyChange(css::beans::PropertyChangeEvent const &rEvt) override
Notify of the property change.
void addListener(ConfigurationListenerPropertyBase *pListener)
Listen for the specific property denoted by the listener.
void dispose()
Release various circular references.
virtual void SAL_CALL disposing(css::lang::EventObject const &) override
static SolarMutex * get()
Help components to get the SolarMutex easily.
virtual void SAL_CALL disposing(const css::lang::EventObject &) override
ConfigurationChangesListener(comphelper::detail::ConfigurationWrapper &rWrapper)
virtual void SAL_CALL changesOccurred(const css::util::ChangesEvent &) override
comphelper::detail::ConfigurationWrapper & mrConfigurationWrapper
css::uno::Reference< css::container::XHierarchicalNameAccess > getGroupReadOnly(OUString const &path) const
css::uno::Any getLocalizedPropertyValue(std::u16string_view path) const
bool isReadOnly(OUString const &path) const
SAL_DLLPRIVATE ~ConfigurationWrapper()
css::uno::Any getPropertyValue(OUString const &path) const
static void setPropertyValue(std::shared_ptr< ConfigurationChanges > const &batch, OUString const &path, css::uno::Any const &value)
css::uno::Reference< css::util::XChangesListener > maListener
css::uno::Reference< css::util::XChangesNotifier > maNotifier
friend class ConfigurationChangesListener
css::uno::Reference< css::uno::XComponentContext > context_
static void setLocalizedPropertyValue(std::shared_ptr< ConfigurationChanges > const &batch, OUString const &path, css::uno::Any const &value)
std::unordered_map< OUString, css::uno::Any > maPropertyCache
css::uno::Reference< css::container::XNameAccess > getSetReadOnly(OUString const &path) const
static css::uno::Reference< css::container::XNameContainer > getSetReadWrite(std::shared_ptr< ConfigurationChanges > const &batch, OUString const &path)
static ConfigurationWrapper const & get()
static css::uno::Reference< css::container::XHierarchicalNameReplace > getGroupReadWrite(std::shared_ptr< ConfigurationChanges > const &batch, OUString const &path)
std::shared_ptr< ConfigurationChanges > createChanges() const
SAL_DLLPRIVATE ConfigurationWrapper()
css::uno::Reference< css::uno::XInterface > access_
#define SAL_WARN_IF(condition, area, stream)
const LanguageTag & getLocale()
Get the current LOK's locale.
Reference< XComponentContext > getProcessComponentContext()
This function gets the process service factory's default component context.
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
static PropertyMapEntry const * find(const rtl::Reference< PropertySetInfo > &mxInfo, const OUString &aName) noexcept
uno::Reference< uno::XComponentContext > context_