1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_UNOTOOLS_CONFIGITEM_HXX
21 #define INCLUDED_UNOTOOLS_CONFIGITEM_HXX
23 #include <sal/types.h>
24 #include <rtl/ustring.hxx>
25 #include <com/sun/star/uno/Sequence.h>
26 #include <com/sun/star/uno/Reference.h>
27 #include <unotools/unotoolsdllapi.h>
28 #include <unotools/options.hxx>
29 #include <o3tl/typed_flags_set.hxx>
31 namespace com
{ namespace sun
{ namespace star
{
39 class XHierarchicalNameAccess
;
42 class XChangesListener
;
46 enum class ConfigItemMode
55 template<> struct typed_flags
<ConfigItemMode
> : is_typed_flags
<ConfigItemMode
, 0x07> {};
61 enum class ConfigNameFormat
63 LocalNode
, // local node name, for use in XNameAccess etc. ("Item", "Q & A")
64 LocalPath
, // one-level relative path, for use when building paths etc. ("Item", "Typ['Q & A']")
67 class UNOTOOLS_DLLPUBLIC ConfigItem
: public ConfigurationBroadcaster
69 friend class ConfigChangeListener_Impl
;
70 friend class ConfigManager
;
72 const OUString sSubTree
;
73 css::uno::Reference
< css::container::XHierarchicalNameAccess
>
75 css::uno::Reference
< css::util::XChangesListener
>
77 ConfigItemMode
const m_nMode
;
79 bool m_bEnableInternalNotification
;
80 sal_Int16 m_nInValueChange
;
82 void RemoveChangesListener();
84 const css::uno::Sequence
<OUString
>& aPropertyNames
);
86 // In special mode ALL_LOCALES we must support reading/writing of localized cfg entries as Sequence< PropertyValue >.
87 // These methods are helper to convert given lists of names and Any-values.
88 // format: PropertyValue.Name = <locale as ISO string>
89 // PropertyValue.Value = <value; type depends from cfg entry!>
96 void impl_packLocalizedProperties ( const css::uno::Sequence
< OUString
>& lInNames
,
97 const css::uno::Sequence
< css::uno::Any
>& lInValues
,
98 css::uno::Sequence
< css::uno::Any
>& lOutValues
);
99 void impl_unpackLocalizedProperties ( const css::uno::Sequence
< OUString
>& lInNames
,
100 const css::uno::Sequence
< css::uno::Any
>& lInValues
,
101 css::uno::Sequence
< OUString
>& lOutNames
,
102 css::uno::Sequence
< css::uno::Any
>& lOutValues
);
104 css::uno::Reference
< css::container::XHierarchicalNameAccess
>
106 /** writes the changed values into the sub tree.
107 Private and only called from non-virtual public Commit(). */
108 virtual void ImplCommit() = 0;
111 explicit ConfigItem(const OUString
&rSubTree
,
112 ConfigItemMode nMode
= ConfigItemMode::NONE
);
114 void SetModified (); // mark item as modified
115 void ClearModified(); // reset state after commit!
117 css::uno::Sequence
< css::uno::Any
>
118 GetProperties(const css::uno::Sequence
< OUString
>& rNames
);
120 css::uno::Sequence
< sal_Bool
>
121 GetReadOnlyStates(const css::uno::Sequence
< OUString
>& rNames
);
124 const css::uno::Sequence
< OUString
>& rNames
,
125 const css::uno::Sequence
< css::uno::Any
>& rValues
);
127 /** enables notifications about changes on selected sub nodes/values
129 Before calling this method a second time for a possibly changed node/value set,
130 you must disable the current notifications by calling DisableNotification.
133 @see DisableNotification
135 bool EnableNotification(const css::uno::Sequence
< OUString
>& rNames
,
136 bool bEnableInternalNotification
= false);
137 /** disables notifications about changes on sub nodes/values, which previously had
138 been enabled with EnableNotification
140 @see EnableNotification
142 void DisableNotification();
144 //returns all members of a node in a specific format
145 css::uno::Sequence
< OUString
>
146 GetNodeNames(const OUString
& rNode
);
147 //returns all members of a node in a specific format
148 css::uno::Sequence
< OUString
>
149 GetNodeNames(const OUString
& rNode
, ConfigNameFormat eFormat
);
150 // remove all members of a set
151 bool ClearNodeSet(const OUString
& rNode
);
152 // remove selected members of a set
153 bool ClearNodeElements(const OUString
& rNode
,
154 css::uno::Sequence
< OUString
> const & rElements
);
155 // change or add members to a set
156 bool SetSetProperties(const OUString
& rNode
, const css::uno::Sequence
< css::beans::PropertyValue
>& rValues
);
157 // remove, change or add members of a set
158 bool ReplaceSetProperties(const OUString
& rNode
, const css::uno::Sequence
< css::beans::PropertyValue
>& rValues
);
159 // add a new node without setting any properties
160 bool AddNode(const OUString
& rNode
, const OUString
& rNewNode
);
163 virtual ~ConfigItem() override
;
165 ConfigItem(ConfigItem
const &) = default;
166 ConfigItem(ConfigItem
&&) = default;
167 ConfigItem
& operator =(ConfigItem
const &) = delete; // due to const sSubTree
168 ConfigItem
& operator =(ConfigItem
&&) = delete; // due to const sSubTree
170 /** is called from the ConfigManager before application ends of from the
171 PropertyChangeListener if the sub tree broadcasts changes. */
172 virtual void Notify( const css::uno::Sequence
<OUString
>& aPropertyNames
)=0;
174 const OUString
& GetSubTreeName() const {return sSubTree
;}
176 bool IsModified() const { return m_bIsModified
;}
180 ConfigItemMode
GetMode() const { return m_nMode
;}
183 #endif // INCLUDED_UNOTOOLS_CONFIGITEM_HXX
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */