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