LCOV - code coverage report
Current view: top level - sdext/source/presenter - PresenterConfigurationAccess.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2 122 1.6 %
Date: 2014-04-11 Functions: 2 17 11.8 %
Legend: Lines: hit not hit

          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             : #include "PresenterConfigurationAccess.hxx"
      21             : 
      22             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      23             : #include <com/sun/star/beans/PropertyValue.hpp>
      24             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      25             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      26             : #include <com/sun/star/util/XChangesBatch.hpp>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::com::sun::star::uno;
      30             : 
      31             : namespace sdext { namespace presenter {
      32             : 
      33           4 : const OUString PresenterConfigurationAccess::msPresenterScreenRootName =
      34             :     "/org.openoffice.Office.PresenterScreen/";
      35             : 
      36           0 : PresenterConfigurationAccess::PresenterConfigurationAccess (
      37             :     const Reference<XComponentContext>& rxContext,
      38             :     const OUString& rsRootName,
      39             :     WriteMode eMode)
      40             :     : mxRoot(),
      41           0 :       maNode()
      42             : {
      43             :     try
      44             :     {
      45           0 :         if (rxContext.is())
      46             :         {
      47           0 :             Sequence<Any> aCreationArguments(3);
      48           0 :             aCreationArguments[0] = makeAny(beans::PropertyValue(
      49             :                 "nodepath",
      50             :                 0,
      51             :                 makeAny(rsRootName),
      52           0 :                 beans::PropertyState_DIRECT_VALUE));
      53           0 :             aCreationArguments[1] = makeAny(beans::PropertyValue(
      54             :                 "depth",
      55             :                 0,
      56             :                 makeAny((sal_Int32)-1),
      57           0 :                 beans::PropertyState_DIRECT_VALUE));
      58           0 :             aCreationArguments[2] = makeAny(beans::PropertyValue(
      59             :                 "lazywrite",
      60             :                 0,
      61             :                 makeAny(true),
      62           0 :                 beans::PropertyState_DIRECT_VALUE));
      63             : 
      64           0 :             OUString sAccessService;
      65           0 :             if (eMode == READ_ONLY)
      66           0 :                 sAccessService = "com.sun.star.configuration.ConfigurationAccess";
      67             :             else
      68           0 :                 sAccessService = "com.sun.star.configuration.ConfigurationUpdateAccess";
      69             : 
      70             :             Reference<lang::XMultiServiceFactory> xProvider =
      71           0 :                 configuration::theDefaultProvider::get( rxContext );
      72           0 :             mxRoot = xProvider->createInstanceWithArguments(
      73           0 :                 sAccessService, aCreationArguments);
      74           0 :             maNode <<= mxRoot;
      75             :         }
      76             :     }
      77           0 :     catch (const Exception& rException)
      78             :     {
      79             :         OSL_TRACE ("caught exception while opening configuration: %s",
      80             :             OUStringToOString(rException.Message,
      81             :                 RTL_TEXTENCODING_UTF8).getStr());
      82             :     }
      83           0 : }
      84             : 
      85           0 : PresenterConfigurationAccess::~PresenterConfigurationAccess (void)
      86             : {
      87           0 : }
      88             : 
      89           0 : bool PresenterConfigurationAccess::IsValid (void) const
      90             : {
      91           0 :     return mxRoot.is();
      92             : }
      93             : 
      94           0 : Any PresenterConfigurationAccess::GetConfigurationNode (const OUString& sPathToNode)
      95             : {
      96             :     return GetConfigurationNode(
      97             :         Reference<container::XHierarchicalNameAccess>(mxRoot, UNO_QUERY),
      98           0 :         sPathToNode);
      99             : }
     100             : 
     101           0 : bool PresenterConfigurationAccess::GoToChild (const OUString& rsPathToNode)
     102             : {
     103           0 :     if ( ! IsValid())
     104           0 :         return false;
     105             : 
     106           0 :     Reference<container::XHierarchicalNameAccess> xNode (maNode, UNO_QUERY);
     107           0 :     if (xNode.is())
     108             :     {
     109           0 :         maNode = GetConfigurationNode(
     110             :             Reference<container::XHierarchicalNameAccess>(maNode, UNO_QUERY),
     111           0 :             rsPathToNode);
     112           0 :         if (Reference<XInterface>(maNode, UNO_QUERY).is())
     113           0 :             return true;
     114             :     }
     115             : 
     116           0 :     mxRoot = NULL;
     117           0 :     return false;
     118             : }
     119             : 
     120           0 : bool PresenterConfigurationAccess::GoToChild (const Predicate& rPredicate)
     121             : {
     122           0 :     if ( ! IsValid())
     123           0 :         return false;
     124             : 
     125           0 :     maNode = Find(Reference<container::XNameAccess>(maNode,UNO_QUERY), rPredicate);
     126           0 :     if (Reference<XInterface>(maNode, UNO_QUERY).is())
     127           0 :         return true;
     128             : 
     129           0 :     mxRoot = NULL;
     130           0 :     return false;
     131             : }
     132             : 
     133           0 : bool PresenterConfigurationAccess::SetProperty (
     134             :     const OUString& rsPropertyName,
     135             :     const Any& rValue)
     136             : {
     137           0 :     Reference<beans::XPropertySet> xProperties (maNode, UNO_QUERY);
     138           0 :     if (xProperties.is())
     139             :     {
     140           0 :         xProperties->setPropertyValue(rsPropertyName, rValue);
     141           0 :         return true;
     142             :     }
     143             :     else
     144           0 :         return false;
     145             : }
     146             : 
     147           0 : Any PresenterConfigurationAccess::GetConfigurationNode (
     148             :     const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
     149             :     const OUString& sPathToNode)
     150             : {
     151           0 :     if (sPathToNode.isEmpty())
     152           0 :         return Any(rxNode);
     153             : 
     154             :     try
     155             :     {
     156           0 :         if (rxNode.is())
     157             :         {
     158           0 :             return rxNode->getByHierarchicalName(sPathToNode);
     159             :         }
     160             :     }
     161           0 :     catch (const Exception& rException)
     162             :     {
     163             :         OSL_TRACE ("caught exception while getting configuration node %s: %s",
     164             :             OUStringToOString(sPathToNode, RTL_TEXTENCODING_UTF8).getStr(),
     165             :             OUStringToOString(rException.Message, RTL_TEXTENCODING_UTF8).getStr());
     166             :     }
     167             : 
     168           0 :     return Any();
     169             : }
     170             : 
     171           0 : Reference<beans::XPropertySet> PresenterConfigurationAccess::GetNodeProperties (
     172             :     const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
     173             :     const OUString& rsPathToNode)
     174             : {
     175           0 :     return Reference<beans::XPropertySet>(GetConfigurationNode(rxNode, rsPathToNode), UNO_QUERY);
     176             : }
     177             : 
     178           0 : void PresenterConfigurationAccess::CommitChanges (void)
     179             : {
     180           0 :     Reference<util::XChangesBatch> xConfiguration (mxRoot, UNO_QUERY);
     181           0 :     if (xConfiguration.is())
     182           0 :         xConfiguration->commitChanges();
     183           0 : }
     184             : 
     185           0 : void PresenterConfigurationAccess::ForAll (
     186             :     const Reference<container::XNameAccess>& rxContainer,
     187             :     const ::std::vector<OUString>& rArguments,
     188             :     const ItemProcessor& rProcessor)
     189             : {
     190           0 :     if (rxContainer.is())
     191             :     {
     192           0 :         ::std::vector<Any> aValues(rArguments.size());
     193           0 :         Sequence<OUString> aKeys (rxContainer->getElementNames());
     194           0 :         for (sal_Int32 nItemIndex=0; nItemIndex<aKeys.getLength(); ++nItemIndex)
     195             :         {
     196           0 :             bool bHasAllValues (true);
     197           0 :             const OUString& rsKey (aKeys[nItemIndex]);
     198           0 :             Reference<container::XNameAccess> xSetItem (rxContainer->getByName(rsKey), UNO_QUERY);
     199           0 :             Reference<beans::XPropertySet> xSet (xSetItem, UNO_QUERY);
     200             :             OSL_ASSERT(xSet.is());
     201           0 :             if (xSetItem.is())
     202             :             {
     203             :                 // Get from the current item of the container the children
     204             :                 // that match the names in the rArguments list.
     205           0 :                 for (sal_uInt32 nValueIndex=0; nValueIndex<aValues.size(); ++nValueIndex)
     206             :                 {
     207           0 :                     if ( ! xSetItem->hasByName(rArguments[nValueIndex]))
     208           0 :                         bHasAllValues = false;
     209             :                     else
     210           0 :                         aValues[nValueIndex] = xSetItem->getByName(rArguments[nValueIndex]);
     211             :                 }
     212             :             }
     213             :             else
     214           0 :                 bHasAllValues = false;
     215           0 :             if (bHasAllValues)
     216           0 :                 rProcessor(rsKey,aValues);
     217           0 :         }
     218             :     }
     219           0 : }
     220             : 
     221           0 : void PresenterConfigurationAccess::ForAll (
     222             :     const Reference<container::XNameAccess>& rxContainer,
     223             :     const PropertySetProcessor& rProcessor)
     224             : {
     225           0 :     if (rxContainer.is())
     226             :     {
     227           0 :         Sequence<OUString> aKeys (rxContainer->getElementNames());
     228           0 :         for (sal_Int32 nItemIndex=0; nItemIndex<aKeys.getLength(); ++nItemIndex)
     229             :         {
     230           0 :             const OUString& rsKey (aKeys[nItemIndex]);
     231           0 :             Reference<beans::XPropertySet> xSet (rxContainer->getByName(rsKey), UNO_QUERY);
     232           0 :             if (xSet.is())
     233           0 :                 rProcessor(rsKey, xSet);
     234           0 :         }
     235             :     }
     236           0 : }
     237             : 
     238           0 : Any PresenterConfigurationAccess::Find (
     239             :     const Reference<container::XNameAccess>& rxContainer,
     240             :     const Predicate& rPredicate)
     241             : {
     242           0 :     if (rxContainer.is())
     243             :     {
     244           0 :         Sequence<OUString> aKeys (rxContainer->getElementNames());
     245           0 :         for (sal_Int32 nItemIndex=0; nItemIndex<aKeys.getLength(); ++nItemIndex)
     246             :         {
     247             :             Reference<beans::XPropertySet> xProperties (
     248           0 :                 rxContainer->getByName(aKeys[nItemIndex]),
     249           0 :                 UNO_QUERY);
     250           0 :             if (xProperties.is())
     251           0 :                 if (rPredicate(aKeys[nItemIndex], xProperties))
     252           0 :                     return Any(xProperties);
     253           0 :         }
     254             :     }
     255           0 :     return Any();
     256             : }
     257             : 
     258           0 : bool PresenterConfigurationAccess::IsStringPropertyEqual (
     259             :     const OUString& rsValue,
     260             :     const OUString& rsPropertyName,
     261             :     const css::uno::Reference<css::beans::XPropertySet>& rxNode)
     262             : {
     263           0 :     OUString sValue;
     264           0 :     if (GetProperty(rxNode, rsPropertyName) >>= sValue)
     265           0 :         return sValue == rsValue;
     266             :     else
     267           0 :         return false;
     268             : }
     269             : 
     270           0 : Any PresenterConfigurationAccess::GetProperty (
     271             :     const Reference<beans::XPropertySet>& rxProperties,
     272             :     const OUString& rsKey)
     273             : {
     274             :     OSL_ASSERT(rxProperties.is());
     275           0 :     if ( ! rxProperties.is())
     276           0 :         return Any();
     277             :     try
     278             :     {
     279           0 :         Reference<beans::XPropertySetInfo> xInfo (rxProperties->getPropertySetInfo());
     280           0 :         if (xInfo.is())
     281           0 :             if ( ! xInfo->hasPropertyByName(rsKey))
     282           0 :                 return Any();
     283           0 :         return rxProperties->getPropertyValue(rsKey);
     284             :     }
     285           0 :     catch (beans::UnknownPropertyException&)
     286             :     {
     287             :     }
     288           0 :     return Any();
     289             : }
     290             : 
     291          12 : } } // end of namespace sdext::tools
     292             : 
     293             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10