1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gallery1.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #define ENABLE_BYTESTRING_STREAM_OPERATORS
36 #include <tools/vcompat.hxx>
37 #include <ucbhelper/content.hxx>
38 #include <unotools/ucbstreamhelper.hxx>
39 #include <svtools/pathoptions.hxx>
40 #include <sfx2/docfile.hxx>
41 #include "gallery.hxx"
42 #include "galmisc.hxx"
43 #include "galtheme.hxx"
44 #include "gallery1.hxx"
45 #include <com/sun/star/sdbc/XResultSet.hpp>
46 #include <com/sun/star/ucb/XContentAccess.hpp>
48 #define ENABLE_BYTESTRING_STREAM_OPERATORS
54 using namespace ::rtl
;
55 using namespace ::com::sun::star
;
57 // ---------------------
58 // - GalleryThemeEntry -
59 // ---------------------
61 GalleryThemeEntry::GalleryThemeEntry( const INetURLObject
& rBaseURL
, const String
& rName
,
62 UINT32 _nFileNumber
, BOOL _bReadOnly
, BOOL _bImported
,
63 BOOL _bNewFile
, UINT32 _nId
, BOOL _bThemeNameFromResource
) :
64 nFileNumber ( _nFileNumber
),
66 bReadOnly ( _bReadOnly
|| _bImported
),
67 bImported ( _bImported
),
68 bThemeNameFromResource ( _bThemeNameFromResource
)
70 INetURLObject
aURL( rBaseURL
);
71 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
72 String
aFileName( String( RTL_CONSTASCII_USTRINGPARAM( "sg" ) ) );
74 aURL
.Append( ( aFileName
+= String::CreateFromInt32( nFileNumber
) ) += String( RTL_CONSTASCII_USTRINGPARAM( ".thm" ) ) );
75 aThmURL
= ImplGetURLIgnoreCase( aURL
);
77 aURL
.setExtension( String( RTL_CONSTASCII_USTRINGPARAM( "sdg" ) ) );
78 aSdgURL
= ImplGetURLIgnoreCase( aURL
);
80 aURL
.setExtension( String( RTL_CONSTASCII_USTRINGPARAM( "sdv" ) ) );
81 aSdvURL
= ImplGetURLIgnoreCase( aURL
);
83 SetModified( _bNewFile
);
85 if( nId
&& bThemeNameFromResource
)
86 aName
= String( GAL_RESID( RID_GALLERYSTR_THEME_START
+ (USHORT
) nId
) );
92 // -----------------------------------------------------------------------------
94 INetURLObject
GalleryThemeEntry::ImplGetURLIgnoreCase( const INetURLObject
& rURL
) const
96 INetURLObject
aURL( rURL
);
100 // check original file name
101 if( FileExists( aURL
) )
105 // check upper case file name
106 aURL
.setName( aURL
.getName().toAsciiUpperCase() );
108 if( FileExists( aURL
) )
112 // check lower case file name
113 aURL
.setName( aURL
.getName().toAsciiLowerCase() );
115 if( FileExists( aURL
) )
123 // -----------------------------------------------------------------------------
125 void GalleryThemeEntry::SetName( const String
& rNewName
)
127 if( aName
!= rNewName
)
131 bThemeNameFromResource
= FALSE
;
135 // -----------------------------------------------------------------------------
137 void GalleryThemeEntry::SetId( UINT32 nNewId
, BOOL bResetThemeName
)
141 bThemeNameFromResource
= ( nId
&& bResetThemeName
);
144 // ---------------------------
145 // - GalleryImportThemeEntry -
146 // ---------------------------
148 SvStream
& operator<<( SvStream
& rOut
, const GalleryImportThemeEntry
& rEntry
)
152 rOut
<< ByteString( rEntry
.aThemeName
, RTL_TEXTENCODING_UTF8
) <<
153 ByteString( rEntry
.aUIName
, RTL_TEXTENCODING_UTF8
) <<
154 ByteString( String(rEntry
.aURL
.GetMainURL( INetURLObject::NO_DECODE
)), RTL_TEXTENCODING_UTF8
) <<
155 ByteString( rEntry
.aImportName
, RTL_TEXTENCODING_UTF8
) <<
161 // ------------------------------------------------------------------------
163 SvStream
& operator>>( SvStream
& rIn
, GalleryImportThemeEntry
& rEntry
)
167 rIn
>> aTmpStr
; rEntry
.aThemeName
= String( aTmpStr
, RTL_TEXTENCODING_UTF8
);
168 rIn
>> aTmpStr
; rEntry
.aUIName
= String( aTmpStr
, RTL_TEXTENCODING_UTF8
);
169 rIn
>> aTmpStr
; rEntry
.aURL
= INetURLObject( String( aTmpStr
, RTL_TEXTENCODING_UTF8
) );
170 rIn
>> aTmpStr
; rEntry
.aImportName
= String( aTmpStr
, RTL_TEXTENCODING_UTF8
);
176 // --------------------------
177 // - GalleryThemeCacheEntry -
178 // --------------------------
180 class GalleryThemeCacheEntry
184 const GalleryThemeEntry
* mpThemeEntry
;
185 GalleryTheme
* mpTheme
;
189 GalleryThemeCacheEntry( const GalleryThemeEntry
* pThemeEntry
, GalleryTheme
* pTheme
) :
190 mpThemeEntry( pThemeEntry
), mpTheme( pTheme
) {}
191 ~GalleryThemeCacheEntry() { delete mpTheme
; }
193 const GalleryThemeEntry
* GetThemeEntry() const { return mpThemeEntry
; }
194 GalleryTheme
* GetTheme() const { return mpTheme
; }
201 Gallery::Gallery( const String
& rMultiPath
)
202 : nReadTextEncoding ( gsl_getSystemTextEncoding() )
203 , nLastFileNumber ( 0 )
204 , bMultiPath ( FALSE
)
206 ImplLoad( rMultiPath
);
209 // ------------------------------------------------------------------------
213 // Themen-Liste loeschen
214 for( GalleryThemeEntry
* pThemeEntry
= aThemeList
.First(); pThemeEntry
; pThemeEntry
= aThemeList
.Next() )
217 // Import-Liste loeschen
218 for( GalleryImportThemeEntry
* pImportEntry
= aImportList
.First(); pImportEntry
; pImportEntry
= aImportList
.Next() )
222 // ------------------------------------------------------------------------
224 Gallery
* Gallery::GetGalleryInstance()
226 static Gallery
* pGallery
= NULL
;
230 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
233 pGallery
= new Gallery( SvtPathOptions().GetGalleryPath() );
240 // ------------------------------------------------------------------------
242 void Gallery::ImplLoad( const String
& rMultiPath
)
244 const USHORT nTokenCount
= rMultiPath
.GetTokenCount( ';' );
245 sal_Bool bIsReadOnlyDir
;
247 bMultiPath
= ( nTokenCount
> 0 );
249 INetURLObject
aCurURL(SvtPathOptions().GetConfigPath());
250 ImplLoadSubDirs( aCurURL
, bIsReadOnlyDir
);
252 if( !bIsReadOnlyDir
)
257 aRelURL
= INetURLObject( rMultiPath
.GetToken( 0, ';' ) );
259 for( USHORT i
= 0UL; i
< nTokenCount
; i
++ )
261 aCurURL
= INetURLObject(rMultiPath
.GetToken( i
, ';' ));
263 ImplLoadSubDirs( aCurURL
, bIsReadOnlyDir
);
265 if( !bIsReadOnlyDir
)
270 aRelURL
= INetURLObject( rMultiPath
);
272 DBG_ASSERT( aUserURL
.GetProtocol() != INET_PROT_NOT_VALID
, "no writable Gallery user directory available" );
273 DBG_ASSERT( aRelURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
278 // ------------------------------------------------------------------------
280 void Gallery::ImplLoadSubDirs( const INetURLObject
& rBaseURL
, sal_Bool
& rbDirIsReadOnly
)
282 rbDirIsReadOnly
= sal_False
;
286 uno::Reference
< ucb::XCommandEnvironment
> xEnv
;
287 ::ucbhelper::Content
aCnt( rBaseURL
.GetMainURL( INetURLObject::NO_DECODE
), xEnv
);
289 uno::Sequence
< OUString
> aProps( 1 );
290 aProps
.getArray()[ 0 ] = OUString::createFromAscii( "Url" );
292 uno::Reference
< sdbc::XResultSet
> xResultSet( aCnt
.createCursor( aProps
, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY
) );
296 // check readonlyness the very hard way
297 INetURLObject
aTestURL( rBaseURL
);
298 String
aTestFile( RTL_CONSTASCII_USTRINGPARAM( "cdefghij.klm" ) );
300 aTestURL
.Append( aTestFile
);
301 SvStream
* pTestStm
= ::utl::UcbStreamHelper::CreateStream( aTestURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_WRITE
);
307 if( pTestStm
->GetError() )
308 rbDirIsReadOnly
= sal_True
;
311 KillFile( aTestURL
);
314 rbDirIsReadOnly
= sal_True
;
316 catch( const ucb::ContentCreationException
& )
319 catch( const uno::RuntimeException
& )
322 catch( const uno::Exception
& )
326 if( xResultSet
.is() )
328 uno::Reference
< ucb::XContentAccess
> xContentAccess( xResultSet
, uno::UNO_QUERY
);
330 if( xContentAccess
.is() )
332 while( xResultSet
->next() )
334 INetURLObject
aThmURL( xContentAccess
->queryContentIdentifierString() );
336 if(aThmURL
.GetExtension().equalsIgnoreAsciiCaseAscii("thm"))
338 INetURLObject
aSdgURL( aThmURL
); aSdgURL
.SetExtension( OUString::createFromAscii( "sdg" ) );
339 INetURLObject
aSdvURL( aThmURL
); aSdvURL
.SetExtension( OUString::createFromAscii( "sdv" ) );
340 const OUString
aTitleProp( OUString::createFromAscii( "Title" ) );
341 const OUString
aReadOnlyProp( OUString::createFromAscii( "IsReadOnly" ) );
343 sal_Bool bReadOnly
= sal_False
;
347 ::ucbhelper::Content
aThmCnt( aThmURL
.GetMainURL( INetURLObject::NO_DECODE
), xEnv
);
348 ::ucbhelper::Content
aSdgCnt( aSdgURL
.GetMainURL( INetURLObject::NO_DECODE
), xEnv
);
349 ::ucbhelper::Content
aSdvCnt( aSdvURL
.GetMainURL( INetURLObject::NO_DECODE
), xEnv
);
353 aThmCnt
.getPropertyValue( aTitleProp
) >>= aTitle
;
355 catch( const uno::RuntimeException
& )
358 catch( const uno::Exception
& )
362 if( aTitle
.getLength() )
366 aThmCnt
.getPropertyValue( aReadOnlyProp
) >>= bReadOnly
;
368 catch( const uno::RuntimeException
& )
371 catch( const uno::Exception
& )
379 aSdgCnt
.getPropertyValue( aTitleProp
) >>= aTitle
;
381 catch( const ::com::sun::star::uno::RuntimeException
& )
384 catch( const ::com::sun::star::uno::Exception
& )
388 if( aTitle
.getLength() )
392 aSdgCnt
.getPropertyValue( aReadOnlyProp
) >>= bReadOnly
;
394 catch( const uno::RuntimeException
& )
397 catch( const uno::Exception
& )
407 aSdvCnt
.getPropertyValue( aTitleProp
) >>= aTitle
;
409 catch( const ::com::sun::star::uno::RuntimeException
& )
412 catch( const ::com::sun::star::uno::Exception
& )
416 if( aTitle
.getLength() )
420 aSdvCnt
.getPropertyValue( aReadOnlyProp
) >>= bReadOnly
;
422 catch( const uno::RuntimeException
& )
425 catch( const uno::Exception
& )
431 GalleryThemeEntry
* pEntry
= GalleryTheme::CreateThemeEntry( aThmURL
, rbDirIsReadOnly
|| bReadOnly
);
435 const ULONG nFileNumber
= (ULONG
) String(aThmURL
.GetBase()).Erase( 0, 2 ).Erase( 6 ).ToInt32();
437 aThemeList
.Insert( pEntry
, LIST_APPEND
);
439 if( nFileNumber
> nLastFileNumber
)
440 nLastFileNumber
= nFileNumber
;
444 catch( const ucb::ContentCreationException
& )
447 catch( const uno::RuntimeException
& )
450 catch( const uno::Exception
& )
458 catch( const ucb::ContentCreationException
& )
461 catch( const uno::RuntimeException
& )
464 catch( const uno::Exception
& )
469 // ------------------------------------------------------------------------
471 void Gallery::ImplLoadImports()
473 INetURLObject
aURL( GetUserURL() );
475 aURL
.Append( String( RTL_CONSTASCII_USTRINGPARAM( "gallery.sdi" ) ) );
477 if( FileExists( aURL
) )
479 SvStream
* pIStm
= ::utl::UcbStreamHelper::CreateStream( aURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_READ
);
483 GalleryThemeEntry
* pThemeEntry
;
484 GalleryImportThemeEntry
* pImportEntry
;
492 for( pImportEntry
= aImportList
.First(); pImportEntry
; pImportEntry
= aImportList
.Next() )
498 if( nInventor
== COMPAT_FORMAT( 'S', 'G', 'A', '3' ) )
500 *pIStm
>> nId
>> nCount
>> nTempCharSet
;
502 for( i
= 0; i
< nCount
; i
++ )
504 pImportEntry
= new GalleryImportThemeEntry
;
506 *pIStm
>> *pImportEntry
;
507 aImportList
.Insert( pImportEntry
, LIST_APPEND
);
508 aFile
= INetURLObject( pImportEntry
->aURL
);
509 pThemeEntry
= new GalleryThemeEntry( aFile
,
510 pImportEntry
->aUIName
,
511 String(aFile
.GetBase()).Erase( 0, 2 ).Erase( 6 ).ToInt32(),
512 TRUE
, TRUE
, FALSE
, 0, FALSE
);
514 aThemeList
.Insert( pThemeEntry
, LIST_APPEND
);
523 // ------------------------------------------------------------------------
525 void Gallery::ImplWriteImportList()
527 INetURLObject
aURL( GetUserURL() );
528 aURL
.Append( ( String( "gallery.sdi", RTL_TEXTENCODING_UTF8
) ) );
529 SvStream
* pOStm
= ::utl::UcbStreamHelper::CreateStream( aURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_WRITE
| STREAM_TRUNC
);
533 const UINT32 nInventor
= (UINT32
) COMPAT_FORMAT( 'S', 'G', 'A', '3' );
534 const UINT16 nId
= 0x0004;
536 *pOStm
<< nInventor
<< nId
<< (UINT32
) aImportList
.Count() << (UINT16
) gsl_getSystemTextEncoding();
538 for( GalleryImportThemeEntry
* pImportEntry
= aImportList
.First(); pImportEntry
; pImportEntry
= aImportList
.Next() )
539 *pOStm
<< *pImportEntry
;
541 if( pOStm
->GetError() )
542 ErrorHandler::HandleError( ERRCODE_IO_GENERAL
);
548 // ------------------------------------------------------------------------
550 GalleryThemeEntry
* Gallery::ImplGetThemeEntry( const String
& rThemeName
)
552 GalleryThemeEntry
* pFound
= NULL
;
554 if( rThemeName
.Len() )
555 for( GalleryThemeEntry
* pEntry
= aThemeList
.First(); pEntry
&& !pFound
; pEntry
= aThemeList
.Next() )
556 if( rThemeName
== pEntry
->GetThemeName() )
562 // ------------------------------------------------------------------------
564 GalleryImportThemeEntry
* Gallery::ImplGetImportThemeEntry( const String
& rImportName
)
566 GalleryImportThemeEntry
* pFound
= NULL
;
568 for( GalleryImportThemeEntry
* pImportEntry
= aImportList
.First(); pImportEntry
&& !pFound
; pImportEntry
= aImportList
.Next() )
569 if ( rImportName
== pImportEntry
->aUIName
)
570 pFound
= pImportEntry
;
575 // ------------------------------------------------------------------------
577 String
Gallery::GetThemeName( ULONG nThemeId
) const
579 GalleryThemeEntry
* pFound
= NULL
;
581 for( ULONG n
= 0, nCount
= aThemeList
.Count(); n
< nCount
; n
++ )
583 GalleryThemeEntry
* pEntry
= aThemeList
.GetObject( n
);
585 if( nThemeId
== pEntry
->GetId() )
589 // try fallback, if no entry was found
592 ByteString aFallback
;
596 case( GALLERY_THEME_3D
): aFallback
= "3D"; break;
597 case( GALLERY_THEME_BULLETS
): aFallback
= "Bullets"; break;
598 case( GALLERY_THEME_HOMEPAGE
): aFallback
= "Homepage"; break;
599 case( GALLERY_THEME_HTMLBUTTONS
): aFallback
= "private://gallery/hidden/HtmlExportButtons"; break;
600 case( GALLERY_THEME_POWERPOINT
): aFallback
= "private://gallery/hidden/imgppt"; break;
601 case( GALLERY_THEME_FONTWORK
): aFallback
= "private://gallery/hidden/fontwork"; break;
602 case( GALLERY_THEME_FONTWORK_VERTICAL
): aFallback
= "private://gallery/hidden/fontworkvertical"; break;
603 case( GALLERY_THEME_RULERS
): aFallback
= "Rulers"; break;
604 case( GALLERY_THEME_SOUNDS
): aFallback
= "Sounds"; break;
610 pFound
= ( (Gallery
*) this )->ImplGetThemeEntry( String::CreateFromAscii( aFallback
.GetBuffer() ) );
613 return( pFound
? pFound
->GetThemeName() : String() );
616 // ------------------------------------------------------------------------
618 BOOL
Gallery::HasTheme( const String
& rThemeName
)
620 return( ImplGetThemeEntry( rThemeName
) != NULL
);
623 // ------------------------------------------------------------------------
625 BOOL
Gallery::CreateTheme( const String
& rThemeName
, UINT32 nNumFrom
)
629 if( !HasTheme( rThemeName
) && ( GetUserURL().GetProtocol() != INET_PROT_NOT_VALID
) )
631 nLastFileNumber
=nNumFrom
> nLastFileNumber
? nNumFrom
: ++nLastFileNumber
;
632 GalleryThemeEntry
* pNewEntry
= new GalleryThemeEntry( GetUserURL(), rThemeName
,
634 FALSE
, FALSE
, TRUE
, 0, FALSE
);
636 aThemeList
.Insert( pNewEntry
, LIST_APPEND
);
637 delete( new GalleryTheme( this, pNewEntry
) );
638 Broadcast( GalleryHint( GALLERY_HINT_THEME_CREATED
, rThemeName
) );
645 // ------------------------------------------------------------------------
647 BOOL
Gallery::CreateImportTheme( const INetURLObject
& rURL
, const String
& rImportName
)
649 INetURLObject
aURL( rURL
);
652 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
654 if( FileExists( aURL
) )
656 SvStream
* pIStm
= ::utl::UcbStreamHelper::CreateStream( aURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_READ
);
666 ErrorHandler::HandleError( ERRCODE_IO_GENERAL
);
670 String aThemeName
; *pIStm
>> aTmpStr
; aThemeName
= String( aTmpStr
, RTL_TEXTENCODING_UTF8
);
671 GalleryThemeEntry
* pThemeEntry
= new GalleryThemeEntry( aURL
, rImportName
,
672 String(aURL
.GetBase()).Erase( 0, 2 ).Erase( 6 ).ToInt32(),
673 TRUE
, TRUE
, TRUE
, 0, FALSE
);
674 GalleryTheme
* pImportTheme
= new GalleryTheme( this, pThemeEntry
);
676 pIStm
->Seek( STREAM_SEEK_TO_BEGIN
);
677 *pIStm
>> *pImportTheme
;
678 nStmErr
= pIStm
->GetError();
683 ErrorHandler::HandleError( ERRCODE_IO_GENERAL
);
687 String
aName( rImportName
);
688 String
aNewName( aName
);
693 while ( HasTheme( aNewName
) && ( nCount
++ < 16000 ) )
696 aNewName
+= String::CreateFromInt32( nCount
);
699 pImportTheme
->SetImportName( aNewName
);
700 aThemeList
.Insert( pThemeEntry
, LIST_APPEND
);
702 // Thema in Import-Liste eintragen und Import-Liste speichern
703 GalleryImportThemeEntry
* pImportEntry
= new GalleryImportThemeEntry
;
704 pImportEntry
->aThemeName
= pImportEntry
->aUIName
= aNewName
;
705 pImportEntry
->aURL
= rURL
;
706 pImportEntry
->aImportName
= rImportName
;
707 aImportList
.Insert( pImportEntry
, LIST_APPEND
);
708 ImplWriteImportList();
722 // ------------------------------------------------------------------------
724 BOOL
Gallery::RenameTheme( const String
& rOldName
, const String
& rNewName
)
726 GalleryThemeEntry
* pThemeEntry
= ImplGetThemeEntry( rOldName
);
729 // Ueberpruefen, ob neuer Themenname schon vorhanden ist
730 if( pThemeEntry
&& !HasTheme( rNewName
) && ( !pThemeEntry
->IsReadOnly() || pThemeEntry
->IsImported() ) )
732 SfxListener aListener
;
733 GalleryTheme
* pThm
= AcquireTheme( rOldName
, aListener
);
737 const String
aOldName( rOldName
);
739 pThemeEntry
->SetName( rNewName
);
742 if( pThemeEntry
->IsImported() )
744 pThm
->SetImportName( rNewName
);
746 GalleryImportThemeEntry
* pImportEntry
= ImplGetImportThemeEntry( rOldName
);
750 pImportEntry
->aUIName
= rNewName
;
751 ImplWriteImportList();
755 Broadcast( GalleryHint( GALLERY_HINT_THEME_RENAMED
, aOldName
, pThm
->GetName() ) );
756 ReleaseTheme( pThm
, aListener
);
764 // ------------------------------------------------------------------------
766 BOOL
Gallery::RemoveTheme( const String
& rThemeName
)
768 GalleryThemeEntry
* pThemeEntry
= ImplGetThemeEntry( rThemeName
);
771 if( pThemeEntry
&& ( !pThemeEntry
->IsReadOnly() || pThemeEntry
->IsImported() ) )
773 Broadcast( GalleryHint( GALLERY_HINT_CLOSE_THEME
, rThemeName
) );
775 if( pThemeEntry
->IsImported() )
777 GalleryImportThemeEntry
* pImportEntry
= ImplGetImportThemeEntry( rThemeName
);
781 delete aImportList
.Remove( pImportEntry
);
782 ImplWriteImportList();
787 SfxListener aListener
;
788 GalleryTheme
* pThm
= AcquireTheme( rThemeName
, aListener
);
792 INetURLObject
aThmURL( pThm
->GetThmURL() );
793 INetURLObject
aSdgURL( pThm
->GetSdgURL() );
794 INetURLObject
aSdvURL( pThm
->GetSdvURL() );
796 ReleaseTheme( pThm
, aListener
);
804 delete aThemeList
.Remove( pThemeEntry
);
805 Broadcast( GalleryHint( GALLERY_HINT_THEME_REMOVED
, rThemeName
) );
813 // ------------------------------------------------------------------------
815 INetURLObject
Gallery::GetImportURL( const String
& rThemeName
)
818 GalleryImportThemeEntry
* pImportEntry
= ImplGetImportThemeEntry( rThemeName
);
822 aURL
= pImportEntry
->aURL
;
823 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
829 // ------------------------------------------------------------------------
831 GalleryTheme
* Gallery::ImplGetCachedTheme( const GalleryThemeEntry
* pThemeEntry
)
833 GalleryTheme
* pTheme
= NULL
;
837 GalleryThemeCacheEntry
* pEntry
;
839 for( pEntry
= (GalleryThemeCacheEntry
*) aThemeCache
.First(); pEntry
&& !pTheme
; pEntry
= (GalleryThemeCacheEntry
*) aThemeCache
.Next() )
840 if( pThemeEntry
== pEntry
->GetThemeEntry() )
841 pTheme
= pEntry
->GetTheme();
847 if( !pThemeEntry
->IsImported() )
848 aURL
= pThemeEntry
->GetThmURL();
850 aURL
= GetImportURL( pThemeEntry
->GetThemeName() );
852 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
854 if( FileExists( aURL
) )
856 SvStream
* pIStm
= ::utl::UcbStreamHelper::CreateStream( aURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_READ
);
860 pTheme
= new GalleryTheme( this, (GalleryThemeEntry
*) pThemeEntry
);
863 if( pIStm
->GetError() )
864 delete pTheme
, pTheme
= NULL
;
865 else if( pThemeEntry
->IsImported() )
866 pTheme
->SetImportName( pThemeEntry
->GetThemeName() );
873 aThemeCache
.Insert( new GalleryThemeCacheEntry( pThemeEntry
, pTheme
), LIST_APPEND
);
880 // ------------------------------------------------------------------------
882 void Gallery::ImplDeleteCachedTheme( GalleryTheme
* pTheme
)
884 GalleryThemeCacheEntry
* pEntry
;
887 for( pEntry
= (GalleryThemeCacheEntry
*) aThemeCache
.First(); pEntry
&& !bDone
; pEntry
= (GalleryThemeCacheEntry
*) aThemeCache
.Next() )
889 if( pTheme
== pEntry
->GetTheme() )
891 delete (GalleryThemeCacheEntry
*) aThemeCache
.Remove( pEntry
);
897 // ------------------------------------------------------------------------
899 GalleryTheme
* Gallery::AcquireTheme( const String
& rThemeName
, SfxListener
& rListener
)
901 GalleryTheme
* pTheme
= NULL
;
902 GalleryThemeEntry
* pThemeEntry
= ImplGetThemeEntry( rThemeName
);
904 if( pThemeEntry
&& ( ( pTheme
= ImplGetCachedTheme( pThemeEntry
) ) != NULL
) )
905 rListener
.StartListening( *pTheme
);
910 // ------------------------------------------------------------------------
912 void Gallery::ReleaseTheme( GalleryTheme
* pTheme
, SfxListener
& rListener
)
916 rListener
.EndListening( *pTheme
);
918 if( !pTheme
->HasListeners() )
919 ImplDeleteCachedTheme( pTheme
);