LCOV - code coverage report
Current view: top level - svx/source/unogallery - unogalthemeprovider.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 14 85 16.5 %
Date: 2015-06-13 12:38:46 Functions: 6 17 35.3 %
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 <rtl/ref.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : #include <unotools/pathoptions.hxx>
      28             : #include <comphelper/servicehelper.hxx>
      29             : #include <cppuhelper/supportsservice.hxx>
      30             : #include <com/sun/star/gallery/XGalleryTheme.hpp>
      31             : #include <com/sun/star/beans/PropertyValue.hpp>
      32             : #include <com/sun/star/uno/XComponentContext.hpp>
      33             : 
      34             : using namespace ::com::sun::star;
      35             : 
      36             : namespace {
      37             : 
      38           1 : GalleryThemeProvider::GalleryThemeProvider() :
      39           1 :     mbHiddenThemes( false )
      40             : {
      41           1 :     mpGallery = ::Gallery::GetGalleryInstance();
      42           1 : }
      43             : 
      44           2 : GalleryThemeProvider::~GalleryThemeProvider()
      45             : {
      46           2 : }
      47             : 
      48           1 : OUString SAL_CALL GalleryThemeProvider::getImplementationName()
      49             :     throw( uno::RuntimeException, std::exception )
      50             : {
      51           1 :     return OUString( "com.sun.star.comp.gallery.GalleryThemeProvider" );
      52             : }
      53             : 
      54           0 : sal_Bool SAL_CALL GalleryThemeProvider::supportsService( const OUString& ServiceName )
      55             :     throw( uno::RuntimeException, std::exception )
      56             : {
      57           0 :     return cppu::supportsService( this, ServiceName );
      58             : }
      59             : 
      60           1 : uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames()
      61             :     throw( uno::RuntimeException, std::exception )
      62             : {
      63           1 :     uno::Sequence< OUString > aSeq( 1 );
      64           1 :     aSeq.getArray()[ 0 ] = "com.sun.star.gallery.GalleryThemeProvider";
      65           1 :     return aSeq;
      66             : }
      67             : 
      68           0 : uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes()
      69             :     throw(uno::RuntimeException, std::exception)
      70             : {
      71           0 :     uno::Sequence< uno::Type >  aTypes( 6 );
      72           0 :     uno::Type*                  pTypes = aTypes.getArray();
      73             : 
      74           0 :     *pTypes++ = cppu::UnoType<lang::XServiceInfo>::get();
      75           0 :     *pTypes++ = cppu::UnoType<lang::XTypeProvider>::get();
      76           0 :     *pTypes++ = cppu::UnoType<lang::XInitialization>::get();
      77           0 :     *pTypes++ = cppu::UnoType<container::XElementAccess>::get();
      78           0 :     *pTypes++ = cppu::UnoType<container::XNameAccess>::get();
      79           0 :     *pTypes++ = cppu::UnoType<gallery::XGalleryThemeProvider>::get();
      80             : 
      81           0 :     return aTypes;
      82             : }
      83             : 
      84           0 : uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId()
      85             :     throw(uno::RuntimeException, std::exception)
      86             : {
      87           0 :     return css::uno::Sequence<sal_Int8>();
      88             : }
      89             : 
      90           0 : void SAL_CALL GalleryThemeProvider::initialize( const uno::Sequence< uno::Any >& rArguments )
      91             :     throw ( uno::Exception, uno::RuntimeException, std::exception )
      92             : {
      93           0 :     uno::Sequence< beans::PropertyValue >   aParams;
      94             :     sal_Int32                               i;
      95             : 
      96           0 :     for( i = 0; i < rArguments.getLength(); ++i )
      97             :     {
      98           0 :         if( rArguments[ i ] >>= aParams )
      99           0 :             break;
     100             :     }
     101             : 
     102           0 :     for( i = 0; i < aParams.getLength(); ++i )
     103             :     {
     104           0 :         const beans::PropertyValue& rProp = aParams[ i ];
     105             : 
     106           0 :         if ( rProp.Name == "ProvideHiddenThemes" )
     107           0 :             rProp.Value >>= mbHiddenThemes;
     108           0 :     }
     109           0 : }
     110             : 
     111             : 
     112             : 
     113           0 : uno::Type SAL_CALL GalleryThemeProvider::getElementType()
     114             :     throw (uno::RuntimeException, std::exception)
     115             : {
     116           0 :     return cppu::UnoType<gallery::XGalleryTheme>::get();
     117             : }
     118             : 
     119             : 
     120             : 
     121           0 : sal_Bool SAL_CALL GalleryThemeProvider::hasElements()
     122             :     throw (uno::RuntimeException, std::exception)
     123             : {
     124           0 :     const SolarMutexGuard aGuard;
     125             : 
     126           0 :     return( ( mpGallery != NULL ) && ( mpGallery->GetThemeCount() > 0 ) );
     127             : }
     128             : 
     129             : 
     130             : 
     131           0 : uno::Any SAL_CALL GalleryThemeProvider::getByName( const OUString& rName )
     132             :     throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     133             : {
     134           0 :     const SolarMutexGuard aGuard;
     135           0 :     uno::Any            aRet;
     136             : 
     137           0 :     if( !mpGallery || !mpGallery->HasTheme( rName ) )
     138             :     {
     139           0 :         throw container::NoSuchElementException();
     140             :     }
     141             :     else
     142             :     {
     143           0 :         aRet = uno::makeAny( uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) ) );
     144             :     }
     145             : 
     146           0 :     return aRet;
     147             : }
     148             : 
     149             : 
     150             : 
     151           0 : uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getElementNames()
     152             :     throw (uno::RuntimeException, std::exception)
     153             : {
     154           0 :     const SolarMutexGuard aGuard;
     155           0 :     sal_uInt32                          i = 0, nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0;
     156           0 :     uno::Sequence< OUString >    aSeq( nCount );
     157             : 
     158           0 :     for( ; i < nCount; ++i )
     159             :     {
     160           0 :         const GalleryThemeEntry* pEntry = mpGallery->GetThemeInfo( i );
     161             : 
     162           0 :         if( mbHiddenThemes || !pEntry->IsHidden() )
     163           0 :             aSeq[ nRealCount++ ] = pEntry->GetThemeName();
     164             :     }
     165             : 
     166           0 :     aSeq.realloc( nRealCount );
     167             : 
     168           0 :     return aSeq;
     169             : }
     170             : 
     171             : 
     172             : 
     173           0 : sal_Bool SAL_CALL GalleryThemeProvider::hasByName( const OUString& rName )
     174             :     throw (uno::RuntimeException, std::exception)
     175             : {
     176           0 :     const SolarMutexGuard aGuard;
     177             : 
     178           0 :     bool bRet = false;
     179             : 
     180           0 :     if( mpGallery && mpGallery->HasTheme( rName ) )
     181           0 :         bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() );
     182             : 
     183           0 :     return bRet;
     184             : }
     185             : 
     186             : 
     187             : 
     188           0 : uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName( const OUString& rThemeName )
     189             :     throw (container::ElementExistException, uno::RuntimeException, std::exception)
     190             : {
     191           0 :     const SolarMutexGuard aGuard;
     192           0 :     uno::Reference< gallery::XGalleryTheme >    xRet;
     193             : 
     194           0 :     if( mpGallery )
     195             :     {
     196           0 :         if( mpGallery->HasTheme( rThemeName ) )
     197             :         {
     198           0 :             throw container::ElementExistException();
     199             :         }
     200           0 :         else if( mpGallery->CreateTheme( rThemeName ) )
     201             :         {
     202           0 :             xRet = new ::unogallery::GalleryTheme( rThemeName );
     203             :         }
     204             :     }
     205             : 
     206           0 :     return xRet;
     207             : }
     208             : 
     209             : 
     210             : 
     211           0 : void SAL_CALL GalleryThemeProvider::removeByName( const OUString& rName )
     212             :     throw (container::NoSuchElementException, uno::RuntimeException, std::exception)
     213             : {
     214           0 :     const SolarMutexGuard aGuard;
     215             : 
     216           0 :     if( !mpGallery ||
     217           0 :         !mpGallery->HasTheme( rName ) ||
     218           0 :         ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) )
     219             :     {
     220           0 :         throw container::NoSuchElementException();
     221             :     }
     222             :     else
     223             :     {
     224           0 :         mpGallery->RemoveTheme( rName );
     225           0 :     }
     226           0 : }
     227             : 
     228             : }
     229             : 
     230             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     231           1 : com_sun_star_comp_gallery_GalleryThemeProvider_get_implementation(
     232             :     css::uno::XComponentContext *,
     233             :     css::uno::Sequence<css::uno::Any> const &)
     234             : {
     235           1 :     return cppu::acquire(new GalleryThemeProvider);
     236             : }
     237             : 
     238             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11