LCOV - code coverage report
Current view: top level - framework/source/uifactory - toolbarcontrollerfactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 61 78 78.2 %
Date: 2012-08-25 Functions: 13 18 72.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 59 138 42.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "uifactory/toolbarcontrollerfactory.hxx"
      30                 :            : #include "uifactory/factoryconfiguration.hxx"
      31                 :            : #include <threadhelp/resetableguard.hxx>
      32                 :            : #include "services.h"
      33                 :            : 
      34                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      35                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      36                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      37                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      38                 :            : #include <com/sun/star/container/XContainer.hpp>
      39                 :            : 
      40                 :            : #include <rtl/ustrbuf.hxx>
      41                 :            : #include <cppuhelper/weak.hxx>
      42                 :            : 
      43                 :            : //_________________________________________________________________________________________________________________
      44                 :            : //  Defines
      45                 :            : //_________________________________________________________________________________________________________________
      46                 :            : 
      47                 :            : using namespace com::sun::star::uno;
      48                 :            : using namespace com::sun::star::lang;
      49                 :            : using namespace com::sun::star::beans;
      50                 :            : using namespace com::sun::star::container;
      51                 :            : using namespace ::com::sun::star::frame;
      52                 :            : 
      53                 :            : //_________________________________________________________________________________________________________________
      54                 :            : //  Namespace
      55                 :            : //_________________________________________________________________________________________________________________
      56                 :            : 
      57                 :            : namespace framework
      58                 :            : {
      59                 :            : 
      60                 :            : //*****************************************************************************************************************
      61                 :            : //  XInterface, XTypeProvider, XServiceInfo
      62                 :            : //*****************************************************************************************************************
      63 [ +  - ][ +  - ]:       1605 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   ToolbarControllerFactory                        ,
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
                 [ #  # ]
      64                 :            :                                             ::cppu::OWeakObject                             ,
      65                 :            :                                             SERVICENAME_TOOLBARCONTROLLERFACTORY            ,
      66                 :            :                                             IMPLEMENTATIONNAME_TOOLBARCONTROLLERFACTORY
      67                 :            :                                         )
      68                 :            : 
      69                 :        111 : DEFINE_INIT_SERVICE                     (   ToolbarControllerFactory, {} )
      70                 :            : 
      71                 :        111 : ToolbarControllerFactory::ToolbarControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager ) :
      72                 :            :     ThreadHelpBase(),
      73                 :            :     m_bConfigRead( sal_False ),
      74         [ +  - ]:        111 :     m_xServiceManager( xServiceManager )
      75                 :            : {
      76 [ +  - ][ +  - ]:        111 :     m_pConfigAccess = new ConfigurationAccess_ControllerFactory( m_xServiceManager,rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Controller/Registered/ToolBar" )) );
      77                 :        111 :     m_pConfigAccess->acquire();
      78                 :        111 : }
      79                 :            : 
      80                 :        222 : ToolbarControllerFactory::ToolbarControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager,bool ) :
      81                 :            :     ThreadHelpBase(),
      82                 :            :     m_bConfigRead( sal_False ),
      83         [ +  - ]:        222 :     m_xServiceManager( xServiceManager )
      84                 :            : {
      85                 :        222 :     m_pConfigAccess = NULL;
      86                 :        222 : }
      87                 :            : 
      88         [ +  - ]:        303 : ToolbarControllerFactory::~ToolbarControllerFactory()
      89                 :            : {
      90         [ +  - ]:        303 :     ResetableGuard aLock( m_aLock );
      91                 :            : 
      92                 :            :     // reduce reference count
      93         [ +  - ]:        303 :     m_pConfigAccess->release();
      94         [ -  + ]:        404 : }
      95                 :            : 
      96                 :            : // XMultiComponentFactory
      97                 :          0 : Reference< XInterface > SAL_CALL ToolbarControllerFactory::createInstanceWithContext(
      98                 :            :     const ::rtl::OUString& aServiceSpecifier,
      99                 :            :     const Reference< XComponentContext >& )
     100                 :            : throw (Exception, RuntimeException)
     101                 :            : {
     102                 :            :     // SAFE
     103         [ #  # ]:          0 :     ResetableGuard aLock( m_aLock );
     104                 :            : 
     105         [ #  # ]:          0 :     if ( !m_bConfigRead )
     106                 :            :     {
     107                 :          0 :         m_bConfigRead = sal_True;
     108         [ #  # ]:          0 :         m_pConfigAccess->readConfigurationData();
     109                 :            :     }
     110                 :            : 
     111         [ #  # ]:          0 :     rtl::OUString aServiceName = m_pConfigAccess->getServiceFromCommandModule( aServiceSpecifier, rtl::OUString() );
     112         [ #  # ]:          0 :     if ( !aServiceName.isEmpty() )
     113 [ #  # ][ #  # ]:          0 :         return m_xServiceManager->createInstance( aServiceName );
     114                 :            :     else
     115         [ #  # ]:          0 :         return Reference< XInterface >();
     116                 :            :     // SAFE
     117                 :            : }
     118                 :            : 
     119                 :       2021 : Reference< XInterface > SAL_CALL ToolbarControllerFactory::createInstanceWithArgumentsAndContext(
     120                 :            :     const ::rtl::OUString&                  ServiceSpecifier,
     121                 :            :     const Sequence< Any >&                  Arguments,
     122                 :            :     const Reference< XComponentContext >& )
     123                 :            : throw (Exception, RuntimeException)
     124                 :            : {
     125         [ +  - ]:       2021 :     const rtl::OUString aPropModuleName( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
     126         [ +  - ]:       2021 :     const rtl::OUString aPropValueName( RTL_CONSTASCII_USTRINGPARAM( "Value" ));
     127                 :            : 
     128                 :       2021 :     rtl::OUString   aPropName;
     129                 :       2021 :     PropertyValue   aPropValue;
     130                 :            : 
     131                 :            :     // Retrieve the optional module name form the Arguments sequence. It is used as a part of
     132                 :            :     // the hash map key to support different controller implementation for the same URL but different
     133                 :            :     // module!!
     134         [ +  - ]:       2021 :     for ( int i = 0; i < Arguments.getLength(); i++ )
     135                 :            :     {
     136 [ +  - ][ +  - ]:       2021 :         if (( Arguments[i] >>= aPropValue ) && ( aPropValue.Name.equals( aPropModuleName )))
         [ +  - ][ +  - ]
     137                 :            :         {
     138                 :       2021 :             aPropValue.Value >>= aPropName;
     139                 :       2021 :             break;
     140                 :            :         }
     141                 :            :     }
     142                 :            : 
     143         [ +  - ]:       2021 :     Sequence< Any > aNewArgs( Arguments );
     144                 :            : 
     145                 :       2021 :     sal_Int32 nAppendIndex = aNewArgs.getLength();
     146                 :       2021 :     bool bHasValue = m_pConfigAccess->hasValue();
     147 [ +  - ][ +  + ]:       2021 :     aNewArgs.realloc( aNewArgs.getLength() + (bHasValue ? 2 : 1) );
     148                 :            : 
     149                 :            :     // Append the command URL to the Arguments sequence so that one controller can be
     150                 :            :     // used for more than one command URL.
     151         [ +  - ]:       2021 :     aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
     152         [ +  - ]:       2021 :     aPropValue.Value  <<= ServiceSpecifier;
     153 [ +  - ][ +  - ]:       2021 :     aNewArgs[nAppendIndex] <<= aPropValue;
     154                 :            : 
     155         [ +  + ]:       2021 :     if ( bHasValue )
     156                 :            :     {
     157                 :            :         // Append the optional value argument. It's an empty string if no additional info
     158                 :            :         // is provided to the controller.
     159         [ +  - ]:        764 :         rtl::OUString aValue = m_pConfigAccess->getValueFromCommandModule( ServiceSpecifier, aPropName );
     160                 :        764 :         aPropValue.Name = aPropValueName;
     161         [ +  - ]:        764 :         aPropValue.Value <<= aValue;
     162 [ +  - ][ +  - ]:        764 :         aNewArgs[nAppendIndex+1] <<= aPropValue;
     163                 :            :     }
     164                 :            : 
     165                 :            :     {
     166                 :            :         // SAFE
     167         [ +  - ]:       2021 :         ResetableGuard aLock( m_aLock );
     168                 :            : 
     169         [ -  + ]:       2021 :         if ( !m_bConfigRead )
     170                 :            :         {
     171                 :          0 :             m_bConfigRead = sal_True;
     172         [ #  # ]:          0 :             m_pConfigAccess->readConfigurationData();
     173                 :            :         }
     174                 :            : 
     175         [ +  - ]:       2021 :         rtl::OUString aServiceName = m_pConfigAccess->getServiceFromCommandModule( ServiceSpecifier, aPropName );
     176                 :       2021 :         Reference< XMultiServiceFactory > xServiceManager( m_xServiceManager );
     177                 :            : 
     178         [ +  - ]:       2021 :         aLock.unlock();
     179                 :            :         // SAFE
     180                 :            : 
     181                 :            : 
     182         [ +  - ]:       2021 :         if ( !aServiceName.isEmpty() )
     183 [ +  - ][ +  - ]:       2021 :             return xServiceManager->createInstanceWithArguments( aServiceName, aNewArgs );
     184                 :            :         else
     185         [ +  - ]:       2021 :             return Reference< XInterface >();
     186         [ +  - ]:       2021 :     }
     187                 :            : }
     188                 :            : 
     189                 :          0 : Sequence< ::rtl::OUString > SAL_CALL ToolbarControllerFactory::getAvailableServiceNames()
     190                 :            : throw (RuntimeException)
     191                 :            : {
     192                 :          0 :     return Sequence< ::rtl::OUString >();
     193                 :            : }
     194                 :            : 
     195                 :            : // XUIControllerRegistration
     196                 :     376829 : sal_Bool SAL_CALL ToolbarControllerFactory::hasController(
     197                 :            :     const ::rtl::OUString& aCommandURL,
     198                 :            :     const rtl::OUString& aModuleName )
     199                 :            : throw (::com::sun::star::uno::RuntimeException)
     200                 :            : {
     201         [ +  - ]:     376829 :     ResetableGuard aLock( m_aLock );
     202                 :            : 
     203         [ +  + ]:     376829 :     if ( !m_bConfigRead )
     204                 :            :     {
     205                 :        180 :         m_bConfigRead = sal_True;
     206         [ +  - ]:        180 :         m_pConfigAccess->readConfigurationData();
     207                 :            :     }
     208                 :            : 
     209 [ +  - ][ +  - ]:     376829 :     return ( !m_pConfigAccess->getServiceFromCommandModule( aCommandURL, aModuleName ).isEmpty() );
     210                 :            : }
     211                 :            : 
     212                 :          4 : void SAL_CALL ToolbarControllerFactory::registerController(
     213                 :            :     const ::rtl::OUString& aCommandURL,
     214                 :            :     const ::rtl::OUString& aModuleName,
     215                 :            :     const ::rtl::OUString& aControllerImplementationName )
     216                 :            : throw (RuntimeException)
     217                 :            : {
     218                 :            :     // SAFE
     219         [ +  - ]:          4 :     ResetableGuard aLock( m_aLock );
     220                 :            : 
     221         [ -  + ]:          4 :     if ( !m_bConfigRead )
     222                 :            :     {
     223                 :          0 :         m_bConfigRead = sal_True;
     224         [ #  # ]:          0 :         m_pConfigAccess->readConfigurationData();
     225                 :            :     }
     226                 :            : 
     227 [ +  - ][ +  - ]:          4 :     m_pConfigAccess->addServiceToCommandModule( aCommandURL, aModuleName, aControllerImplementationName );
     228                 :            :     // SAFE
     229                 :          4 : }
     230                 :            : 
     231                 :          2 : void SAL_CALL ToolbarControllerFactory::deregisterController(
     232                 :            :     const ::rtl::OUString& aCommandURL,
     233                 :            :     const rtl::OUString& aModuleName )
     234                 :            : throw (RuntimeException)
     235                 :            : {
     236                 :            :     // SAFE
     237         [ +  - ]:          2 :     ResetableGuard aLock( m_aLock );
     238                 :            : 
     239         [ -  + ]:          2 :     if ( !m_bConfigRead )
     240                 :            :     {
     241                 :          0 :         m_bConfigRead = sal_True;
     242         [ #  # ]:          0 :         m_pConfigAccess->readConfigurationData();
     243                 :            :     }
     244                 :            : 
     245 [ +  - ][ +  - ]:          2 :     m_pConfigAccess->removeServiceFromCommandModule( aCommandURL, aModuleName );
     246                 :            :     // SAFE
     247                 :          2 : }
     248                 :            : 
     249                 :            : } // namespace framework
     250                 :            : 
     251                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10