LibreOffice Module unotools (master) 1
configitem.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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_UNOTOOLS_CONFIGITEM_HXX
21#define INCLUDED_UNOTOOLS_CONFIGITEM_HXX
22
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>
28#include <unotools/options.hxx>
30
31namespace com::sun::star {
32 namespace uno{
33 class Any;
34 }
35 namespace beans{
36 struct PropertyValue;
37 }
38 namespace container{
39 class XHierarchicalNameAccess;
40 }
41 namespace util{
42 class XChangesListener;
43 }
44}
45
47{
48 NONE = 0x00,
49 AllLocales = 0x02,
50 ReleaseTree = 0x04,
51};
52
53namespace o3tl
54{
55 template<> struct typed_flags<ConfigItemMode> : is_typed_flags<ConfigItemMode, 0x06> {};
56}
57
58namespace utl
59{
60
62 {
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']")
65 };
66
68 {
70 friend class ConfigManager;
71
72 const OUString sSubTree;
73 css::uno::Reference< css::container::XHierarchicalNameAccess>
75 css::uno::Reference< css::util::XChangesListener >
81
82 void RemoveChangesListener();
83 void CallNotify(
84 const css::uno::Sequence<OUString>& aPropertyNames);
85
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);
104
105 css::uno::Reference< css::container::XHierarchicalNameAccess>
106 GetTree();
109 virtual void ImplCommit() = 0;
110
111 protected:
112 explicit ConfigItem(OUString aSubTree,
114
115 void SetModified (); // mark item as modified
116 void ClearModified(); // reset state after commit!
117
118 css::uno::Sequence< css::uno::Any>
119 GetProperties(const css::uno::Sequence< OUString >& rNames);
120
121 css::uno::Sequence< sal_Bool >
122 GetReadOnlyStates(const css::uno::Sequence< OUString >& rNames);
123
125 const css::uno::Sequence< OUString >& rNames,
126 const css::uno::Sequence< css::uno::Any>& rValues);
127
136 bool EnableNotification(const css::uno::Sequence< OUString >& rNames,
137 bool bEnableInternalNotification = false);
143 void DisableNotification();
144
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);
162
163 public:
164 virtual ~ConfigItem() override;
165
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
170
173 virtual void Notify( const css::uno::Sequence<OUString>& aPropertyNames)=0;
174
175 const OUString& GetSubTreeName() const {return sSubTree;}
176
177 bool IsModified() const { return m_bIsModified;}
178
179 void Commit();
180
181 ConfigItemMode GetMode() const { return m_nMode;}
182
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
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);
211 };
212}//namespace utl
213#endif // INCLUDED_UNOTOOLS_CONFIGITEM_HXX
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
ConfigItem(ConfigItem &&)=default
bool SetSetProperties(const OUString &rNode, const css::uno::Sequence< css::beans::PropertyValue > &rValues)
static bool PutProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues, bool bAllLocales)
static bool SetSetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const OUString &rNode, const css::uno::Sequence< css::beans::PropertyValue > &rValues)
sal_Int16 m_nInValueChange
Definition: configitem.hxx:80
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames)=0
is called from the ConfigManager before application ends of from the PropertyChangeListener if the su...
virtual void ImplCommit()=0
writes the changed values into the sub tree.
ConfigItem(ConfigItem const &)=default
css::uno::Reference< css::util::XChangesListener > xChangeLstnr
Definition: configitem.hxx:76
const OUString & GetSubTreeName() const
Definition: configitem.hxx:175
css::uno::Reference< css::container::XHierarchicalNameAccess > m_xHierarchyAccess
Definition: configitem.hxx:74
bool IsModified() const
Definition: configitem.hxx:177
bool m_bEnableInternalNotification
Definition: configitem.hxx:79
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
bool PutProperties(const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues)
bool ReplaceSetProperties(const OUString &rNode, const css::uno::Sequence< css::beans::PropertyValue > &rValues)
ConfigItemMode m_nMode
Definition: configitem.hxx:77
const OUString sSubTree
Definition: configitem.hxx:72
ConfigItemMode GetMode() const
Definition: configitem.hxx:181
static bool ReplaceSetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const OUString &rNode, const css::uno::Sequence< css::beans::PropertyValue > &rValues, bool bAllLocales)
ConfigItemMode
Definition: configitem.hxx:47
NONE
ConfigNameFormat
Definition: configitem.hxx:62
#define UNOTOOLS_DLLPUBLIC