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 11 : GalleryThemeEntry::GalleryThemeEntry( const INetURLObject& rBaseURL, const String& rName,
49 : sal_Bool _bReadOnly, sal_Bool _bNewFile,
50 : sal_uInt32 _nId, sal_Bool _bThemeNameFromResource ) :
51 : nId ( _nId ),
52 : bReadOnly ( _bReadOnly ),
53 11 : bThemeNameFromResource ( _bThemeNameFromResource )
54 : {
55 11 : INetURLObject aURL( rBaseURL );
56 : DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
57 :
58 11 : aURL.setExtension( "thm" );
59 11 : aThmURL = ImplGetURLIgnoreCase( aURL );
60 :
61 11 : aURL.setExtension( "sdg" );
62 11 : aSdgURL = ImplGetURLIgnoreCase( aURL );
63 :
64 11 : aURL.setExtension( "sdv" );
65 11 : aSdvURL = ImplGetURLIgnoreCase( aURL );
66 :
67 11 : aURL.setExtension( "str" );
68 11 : aStrURL = ImplGetURLIgnoreCase( aURL );
69 :
70 11 : SetModified( _bNewFile );
71 :
72 11 : aName = ReadStrFromIni( "name" );
73 :
74 : // This is awful - we shouldn't use these resources if we
75 : // possibly can avoid them
76 11 : if( aName.isEmpty() && nId && bThemeNameFromResource )
77 0 : aName = GAL_RESSTR( RID_GALLERYSTR_THEME_START + (sal_uInt16) nId );
78 :
79 11 : if( aName.isEmpty() )
80 11 : aName = rName;
81 11 : }
82 :
83 : // -----------------------------------------------------------------------------
84 :
85 44 : INetURLObject GalleryThemeEntry::ImplGetURLIgnoreCase( const INetURLObject& rURL ) const
86 : {
87 44 : INetURLObject aURL( rURL );
88 :
89 : // check original file name
90 44 : if( !FileExists( aURL ) )
91 : {
92 : // check upper case file name
93 44 : aURL.setName( aURL.getName().toAsciiUpperCase() );
94 :
95 44 : if(!FileExists( aURL ) )
96 : {
97 : // check lower case file name
98 44 : aURL.setName( aURL.getName().toAsciiLowerCase() );
99 : }
100 : }
101 :
102 44 : return aURL;
103 : }
104 :
105 : // -----------------------------------------------------------------------------
106 :
107 0 : void GalleryThemeEntry::SetName( const OUString& rNewName )
108 : {
109 0 : if( aName != rNewName )
110 : {
111 0 : aName = rNewName;
112 0 : SetModified( sal_True );
113 0 : bThemeNameFromResource = sal_False;
114 : }
115 0 : }
116 :
117 : // -----------------------------------------------------------------------------
118 :
119 11 : void GalleryThemeEntry::SetId( sal_uInt32 nNewId, sal_Bool bResetThemeName )
120 : {
121 11 : nId = nNewId;
122 11 : SetModified( sal_True );
123 11 : bThemeNameFromResource = ( nId && bResetThemeName );
124 11 : }
125 :
126 : // --------------------------
127 : // - GalleryThemeCacheEntry -
128 : // --------------------------
129 :
130 : class GalleryThemeCacheEntry
131 : {
132 : private:
133 :
134 : const GalleryThemeEntry* mpThemeEntry;
135 : GalleryTheme* mpTheme;
136 :
137 : public:
138 :
139 11 : GalleryThemeCacheEntry( const GalleryThemeEntry* pThemeEntry, GalleryTheme* pTheme ) :
140 11 : mpThemeEntry( pThemeEntry ), mpTheme( pTheme ) {}
141 11 : ~GalleryThemeCacheEntry() { delete mpTheme; }
142 :
143 0 : const GalleryThemeEntry* GetThemeEntry() const { return mpThemeEntry; }
144 11 : GalleryTheme* GetTheme() const { return mpTheme; }
145 : };
146 :
147 : // -----------
148 : // - Gallery -
149 : // -----------
150 :
151 11 : Gallery::Gallery( const OUString& rMultiPath )
152 11 : : nReadTextEncoding ( osl_getThreadTextEncoding() )
153 22 : , bMultiPath ( sal_False )
154 : {
155 11 : ImplLoad( rMultiPath );
156 11 : }
157 :
158 : // ------------------------------------------------------------------------
159 :
160 33 : Gallery::~Gallery()
161 : {
162 : // Themen-Liste loeschen
163 22 : for ( size_t i = 0, n = aThemeList.size(); i < n; ++i )
164 11 : delete aThemeList[ i ];
165 11 : aThemeList.clear();
166 22 : }
167 :
168 : // ------------------------------------------------------------------------
169 :
170 0 : Gallery* Gallery::GetGalleryInstance()
171 : {
172 : static Gallery* pGallery = NULL;
173 :
174 0 : if( !pGallery )
175 : {
176 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
177 0 : if( !pGallery )
178 : {
179 0 : pGallery = new Gallery( SvtPathOptions().GetGalleryPath() );
180 0 : }
181 : }
182 :
183 0 : return pGallery;
184 : }
185 :
186 : // ------------------------------------------------------------------------
187 :
188 11 : void Gallery::ImplLoad( const OUString& rMultiPath )
189 : {
190 11 : const sal_Int32 nTokenCount = comphelper::string::getTokenCount(rMultiPath, ';');
191 : sal_Bool bIsReadOnlyDir;
192 :
193 11 : bMultiPath = ( nTokenCount > 0 );
194 :
195 11 : INetURLObject aCurURL(SvtPathOptions().GetConfigPath());
196 11 : ImplLoadSubDirs( aCurURL, bIsReadOnlyDir );
197 :
198 11 : if( !bIsReadOnlyDir )
199 11 : aUserURL = aCurURL;
200 :
201 11 : if( bMultiPath )
202 : {
203 11 : aRelURL = INetURLObject( comphelper::string::getToken(rMultiPath, 0, ';') );
204 :
205 22 : for( sal_Int32 i = 0; i < nTokenCount; ++i )
206 : {
207 11 : aCurURL = INetURLObject(comphelper::string::getToken(rMultiPath, i, ';'));
208 :
209 11 : ImplLoadSubDirs( aCurURL, bIsReadOnlyDir );
210 :
211 11 : if( !bIsReadOnlyDir )
212 11 : aUserURL = aCurURL;
213 : }
214 : }
215 : else
216 0 : aRelURL = INetURLObject( rMultiPath );
217 :
218 : DBG_ASSERT( aUserURL.GetProtocol() != INET_PROT_NOT_VALID, "no writable Gallery user directory available" );
219 11 : DBG_ASSERT( aRelURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
220 11 : }
221 :
222 : // ------------------------------------------------------------------------
223 :
224 22 : void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, sal_Bool& rbDirIsReadOnly )
225 : {
226 22 : rbDirIsReadOnly = sal_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 ] = OUString("Url");
235 :
236 33 : uno::Reference< sdbc::XResultSet > xResultSet( aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) );
237 :
238 : try
239 : {
240 : // check readonlyness the very hard way
241 11 : INetURLObject aTestURL( rBaseURL );
242 22 : String aTestFile( RTL_CONSTASCII_USTRINGPARAM( "cdefghij.klm" ) );
243 :
244 11 : aTestURL.Append( aTestFile );
245 11 : SvStream* pTestStm = ::utl::UcbStreamHelper::CreateStream( aTestURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
246 :
247 11 : if( pTestStm )
248 : {
249 11 : *pTestStm << sal_Int32(1);
250 :
251 11 : if( pTestStm->GetError() )
252 0 : rbDirIsReadOnly = sal_True;
253 :
254 11 : delete pTestStm;
255 11 : KillFile( aTestURL );
256 : }
257 : else
258 11 : rbDirIsReadOnly = sal_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 11 : if( xResultSet.is() )
271 : {
272 11 : uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
273 :
274 11 : if( xContentAccess.is() )
275 : {
276 11 : static const OUString s_sTitle("Title");
277 11 : static const OUString s_sIsReadOnly("IsReadOnly");
278 11 : static const OUString s_sSDG_EXT("sdg");
279 11 : static const OUString s_sSDV_EXT("sdv");
280 :
281 22 : while( xResultSet->next() )
282 : {
283 0 : INetURLObject aThmURL( xContentAccess->queryContentIdentifierString() );
284 :
285 0 : 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 0 : }
395 11 : }
396 22 : }
397 : }
398 0 : catch( const ucb::ContentCreationException& )
399 : {
400 : }
401 0 : catch( const uno::RuntimeException& )
402 : {
403 : }
404 11 : catch( const uno::Exception& )
405 : {
406 : }
407 22 : }
408 :
409 : // ------------------------------------------------------------------------
410 :
411 33 : GalleryThemeEntry* Gallery::ImplGetThemeEntry( const OUString& rThemeName )
412 : {
413 33 : GalleryThemeEntry* pFound = NULL;
414 :
415 33 : if( !rThemeName.isEmpty() )
416 : {
417 44 : for ( size_t i = 0, n = aThemeList.size(); i < n && !pFound; ++i )
418 11 : if( rThemeName == aThemeList[ i ]->GetThemeName() )
419 11 : pFound = aThemeList[ i ];
420 : }
421 :
422 33 : return pFound;
423 : }
424 :
425 : // ------------------------------------------------------------------------
426 :
427 0 : OUString Gallery::GetThemeName( sal_uIntPtr nThemeId ) const
428 : {
429 0 : GalleryThemeEntry* pFound = NULL;
430 :
431 0 : for ( size_t i = 0, n = aThemeList.size(); i < n && !pFound; ++i )
432 : {
433 0 : GalleryThemeEntry* pEntry = aThemeList[ i ];
434 0 : if( nThemeId == pEntry->GetId() )
435 0 : pFound = pEntry;
436 : }
437 :
438 : // try fallback, if no entry was found
439 0 : if( !pFound )
440 : {
441 0 : OString aFallback;
442 :
443 0 : switch( nThemeId )
444 : {
445 : case( GALLERY_THEME_3D ):
446 0 : aFallback = "3D";
447 0 : break;
448 : case( GALLERY_THEME_BULLETS ):
449 0 : aFallback = "Bullets";
450 0 : break;
451 : case( GALLERY_THEME_HOMEPAGE ):
452 0 : aFallback = "Homepage";
453 0 : break;
454 : case( GALLERY_THEME_POWERPOINT ):
455 0 : aFallback = "private://gallery/hidden/imgppt";
456 0 : break;
457 : case( GALLERY_THEME_FONTWORK ):
458 0 : aFallback = "private://gallery/hidden/fontwork";
459 0 : break;
460 : case( GALLERY_THEME_FONTWORK_VERTICAL ):
461 0 : aFallback = "private://gallery/hidden/fontworkvertical";
462 0 : break;
463 : case( GALLERY_THEME_SOUNDS ):
464 0 : aFallback = "Sounds";
465 0 : break;
466 : case( RID_GALLERYSTR_THEME_ARROWS ):
467 0 : aFallback = "Arrows";
468 0 : break;
469 : case( RID_GALLERYSTR_THEME_COMPUTERS ):
470 0 : aFallback = "Computers";
471 0 : break;
472 : case( RID_GALLERYSTR_THEME_DIAGRAMS ):
473 0 : aFallback = "Diagrams";
474 0 : break;
475 : case( RID_GALLERYSTR_THEME_EDUCATION ):
476 0 : aFallback = "Education";
477 0 : break;
478 : case( RID_GALLERYSTR_THEME_ENVIRONMENT ):
479 0 : aFallback = "Environment";
480 0 : break;
481 : case( RID_GALLERYSTR_THEME_FINANCE ):
482 0 : aFallback = "Finance";
483 0 : break;
484 : case( RID_GALLERYSTR_THEME_PEOPLE ):
485 0 : aFallback = "People";
486 0 : break;
487 : case( RID_GALLERYSTR_THEME_SYMBOLS ):
488 0 : aFallback = "Symbols";
489 0 : break;
490 : case( RID_GALLERYSTR_THEME_TRANSPORT ):
491 0 : aFallback = "Transport";
492 0 : break;
493 : case( RID_GALLERYSTR_THEME_TXTSHAPES ):
494 0 : aFallback = "Textshapes";
495 0 : break;
496 : default:
497 0 : break;
498 : }
499 :
500 0 : pFound = const_cast<Gallery*>(this)->ImplGetThemeEntry(OStringToOUString(aFallback, RTL_TEXTENCODING_ASCII_US));
501 : }
502 :
503 0 : return( pFound ? pFound->GetThemeName() : OUString() );
504 : }
505 :
506 : // ------------------------------------------------------------------------
507 :
508 22 : sal_Bool Gallery::HasTheme( const String& rThemeName )
509 : {
510 22 : return( ImplGetThemeEntry( rThemeName ) != NULL );
511 : }
512 :
513 : // ------------------------------------------------------------------------
514 :
515 11 : sal_Bool Gallery::CreateTheme( const String& rThemeName )
516 : {
517 11 : sal_Bool bRet = sal_False;
518 :
519 11 : if( !HasTheme( rThemeName ) && ( GetUserURL().GetProtocol() != INET_PROT_NOT_VALID ) )
520 : {
521 11 : INetURLObject aURL( GetUserURL() );
522 11 : aURL.Append( rThemeName );
523 : GalleryThemeEntry* pNewEntry = new GalleryThemeEntry( aURL, rThemeName,
524 11 : sal_False, sal_True, 0, sal_False );
525 :
526 11 : aThemeList.push_back( pNewEntry );
527 11 : delete( new GalleryTheme( this, pNewEntry ) );
528 11 : Broadcast( GalleryHint( GALLERY_HINT_THEME_CREATED, rThemeName ) );
529 11 : bRet = sal_True;
530 : }
531 :
532 11 : return bRet;
533 : }
534 :
535 : // ------------------------------------------------------------------------
536 :
537 0 : sal_Bool Gallery::RenameTheme( const String& rOldName, const String& rNewName )
538 : {
539 0 : GalleryThemeEntry* pThemeEntry = ImplGetThemeEntry( rOldName );
540 0 : sal_Bool bRet = sal_False;
541 :
542 : // Ueberpruefen, ob neuer Themenname schon vorhanden ist
543 0 : if( pThemeEntry && !HasTheme( rNewName ) && !pThemeEntry->IsReadOnly() )
544 : {
545 0 : SfxListener aListener;
546 0 : GalleryTheme* pThm = AcquireTheme( rOldName, aListener );
547 :
548 0 : if( pThm )
549 : {
550 0 : const String aOldName( rOldName );
551 :
552 0 : pThemeEntry->SetName( rNewName );
553 0 : pThm->ImplWrite();
554 :
555 0 : Broadcast( GalleryHint( GALLERY_HINT_THEME_RENAMED, aOldName, pThm->GetName() ) );
556 0 : ReleaseTheme( pThm, aListener );
557 0 : bRet = sal_True;
558 0 : }
559 : }
560 :
561 0 : return bRet;
562 : }
563 :
564 : // ------------------------------------------------------------------------
565 :
566 0 : sal_Bool Gallery::RemoveTheme( const String& rThemeName )
567 : {
568 0 : GalleryThemeEntry* pThemeEntry = ImplGetThemeEntry( rThemeName );
569 0 : sal_Bool bRet = sal_False;
570 :
571 0 : if( pThemeEntry && !pThemeEntry->IsReadOnly() )
572 : {
573 0 : Broadcast( GalleryHint( GALLERY_HINT_CLOSE_THEME, rThemeName ) );
574 :
575 0 : SfxListener aListener;
576 0 : GalleryTheme* pThm = AcquireTheme( rThemeName, aListener );
577 :
578 0 : if( pThm )
579 : {
580 0 : INetURLObject aThmURL( pThm->GetThmURL() );
581 0 : INetURLObject aSdgURL( pThm->GetSdgURL() );
582 0 : INetURLObject aSdvURL( pThm->GetSdvURL() );
583 0 : INetURLObject aStrURL( pThm->GetSdvURL() );
584 :
585 0 : ReleaseTheme( pThm, aListener );
586 :
587 0 : KillFile( aThmURL );
588 0 : KillFile( aSdgURL );
589 0 : KillFile( aSdvURL );
590 0 : KillFile( aStrURL );
591 : }
592 :
593 0 : for ( GalleryThemeList::iterator it = aThemeList.begin(); it != aThemeList.end(); ++it )
594 : {
595 0 : if ( pThemeEntry == *it ) {
596 0 : delete pThemeEntry;
597 0 : aThemeList.erase( it );
598 0 : break;
599 : }
600 : }
601 :
602 0 : Broadcast( GalleryHint( GALLERY_HINT_THEME_REMOVED, rThemeName ) );
603 :
604 0 : bRet = sal_True;
605 : }
606 :
607 0 : return bRet;
608 : }
609 :
610 : // ------------------------------------------------------------------------
611 :
612 11 : GalleryTheme* Gallery::ImplGetCachedTheme( const GalleryThemeEntry* pThemeEntry )
613 : {
614 11 : GalleryTheme* pTheme = NULL;
615 :
616 11 : if( pThemeEntry )
617 : {
618 11 : for (GalleryCacheThemeList::const_iterator it = aThemeCache.begin(); it != aThemeCache.end(); ++it)
619 : {
620 0 : if (pThemeEntry == (*it)->GetThemeEntry())
621 : {
622 0 : pTheme = (*it)->GetTheme();
623 0 : break;
624 : }
625 : }
626 :
627 11 : if( !pTheme )
628 : {
629 11 : INetURLObject aURL = pThemeEntry->GetThmURL();
630 :
631 : DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
632 :
633 11 : if( FileExists( aURL ) )
634 : {
635 11 : SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
636 :
637 11 : if( pIStm )
638 : {
639 11 : pTheme = new GalleryTheme( this, (GalleryThemeEntry*) pThemeEntry );
640 11 : *pIStm >> *pTheme;
641 :
642 11 : if( pIStm->GetError() )
643 : {
644 0 : delete pTheme, pTheme = NULL;
645 : }
646 :
647 11 : delete pIStm;
648 : }
649 : }
650 :
651 11 : if( pTheme )
652 11 : aThemeCache.push_back( new GalleryThemeCacheEntry( pThemeEntry, pTheme ));
653 : }
654 : }
655 :
656 11 : return pTheme;
657 : }
658 :
659 : // ------------------------------------------------------------------------
660 :
661 11 : void Gallery::ImplDeleteCachedTheme( GalleryTheme* pTheme )
662 : {
663 11 : for (GalleryCacheThemeList::iterator it = aThemeCache.begin(); it != aThemeCache.end(); ++it)
664 : {
665 11 : if (pTheme == (*it)->GetTheme())
666 : {
667 11 : delete *it;
668 11 : aThemeCache.erase(it);
669 11 : break;
670 : }
671 : }
672 11 : }
673 :
674 : // ------------------------------------------------------------------------
675 :
676 11 : GalleryTheme* Gallery::AcquireTheme( const String& rThemeName, SfxListener& rListener )
677 : {
678 11 : GalleryTheme* pTheme = NULL;
679 11 : GalleryThemeEntry* pThemeEntry = ImplGetThemeEntry( rThemeName );
680 :
681 11 : if( pThemeEntry && ( ( pTheme = ImplGetCachedTheme( pThemeEntry ) ) != NULL ) )
682 11 : rListener.StartListening( *pTheme );
683 :
684 11 : return pTheme;
685 : }
686 :
687 : // ------------------------------------------------------------------------
688 :
689 11 : void Gallery::ReleaseTheme( GalleryTheme* pTheme, SfxListener& rListener )
690 : {
691 11 : if( pTheme )
692 : {
693 11 : rListener.EndListening( *pTheme );
694 :
695 11 : if( !pTheme->HasListeners() )
696 11 : ImplDeleteCachedTheme( pTheme );
697 : }
698 11 : }
699 :
700 0 : sal_Bool GalleryThemeEntry::IsDefault() const
701 258 : { return( ( nId > 0 ) && ( nId != ( RID_GALLERYSTR_THEME_MYTHEME - RID_GALLERYSTR_THEME_START ) ) ); }
702 :
703 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|