LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uifactory - toolbarcontrollerfactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 78 26.9 %
Date: 2012-12-27 Functions: 10 18 55.6 %
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 "uifactory/toolbarcontrollerfactory.hxx"
      21             : #include "uifactory/factoryconfiguration.hxx"
      22             : #include <threadhelp/resetableguard.hxx>
      23             : #include "services.h"
      24             : 
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/container/XNameAccess.hpp>
      28             : #include <com/sun/star/container/XNameContainer.hpp>
      29             : #include <com/sun/star/container/XContainer.hpp>
      30             : 
      31             : #include <rtl/ustrbuf.hxx>
      32             : #include <cppuhelper/weak.hxx>
      33             : 
      34             : //_________________________________________________________________________________________________________________
      35             : //  Defines
      36             : //_________________________________________________________________________________________________________________
      37             : 
      38             : using namespace com::sun::star::uno;
      39             : using namespace com::sun::star::lang;
      40             : using namespace com::sun::star::beans;
      41             : using namespace com::sun::star::container;
      42             : using namespace ::com::sun::star::frame;
      43             : 
      44             : //_________________________________________________________________________________________________________________
      45             : //  Namespace
      46             : //_________________________________________________________________________________________________________________
      47             : 
      48             : namespace framework
      49             : {
      50             : 
      51             : //*****************************************************************************************************************
      52             : //  XInterface, XTypeProvider, XServiceInfo
      53             : //*****************************************************************************************************************
      54         112 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   ToolbarControllerFactory                        ,
      55             :                                             ::cppu::OWeakObject                             ,
      56             :                                             DECLARE_ASCII("com.sun.star.frame.ToolBarControllerFactory"),
      57             :                                             IMPLEMENTATIONNAME_TOOLBARCONTROLLERFACTORY
      58             :                                         )
      59             : 
      60           8 : DEFINE_INIT_SERVICE                     (   ToolbarControllerFactory, {} )
      61             : 
      62           8 : ToolbarControllerFactory::ToolbarControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager ) :
      63             :     ThreadHelpBase(),
      64             :     m_bConfigRead( sal_False ),
      65           8 :     m_xServiceManager( xServiceManager )
      66             : {
      67           8 :     m_pConfigAccess = new ConfigurationAccess_ControllerFactory( comphelper::getComponentContext(m_xServiceManager), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Controller/Registered/ToolBar" )) );
      68           8 :     m_pConfigAccess->acquire();
      69           8 : }
      70             : 
      71          16 : ToolbarControllerFactory::ToolbarControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager,bool ) :
      72             :     ThreadHelpBase(),
      73             :     m_bConfigRead( sal_False ),
      74          16 :     m_xServiceManager( xServiceManager )
      75             : {
      76          16 :     m_pConfigAccess = NULL;
      77          16 : }
      78             : 
      79           7 : ToolbarControllerFactory::~ToolbarControllerFactory()
      80             : {
      81           3 :     ResetableGuard aLock( m_aLock );
      82             : 
      83             :     // reduce reference count
      84           3 :     m_pConfigAccess->release();
      85           4 : }
      86             : 
      87             : // XMultiComponentFactory
      88           0 : Reference< XInterface > SAL_CALL ToolbarControllerFactory::createInstanceWithContext(
      89             :     const ::rtl::OUString& aServiceSpecifier,
      90             :     const Reference< XComponentContext >& )
      91             : throw (Exception, RuntimeException)
      92             : {
      93             :     // SAFE
      94           0 :     ResetableGuard aLock( m_aLock );
      95             : 
      96           0 :     if ( !m_bConfigRead )
      97             :     {
      98           0 :         m_bConfigRead = sal_True;
      99           0 :         m_pConfigAccess->readConfigurationData();
     100             :     }
     101             : 
     102           0 :     rtl::OUString aServiceName = m_pConfigAccess->getServiceFromCommandModule( aServiceSpecifier, rtl::OUString() );
     103           0 :     if ( !aServiceName.isEmpty() )
     104           0 :         return m_xServiceManager->createInstance( aServiceName );
     105             :     else
     106           0 :         return Reference< XInterface >();
     107             :     // SAFE
     108             : }
     109             : 
     110           0 : Reference< XInterface > SAL_CALL ToolbarControllerFactory::createInstanceWithArgumentsAndContext(
     111             :     const ::rtl::OUString&                  ServiceSpecifier,
     112             :     const Sequence< Any >&                  Arguments,
     113             :     const Reference< XComponentContext >& )
     114             : throw (Exception, RuntimeException)
     115             : {
     116           0 :     const rtl::OUString aPropModuleName( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
     117           0 :     const rtl::OUString aPropValueName( RTL_CONSTASCII_USTRINGPARAM( "Value" ));
     118             : 
     119           0 :     rtl::OUString   aPropName;
     120           0 :     PropertyValue   aPropValue;
     121             : 
     122             :     // Retrieve the optional module name form the Arguments sequence. It is used as a part of
     123             :     // the hash map key to support different controller implementation for the same URL but different
     124             :     // module!!
     125           0 :     for ( int i = 0; i < Arguments.getLength(); i++ )
     126             :     {
     127           0 :         if (( Arguments[i] >>= aPropValue ) && ( aPropValue.Name.equals( aPropModuleName )))
     128             :         {
     129           0 :             aPropValue.Value >>= aPropName;
     130           0 :             break;
     131             :         }
     132             :     }
     133             : 
     134           0 :     Sequence< Any > aNewArgs( Arguments );
     135             : 
     136           0 :     sal_Int32 nAppendIndex = aNewArgs.getLength();
     137           0 :     bool bHasValue = m_pConfigAccess->hasValue();
     138           0 :     aNewArgs.realloc( aNewArgs.getLength() + (bHasValue ? 2 : 1) );
     139             : 
     140             :     // Append the command URL to the Arguments sequence so that one controller can be
     141             :     // used for more than one command URL.
     142           0 :     aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
     143           0 :     aPropValue.Value  <<= ServiceSpecifier;
     144           0 :     aNewArgs[nAppendIndex] <<= aPropValue;
     145             : 
     146           0 :     if ( bHasValue )
     147             :     {
     148             :         // Append the optional value argument. It's an empty string if no additional info
     149             :         // is provided to the controller.
     150           0 :         rtl::OUString aValue = m_pConfigAccess->getValueFromCommandModule( ServiceSpecifier, aPropName );
     151           0 :         aPropValue.Name = aPropValueName;
     152           0 :         aPropValue.Value <<= aValue;
     153           0 :         aNewArgs[nAppendIndex+1] <<= aPropValue;
     154             :     }
     155             : 
     156             :     {
     157             :         // SAFE
     158           0 :         ResetableGuard aLock( m_aLock );
     159             : 
     160           0 :         if ( !m_bConfigRead )
     161             :         {
     162           0 :             m_bConfigRead = sal_True;
     163           0 :             m_pConfigAccess->readConfigurationData();
     164             :         }
     165             : 
     166           0 :         rtl::OUString aServiceName = m_pConfigAccess->getServiceFromCommandModule( ServiceSpecifier, aPropName );
     167           0 :         Reference< XMultiServiceFactory > xServiceManager( m_xServiceManager );
     168             : 
     169           0 :         aLock.unlock();
     170             :         // SAFE
     171             : 
     172             : 
     173           0 :         if ( !aServiceName.isEmpty() )
     174           0 :             return xServiceManager->createInstanceWithArguments( aServiceName, aNewArgs );
     175             :         else
     176           0 :             return Reference< XInterface >();
     177           0 :     }
     178             : }
     179             : 
     180           0 : Sequence< ::rtl::OUString > SAL_CALL ToolbarControllerFactory::getAvailableServiceNames()
     181             : throw (RuntimeException)
     182             : {
     183           0 :     return Sequence< ::rtl::OUString >();
     184             : }
     185             : 
     186             : // XUIControllerRegistration
     187        2360 : sal_Bool SAL_CALL ToolbarControllerFactory::hasController(
     188             :     const ::rtl::OUString& aCommandURL,
     189             :     const rtl::OUString& aModuleName )
     190             : throw (::com::sun::star::uno::RuntimeException)
     191             : {
     192        2360 :     ResetableGuard aLock( m_aLock );
     193             : 
     194        2360 :     if ( !m_bConfigRead )
     195             :     {
     196           8 :         m_bConfigRead = sal_True;
     197           8 :         m_pConfigAccess->readConfigurationData();
     198             :     }
     199             : 
     200        2360 :     return ( !m_pConfigAccess->getServiceFromCommandModule( aCommandURL, aModuleName ).isEmpty() );
     201             : }
     202             : 
     203           0 : void SAL_CALL ToolbarControllerFactory::registerController(
     204             :     const ::rtl::OUString& aCommandURL,
     205             :     const ::rtl::OUString& aModuleName,
     206             :     const ::rtl::OUString& aControllerImplementationName )
     207             : throw (RuntimeException)
     208             : {
     209             :     // SAFE
     210           0 :     ResetableGuard aLock( m_aLock );
     211             : 
     212           0 :     if ( !m_bConfigRead )
     213             :     {
     214           0 :         m_bConfigRead = sal_True;
     215           0 :         m_pConfigAccess->readConfigurationData();
     216             :     }
     217             : 
     218           0 :     m_pConfigAccess->addServiceToCommandModule( aCommandURL, aModuleName, aControllerImplementationName );
     219             :     // SAFE
     220           0 : }
     221             : 
     222           0 : void SAL_CALL ToolbarControllerFactory::deregisterController(
     223             :     const ::rtl::OUString& aCommandURL,
     224             :     const rtl::OUString& aModuleName )
     225             : throw (RuntimeException)
     226             : {
     227             :     // SAFE
     228           0 :     ResetableGuard aLock( m_aLock );
     229             : 
     230           0 :     if ( !m_bConfigRead )
     231             :     {
     232           0 :         m_bConfigRead = sal_True;
     233           0 :         m_pConfigAccess->readConfigurationData();
     234             :     }
     235             : 
     236           0 :     m_pConfigAccess->removeServiceFromCommandModule( aCommandURL, aModuleName );
     237             :     // SAFE
     238           0 : }
     239             : 
     240             : } // namespace framework
     241             : 
     242             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10