Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/unotools/configitem.hxx
Line
Count
Source
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/ref.hxx>
25
#include <rtl/ustring.hxx>
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>
30
31
namespace com::sun::star {
32
    namespace uno{
33
        class Any;
34
        template <class E> class Sequence;
35
    }
36
    namespace beans{
37
        struct PropertyValue;
38
    }
39
    namespace container{
40
        class XHierarchicalNameAccess;
41
    }
42
}
43
44
enum class ConfigItemMode
45
{
46
    NONE               = 0x00,
47
    AllLocales         = 0x02,
48
    ReleaseTree        = 0x04,
49
};
50
51
namespace o3tl
52
{
53
    template<> struct typed_flags<ConfigItemMode> : is_typed_flags<ConfigItemMode, 0x06> {};
54
}
55
56
namespace utl
57
{
58
class ConfigChangeListener_Impl;
59
60
    enum class ConfigNameFormat
61
    {
62
        LocalNode,     // local node name, for use in XNameAccess etc. ("Item", "Q & A")
63
        LocalPath,     // one-level relative path, for use when building paths etc.  ("Item", "Typ['Q &amp; A']")
64
    };
65
66
    class UNOTOOLS_DLLPUBLIC ConfigItem : public ConfigurationBroadcaster
67
    {
68
            friend class ConfigChangeListener_Impl;
69
            friend class ConfigManager;
70
71
            const OUString              sSubTree;
72
            css::uno::Reference< css::container::XHierarchicalNameAccess>
73
                                        m_xHierarchyAccess;
74
            rtl::Reference< ConfigChangeListener_Impl >
75
                                        xChangeLstnr;
76
            ConfigItemMode              m_nMode;
77
            bool                        m_bIsModified;
78
            bool                        m_bEnableInternalNotification;
79
            sal_Int16                   m_nInValueChange;
80
81
            void                    RemoveChangesListener();
82
            void                    CallNotify(
83
                                const css::uno::Sequence<OUString>& aPropertyNames);
84
85
            css::uno::Reference< css::container::XHierarchicalNameAccess>
86
                                        GetTree();
87
            /** writes the changed values into the sub tree.
88
                Private and only called from non-virtual public Commit().  */
89
            virtual void            ImplCommit() = 0;
90
91
        protected:
92
            explicit ConfigItem(OUString aSubTree,
93
                        ConfigItemMode nMode = ConfigItemMode::NONE);
94
95
            void                    SetModified  (); // mark item as modified
96
            void                    ClearModified(); // reset state after commit!
97
98
            css::uno::Sequence< css::uno::Any>
99
                                    GetProperties(const css::uno::Sequence< OUString >& rNames);
100
101
            css::uno::Sequence< sal_Bool >
102
                                    GetReadOnlyStates(const css::uno::Sequence< OUString >& rNames);
103
104
            bool                PutProperties(
105
                                        const css::uno::Sequence< OUString >& rNames,
106
                                        const css::uno::Sequence< css::uno::Any>& rValues);
107
108
            /** enables notifications about changes on selected sub nodes/values
109
110
                Before calling this method a second time for a possibly changed node/value set,
111
                you must disable the current notifications by calling DisableNotification.
112
113
                @see Notify
114
                @see DisableNotification
115
            */
116
            bool                EnableNotification(const css::uno::Sequence< OUString >& rNames,
117
                                        bool bEnableInternalNotification = false);
118
            /** disables notifications about changes on sub nodes/values, which previously had
119
                been enabled with EnableNotification
120
                @see Notify
121
                @see EnableNotification
122
            */
123
            void                    DisableNotification();
124
125
            //returns all members of a node in a specific format
126
            css::uno::Sequence< OUString >
127
                                    GetNodeNames(const OUString& rNode);
128
            //returns all members of a node in a specific format
129
            css::uno::Sequence< OUString >
130
                                    GetNodeNames(const OUString& rNode, ConfigNameFormat eFormat);
131
            // remove all members of a set
132
            bool                ClearNodeSet(const OUString& rNode);
133
            // remove selected members of a set
134
            bool                ClearNodeElements(const OUString& rNode,
135
                                        css::uno::Sequence< OUString > const & rElements);
136
            // change or add members to a set
137
            bool                SetSetProperties(const OUString& rNode, const css::uno::Sequence< css::beans::PropertyValue >& rValues);
138
            // remove, change or add members of a set
139
            bool                ReplaceSetProperties(const OUString& rNode, const css::uno::Sequence< css::beans::PropertyValue >& rValues);
140
            // add a new node without setting any properties
141
            bool                AddNode(const OUString& rNode, const OUString& rNewNode);
142
143
        public:
144
            virtual ~ConfigItem() override;
145
146
            ConfigItem(ConfigItem const &);
147
            ConfigItem(ConfigItem &&);
148
            ConfigItem & operator =(ConfigItem const &) = delete; // due to const sSubTree
149
            ConfigItem & operator =(ConfigItem &&) = delete; // due to const sSubTree
150
151
            /** is called from the ConfigManager before application ends of from the
152
                PropertyChangeListener if the sub tree broadcasts changes. */
153
            virtual void            Notify( const css::uno::Sequence<OUString>& aPropertyNames)=0;
154
155
0
            const OUString&         GetSubTreeName() const {return sSubTree;}
156
157
536k
            bool IsModified() const { return m_bIsModified;}
158
159
            void                    Commit();
160
161
0
            ConfigItemMode GetMode() const { return m_nMode;}
162
163
            //returns all members of a node in a specific format
164
            static css::uno::Sequence< OUString > GetNodeNames(
165
                    css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
166
                    const OUString& rNode, ConfigNameFormat eFormat);
167
            static css::uno::Sequence< css::uno::Any> GetProperties(
168
                    css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
169
                    const css::uno::Sequence< OUString >& rNames,
170
                    bool bAllLocales);
171
            static bool PutProperties(
172
                    css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
173
                    const css::uno::Sequence< OUString >& rNames,
174
                    const css::uno::Sequence< css::uno::Any>& rValues,
175
                    bool bAllLocales);
176
            // remove all members of a set
177
            static bool ClearNodeSet(
178
                    css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
179
                    const OUString& rNode);
180
            // remove, change or add members of a set
181
            static bool ReplaceSetProperties(
182
                    css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
183
                    const OUString& rNode,
184
                    const css::uno::Sequence< css::beans::PropertyValue >& rValues,
185
                    bool bAllLocales);
186
            // change or add members to a set
187
            static bool SetSetProperties(
188
                    css::uno::Reference<css::container::XHierarchicalNameAccess> const & xHierarchyAccess,
189
                    const OUString& rNode,
190
                    const css::uno::Sequence< css::beans::PropertyValue >& rValues);
191
    };
192
}//namespace utl
193
#endif // INCLUDED_UNOTOOLS_CONFIGITEM_HXX
194
195
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */