22#include <com/sun/star/lang/XMultiServiceFactory.hpp>
23#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
24#include <com/sun/star/configuration/theDefaultProvider.hpp>
25#include <com/sun/star/util/XChangesBatch.hpp>
27#include <osl/diagnose.h>
37 const Reference<XComponentContext>& rxContext,
38 const OUString& rsRootName,
51 OUString sAccessService;
53 sAccessService =
"com.sun.star.configuration.ConfigurationAccess";
55 sAccessService =
"com.sun.star.configuration.ConfigurationUpdateAccess";
57 Reference<lang::XMultiServiceFactory> xProvider =
58 configuration::theDefaultProvider::get( rxContext );
59 mxRoot = xProvider->createInstanceWithArguments(
60 sAccessService, aCreationArguments);
82 Reference<container::XHierarchicalNameAccess>(
mxRoot, UNO_QUERY),
91 Reference<container::XHierarchicalNameAccess> xNode (
maNode, UNO_QUERY);
95 Reference<container::XHierarchicalNameAccess>(
maNode, UNO_QUERY),
97 if (Reference<XInterface>(
maNode, UNO_QUERY).is())
110 maNode =
Find(Reference<container::XNameAccess>(
maNode,UNO_QUERY), rPredicate);
111 if (Reference<XInterface>(
maNode, UNO_QUERY).is())
119 const OUString& rsPropertyName,
122 Reference<beans::XPropertySet> xProperties (
maNode, UNO_QUERY);
123 if (xProperties.is())
125 xProperties->setPropertyValue(rsPropertyName, rValue);
133 const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
134 const OUString& sPathToNode)
136 if (sPathToNode.isEmpty())
143 return rxNode->getByHierarchicalName(sPathToNode);
148 TOOLS_WARN_EXCEPTION(
"sdext.presenter",
"caught exception while getting configuration node " << sPathToNode);
155 const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
156 const OUString& rsPathToNode)
163 Reference<util::XChangesBatch> xConfiguration (
mxRoot, UNO_QUERY);
164 if (xConfiguration.is())
165 xConfiguration->commitChanges();
169 const Reference<container::XNameAccess>& rxContainer,
170 const ::std::vector<OUString>& rArguments,
171 const ItemProcessor& rProcessor)
173 if (!rxContainer.is())
176 ::std::vector<Any> aValues(rArguments.size());
177 const Sequence<OUString> aKeys (rxContainer->getElementNames());
178 for (
const OUString& rsKey : aKeys)
180 bool bHasAllValues (
true);
181 Reference<container::XNameAccess> xSetItem (rxContainer->getByName(rsKey), UNO_QUERY);
182 Reference<beans::XPropertySet> xSet (xSetItem, UNO_QUERY);
183 OSL_ASSERT(xSet.is());
188 for (
size_t nValueIndex=0; nValueIndex<aValues.size(); ++nValueIndex)
190 if ( ! xSetItem->hasByName(rArguments[nValueIndex]))
191 bHasAllValues =
false;
193 aValues[nValueIndex] = xSetItem->getByName(rArguments[nValueIndex]);
197 bHasAllValues =
false;
204 const Reference<container::XNameAccess>& rxContainer,
205 const PropertySetProcessor& rProcessor)
207 if (rxContainer.is())
209 const Sequence<OUString> aKeys (rxContainer->getElementNames());
210 for (
const OUString& rsKey : aKeys)
212 Reference<beans::XPropertySet> xSet (rxContainer->getByName(rsKey), UNO_QUERY);
220 const Reference<container::XNameAccess>& rxContainer,
223 if (rxContainer.is())
225 const Sequence<OUString> aKeys (rxContainer->getElementNames());
226 for (
const auto& rKey : aKeys)
228 Reference<beans::XPropertySet> xProperties (
229 rxContainer->getByName(rKey),
231 if (xProperties.is())
232 if (rPredicate(rKey, xProperties))
233 return Any(xProperties);
240 std::u16string_view rsValue,
241 const OUString& rsPropertyName,
242 const css::uno::Reference<css::beans::XPropertySet>& rxNode)
245 if (
GetProperty(rxNode, rsPropertyName) >>= sValue)
246 return sValue == rsValue;
252 const Reference<beans::XPropertySet>& rxProperties,
253 const OUString& rsKey)
255 OSL_ASSERT(rxProperties.is());
256 if ( ! rxProperties.is())
260 Reference<beans::XPropertySetInfo> xInfo (rxProperties->getPropertySetInfo());
262 if ( ! xInfo->hasPropertyByName(rsKey))
264 return rxProperties->getPropertyValue(rsKey);
266 catch (beans::UnknownPropertyException&)
const ::rtl::Reference< IEventProcessor > & rProcessor
~PresenterConfigurationAccess()
bool IsValid() const
Return <TRUE> when opening the configuration (via creating a new PresenterConfigurationAccess object)...
css::uno::Reference< css::uno::XInterface > mxRoot
bool SetProperty(const OUString &rsPropertyName, const css::uno::Any &rValue)
Modify the property child of the currently focused node.
PresenterConfigurationAccess(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const OUString &rsRootName, WriteMode eMode)
Create a new object to access the configuration entries below the given root.
bool GoToChild(const OUString &rsPathToNode)
Move the focused node to the (possibly indirect) child specified by the given path.
css::uno::Any GetConfigurationNode(const OUString &rsPathToNode)
Return a configuration node below the root of the called object.
static css::uno::Any GetProperty(const css::uno::Reference< css::beans::XPropertySet > &rxProperties, const OUString &rsKey)
This method wraps a call to getPropertyValue() and returns an empty Any instead of throwing an except...
static void ForAll(const css::uno::Reference< css::container::XNameAccess > &rxContainer, const ::std::vector< OUString > &rArguments, const ItemProcessor &rProcessor)
Execute a functor for all elements of the given container.
void CommitChanges()
Write any changes that have been made back to the configuration.
static bool IsStringPropertyEqual(std::u16string_view rsValue, const OUString &rsPropertyName, const css::uno::Reference< css::beans::XPropertySet > &rxNode)
static css::uno::Reference< css::beans::XPropertySet > GetNodeProperties(const css::uno::Reference< css::container::XHierarchicalNameAccess > &rxNode, const OUString &rsPathToNode)
static css::uno::Any Find(const css::uno::Reference< css::container::XNameAccess > &rxContainer, const Predicate &rPredicate)
::std::function< bool(const OUString &, const css::uno::Reference< css::beans::XPropertySet > &)> Predicate
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)