LCOV - code coverage report
Current view: top level - framework/source/uiconfiguration - moduleuicfgsupplier.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 46 59 78.0 %
Date: 2015-06-13 12:38:46 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 <unordered_map>
      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] = "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 std::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         109 : ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier( const Reference< XComponentContext >& xContext ) :
     105             :     ModuleUIConfigurationManagerSupplier_BASE(m_aMutex)
     106             :     , m_xModuleMgr( ModuleManager::create( xContext ) )
     107         109 :     , m_xContext( xContext )
     108             : {
     109             :     try
     110             :     {
     111             :         // Retrieve known modules and insert them into our unordered_map to speed-up access time.
     112         109 :         Reference< XNameAccess > xNameAccess( m_xModuleMgr, UNO_QUERY_THROW );
     113         218 :         const Sequence< OUString >     aNameSeq   = xNameAccess->getElementNames();
     114         109 :         const OUString*                pNameSeq   = aNameSeq.getConstArray();
     115        2398 :         for ( sal_Int32 n = 0; n < aNameSeq.getLength(); n++ )
     116        2398 :             m_aModuleToModuleUICfgMgrMap.insert( ModuleToModuleCfgMgr::value_type(  pNameSeq[n], Reference< XModuleUIConfigurationManager2 >() ));
     117             :     }
     118           0 :     catch(...)
     119             :     {
     120             :     }
     121         109 : }
     122             : 
     123         321 : ModuleUIConfigurationManagerSupplier::~ModuleUIConfigurationManagerSupplier()
     124             : {
     125         107 :     disposing();
     126         214 : }
     127             : 
     128         214 : void SAL_CALL ModuleUIConfigurationManagerSupplier::disposing()
     129             : {
     130         214 :     osl::MutexGuard g(rBHelper.rMutex);
     131             : 
     132             :     // dispose all our module user interface configuration managers
     133         214 :     ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.begin();
     134        2675 :     while ( pIter != m_aModuleToModuleUICfgMgrMap.end() )
     135             :     {
     136        2247 :         Reference< XComponent > xComponent( pIter->second, UNO_QUERY );
     137        2247 :         if ( xComponent.is() )
     138         129 :             xComponent->dispose();
     139        2247 :         ++pIter;
     140        2247 :     }
     141         214 :     m_aModuleToModuleUICfgMgrMap.clear();
     142         214 :     m_xModuleMgr.clear();
     143         214 : }
     144             : 
     145             : // XModuleUIConfigurationManagerSupplier
     146       70708 : Reference< XUIConfigurationManager > SAL_CALL ModuleUIConfigurationManagerSupplier::getUIConfigurationManager( const OUString& sModuleIdentifier )
     147             : throw ( NoSuchElementException, RuntimeException, std::exception)
     148             : {
     149       70708 :     osl::MutexGuard g(rBHelper.rMutex);
     150             :     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
     151             : 
     152       70708 :     ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.find( sModuleIdentifier );
     153       70708 :     if ( pIter == m_aModuleToModuleUICfgMgrMap.end() )
     154           0 :         throw NoSuchElementException();
     155             : //TODO_AS    impl_initStorages();
     156             : 
     157             :     // Create instance on demand
     158       70708 :     if ( !pIter->second.is() )
     159             :     {
     160         140 :         OUString sShort;
     161             :         try
     162             :         {
     163         140 :             Sequence< PropertyValue > lProps;
     164         280 :             Reference< XNameAccess > xCont(m_xModuleMgr, UNO_QUERY);
     165         140 :             xCont->getByName(sModuleIdentifier) >>= lProps;
     166        1400 :             for (sal_Int32 i=0; i<lProps.getLength(); ++i)
     167             :             {
     168        1400 :                 if ( lProps[i].Name == "ooSetupFactoryShortName" )
     169             :                 {
     170         140 :                     lProps[i].Value >>= sShort;
     171         140 :                     break;
     172             :                 }
     173         140 :             }
     174             :         }
     175           0 :         catch( const Exception& )
     176             :         {
     177           0 :             sShort.clear();
     178             :         }
     179             : 
     180         140 :         if (sShort.isEmpty())
     181           0 :             throw NoSuchElementException();
     182             : 
     183         140 :         pIter->second = css::ui::ModuleUIConfigurationManager::createDefault(m_xContext, sShort, sModuleIdentifier);
     184             :     }
     185             : 
     186       70708 :     return pIter->second;
     187             : }
     188             : 
     189         109 : struct Instance {
     190         109 :     explicit Instance(
     191             :         css::uno::Reference<css::uno::XComponentContext> const & context):
     192             :         instance(static_cast<cppu::OWeakObject *>(
     193         109 :                     new ModuleUIConfigurationManagerSupplier(context)))
     194             :     {
     195         109 :     }
     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         112 : 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         112 :                 Singleton::get(context).instance.get()));
     214             : }
     215             : 
     216             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11