LCOV - code coverage report
Current view: top level - framework/source/uiconfiguration - moduleuicfgsupplier.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 46 59 78.0 %
Date: 2014-04-11 Functions: 8 11 72.7 %
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 <stdtypes.h>
      21             : 
      22             : #include <com/sun/star/beans/XPropertySet.hpp>
      23             : #include <com/sun/star/container/XNameAccess.hpp>
      24             : #include <com/sun/star/embed/ElementModes.hpp>
      25             : #include <com/sun/star/frame/ModuleManager.hpp>
      26             : #include <com/sun/star/io/XOutputStream.hpp>
      27             : #include <com/sun/star/io/XInputStream.hpp>
      28             : #include <com/sun/star/io/XSeekable.hpp>
      29             : #include <com/sun/star/embed/XPackageStructureCreator.hpp>
      30             : #include <com/sun/star/ui/ModuleUIConfigurationManager.hpp>
      31             : #include <com/sun/star/lang/XServiceInfo.hpp>
      32             : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
      33             : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
      34             : #include <com/sun/star/ui/XModuleUIConfigurationManager2.hpp>
      35             : #include <com/sun/star/frame/XModuleManager2.hpp>
      36             : 
      37             : #include <cppuhelper/basemutex.hxx>
      38             : #include <cppuhelper/compbase2.hxx>
      39             : #include <cppuhelper/supportsservice.hxx>
      40             : #include <vcl/svapp.hxx>
      41             : 
      42             : #include <boost/unordered_map.hpp>
      43             : 
      44             : using namespace com::sun::star::uno;
      45             : using namespace com::sun::star::io;
      46             : using namespace com::sun::star::lang;
      47             : using namespace com::sun::star::container;
      48             : using namespace com::sun::star::beans;
      49             : using namespace com::sun::star::embed;
      50             : using namespace ::com::sun::star::ui;
      51             : using namespace ::com::sun::star::frame;
      52             : using namespace framework;
      53             : 
      54             : namespace {
      55             : 
      56             : typedef cppu::WeakComponentImplHelper2<
      57             :     css::lang::XServiceInfo,
      58             :     css::ui::XModuleUIConfigurationManagerSupplier >
      59             :         ModuleUIConfigurationManagerSupplier_BASE;
      60             : 
      61             : class ModuleUIConfigurationManagerSupplier : private cppu::BaseMutex,
      62             :                                              public ModuleUIConfigurationManagerSupplier_BASE
      63             : {
      64             : public:
      65             :     ModuleUIConfigurationManagerSupplier( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
      66             :     virtual ~ModuleUIConfigurationManagerSupplier();
      67             : 
      68           0 :     virtual OUString SAL_CALL getImplementationName()
      69             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      70             :     {
      71           0 :         return OUString("com.sun.star.comp.framework.ModuleUIConfigurationManagerSupplier");
      72             :     }
      73             : 
      74           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
      75             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      76             :     {
      77           0 :         return cppu::supportsService(this, ServiceName);
      78             :     }
      79             : 
      80           0 :     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
      81             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      82             :     {
      83           0 :         css::uno::Sequence< OUString > aSeq(1);
      84           0 :         aSeq[0] = OUString("com.sun.star.ui.ModuleUIConfigurationManagerSupplier");
      85           0 :         return aSeq;
      86             :     }
      87             : 
      88             :     // XModuleUIConfigurationManagerSupplier
      89             :     virtual css::uno::Reference< css::ui::XUIConfigurationManager > SAL_CALL getUIConfigurationManager( const OUString& ModuleIdentifier )
      90             :         throw (css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      91             : 
      92             : private:
      93             :     virtual void SAL_CALL disposing() SAL_OVERRIDE;
      94             : 
      95             :     typedef ::boost::unordered_map< OUString, css::uno::Reference< css::ui::XModuleUIConfigurationManager2 >, OUStringHash, ::std::equal_to< OUString > > ModuleToModuleCfgMgr;
      96             : 
      97             : //TODO_AS            void impl_initStorages();
      98             : 
      99             :     // private methods
     100             :     ModuleToModuleCfgMgr                                                                m_aModuleToModuleUICfgMgrMap;
     101             :     css::uno::Reference< css::frame::XModuleManager2 >          m_xModuleMgr;
     102             :     css::uno::Reference< css::uno::XComponentContext >            m_xContext;
     103             : };
     104             : 
     105          69 : ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier( const Reference< XComponentContext >& xContext ) :
     106             :     ModuleUIConfigurationManagerSupplier_BASE(m_aMutex)
     107             :     , m_xModuleMgr( ModuleManager::create( xContext ) )
     108          69 :     , m_xContext( xContext )
     109             : {
     110             :     try
     111             :     {
     112             :         // Retrieve known modules and insert them into our boost::unordered_map to speed-up access time.
     113          69 :         Reference< XNameAccess > xNameAccess( m_xModuleMgr, UNO_QUERY_THROW );
     114         138 :         const Sequence< OUString >     aNameSeq   = xNameAccess->getElementNames();
     115          69 :         const OUString*                pNameSeq   = aNameSeq.getConstArray();
     116        1587 :         for ( sal_Int32 n = 0; n < aNameSeq.getLength(); n++ )
     117        1587 :             m_aModuleToModuleUICfgMgrMap.insert( ModuleToModuleCfgMgr::value_type(  pNameSeq[n], Reference< XModuleUIConfigurationManager2 >() ));
     118             :     }
     119           0 :     catch(...)
     120             :     {
     121             :     }
     122          69 : }
     123             : 
     124         204 : ModuleUIConfigurationManagerSupplier::~ModuleUIConfigurationManagerSupplier()
     125             : {
     126          68 :     disposing();
     127         136 : }
     128             : 
     129         136 : void SAL_CALL ModuleUIConfigurationManagerSupplier::disposing()
     130             : {
     131         136 :     osl::MutexGuard g(rBHelper.rMutex);
     132             : 
     133             :     // dispose all our module user interface configuration managers
     134         136 :     ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.begin();
     135        1768 :     while ( pIter != m_aModuleToModuleUICfgMgrMap.end() )
     136             :     {
     137        1496 :         Reference< XComponent > xComponent( pIter->second, UNO_QUERY );
     138        1496 :         if ( xComponent.is() )
     139          87 :             xComponent->dispose();
     140        1496 :         ++pIter;
     141        1496 :     }
     142         136 :     m_aModuleToModuleUICfgMgrMap.clear();
     143         136 :     m_xModuleMgr.clear();
     144         136 : }
     145             : 
     146             : // XModuleUIConfigurationManagerSupplier
     147       40394 : Reference< XUIConfigurationManager > SAL_CALL ModuleUIConfigurationManagerSupplier::getUIConfigurationManager( const OUString& sModuleIdentifier )
     148             : throw ( NoSuchElementException, RuntimeException, std::exception)
     149             : {
     150       40394 :     osl::MutexGuard g(rBHelper.rMutex);
     151             :     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
     152             : 
     153       40394 :     ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.find( sModuleIdentifier );
     154       40394 :     if ( pIter == m_aModuleToModuleUICfgMgrMap.end() )
     155           0 :         throw NoSuchElementException();
     156             : //TODO_AS    impl_initStorages();
     157             : 
     158             :     // Create instance on demand
     159       40394 :     if ( !pIter->second.is() )
     160             :     {
     161          97 :         OUString sShort;
     162             :         try
     163             :         {
     164          97 :             Sequence< PropertyValue > lProps;
     165         194 :             Reference< XNameAccess > xCont(m_xModuleMgr, UNO_QUERY);
     166          97 :             xCont->getByName(sModuleIdentifier) >>= lProps;
     167         873 :             for (sal_Int32 i=0; i<lProps.getLength(); ++i)
     168             :             {
     169         873 :                 if ( lProps[i].Name == "ooSetupFactoryShortName" )
     170             :                 {
     171          97 :                     lProps[i].Value >>= sShort;
     172          97 :                     break;
     173             :                 }
     174          97 :             }
     175             :         }
     176           0 :         catch( const Exception& )
     177             :         {
     178           0 :             sShort = OUString();
     179             :         }
     180             : 
     181          97 :         if (sShort.isEmpty())
     182           0 :             throw NoSuchElementException();
     183             : 
     184          97 :         pIter->second = css::ui::ModuleUIConfigurationManager::createDefault(m_xContext, sShort, sModuleIdentifier);
     185             :     }
     186             : 
     187       40394 :     return pIter->second;
     188             : }
     189             : 
     190          69 : struct Instance {
     191          69 :     explicit Instance(
     192             :         css::uno::Reference<css::uno::XComponentContext> const & context):
     193             :         instance(static_cast<cppu::OWeakObject *>(
     194          69 :                     new ModuleUIConfigurationManagerSupplier(context)))
     195             :     {
     196          69 :     }
     197             : 
     198             :     css::uno::Reference<css::uno::XInterface> instance;
     199             : };
     200             : 
     201             : struct Singleton:
     202             :     public rtl::StaticWithArg<
     203             :         Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton>
     204             : {};
     205             : 
     206             : }
     207             : 
     208             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     209          72 : com_sun_star_comp_framework_ModuleUIConfigurationManagerSupplier_get_implementation(
     210             :     css::uno::XComponentContext *context,
     211             :     css::uno::Sequence<css::uno::Any> const &)
     212             : {
     213             :     return cppu::acquire(static_cast<cppu::OWeakObject *>(
     214          72 :                 Singleton::get(context).instance.get()));
     215             : }
     216             : 
     217             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10