LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sfx2/source/appl - appbaslib.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 72 59.7 %
Date: 2013-07-09 Functions: 12 18 66.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             : 
      21             : #include "appbaslib.hxx"
      22             : 
      23             : #include <sfx2/sfxuno.hxx>
      24             : #include "sfxtypes.hxx"
      25             : #include <sfx2/app.hxx>
      26             : 
      27             : #include <basic/basmgr.hxx>
      28             : #include <tools/diagnose_ex.h>
      29             : #include <comphelper/processfactory.hxx>
      30             : 
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::lang;
      33             : using namespace ::com::sun::star::script;
      34             : using namespace ::com::sun::star::embed;
      35             : using ::osl::MutexGuard;
      36             : using ::osl::Mutex;
      37             : 
      38             : //============================================================================
      39        1903 : SfxBasicManagerHolder::SfxBasicManagerHolder()
      40        1903 :     :mpBasicManager( NULL )
      41             : {
      42        1903 : }
      43             : 
      44        2162 : void SfxBasicManagerHolder::reset( BasicManager* _pBasicManager )
      45             : {
      46        2162 :     impl_releaseContainers();
      47             : 
      48             : #ifdef DISABLE_SCRIPTING
      49             :     (void) _pBasicManager;
      50             : #else
      51             :     // Note: we do not delete the old BasicManager. BasicManager instances are
      52             :     // nowadays obtained from the BasicManagerRepository, and the ownership is with
      53             :     // the repository.
      54             :     // @see basic::BasicManagerRepository::getApplicationBasicManager
      55             :     // @see basic::BasicManagerRepository::getDocumentBasicManager
      56        2162 :     mpBasicManager = _pBasicManager;
      57             : 
      58        2162 :     if ( mpBasicManager )
      59             :     {
      60             :         try
      61             :         {
      62         459 :             mxBasicContainer.set( mpBasicManager->GetScriptLibraryContainer(), UNO_QUERY_THROW );
      63         459 :             mxDialogContainer.set( mpBasicManager->GetDialogLibraryContainer(), UNO_QUERY_THROW  );
      64             :         }
      65           0 :         catch( const Exception& )
      66             :         {
      67             :             DBG_UNHANDLED_EXCEPTION();
      68             :         }
      69             :     }
      70             : #endif
      71        2162 : }
      72             : 
      73          31 : void SfxBasicManagerHolder::storeAllLibraries()
      74             : {
      75             : #ifndef DISABLE_SCRIPTING
      76             :     OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
      77             :     try
      78             :     {
      79          31 :         if ( mxBasicContainer.is() )
      80          31 :             mxBasicContainer->storeLibraries();
      81          31 :         if ( mxDialogContainer.is() )
      82          31 :             mxDialogContainer->storeLibraries();
      83             :     }
      84           0 :     catch( const Exception& )
      85             :     {
      86             :         DBG_UNHANDLED_EXCEPTION();
      87             :     }
      88             : #endif
      89          31 : }
      90             : 
      91         311 : void SfxBasicManagerHolder::setStorage( const Reference< XStorage >& _rxStorage )
      92             : {
      93             : #ifdef DISABLE_SCRIPTING
      94             :     (void) _rxStorage;
      95             : #else
      96             :     try
      97             :     {
      98         311 :         if ( mxBasicContainer.is() )
      99         306 :             mxBasicContainer->setRootStorage( _rxStorage );
     100         311 :         if ( mxDialogContainer.is() )
     101         306 :             mxDialogContainer->setRootStorage( _rxStorage );
     102             :     }
     103           0 :     catch( const Exception& )
     104             :     {
     105             :         DBG_UNHANDLED_EXCEPTION();
     106             :     }
     107             : #endif
     108         311 : }
     109             : 
     110         320 : void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference< XStorage >& _rxStorage )
     111             : {
     112             : #ifdef DISABLE_SCRIPTING
     113             :     (void) _rxStorage;
     114             : #else
     115             :     OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
     116             : 
     117         320 :     if ( mxBasicContainer.is() )
     118         320 :         mxBasicContainer->storeLibrariesToStorage( _rxStorage );
     119         320 :     if ( mxDialogContainer.is() )
     120         320 :         mxDialogContainer->storeLibrariesToStorage( _rxStorage );
     121             : #endif
     122         320 : }
     123             : 
     124          37 : Reference< XLibraryContainer > SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType )
     125             : {
     126             :     OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
     127             : 
     128          37 :     switch ( _eType )
     129             :     {
     130          37 :     case SCRIPTS:   return mxBasicContainer.get();
     131           0 :     case DIALOGS:   return mxDialogContainer.get();
     132             :     }
     133             :     OSL_FAIL( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
     134           0 :     return NULL;
     135             : }
     136             : 
     137        2162 : void SfxBasicManagerHolder::impl_releaseContainers()
     138             : {
     139        2162 :     mxBasicContainer.clear();
     140        2162 :     mxDialogContainer.clear();
     141        2162 : }
     142             : 
     143             : sal_Bool
     144          17 : SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( Sequence< OUString >& sModules )
     145             : {
     146             : #ifdef DISABLE_SCRIPTING
     147             :     (void) sModules;
     148             : #else
     149          17 :     if ( mpBasicManager )
     150          17 :         return mpBasicManager->LegacyPsswdBinaryLimitExceeded( sModules );
     151             : #endif
     152           0 :     return sal_True;
     153             : }
     154             : 
     155             : //============================================================================
     156             : // Service for application library container
     157           0 : SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationDialogLibraryContainer )
     158             : 
     159           0 : Sequence< OUString > SfxApplicationDialogLibraryContainer::impl_getStaticSupportedServiceNames()
     160             : {
     161           0 :     static Sequence< OUString > seqServiceNames( 1 );
     162             :     static sal_Bool bNeedsInit = sal_True;
     163             : 
     164           0 :     MutexGuard aGuard( Mutex::getGlobalMutex() );
     165           0 :     if( bNeedsInit )
     166             :     {
     167           0 :         OUString* pSeq = seqServiceNames.getArray();
     168           0 :         pSeq[0] = OUString("com.sun.star.script.ApplicationDialogLibraryContainer");
     169           0 :         bNeedsInit = sal_False;
     170             :     }
     171           0 :     return seqServiceNames;
     172             : }
     173             : 
     174         284 : OUString SfxApplicationDialogLibraryContainer::impl_getStaticImplementationName()
     175             : {
     176         284 :     return OUString("com.sun.star.comp.sfx2.ApplicationDialogLibraryContainer");
     177             : }
     178             : 
     179           0 : Reference< XInterface > SAL_CALL SfxApplicationDialogLibraryContainer::impl_createInstance
     180             :     ( const Reference< XMultiServiceFactory >& )
     181             :         throw( Exception )
     182             : {
     183           0 :     SFX_APP()->GetBasicManager();
     184             :     Reference< XInterface > xRet =
     185           0 :         Reference< XInterface >( SFX_APP()->GetDialogContainer(), UNO_QUERY );
     186           0 :     return xRet;
     187             : }
     188             : 
     189             : //============================================================================
     190             : // Service for application library container
     191           0 : SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationScriptLibraryContainer )
     192             : 
     193           0 : Sequence< OUString > SfxApplicationScriptLibraryContainer::impl_getStaticSupportedServiceNames()
     194             : {
     195           0 :     Sequence< OUString > seqServiceNames( 1 );
     196           0 :     OUString* pSeq = seqServiceNames.getArray();
     197           0 :     pSeq[0] = OUString("com.sun.star.script.ApplicationScriptLibraryContainer");
     198           0 :     return seqServiceNames;
     199             : }
     200             : 
     201         284 : OUString SfxApplicationScriptLibraryContainer::impl_getStaticImplementationName()
     202             : {
     203         284 :     return OUString("com.sun.star.comp.sfx2.ApplicationScriptLibraryContainer");
     204             : }
     205             : 
     206           0 : Reference< XInterface > SAL_CALL SfxApplicationScriptLibraryContainer::impl_createInstance
     207             :     ( const Reference< XMultiServiceFactory >& )
     208             :         throw( Exception )
     209             : {
     210           0 :     SFX_APP()->GetBasicManager();
     211             :     Reference< XInterface > xRet =
     212           0 :         Reference< XInterface >( SFX_APP()->GetBasicContainer(), UNO_QUERY );
     213           0 :     return xRet;
     214         408 : }
     215             : 
     216             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10