Line data Source code
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_SD_SOURCE_UI_INC_TOOLS_CONFIGURATIONACCESS_HXX
21 : #define INCLUDED_SD_SOURCE_UI_INC_TOOLS_CONFIGURATIONACCESS_HXX
22 :
23 : #include <rtl/ustring.hxx>
24 : #include <com/sun/star/container/XNameAccess.hpp>
25 : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
26 : #include <com/sun/star/uno/XComponentContext.hpp>
27 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 : #include <vector>
29 : #include <boost/function.hpp>
30 :
31 : namespace sd { namespace tools {
32 :
33 : /** This class gives access to the configuration. Create an object of this
34 : class for one node of the configuration. This will be the root node.
35 : Its children are then accessible through the new ConfigurationAccess
36 : object.
37 : */
38 424 : class ConfigurationAccess
39 : {
40 : public:
41 : enum WriteMode { READ_WRITE, READ_ONLY };
42 :
43 : /** Create a new object to access the configuration entries below the
44 : given root.
45 : @param rsRootName
46 : Name of the root.
47 : @param eMode
48 : This flag specifies whether to give read-write or read-only
49 : access.
50 : */
51 : ConfigurationAccess(
52 : const OUString& rsRootName,
53 : const WriteMode eMode);
54 :
55 : ConfigurationAccess(
56 : const css::uno::Reference<css::uno::XComponentContext>& rxContext,
57 : const OUString& rsRootName,
58 : const WriteMode eMode);
59 :
60 : /** Return a configuration node below the root of the called object.
61 : @param rsPathToNode
62 : The relative path from the root (as given the constructor) to
63 : the node.
64 : @return
65 : The type of the returned node varies with the requested node.
66 : It is empty when the node was not found.
67 : */
68 : css::uno::Any GetConfigurationNode (
69 : const OUString& rsPathToNode);
70 :
71 : /** Return a configuration node below the given node.
72 : @param rxNode
73 : The node that acts as root to the given relative path.
74 : @param rsPathToNode
75 : The relative path from the given node to the requested node.
76 : @return
77 : The type of the returned node varies with the requested node.
78 : It is empty when the node was not found.
79 : */
80 : static css::uno::Any GetConfigurationNode (
81 : const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
82 : const OUString& rsPathToNode);
83 :
84 : /** Write any changes that have been made back to the configuration.
85 : This call is ignored when the called ConfigurationAccess object was
86 : not create with read-write mode.
87 : */
88 : void CommitChanges (void);
89 :
90 : /** This functor is typically called for every item in a set. Its two
91 : parameters are the name of key item (often of no further interest)
92 : and the value of the item.
93 : */
94 : typedef ::boost::function<void(
95 : const OUString&,
96 : const std::vector<css::uno::Any>&) > Functor;
97 :
98 : /** Execute a functor for all elements of the given container.
99 : @param rxContainer
100 : The container is a XNameAccess to a list of the configuration.
101 : This can be a node returned by GetConfigurationNode().
102 : @param rArguments
103 : The functor is called with arguments that are children of each
104 : element of the container. The set of children is specified this
105 : list.
106 : @param rFunctor
107 : The functor to be executed for some or all of the elements in
108 : the given container.
109 : */
110 : static void ForAll (
111 : const css::uno::Reference<css::container::XNameAccess>& rxContainer,
112 : const ::std::vector<OUString>& rArguments,
113 : const Functor& rFunctor);
114 :
115 : /** Fill a list with the string contents of all sub-elements in the given container.
116 : @param rxContainer
117 : The container is a XNameAccess to a list of the configuration.
118 : This can be a node returned by GetConfigurationNode().
119 : @param rsArgument
120 : This specifies which string children of the elements in the
121 : container are to be inserted into the list. The specified child
122 : has to be of type string.
123 : @param rList
124 : The list to be filled.
125 : */
126 : static void FillList(
127 : const css::uno::Reference<css::container::XNameAccess>& rxContainer,
128 : const OUString& rsArgument,
129 : ::std::vector<OUString>& rList);
130 :
131 : private:
132 : css::uno::Reference<css::uno::XInterface> mxRoot;
133 :
134 : void Initialize (
135 : const css::uno::Reference<css::lang::XMultiServiceFactory>& rxProvider,
136 : const OUString& rsRootName,
137 : const WriteMode eMode);
138 : };
139 :
140 : } } // end of namespace sd::tools
141 :
142 : #endif
143 :
144 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|