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

Generated by: LCOV version 1.10