LCOV - code coverage report
Current view: top level - libreoffice/svx/source/unogallery - unogalthemeprovider.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 98 0.0 %
Date: 2012-12-27 Functions: 0 21 0.0 %
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 "unogalthemeprovider.hxx"
      22             : #include "unogaltheme.hxx"
      23             : #include "svx/gallery1.hxx"
      24             : #include <osl/mutex.hxx>
      25             : #include <vcl/svapp.hxx>
      26             : #include <unotools/pathoptions.hxx>
      27             : #include <comphelper/servicehelper.hxx>
      28             : #include <com/sun/star/gallery/XGalleryTheme.hpp>
      29             : #include <com/sun/star/beans/PropertyValue.hpp>
      30             : 
      31             : using namespace ::com::sun::star;
      32             : 
      33             : namespace unogallery {
      34             : 
      35             : // --------------------
      36             : // - Helper functions -
      37             : // --------------------
      38             : 
      39           0 : uno::Reference< uno::XInterface > SAL_CALL GalleryThemeProvider_createInstance(
      40             :     const uno::Reference< lang::XMultiServiceFactory > & )
      41             :     throw( uno::Exception )
      42             : {
      43           0 :     return *( new GalleryThemeProvider() );
      44             : }
      45             : 
      46             : // -----------------------------------------------------------------------------
      47             : 
      48           0 : uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider_getSupportedServiceNames()
      49             :     throw()
      50             : {
      51           0 :     return GalleryThemeProvider::getSupportedServiceNames_Static();
      52             : }
      53             : 
      54             : // -----------------------------------------------------------------------------
      55             : 
      56           0 : ::rtl::OUString SAL_CALL GalleryThemeProvider_getImplementationName()
      57             :     throw()
      58             : {
      59           0 :     return GalleryThemeProvider::getImplementationName_Static();
      60             : }
      61             : 
      62             : // -----------------
      63             : // - GalleryThemeProvider -
      64             : // -----------------
      65             : 
      66           0 : GalleryThemeProvider::GalleryThemeProvider() :
      67           0 :     mbHiddenThemes( sal_False )
      68             : {
      69           0 :     mpGallery = ::Gallery::GetGalleryInstance();
      70           0 : }
      71             : 
      72             : // ------------------------------------------------------------------------------
      73             : 
      74           0 : GalleryThemeProvider::~GalleryThemeProvider()
      75             : {
      76           0 : }
      77             : 
      78             : // ------------------------------------------------------------------------------
      79             : 
      80           0 : SVX_DLLPUBLIC ::rtl::OUString GalleryThemeProvider::getImplementationName_Static()
      81             :     throw()
      82             : {
      83           0 :     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.gallery.GalleryThemeProvider" ) );
      84             : }
      85             : 
      86             : // ------------------------------------------------------------------------------
      87             : 
      88           0 : SVX_DLLPUBLIC uno::Sequence< ::rtl::OUString > GalleryThemeProvider::getSupportedServiceNames_Static()
      89             :     throw()
      90             : {
      91           0 :     uno::Sequence< ::rtl::OUString > aSeq( 1 );
      92             : 
      93           0 :     aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.gallery.GalleryThemeProvider" ) );
      94             : 
      95           0 :     return aSeq;
      96             : }
      97             : 
      98             : // ------------------------------------------------------------------------------
      99             : 
     100           0 : ::rtl::OUString SAL_CALL GalleryThemeProvider::getImplementationName()
     101             :     throw( uno::RuntimeException )
     102             : {
     103           0 :     return getImplementationName_Static();
     104             : }
     105             : 
     106             : // ------------------------------------------------------------------------------
     107             : 
     108           0 : sal_Bool SAL_CALL GalleryThemeProvider::supportsService( const ::rtl::OUString& ServiceName )
     109             :     throw( uno::RuntimeException )
     110             : {
     111           0 :     uno::Sequence< ::rtl::OUString >    aSNL( getSupportedServiceNames() );
     112           0 :     const ::rtl::OUString*              pArray = aSNL.getConstArray();
     113             : 
     114           0 :     for( int i = 0; i < aSNL.getLength(); i++ )
     115           0 :         if( pArray[i] == ServiceName )
     116           0 :             return true;
     117             : 
     118           0 :     return false;
     119             : }
     120             : 
     121             : // ------------------------------------------------------------------------------
     122             : 
     123           0 : uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames()
     124             :     throw( uno::RuntimeException )
     125             : {
     126           0 :     return getSupportedServiceNames_Static();
     127             : }
     128             : 
     129             : // ------------------------------------------------------------------------------
     130             : 
     131           0 : uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes()
     132             :     throw(uno::RuntimeException)
     133             : {
     134           0 :     uno::Sequence< uno::Type >  aTypes( 6 );
     135           0 :     uno::Type*                  pTypes = aTypes.getArray();
     136             : 
     137           0 :     *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
     138           0 :     *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
     139           0 :     *pTypes++ = ::getCppuType((const uno::Reference< lang::XInitialization>*)0);
     140           0 :     *pTypes++ = ::getCppuType((const uno::Reference< container::XElementAccess>*)0);
     141           0 :     *pTypes++ = ::getCppuType((const uno::Reference< container::XNameAccess>*)0);
     142           0 :     *pTypes++ = ::getCppuType((const uno::Reference< gallery::XGalleryThemeProvider>*)0);
     143             : 
     144           0 :     return aTypes;
     145             : }
     146             : 
     147             : namespace
     148             : {
     149             :     class theGalleryThemeProviderImplementationId : public rtl::Static< UnoTunnelIdInit, theGalleryThemeProviderImplementationId > {};
     150             : }
     151             : 
     152           0 : uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId()
     153             :     throw(uno::RuntimeException)
     154             : {
     155           0 :     return theGalleryThemeProviderImplementationId::get().getSeq();
     156             : }
     157             : 
     158             : // ------------------------------------------------------------------------------
     159             : 
     160           0 : void SAL_CALL GalleryThemeProvider::initialize( const uno::Sequence< uno::Any >& rArguments )
     161             :     throw ( uno::Exception, uno::RuntimeException )
     162             : {
     163           0 :     uno::Sequence< beans::PropertyValue >   aParams;
     164             :     sal_Int32                               i;
     165             : 
     166           0 :     for( i = 0; i < rArguments.getLength(); ++i )
     167             :     {
     168           0 :         if( rArguments[ i ] >>= aParams )
     169           0 :             break;
     170             :     }
     171             : 
     172           0 :     for( i = 0; i < aParams.getLength(); ++i )
     173             :     {
     174           0 :         const beans::PropertyValue& rProp = aParams[ i ];
     175             : 
     176           0 :         if ( rProp.Name == "ProvideHiddenThemes" )
     177           0 :             rProp.Value >>= mbHiddenThemes;
     178           0 :     }
     179           0 : }
     180             : 
     181             : // ------------------------------------------------------------------------------
     182             : 
     183           0 : uno::Type SAL_CALL GalleryThemeProvider::getElementType()
     184             :     throw (uno::RuntimeException)
     185             : {
     186           0 :     return ::getCppuType( (const uno::Reference< gallery::XGalleryTheme >*) 0);
     187             : }
     188             : 
     189             : // ------------------------------------------------------------------------------
     190             : 
     191           0 : sal_Bool SAL_CALL GalleryThemeProvider::hasElements()
     192             :     throw (uno::RuntimeException)
     193             : {
     194           0 :     const SolarMutexGuard aGuard;
     195             : 
     196           0 :     return( ( mpGallery != NULL ) && ( mpGallery->GetThemeCount() > 0 ) );
     197             : }
     198             : 
     199             : // ------------------------------------------------------------------------------
     200             : 
     201           0 : uno::Any SAL_CALL GalleryThemeProvider::getByName( const ::rtl::OUString& rName )
     202             :     throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     203             : {
     204           0 :     const SolarMutexGuard aGuard;
     205           0 :     uno::Any            aRet;
     206             : 
     207           0 :     if( !mpGallery || !mpGallery->HasTheme( rName ) )
     208             :     {
     209           0 :         throw container::NoSuchElementException();
     210             :     }
     211             :     else
     212             :     {
     213           0 :         aRet = uno::makeAny( uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) ) );
     214             :     }
     215             : 
     216           0 :     return aRet;
     217             : }
     218             : 
     219             : // ------------------------------------------------------------------------------
     220             : 
     221           0 : uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider::getElementNames()
     222             :     throw (uno::RuntimeException)
     223             : {
     224           0 :     const SolarMutexGuard aGuard;
     225           0 :     sal_uInt32                          i = 0, nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0;
     226           0 :     uno::Sequence< ::rtl::OUString >    aSeq( nCount );
     227             : 
     228           0 :     for( ; i < nCount; ++i )
     229             :     {
     230           0 :         const GalleryThemeEntry* pEntry = mpGallery->GetThemeInfo( i );
     231             : 
     232           0 :         if( mbHiddenThemes || !pEntry->IsHidden() )
     233           0 :             aSeq[ nRealCount++ ] = pEntry->GetThemeName();
     234             :     }
     235             : 
     236           0 :     aSeq.realloc( nRealCount );
     237             : 
     238           0 :     return aSeq;
     239             : }
     240             : 
     241             : // ------------------------------------------------------------------------------
     242             : 
     243           0 : sal_Bool SAL_CALL GalleryThemeProvider::hasByName( const ::rtl::OUString& rName )
     244             :     throw (uno::RuntimeException)
     245             : {
     246           0 :     const SolarMutexGuard aGuard;
     247             : 
     248           0 :     sal_Bool bRet = sal_False;
     249             : 
     250           0 :     if( mpGallery && mpGallery->HasTheme( rName ) )
     251           0 :         bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() );
     252             : 
     253           0 :     return( bRet );
     254             : }
     255             : 
     256             : // ------------------------------------------------------------------------------
     257             : 
     258           0 : uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName( const ::rtl::OUString& rThemeName )
     259             :     throw (container::ElementExistException, uno::RuntimeException)
     260             : {
     261           0 :     const SolarMutexGuard aGuard;
     262           0 :     uno::Reference< gallery::XGalleryTheme >    xRet;
     263             : 
     264           0 :     if( mpGallery )
     265             :     {
     266           0 :         if( mpGallery->HasTheme( rThemeName ) )
     267             :         {
     268           0 :             throw container::ElementExistException();
     269             :         }
     270           0 :         else if( mpGallery->CreateTheme( rThemeName ) )
     271             :         {
     272           0 :             xRet = new ::unogallery::GalleryTheme( rThemeName );
     273             :         }
     274             :     }
     275             : 
     276           0 :     return xRet;
     277             : }
     278             : 
     279             : // ------------------------------------------------------------------------------
     280             : 
     281           0 : void SAL_CALL GalleryThemeProvider::removeByName( const ::rtl::OUString& rName )
     282             :     throw (container::NoSuchElementException, uno::RuntimeException)
     283             : {
     284           0 :     const SolarMutexGuard aGuard;
     285             : 
     286           0 :     if( !mpGallery ||
     287           0 :         !mpGallery->HasTheme( rName ) ||
     288           0 :         ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) )
     289             :     {
     290           0 :         throw container::NoSuchElementException();
     291             :     }
     292             :     else
     293             :     {
     294           0 :         mpGallery->RemoveTheme( rName );
     295           0 :     }
     296           0 : }
     297             : 
     298             : }
     299             : 
     300             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10