vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / sdext / source / presenter / PresenterConfigurationAccess.cxx
blobc83376fab5a820fa0409fe04f35af33340cc55b4
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 #include "PresenterConfigurationAccess.hxx"
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>
26 #include <comphelper/propertysequence.hxx>
27 #include <osl/diagnose.h>
28 #include <tools/diagnose_ex.h>
29 #include <sal/log.hxx>
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
34 namespace sdext { namespace presenter {
36 const OUString PresenterConfigurationAccess::msPresenterScreenRootName =
37 "/org.openoffice.Office.PresenterScreen/";
39 PresenterConfigurationAccess::PresenterConfigurationAccess (
40 const Reference<XComponentContext>& rxContext,
41 const OUString& rsRootName,
42 WriteMode eMode)
43 : mxRoot(),
44 maNode()
46 try
48 if (rxContext.is())
50 uno::Sequence<uno::Any> aCreationArguments(comphelper::InitAnyPropertySequence(
52 {"nodepath", uno::Any(rsRootName)},
53 {"depth", uno::Any(sal_Int32(-1))}
54 }));
56 OUString sAccessService;
57 if (eMode == READ_ONLY)
58 sAccessService = "com.sun.star.configuration.ConfigurationAccess";
59 else
60 sAccessService = "com.sun.star.configuration.ConfigurationUpdateAccess";
62 Reference<lang::XMultiServiceFactory> xProvider =
63 configuration::theDefaultProvider::get( rxContext );
64 mxRoot = xProvider->createInstanceWithArguments(
65 sAccessService, aCreationArguments);
66 maNode <<= mxRoot;
69 catch (const Exception&)
71 DBG_UNHANDLED_EXCEPTION("sdext.presenter", "caught exception while opening configuration");
75 PresenterConfigurationAccess::~PresenterConfigurationAccess()
79 bool PresenterConfigurationAccess::IsValid() const
81 return mxRoot.is();
84 Any PresenterConfigurationAccess::GetConfigurationNode (const OUString& sPathToNode)
86 return GetConfigurationNode(
87 Reference<container::XHierarchicalNameAccess>(mxRoot, UNO_QUERY),
88 sPathToNode);
91 bool PresenterConfigurationAccess::GoToChild (const OUString& rsPathToNode)
93 if ( ! IsValid())
94 return false;
96 Reference<container::XHierarchicalNameAccess> xNode (maNode, UNO_QUERY);
97 if (xNode.is())
99 maNode = GetConfigurationNode(
100 Reference<container::XHierarchicalNameAccess>(maNode, UNO_QUERY),
101 rsPathToNode);
102 if (Reference<XInterface>(maNode, UNO_QUERY).is())
103 return true;
106 mxRoot = nullptr;
107 return false;
110 bool PresenterConfigurationAccess::GoToChild (const Predicate& rPredicate)
112 if ( ! IsValid())
113 return false;
115 maNode = Find(Reference<container::XNameAccess>(maNode,UNO_QUERY), rPredicate);
116 if (Reference<XInterface>(maNode, UNO_QUERY).is())
117 return true;
119 mxRoot = nullptr;
120 return false;
123 bool PresenterConfigurationAccess::SetProperty (
124 const OUString& rsPropertyName,
125 const Any& rValue)
127 Reference<beans::XPropertySet> xProperties (maNode, UNO_QUERY);
128 if (xProperties.is())
130 xProperties->setPropertyValue(rsPropertyName, rValue);
131 return true;
133 else
134 return false;
137 Any PresenterConfigurationAccess::GetConfigurationNode (
138 const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
139 const OUString& sPathToNode)
141 if (sPathToNode.isEmpty())
142 return Any(rxNode);
146 if (rxNode.is())
148 return rxNode->getByHierarchicalName(sPathToNode);
151 catch (const Exception&)
153 TOOLS_WARN_EXCEPTION("sdext.presenter", "caught exception while getting configuration node " << sPathToNode);
156 return Any();
159 Reference<beans::XPropertySet> PresenterConfigurationAccess::GetNodeProperties (
160 const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
161 const OUString& rsPathToNode)
163 return Reference<beans::XPropertySet>(GetConfigurationNode(rxNode, rsPathToNode), UNO_QUERY);
166 void PresenterConfigurationAccess::CommitChanges()
168 Reference<util::XChangesBatch> xConfiguration (mxRoot, UNO_QUERY);
169 if (xConfiguration.is())
170 xConfiguration->commitChanges();
173 void PresenterConfigurationAccess::ForAll (
174 const Reference<container::XNameAccess>& rxContainer,
175 const ::std::vector<OUString>& rArguments,
176 const ItemProcessor& rProcessor)
178 if (!rxContainer.is())
179 return;
181 ::std::vector<Any> aValues(rArguments.size());
182 const Sequence<OUString> aKeys (rxContainer->getElementNames());
183 for (const OUString& rsKey : aKeys)
185 bool bHasAllValues (true);
186 Reference<container::XNameAccess> xSetItem (rxContainer->getByName(rsKey), UNO_QUERY);
187 Reference<beans::XPropertySet> xSet (xSetItem, UNO_QUERY);
188 OSL_ASSERT(xSet.is());
189 if (xSetItem.is())
191 // Get from the current item of the container the children
192 // that match the names in the rArguments list.
193 for (size_t nValueIndex=0; nValueIndex<aValues.size(); ++nValueIndex)
195 if ( ! xSetItem->hasByName(rArguments[nValueIndex]))
196 bHasAllValues = false;
197 else
198 aValues[nValueIndex] = xSetItem->getByName(rArguments[nValueIndex]);
201 else
202 bHasAllValues = false;
203 if (bHasAllValues)
204 rProcessor(aValues);
208 void PresenterConfigurationAccess::ForAll (
209 const Reference<container::XNameAccess>& rxContainer,
210 const PropertySetProcessor& rProcessor)
212 if (rxContainer.is())
214 const Sequence<OUString> aKeys (rxContainer->getElementNames());
215 for (const OUString& rsKey : aKeys)
217 Reference<beans::XPropertySet> xSet (rxContainer->getByName(rsKey), UNO_QUERY);
218 if (xSet.is())
219 rProcessor(rsKey, xSet);
224 Any PresenterConfigurationAccess::Find (
225 const Reference<container::XNameAccess>& rxContainer,
226 const Predicate& rPredicate)
228 if (rxContainer.is())
230 const Sequence<OUString> aKeys (rxContainer->getElementNames());
231 for (const auto& rKey : aKeys)
233 Reference<beans::XPropertySet> xProperties (
234 rxContainer->getByName(rKey),
235 UNO_QUERY);
236 if (xProperties.is())
237 if (rPredicate(rKey, xProperties))
238 return Any(xProperties);
241 return Any();
244 bool PresenterConfigurationAccess::IsStringPropertyEqual (
245 const OUString& rsValue,
246 const OUString& rsPropertyName,
247 const css::uno::Reference<css::beans::XPropertySet>& rxNode)
249 OUString sValue;
250 if (GetProperty(rxNode, rsPropertyName) >>= sValue)
251 return sValue == rsValue;
252 else
253 return false;
256 Any PresenterConfigurationAccess::GetProperty (
257 const Reference<beans::XPropertySet>& rxProperties,
258 const OUString& rsKey)
260 OSL_ASSERT(rxProperties.is());
261 if ( ! rxProperties.is())
262 return Any();
265 Reference<beans::XPropertySetInfo> xInfo (rxProperties->getPropertySetInfo());
266 if (xInfo.is())
267 if ( ! xInfo->hasPropertyByName(rsKey))
268 return Any();
269 return rxProperties->getPropertyValue(rsKey);
271 catch (beans::UnknownPropertyException&)
274 return Any();
277 } } // end of namespace sdext::tools
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */