Update git submodules
[LibreOffice.git] / include / unotools / configitem.hxx
blob7692bd3d6c9e4c90796021c94b8a2a12e39697fb
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/.
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::sun::star {
32 namespace uno{
33 class Any;
35 namespace beans{
36 struct PropertyValue;
38 namespace container{
39 class XHierarchicalNameAccess;
41 namespace util{
42 class XChangesListener;
46 enum class ConfigItemMode
48 NONE = 0x00,
49 AllLocales = 0x02,
50 ReleaseTree = 0x04,
53 namespace o3tl
55 template<> struct typed_flags<ConfigItemMode> : is_typed_flags<ConfigItemMode, 0x06> {};
58 namespace utl
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 &amp; 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>
74 m_xHierarchyAccess;
75 css::uno::Reference< css::util::XChangesListener >
76 xChangeLstnr;
77 ConfigItemMode m_nMode;
78 bool m_bIsModified;
79 bool m_bEnableInternalNotification;
80 sal_Int16 m_nInValueChange;
82 void RemoveChangesListener();
83 void CallNotify(
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!>
90 // e.g.
91 // LOCALIZED NODE
92 // "UIName"
93 // LOCALE VALUE
94 // "de" "Mein Name"
95 // "en-US" "my name"
96 static 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 static void impl_unpackLocalizedProperties (
100 const css::uno::Sequence< OUString >& lInNames ,
101 const css::uno::Sequence< css::uno::Any >& lInValues ,
102 css::uno::Sequence< OUString >& lOutNames ,
103 css::uno::Sequence< css::uno::Any >& lOutValues);
105 css::uno::Reference< css::container::XHierarchicalNameAccess>
106 GetTree();
107 /** writes the changed values into the sub tree.
108 Private and only called from non-virtual public Commit(). */
109 virtual void ImplCommit() = 0;
111 protected:
112 explicit ConfigItem(OUString aSubTree,
113 ConfigItemMode nMode = ConfigItemMode::NONE);
115 void SetModified (); // mark item as modified
116 void ClearModified(); // reset state after commit!
118 css::uno::Sequence< css::uno::Any>
119 GetProperties(const css::uno::Sequence< OUString >& rNames);
121 css::uno::Sequence< sal_Bool >
122 GetReadOnlyStates(const css::uno::Sequence< OUString >& rNames);
124 bool PutProperties(
125 const css::uno::Sequence< OUString >& rNames,
126 const css::uno::Sequence< css::uno::Any>& rValues);
128 /** enables notifications about changes on selected sub nodes/values
130 Before calling this method a second time for a possibly changed node/value set,
131 you must disable the current notifications by calling DisableNotification.
133 @see Notify
134 @see DisableNotification
136 bool EnableNotification(const css::uno::Sequence< OUString >& rNames,
137 bool bEnableInternalNotification = false);
138 /** disables notifications about changes on sub nodes/values, which previously had
139 been enabled with EnableNotification
140 @see Notify
141 @see EnableNotification
143 void DisableNotification();
145 //returns all members of a node in a specific format
146 css::uno::Sequence< OUString >
147 GetNodeNames(const OUString& rNode);
148 //returns all members of a node in a specific format
149 css::uno::Sequence< OUString >
150 GetNodeNames(const OUString& rNode, ConfigNameFormat eFormat);
151 // remove all members of a set
152 bool ClearNodeSet(const OUString& rNode);
153 // remove selected members of a set
154 bool ClearNodeElements(const OUString& rNode,
155 css::uno::Sequence< OUString > const & rElements);
156 // change or add members to a set
157 bool SetSetProperties(const OUString& rNode, const css::uno::Sequence< css::beans::PropertyValue >& rValues);
158 // remove, change or add members of a set
159 bool ReplaceSetProperties(const OUString& rNode, const css::uno::Sequence< css::beans::PropertyValue >& rValues);
160 // add a new node without setting any properties
161 bool AddNode(const OUString& rNode, const OUString& rNewNode);
163 public:
164 virtual ~ConfigItem() override;
166 ConfigItem(ConfigItem const &) = default;
167 ConfigItem(ConfigItem &&) = default;
168 ConfigItem & operator =(ConfigItem const &) = delete; // due to const sSubTree
169 ConfigItem & operator =(ConfigItem &&) = delete; // due to const sSubTree
171 /** is called from the ConfigManager before application ends of from the
172 PropertyChangeListener if the sub tree broadcasts changes. */
173 virtual void Notify( const css::uno::Sequence<OUString>& aPropertyNames)=0;
175 const OUString& GetSubTreeName() const {return sSubTree;}
177 bool IsModified() const { return m_bIsModified;}
179 void Commit();
181 ConfigItemMode GetMode() const { return m_nMode;}
183 //returns all members of a node in a specific format
184 static css::uno::Sequence< OUString > GetNodeNames(
185 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
186 const OUString& rNode, ConfigNameFormat eFormat);
187 static css::uno::Sequence< css::uno::Any> GetProperties(
188 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
189 const css::uno::Sequence< OUString >& rNames,
190 bool bAllLocales);
191 static bool PutProperties(
192 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
193 const css::uno::Sequence< OUString >& rNames,
194 const css::uno::Sequence< css::uno::Any>& rValues,
195 bool bAllLocales);
196 // remove all members of a set
197 static bool ClearNodeSet(
198 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
199 const OUString& rNode);
200 // remove, change or add members of a set
201 static bool ReplaceSetProperties(
202 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
203 const OUString& rNode,
204 const css::uno::Sequence< css::beans::PropertyValue >& rValues,
205 bool bAllLocales);
206 // change or add members to a set
207 static bool SetSetProperties(
208 css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
209 const OUString& rNode,
210 const css::uno::Sequence< css::beans::PropertyValue >& rValues);
212 }//namespace utl
213 #endif // INCLUDED_UNOTOOLS_CONFIGITEM_HXX
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */