/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include "PresenterConfigurationAccess.hxx" #include #include #include #include #include #include #include #include using namespace ::com::sun::star; using namespace ::com::sun::star::uno; namespace sdext { namespace presenter { const OUString PresenterConfigurationAccess::msPresenterScreenRootName = "/org.openoffice.Office.PresenterScreen/"; PresenterConfigurationAccess::PresenterConfigurationAccess ( const Reference& rxContext, const OUString& rsRootName, WriteMode eMode) : mxRoot(), maNode() { try { if (rxContext.is()) { uno::Sequence aCreationArguments(comphelper::InitAnyPropertySequence( { {"nodepath", uno::Any(rsRootName)}, {"depth", uno::Any(sal_Int32(-1))} })); OUString sAccessService; if (eMode == READ_ONLY) sAccessService = "com.sun.star.configuration.ConfigurationAccess"; else sAccessService = "com.sun.star.configuration.ConfigurationUpdateAccess"; Reference xProvider = configuration::theDefaultProvider::get( rxContext ); mxRoot = xProvider->createInstanceWithArguments( sAccessService, aCreationArguments); maNode <<= mxRoot; } } catch (const Exception&) { DBG_UNHANDLED_EXCEPTION("sdext.presenter", "caught exception while opening configuration"); } } PresenterConfigurationAccess::~PresenterConfigurationAccess() { } bool PresenterConfigurationAccess::IsValid() const { return mxRoot.is(); } Any PresenterConfigurationAccess::GetConfigurationNode (const OUString& sPathToNode) { return GetConfigurationNode( Reference(mxRoot, UNO_QUERY), sPathToNode); } bool PresenterConfigurationAccess::GoToChild (const OUString& rsPathToNode) { if ( ! IsValid()) return false; Reference xNode (maNode, UNO_QUERY); if (xNode.is()) { maNode = GetConfigurationNode( Reference(maNode, UNO_QUERY), rsPathToNode); if (Reference(maNode, UNO_QUERY).is()) return true; } mxRoot = nullptr; return false; } bool PresenterConfigurationAccess::GoToChild (const Predicate& rPredicate) { if ( ! IsValid()) return false; maNode = Find(Reference(maNode,UNO_QUERY), rPredicate); if (Reference(maNode, UNO_QUERY).is()) return true; mxRoot = nullptr; return false; } bool PresenterConfigurationAccess::SetProperty ( const OUString& rsPropertyName, const Any& rValue) { Reference xProperties (maNode, UNO_QUERY); if (xProperties.is()) { xProperties->setPropertyValue(rsPropertyName, rValue); return true; } else return false; } Any PresenterConfigurationAccess::GetConfigurationNode ( const css::uno::Reference& rxNode, const OUString& sPathToNode) { if (sPathToNode.isEmpty()) return Any(rxNode); try { if (rxNode.is()) { return rxNode->getByHierarchicalName(sPathToNode); } } catch (const Exception& rException) { SAL_WARN("sdext.presenter", "caught exception while getting configuration node " << sPathToNode << " : " << rException); } return Any(); } Reference PresenterConfigurationAccess::GetNodeProperties ( const css::uno::Reference& rxNode, const OUString& rsPathToNode) { return Reference(GetConfigurationNode(rxNode, rsPathToNode), UNO_QUERY); } void PresenterConfigurationAccess::CommitChanges() { Reference xConfiguration (mxRoot, UNO_QUERY); if (xConfiguration.is()) xConfiguration->commitChanges(); } void PresenterConfigurationAccess::ForAll ( const Reference& rxContainer, const ::std::vector& rArguments, const ItemProcessor& rProcessor) { if (rxContainer.is()) { ::std::vector aValues(rArguments.size()); Sequence aKeys (rxContainer->getElementNames()); for (sal_Int32 nItemIndex=0; nItemIndex xSetItem (rxContainer->getByName(rsKey), UNO_QUERY); Reference xSet (xSetItem, UNO_QUERY); OSL_ASSERT(xSet.is()); if (xSetItem.is()) { // Get from the current item of the container the children // that match the names in the rArguments list. for (size_t nValueIndex=0; nValueIndexhasByName(rArguments[nValueIndex])) bHasAllValues = false; else aValues[nValueIndex] = xSetItem->getByName(rArguments[nValueIndex]); } } else bHasAllValues = false; if (bHasAllValues) rProcessor(aValues); } } } void PresenterConfigurationAccess::ForAll ( const Reference& rxContainer, const PropertySetProcessor& rProcessor) { if (rxContainer.is()) { Sequence aKeys (rxContainer->getElementNames()); for (sal_Int32 nItemIndex=0; nItemIndex xSet (rxContainer->getByName(rsKey), UNO_QUERY); if (xSet.is()) rProcessor(rsKey, xSet); } } } Any PresenterConfigurationAccess::Find ( const Reference& rxContainer, const Predicate& rPredicate) { if (rxContainer.is()) { Sequence aKeys (rxContainer->getElementNames()); for (sal_Int32 nItemIndex=0; nItemIndex xProperties ( rxContainer->getByName(aKeys[nItemIndex]), UNO_QUERY); if (xProperties.is()) if (rPredicate(aKeys[nItemIndex], xProperties)) return Any(xProperties); } } return Any(); } bool PresenterConfigurationAccess::IsStringPropertyEqual ( const OUString& rsValue, const OUString& rsPropertyName, const css::uno::Reference& rxNode) { OUString sValue; if (GetProperty(rxNode, rsPropertyName) >>= sValue) return sValue == rsValue; else return false; } Any PresenterConfigurationAccess::GetProperty ( const Reference& rxProperties, const OUString& rsKey) { OSL_ASSERT(rxProperties.is()); if ( ! rxProperties.is()) return Any(); try { Reference xInfo (rxProperties->getPropertySetInfo()); if (xInfo.is()) if ( ! xInfo->hasPropertyByName(rsKey)) return Any(); return rxProperties->getPropertyValue(rsKey); } catch (beans::UnknownPropertyException&) { } return Any(); } } } // end of namespace sdext::tools /* vim:set shiftwidth=4 softtabstop=4 expandtab: */