LCOV - code coverage report
Current view: top level - svx/source/gallery2 - gallery1.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 155 310 50.0 %
Date: 2014-04-11 Functions: 19 26 73.1 %
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 "sal/config.h"
      21             : 
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <comphelper/string.hxx>
      24             : #include <osl/thread.h>
      25             : #include <tools/vcompat.hxx>
      26             : #include <ucbhelper/content.hxx>
      27             : #include <unotools/ucbstreamhelper.hxx>
      28             : #include <unotools/pathoptions.hxx>
      29             : #include <sfx2/docfile.hxx>
      30             : #include "svx/gallery.hxx"
      31             : #include "gallery.hrc"
      32             : #include "svx/galmisc.hxx"
      33             : #include "svx/galtheme.hxx"
      34             : #include "svx/gallery1.hxx"
      35             : #include <com/sun/star/sdbc/XResultSet.hpp>
      36             : #include <com/sun/star/ucb/XContentAccess.hpp>
      37             : 
      38             : // - Namespaces -
      39             : 
      40             : using namespace ::rtl;
      41             : using namespace ::com::sun::star;
      42             : 
      43             : // - GalleryThemeEntry -
      44             : 
      45          11 : static bool FileExists( const INetURLObject &rURL, const rtl::OUString &rExt )
      46             : {
      47          11 :     INetURLObject aURL( rURL );
      48          11 :     aURL.setExtension( rExt );
      49          11 :     return FileExists( aURL );
      50             : }
      51             : 
      52          11 : GalleryThemeEntry::GalleryThemeEntry( bool bCreateUniqueURL,
      53             :                                       const INetURLObject& rBaseURL, const OUString& rName,
      54             :                                       bool _bReadOnly, bool _bNewFile,
      55             :                                       sal_uInt32 _nId, bool _bThemeNameFromResource ) :
      56             :         nId                     ( _nId ),
      57             :         bReadOnly               ( _bReadOnly ),
      58          11 :         bThemeNameFromResource  ( _bThemeNameFromResource )
      59             : {
      60          11 :     INetURLObject aURL( rBaseURL );
      61             :     DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
      62             : 
      63          11 :     if (bCreateUniqueURL)
      64             :     {
      65          11 :         INetURLObject aBaseNoCase( ImplGetURLIgnoreCase( rBaseURL ) );
      66          11 :         aURL = aBaseNoCase;
      67             :         static sal_Int32 nIdx = 0;
      68          22 :         while( FileExists( aURL, "thm" ) )
      69             :         { // create new URLs
      70           0 :             nIdx++;
      71           0 :             aURL = aBaseNoCase;
      72           0 :             aURL.setName( aURL.getName() + OUString::number(nIdx));
      73          11 :         }
      74             :     }
      75             : 
      76          11 :     aURL.setExtension( "thm" );
      77          11 :     aThmURL = ImplGetURLIgnoreCase( aURL );
      78             : 
      79          11 :     aURL.setExtension( "sdg" );
      80          11 :     aSdgURL = ImplGetURLIgnoreCase( aURL );
      81             : 
      82          11 :     aURL.setExtension( "sdv" );
      83          11 :     aSdvURL = ImplGetURLIgnoreCase( aURL );
      84             : 
      85          11 :     aURL.setExtension( "str" );
      86          11 :     aStrURL = ImplGetURLIgnoreCase( aURL );
      87             : 
      88          11 :     SetModified( _bNewFile );
      89             : 
      90          11 :     aName = ReadStrFromIni( "name" );
      91             : 
      92             :     // This is awful - we shouldn't use these resources if we
      93             :     // possibly can avoid them
      94          11 :     if( aName.isEmpty() && nId && bThemeNameFromResource )
      95           0 :         aName = GAL_RESSTR( RID_GALLERYSTR_THEME_START + (sal_uInt16) nId );
      96             : 
      97          11 :     if( aName.isEmpty() )
      98          11 :         aName = rName;
      99          11 : }
     100             : 
     101          55 : INetURLObject GalleryThemeEntry::ImplGetURLIgnoreCase( const INetURLObject& rURL ) const
     102             : {
     103          55 :     INetURLObject   aURL( rURL );
     104             : 
     105             :     // check original file name
     106          55 :     if( !FileExists( aURL ) )
     107             :     {
     108             :         // check upper case file name
     109          55 :         aURL.setName( aURL.getName().toAsciiUpperCase() );
     110             : 
     111          55 :         if(!FileExists( aURL ) )
     112             :         {
     113             :             // check lower case file name
     114          55 :             aURL.setName( aURL.getName().toAsciiLowerCase() );
     115             :         }
     116             :     }
     117             : 
     118          55 :     return aURL;
     119             : }
     120             : 
     121           0 : void GalleryThemeEntry::SetName( const OUString& rNewName )
     122             : {
     123           0 :     if( aName != rNewName )
     124             :     {
     125           0 :         aName = rNewName;
     126           0 :         SetModified( true );
     127           0 :         bThemeNameFromResource = false;
     128             :     }
     129           0 : }
     130             : 
     131          11 : void GalleryThemeEntry::SetId( sal_uInt32 nNewId, bool bResetThemeName )
     132             : {
     133          11 :     nId = nNewId;
     134          11 :     SetModified( true );
     135          11 :     bThemeNameFromResource = ( nId && bResetThemeName );
     136          11 : }
     137             : 
     138             : // - GalleryThemeCacheEntry -
     139             : 
     140             : class GalleryThemeCacheEntry
     141             : {
     142             : private:
     143             : 
     144             :     const GalleryThemeEntry*        mpThemeEntry;
     145             :     GalleryTheme*                           mpTheme;
     146             : 
     147             : public:
     148             : 
     149          11 :                                 GalleryThemeCacheEntry( const GalleryThemeEntry* pThemeEntry, GalleryTheme* pTheme ) :
     150          11 :                                     mpThemeEntry( pThemeEntry ), mpTheme( pTheme ) {}
     151          11 :                                 ~GalleryThemeCacheEntry() { delete mpTheme; }
     152             : 
     153           0 :     const GalleryThemeEntry*        GetThemeEntry() const { return mpThemeEntry; }
     154          11 :     GalleryTheme*                           GetTheme() const { return mpTheme; }
     155             : };
     156             : 
     157             : // - Gallery -
     158             : 
     159          11 : Gallery::Gallery( const OUString& rMultiPath )
     160          11 : :       nReadTextEncoding   ( osl_getThreadTextEncoding() )
     161          22 : ,       bMultiPath          ( false )
     162             : {
     163          11 :     ImplLoad( rMultiPath );
     164          11 : }
     165             : 
     166          33 : Gallery::~Gallery()
     167             : {
     168             :     // erase theme list
     169          22 :     for ( size_t i = 0, n = aThemeList.size(); i < n; ++i )
     170          11 :         delete aThemeList[ i ];
     171          11 :     aThemeList.clear();
     172          22 : }
     173             : 
     174           0 : Gallery* Gallery::GetGalleryInstance()
     175             : {
     176             :     static Gallery* pGallery = NULL;
     177             : 
     178           0 :     if( !pGallery )
     179             :     {
     180           0 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     181           0 :         if( !pGallery )
     182             :         {
     183           0 :             pGallery = new Gallery( SvtPathOptions().GetGalleryPath() );
     184           0 :         }
     185             :     }
     186             : 
     187           0 :     return pGallery;
     188             : }
     189             : 
     190          11 : void Gallery::ImplLoad( const OUString& rMultiPath )
     191             : {
     192          11 :     const sal_Int32 nTokenCount = comphelper::string::getTokenCount(rMultiPath, ';');
     193             :     bool            bIsReadOnlyDir;
     194             : 
     195          11 :     bMultiPath = ( nTokenCount > 0 );
     196             : 
     197          11 :     INetURLObject aCurURL(SvtPathOptions().GetConfigPath());
     198          11 :     ImplLoadSubDirs( aCurURL, bIsReadOnlyDir );
     199             : 
     200          11 :     if( !bIsReadOnlyDir )
     201          10 :         aUserURL = aCurURL;
     202             : 
     203          11 :     if( bMultiPath )
     204             :     {
     205          11 :         aRelURL = INetURLObject( comphelper::string::getToken(rMultiPath, 0, ';') );
     206             : 
     207          22 :         for( sal_Int32 i = 0; i < nTokenCount; ++i )
     208             :         {
     209          11 :             aCurURL = INetURLObject(comphelper::string::getToken(rMultiPath, i, ';'));
     210             : 
     211          11 :             ImplLoadSubDirs( aCurURL, bIsReadOnlyDir );
     212             : 
     213          11 :             if( !bIsReadOnlyDir )
     214          11 :                 aUserURL = aCurURL;
     215             :         }
     216             :     }
     217             :     else
     218           0 :         aRelURL = INetURLObject( rMultiPath );
     219             : 
     220             :     DBG_ASSERT( aUserURL.GetProtocol() != INET_PROT_NOT_VALID, "no writable Gallery user directory available" );
     221          11 :     DBG_ASSERT( aRelURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     222          11 : }
     223             : 
     224          22 : void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, bool& rbDirIsReadOnly )
     225             : {
     226          22 :     rbDirIsReadOnly = false;
     227             : 
     228             :     try
     229             :     {
     230          22 :         uno::Reference< ucb::XCommandEnvironment > xEnv;
     231          44 :         ::ucbhelper::Content                       aCnt( rBaseURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv, comphelper::getProcessComponentContext() );
     232             : 
     233          44 :         uno::Sequence< OUString > aProps( 1 );
     234          22 :         aProps.getArray()[ 0 ] = "Url";
     235             : 
     236          44 :         uno::Reference< sdbc::XResultSet > xResultSet( aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) );
     237             : 
     238             :         try
     239             :         {
     240             :             // check readonlyness the very hard way
     241          22 :             INetURLObject   aTestURL( rBaseURL );
     242          44 :             OUString        aTestFile( "cdefghij.klm" );
     243             : 
     244          22 :             aTestURL.Append( aTestFile );
     245          22 :             SvStream* pTestStm = ::utl::UcbStreamHelper::CreateStream( aTestURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
     246             : 
     247          22 :             if( pTestStm )
     248             :             {
     249          22 :                 pTestStm->WriteInt32( sal_Int32(1) );
     250             : 
     251          22 :                 if( pTestStm->GetError() )
     252           1 :                     rbDirIsReadOnly = true;
     253             : 
     254          22 :                 delete pTestStm;
     255          22 :                 KillFile( aTestURL );
     256             :             }
     257             :             else
     258          22 :                 rbDirIsReadOnly = true;
     259             :         }
     260           0 :         catch( const ucb::ContentCreationException& )
     261             :         {
     262             :         }
     263           0 :         catch( const uno::RuntimeException& )
     264             :         {
     265             :         }
     266           0 :         catch( const uno::Exception& )
     267             :         {
     268             :         }
     269             : 
     270          22 :         if( xResultSet.is() )
     271             :         {
     272          22 :             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
     273             : 
     274          22 :             if( xContentAccess.is() )
     275             :             {
     276          22 :                 static const OUString s_sTitle("Title");
     277          22 :                 static const OUString s_sIsReadOnly("IsReadOnly");
     278          22 :                 static const OUString s_sSDG_EXT("sdg");
     279          22 :                 static const OUString s_sSDV_EXT("sdv");
     280             : 
     281         121 :                 while( xResultSet->next() )
     282             :                 {
     283          77 :                     INetURLObject aThmURL( xContentAccess->queryContentIdentifierString() );
     284             : 
     285          77 :                     if(aThmURL.GetExtension().equalsIgnoreAsciiCase("thm"))
     286             :                     {
     287           0 :                         INetURLObject   aSdgURL( aThmURL); aSdgURL.SetExtension( s_sSDG_EXT );
     288           0 :                         INetURLObject   aSdvURL( aThmURL ); aSdvURL.SetExtension( s_sSDV_EXT );
     289           0 :                         OUString        aTitle;
     290           0 :                         sal_Bool        bReadOnly = sal_False;
     291             : 
     292             :                         try
     293             :                         {
     294           0 :                             ::ucbhelper::Content aThmCnt( aThmURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv, comphelper::getProcessComponentContext() );
     295           0 :                             ::ucbhelper::Content aSdgCnt( aSdgURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv, comphelper::getProcessComponentContext() );
     296           0 :                             ::ucbhelper::Content aSdvCnt( aSdvURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv, comphelper::getProcessComponentContext() );
     297             : 
     298             :                             try
     299             :                             {
     300           0 :                                 aThmCnt.getPropertyValue( s_sTitle ) >>= aTitle;
     301             :                             }
     302           0 :                             catch( const uno::RuntimeException& )
     303             :                             {
     304             :                             }
     305           0 :                             catch( const uno::Exception& )
     306             :                             {
     307             :                             }
     308             : 
     309           0 :                             if( !aTitle.isEmpty() )
     310             :                             {
     311             :                                 try
     312             :                                 {
     313           0 :                                     aThmCnt.getPropertyValue( s_sIsReadOnly ) >>= bReadOnly;
     314             :                                 }
     315           0 :                                 catch( const uno::RuntimeException& )
     316             :                                 {
     317             :                                 }
     318           0 :                                 catch( const uno::Exception& )
     319             :                                 {
     320             :                                 }
     321             : 
     322           0 :                                 if( !bReadOnly )
     323             :                                 {
     324             :                                     try
     325             :                                     {
     326           0 :                                         aSdgCnt.getPropertyValue( s_sTitle ) >>= aTitle;
     327             :                                     }
     328           0 :                                     catch( const ::com::sun::star::uno::RuntimeException& )
     329             :                                     {
     330             :                                     }
     331           0 :                                     catch( const ::com::sun::star::uno::Exception& )
     332             :                                     {
     333             :                                     }
     334             : 
     335           0 :                                     if( !aTitle.isEmpty() )
     336             :                                     {
     337             :                                         try
     338             :                                         {
     339           0 :                                             aSdgCnt.getPropertyValue( s_sIsReadOnly ) >>= bReadOnly;
     340             :                                         }
     341           0 :                                         catch( const uno::RuntimeException& )
     342             :                                         {
     343             :                                         }
     344           0 :                                         catch( const uno::Exception& )
     345             :                                         {
     346             :                                         }
     347             :                                     }
     348             :                                 }
     349             : 
     350           0 :                                 if( !bReadOnly )
     351             :                                 {
     352             :                                     try
     353             :                                     {
     354           0 :                                         aSdvCnt.getPropertyValue( s_sTitle ) >>= aTitle;
     355             :                                     }
     356           0 :                                     catch( const ::com::sun::star::uno::RuntimeException& )
     357             :                                     {
     358             :                                     }
     359           0 :                                     catch( const ::com::sun::star::uno::Exception& )
     360             :                                     {
     361             :                                     }
     362             : 
     363           0 :                                     if( !aTitle.isEmpty() )
     364             :                                     {
     365             :                                         try
     366             :                                         {
     367           0 :                                             aSdvCnt.getPropertyValue( s_sIsReadOnly ) >>= bReadOnly;
     368             :                                         }
     369           0 :                                         catch( const uno::RuntimeException& )
     370             :                                         {
     371             :                                         }
     372           0 :                                         catch( const uno::Exception& )
     373             :                                         {
     374             :                                         }
     375             :                                     }
     376             :                                 }
     377             : 
     378           0 :                                 GalleryThemeEntry* pEntry = GalleryTheme::CreateThemeEntry( aThmURL, rbDirIsReadOnly || bReadOnly );
     379             : 
     380           0 :                                 if( pEntry )
     381           0 :                                     aThemeList.push_back( pEntry );
     382           0 :                             }
     383             :                         }
     384           0 :                         catch( const ucb::ContentCreationException& )
     385             :                         {
     386             :                         }
     387           0 :                         catch( const uno::RuntimeException& )
     388             :                         {
     389             :                         }
     390           0 :                         catch( const uno::Exception& )
     391             :                         {
     392           0 :                         }
     393             :                     }
     394          77 :                 }
     395          22 :             }
     396          22 :         }
     397             :     }
     398           0 :     catch( const ucb::ContentCreationException& )
     399             :     {
     400             :     }
     401           0 :     catch( const uno::RuntimeException& )
     402             :     {
     403             :     }
     404           0 :     catch( const uno::Exception& )
     405             :     {
     406             :     }
     407          22 : }
     408             : 
     409          33 : GalleryThemeEntry* Gallery::ImplGetThemeEntry( const OUString& rThemeName )
     410             : {
     411          33 :     GalleryThemeEntry* pFound = NULL;
     412             : 
     413          33 :     if( !rThemeName.isEmpty() )
     414             :     {
     415          44 :         for ( size_t i = 0, n = aThemeList.size(); i < n && !pFound; ++i )
     416          11 :             if( rThemeName == aThemeList[ i ]->GetThemeName() )
     417          11 :                 pFound = aThemeList[ i ];
     418             :     }
     419             : 
     420          33 :     return pFound;
     421             : }
     422             : 
     423           0 : OUString Gallery::GetThemeName( sal_uIntPtr nThemeId ) const
     424             : {
     425           0 :     GalleryThemeEntry* pFound = NULL;
     426             : 
     427           0 :     for ( size_t i = 0, n = aThemeList.size(); i < n && !pFound; ++i )
     428             :     {
     429           0 :         GalleryThemeEntry* pEntry = aThemeList[ i ];
     430           0 :         if( nThemeId == pEntry->GetId() )
     431           0 :             pFound = pEntry;
     432             :     }
     433             : 
     434             :     // try fallback, if no entry was found
     435           0 :     if( !pFound )
     436             :     {
     437           0 :         OString aFallback;
     438             : 
     439           0 :         switch( nThemeId )
     440             :         {
     441             :             case( GALLERY_THEME_3D ):
     442           0 :                 aFallback = "3D";
     443           0 :                 break;
     444             :             case( GALLERY_THEME_BULLETS ):
     445           0 :                 aFallback = "Bullets";
     446           0 :                 break;
     447             :             case( GALLERY_THEME_HOMEPAGE ):
     448           0 :                 aFallback = "Homepage";
     449           0 :                 break;
     450             :             case( GALLERY_THEME_POWERPOINT ):
     451           0 :                 aFallback = "private://gallery/hidden/imgppt";
     452           0 :                 break;
     453             :             case( GALLERY_THEME_FONTWORK ):
     454           0 :                 aFallback = "private://gallery/hidden/fontwork";
     455           0 :                 break;
     456             :             case( GALLERY_THEME_FONTWORK_VERTICAL ):
     457           0 :                 aFallback = "private://gallery/hidden/fontworkvertical";
     458           0 :                 break;
     459             :             case( GALLERY_THEME_SOUNDS ):
     460           0 :                 aFallback = "Sounds";
     461           0 :                 break;
     462             :             case( RID_GALLERYSTR_THEME_ARROWS ):
     463           0 :                 aFallback = "Arrows";
     464           0 :                 break;
     465             :             case( RID_GALLERYSTR_THEME_COMPUTERS ):
     466           0 :                 aFallback = "Computers";
     467           0 :                 break;
     468             :             case( RID_GALLERYSTR_THEME_DIAGRAMS ):
     469           0 :                 aFallback = "Diagrams";
     470           0 :                 break;
     471             :             case( RID_GALLERYSTR_THEME_EDUCATION ):
     472           0 :                 aFallback = "Education";
     473           0 :                 break;
     474             :             case( RID_GALLERYSTR_THEME_ENVIRONMENT ):
     475           0 :                 aFallback = "Environment";
     476           0 :                 break;
     477             :             case( RID_GALLERYSTR_THEME_FINANCE ):
     478           0 :                 aFallback = "Finance";
     479           0 :                 break;
     480             :             case( RID_GALLERYSTR_THEME_PEOPLE ):
     481           0 :                 aFallback = "People";
     482           0 :                 break;
     483             :             case( RID_GALLERYSTR_THEME_SYMBOLS ):
     484           0 :                 aFallback = "Symbols";
     485           0 :                 break;
     486             :             case( RID_GALLERYSTR_THEME_TRANSPORT ):
     487           0 :                 aFallback = "Transport";
     488           0 :                 break;
     489             :             case( RID_GALLERYSTR_THEME_TXTSHAPES ):
     490           0 :                 aFallback = "Textshapes";
     491           0 :                 break;
     492             :             default:
     493           0 :                 break;
     494             :         }
     495             : 
     496           0 :         pFound = const_cast<Gallery*>(this)->ImplGetThemeEntry(OStringToOUString(aFallback, RTL_TEXTENCODING_ASCII_US));
     497             :     }
     498             : 
     499           0 :     return( pFound ? pFound->GetThemeName() : OUString() );
     500             : }
     501             : 
     502          22 : bool Gallery::HasTheme( const OUString& rThemeName )
     503             : {
     504          22 :     return( ImplGetThemeEntry( rThemeName ) != NULL );
     505             : }
     506             : 
     507          11 : bool Gallery::CreateTheme( const OUString& rThemeName )
     508             : {
     509          11 :     bool bRet = false;
     510             : 
     511          11 :     if( !HasTheme( rThemeName ) && ( GetUserURL().GetProtocol() != INET_PROT_NOT_VALID ) )
     512             :     {
     513          11 :         INetURLObject aURL( GetUserURL() );
     514          11 :         aURL.Append( rThemeName );
     515             :         GalleryThemeEntry* pNewEntry = new GalleryThemeEntry(
     516             :                 true, aURL, rThemeName,
     517          11 :                 false, true, 0, false );
     518             : 
     519          11 :         aThemeList.push_back( pNewEntry );
     520          11 :         delete( new GalleryTheme( this, pNewEntry ) );
     521          11 :         Broadcast( GalleryHint( GALLERY_HINT_THEME_CREATED, rThemeName ) );
     522          11 :         bRet = true;
     523             :     }
     524             : 
     525          11 :     return bRet;
     526             : }
     527             : 
     528           0 : bool Gallery::RenameTheme( const OUString& rOldName, const OUString& rNewName )
     529             : {
     530           0 :     GalleryThemeEntry*      pThemeEntry = ImplGetThemeEntry( rOldName );
     531           0 :     bool                    bRet = false;
     532             : 
     533             :     // check if the new theme name is already present
     534           0 :     if( pThemeEntry && !HasTheme( rNewName ) && !pThemeEntry->IsReadOnly() )
     535             :     {
     536           0 :         SfxListener   aListener;
     537           0 :         GalleryTheme* pThm = AcquireTheme( rOldName, aListener );
     538             : 
     539           0 :         if( pThm )
     540             :         {
     541           0 :             const OUString aOldName( rOldName );
     542             : 
     543           0 :             pThemeEntry->SetName( rNewName );
     544           0 :             pThm->ImplWrite();
     545             : 
     546           0 :             Broadcast( GalleryHint( GALLERY_HINT_THEME_RENAMED, aOldName, pThm->GetName() ) );
     547           0 :             ReleaseTheme( pThm, aListener );
     548           0 :             bRet = true;
     549           0 :         }
     550             :     }
     551             : 
     552           0 :     return bRet;
     553             : }
     554             : 
     555           0 : bool Gallery::RemoveTheme( const OUString& rThemeName )
     556             : {
     557           0 :     GalleryThemeEntry*  pThemeEntry = ImplGetThemeEntry( rThemeName );
     558           0 :     bool                bRet = false;
     559             : 
     560           0 :     if( pThemeEntry && !pThemeEntry->IsReadOnly() )
     561             :     {
     562           0 :         Broadcast( GalleryHint( GALLERY_HINT_CLOSE_THEME, rThemeName ) );
     563             : 
     564           0 :         SfxListener     aListener;
     565           0 :         GalleryTheme*   pThm = AcquireTheme( rThemeName, aListener );
     566             : 
     567           0 :         if( pThm )
     568             :         {
     569           0 :             INetURLObject   aThmURL( pThm->GetThmURL() );
     570           0 :             INetURLObject   aSdgURL( pThm->GetSdgURL() );
     571           0 :             INetURLObject   aSdvURL( pThm->GetSdvURL() );
     572           0 :             INetURLObject   aStrURL( pThm->GetSdvURL() );
     573             : 
     574           0 :             ReleaseTheme( pThm, aListener );
     575             : 
     576           0 :             KillFile( aThmURL );
     577           0 :             KillFile( aSdgURL );
     578           0 :             KillFile( aSdvURL );
     579           0 :             KillFile( aStrURL );
     580             :         }
     581             : 
     582           0 :         for ( GalleryThemeList::iterator it = aThemeList.begin(); it != aThemeList.end(); ++it )
     583             :         {
     584           0 :             if ( pThemeEntry == *it ) {
     585           0 :                 delete pThemeEntry;
     586           0 :                 aThemeList.erase( it );
     587           0 :                 break;
     588             :             }
     589             :         }
     590             : 
     591           0 :         Broadcast( GalleryHint( GALLERY_HINT_THEME_REMOVED, rThemeName ) );
     592             : 
     593           0 :         bRet = true;
     594             :     }
     595             : 
     596           0 :     return bRet;
     597             : }
     598             : 
     599          11 : GalleryTheme* Gallery::ImplGetCachedTheme( const GalleryThemeEntry* pThemeEntry )
     600             : {
     601          11 :     GalleryTheme* pTheme = NULL;
     602             : 
     603          11 :     if( pThemeEntry )
     604             :     {
     605          11 :         for (GalleryCacheThemeList::const_iterator it = aThemeCache.begin(); it != aThemeCache.end(); ++it)
     606             :         {
     607           0 :             if (pThemeEntry == (*it)->GetThemeEntry())
     608             :             {
     609           0 :                 pTheme = (*it)->GetTheme();
     610           0 :                 break;
     611             :             }
     612             :         }
     613             : 
     614          11 :         if( !pTheme )
     615             :         {
     616          11 :             INetURLObject aURL = pThemeEntry->GetThmURL();
     617             : 
     618             :             DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     619             : 
     620          11 :             if( FileExists( aURL ) )
     621             :             {
     622          11 :                 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
     623             : 
     624          11 :                 if( pIStm )
     625             :                 {
     626          11 :                     pTheme = new GalleryTheme( this, (GalleryThemeEntry*) pThemeEntry );
     627          11 :                     ReadGalleryTheme( *pIStm, *pTheme );
     628             : 
     629          11 :                     if( pIStm->GetError() )
     630             :                     {
     631           0 :                         delete pTheme, pTheme = NULL;
     632             :                     }
     633             : 
     634          11 :                     delete pIStm;
     635             :                 }
     636             :             }
     637             : 
     638          11 :             if( pTheme )
     639          11 :                 aThemeCache.push_back( new GalleryThemeCacheEntry( pThemeEntry, pTheme ));
     640             :         }
     641             :     }
     642             : 
     643          11 :     return pTheme;
     644             : }
     645             : 
     646          11 : void Gallery::ImplDeleteCachedTheme( GalleryTheme* pTheme )
     647             : {
     648          11 :     for (GalleryCacheThemeList::iterator it = aThemeCache.begin(); it != aThemeCache.end(); ++it)
     649             :     {
     650          11 :         if (pTheme == (*it)->GetTheme())
     651             :         {
     652          11 :             delete *it;
     653          11 :             aThemeCache.erase(it);
     654          11 :             break;
     655             :         }
     656             :     }
     657          11 : }
     658             : 
     659          11 : GalleryTheme* Gallery::AcquireTheme( const OUString& rThemeName, SfxListener& rListener )
     660             : {
     661          11 :     GalleryTheme*           pTheme = NULL;
     662          11 :     GalleryThemeEntry*      pThemeEntry = ImplGetThemeEntry( rThemeName );
     663             : 
     664          11 :     if( pThemeEntry && ( ( pTheme = ImplGetCachedTheme( pThemeEntry ) ) != NULL ) )
     665          11 :         rListener.StartListening( *pTheme );
     666             : 
     667          11 :     return pTheme;
     668             : }
     669             : 
     670          11 : void Gallery::ReleaseTheme( GalleryTheme* pTheme, SfxListener& rListener )
     671             : {
     672          11 :     if( pTheme )
     673             :     {
     674          11 :         rListener.EndListening( *pTheme );
     675             : 
     676          11 :         if( !pTheme->HasListeners() )
     677          11 :             ImplDeleteCachedTheme( pTheme );
     678             :     }
     679          11 : }
     680             : 
     681           0 : bool GalleryThemeEntry::IsDefault() const
     682             : {
     683           0 :     return ( nId > 0 ) && ( nId != ( RID_GALLERYSTR_THEME_MYTHEME - RID_GALLERYSTR_THEME_START ) );
     684             : }
     685             : 
     686             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10