LCOV - code coverage report
Current view: top level - framework/source/uiconfiguration - moduleuicfgsupplier.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 47 60 78.3 %
Date: 2014-11-03 Functions: 10 13 76.9 %
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             :     ModuleToModuleCfgMgr                                                                m_aModuleToModuleUICfgMgrMap;
     100             :     css::uno::Reference< css::frame::XModuleManager2 >          m_xModuleMgr;
     101             :     css::uno::Reference< css::uno::XComponentContext >            m_xContext;
     102             : };
     103             : 
     104         162 : ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier( const Reference< XComponentContext >& xContext ) :
     105             :     ModuleUIConfigurationManagerSupplier_BASE(m_aMutex)
     106             :     , m_xModuleMgr( ModuleManager::create( xContext ) )
     107         162 :     , m_xContext( xContext )
     108             : {
     109             :     try
     110             :     {
     111             :         // Retrieve known modules and insert them into our boost::unordered_map to speed-up access time.
     112         162 :         Reference< XNameAccess > xNameAccess( m_xModuleMgr, UNO_QUERY_THROW );
     113         324 :         const Sequence< OUString >     aNameSeq   = xNameAccess->getElementNames();
     114         162 :         const OUString*                pNameSeq   = aNameSeq.getConstArray();
     115        3726 :         for ( sal_Int32 n = 0; n < aNameSeq.getLength(); n++ )
     116        3726 :             m_aModuleToModuleUICfgMgrMap.insert( ModuleToModuleCfgMgr::value_type(  pNameSeq[n], Reference< XModuleUIConfigurationManager2 >() ));
     117             :     }
     118           0 :     catch(...)
     119             :     {
     120             :     }
     121         162 : }
     122             : 
     123         474 : ModuleUIConfigurationManagerSupplier::~ModuleUIConfigurationManagerSupplier()
     124             : {
     125         158 :     disposing();
     126         316 : }
     127             : 
     128         316 : void SAL_CALL ModuleUIConfigurationManagerSupplier::disposing()
     129             : {
     130         316 :     osl::MutexGuard g(rBHelper.rMutex);
     131             : 
     132             :     // dispose all our module user interface configuration managers
     133         316 :     ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.begin();
     134        4108 :     while ( pIter != m_aModuleToModuleUICfgMgrMap.end() )
     135             :     {
     136        3476 :         Reference< XComponent > xComponent( pIter->second, UNO_QUERY );
     137        3476 :         if ( xComponent.is() )
     138         198 :             xComponent->dispose();
     139        3476 :         ++pIter;
     140        3476 :     }
     141         316 :     m_aModuleToModuleUICfgMgrMap.clear();
     142         316 :     m_xModuleMgr.clear();
     143         316 : }
     144             : 
     145             : // XModuleUIConfigurationManagerSupplier
     146      125312 : Reference< XUIConfigurationManager > SAL_CALL ModuleUIConfigurationManagerSupplier::getUIConfigurationManager( const OUString& sModuleIdentifier )
     147             : throw ( NoSuchElementException, RuntimeException, std::exception)
     148             : {
     149      125312 :     osl::MutexGuard g(rBHelper.rMutex);
     150             :     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
     151             : 
     152      125312 :     ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.find( sModuleIdentifier );
     153      125312 :     if ( pIter == m_aModuleToModuleUICfgMgrMap.end() )
     154           0 :         throw NoSuchElementException();
     155             : //TODO_AS    impl_initStorages();
     156             : 
     157             :     // Create instance on demand
     158      125312 :     if ( !pIter->second.is() )
     159             :     {
     160         220 :         OUString sShort;
     161             :         try
     162             :         {
     163         220 :             Sequence< PropertyValue > lProps;
     164         440 :             Reference< XNameAccess > xCont(m_xModuleMgr, UNO_QUERY);
     165         220 :             xCont->getByName(sModuleIdentifier) >>= lProps;
     166        3080 :             for (sal_Int32 i=0; i<lProps.getLength(); ++i)
     167             :             {
     168        3080 :                 if ( lProps[i].Name == "ooSetupFactoryShortName" )
     169             :                 {
     170         220 :                     lProps[i].Value >>= sShort;
     171         220 :                     break;
     172             :                 }
     173         220 :             }
     174             :         }
     175           0 :         catch( const Exception& )
     176             :         {
     177           0 :             sShort = OUString();
     178             :         }
     179             : 
     180         220 :         if (sShort.isEmpty())
     181           0 :             throw NoSuchElementException();
     182             : 
     183         220 :         pIter->second = css::ui::ModuleUIConfigurationManager::createDefault(m_xContext, sShort, sModuleIdentifier);
     184             :     }
     185             : 
     186      125312 :     return pIter->second;
     187             : }
     188             : 
     189         162 : struct Instance {
     190         162 :     explicit Instance(
     191             :         css::uno::Reference<css::uno::XComponentContext> const & context):
     192             :         instance(static_cast<cppu::OWeakObject *>(
     193         162 :                     new ModuleUIConfigurationManagerSupplier(context)))
     194             :     {
     195         162 :     }
     196             : 
     197             :     css::uno::Reference<css::uno::XInterface> instance;
     198             : };
     199             : 
     200             : struct Singleton:
     201             :     public rtl::StaticWithArg<
     202             :         Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton>
     203             : {};
     204             : 
     205             : }
     206             : 
     207             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     208         168 : com_sun_star_comp_framework_ModuleUIConfigurationManagerSupplier_get_implementation(
     209             :     css::uno::XComponentContext *context,
     210             :     css::uno::Sequence<css::uno::Any> const &)
     211             : {
     212             :     return cppu::acquire(static_cast<cppu::OWeakObject *>(
     213         168 :                 Singleton::get(context).instance.get()));
     214         951 : }
     215             : 
     216             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10