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

Generated by: LCOV version 1.10