LibreOffice Module svx (master)  1
gallery1.cxx
Go to the documentation of this file.
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 <config_features.h>
21 
22 #if defined(MACOSX) && HAVE_FEATURE_READONLY_INSTALLSET
23 #define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
24 #include <premac.h>
25 #include <Foundation/Foundation.h>
26 #include <postmac.h>
27 #endif
28 
29 #include <sal/config.h>
30 
32 #include <ucbhelper/content.hxx>
33 #include <com/sun/star/ucb/ContentCreationException.hpp>
34 #include <unotools/configmgr.hxx>
36 #include <unotools/pathoptions.hxx>
37 #include <svx/dialmgr.hxx>
38 #include <svx/gallery.hxx>
39 #include <svx/strings.hrc>
40 #include <strings.hxx>
41 #include <svx/galmisc.hxx>
42 #include <svx/galtheme.hxx>
43 #include <svx/gallery1.hxx>
45 #include <vcl/weld.hxx>
46 #include <com/sun/star/sdbc/XResultSet.hpp>
47 #include <com/sun/star/ucb/XContentAccess.hpp>
48 #include <memory>
49 
50 
51 using namespace ::com::sun::star;
52 
53 
54 const std::pair<sal_uInt16, const char*> aUnlocalized[] =
55 {
63 };
64 
65 const std::pair<sal_uInt16, const char*> aLocalized[] =
66 {
67  { RID_GALLERY_THEME_3D, RID_GALLERYSTR_THEME_3D },
68  { RID_GALLERY_THEME_ANIMATIONS, RID_GALLERYSTR_THEME_ANIMATIONS },
69  { RID_GALLERY_THEME_BULLETS, RID_GALLERYSTR_THEME_BULLETS },
70  { RID_GALLERY_THEME_OFFICE, RID_GALLERYSTR_THEME_OFFICE },
71  { RID_GALLERY_THEME_FLAGS, RID_GALLERYSTR_THEME_FLAGS },
72  { RID_GALLERY_THEME_FLOWCHARTS, RID_GALLERYSTR_THEME_FLOWCHARTS },
73  { RID_GALLERY_THEME_EMOTICONS, RID_GALLERYSTR_THEME_EMOTICONS },
74  { RID_GALLERY_THEME_PHOTOS, RID_GALLERYSTR_THEME_PHOTOS },
75  { RID_GALLERY_THEME_BACKGROUNDS, RID_GALLERYSTR_THEME_BACKGROUNDS },
76  { RID_GALLERY_THEME_HOMEPAGE, RID_GALLERYSTR_THEME_HOMEPAGE },
77  { RID_GALLERY_THEME_INTERACTION, RID_GALLERYSTR_THEME_INTERACTION },
78  { RID_GALLERY_THEME_MAPS, RID_GALLERYSTR_THEME_MAPS },
79  { RID_GALLERY_THEME_PEOPLE, RID_GALLERYSTR_THEME_PEOPLE },
80  { RID_GALLERY_THEME_SURFACES, RID_GALLERYSTR_THEME_SURFACES },
81  { RID_GALLERY_THEME_SOUNDS, RID_GALLERYSTR_THEME_SOUNDS },
82  { RID_GALLERY_THEME_SYMBOLS, RID_GALLERYSTR_THEME_SYMBOLS },
83  { RID_GALLERY_THEME_MYTHEME, RID_GALLERYSTR_THEME_MYTHEME },
84 
85  { RID_GALLERY_THEME_ARROWS, RID_GALLERYSTR_THEME_ARROWS },
86  { RID_GALLERY_THEME_BALLOONS, RID_GALLERYSTR_THEME_BALLOONS },
87  { RID_GALLERY_THEME_KEYBOARD, RID_GALLERYSTR_THEME_KEYBOARD },
88  { RID_GALLERY_THEME_TIME, RID_GALLERYSTR_THEME_TIME },
89  { RID_GALLERY_THEME_PRESENTATION, RID_GALLERYSTR_THEME_PRESENTATION },
90  { RID_GALLERY_THEME_CALENDAR, RID_GALLERYSTR_THEME_CALENDAR },
91  { RID_GALLERY_THEME_NAVIGATION, RID_GALLERYSTR_THEME_NAVIGATION },
92  { RID_GALLERY_THEME_COMMUNICATION, RID_GALLERYSTR_THEME_COMMUNICATION },
93  { RID_GALLERY_THEME_FINANCES, RID_GALLERYSTR_THEME_FINANCES },
94  { RID_GALLERY_THEME_COMPUTER, RID_GALLERYSTR_THEME_COMPUTER },
95 
96  { RID_GALLERY_THEME_CLIMA, RID_GALLERYSTR_THEME_CLIMA },
97  { RID_GALLERY_THEME_EDUCATION, RID_GALLERYSTR_THEME_EDUCATION },
98  { RID_GALLERY_THEME_TROUBLE, RID_GALLERYSTR_THEME_TROUBLE },
99  { RID_GALLERY_THEME_SCREENBEANS, RID_GALLERYSTR_THEME_SCREENBEANS },
100 
101  { RID_GALLERY_THEME_COMPUTERS, RID_GALLERYSTR_THEME_COMPUTERS },
102  { RID_GALLERY_THEME_DIAGRAMS, RID_GALLERYSTR_THEME_DIAGRAMS },
103  { RID_GALLERY_THEME_ENVIRONMENT, RID_GALLERYSTR_THEME_ENVIRONMENT },
104  { RID_GALLERY_THEME_FINANCE, RID_GALLERYSTR_THEME_FINANCE },
105  { RID_GALLERY_THEME_TRANSPORT, RID_GALLERYSTR_THEME_TRANSPORT },
106  { RID_GALLERY_THEME_TXTSHAPES, RID_GALLERYSTR_THEME_TXTSHAPES }
107 };
108 
110  const INetURLObject& rBaseURL, const OUString& rName,
111  bool _bReadOnly, bool _bNewFile,
112  sal_uInt32 _nId, bool _bThemeNameFromResource ) :
113  nId ( _nId ),
114  bReadOnly ( _bReadOnly ),
115  bThemeNameFromResource ( _bThemeNameFromResource )
116 {
117  INetURLObject aURL( rBaseURL );
118  DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
119 
120  if (bCreateUniqueURL)
121  {
123  }
125  mpGalleryBinaryEngine->SetThmExtension(aURL);
126  mpGalleryBinaryEngine->SetSdgExtension(aURL);
127  mpGalleryBinaryEngine->SetSdvExtension(aURL);
128  mpGalleryBinaryEngine->SetStrExtension(aURL);
129 
130  SetModified( _bNewFile );
131 
132  aName = mpGalleryBinaryEngine->ReadStrFromIni( "name" );
133 
134  // This is awful - we shouldn't use these resources if we
135  // possibly can avoid them
136  if( aName.isEmpty() && nId && bThemeNameFromResource )
137  {
138  //some of these are supposed to *not* be localized
139  //so catch them before looking up the resource
140  for (size_t i = 0; i < SAL_N_ELEMENTS(aUnlocalized); ++i)
141  {
142  if (aUnlocalized[i].first == nId)
143  {
144  aName = OUString::createFromAscii(aUnlocalized[i].second);
145  break;
146  }
147  }
148  //look up the rest of the ids in string resources
149  if (aName.isEmpty())
150  {
151  for (size_t i = 0; i < SAL_N_ELEMENTS(aLocalized); ++i)
152  {
153  if (aLocalized[i].first == nId)
154  {
155  aName = SvxResId(aLocalized[i].second);
156  break;
157  }
158  }
159  }
160  }
161 
162  if( aName.isEmpty() )
163  aName = rName;
164 }
165 
166 std::unique_ptr<GalleryBinaryEngine> GalleryThemeEntry::createGalleryBinaryEngine()
167 {
168  std::unique_ptr<GalleryBinaryEngine> pGalleryBinaryEngine = std::make_unique<GalleryBinaryEngine>();
169  return pGalleryBinaryEngine;
170 }
171 
173 {
174  for (size_t i = 0; i < SAL_N_ELEMENTS(aUnlocalized); ++i)
175  rListBox.append_text(OUString::createFromAscii(aUnlocalized[i].second));
176 
177  for (size_t i = 0; i < SAL_N_ELEMENTS(aLocalized); ++i)
178  rListBox.append_text(SvxResId(aLocalized[i].second));
179 }
180 
181 void GalleryThemeEntry::SetName( const OUString& rNewName )
182 {
183  if( aName != rNewName )
184  {
185  aName = rNewName;
186  SetModified( true );
187  bThemeNameFromResource = false;
188  }
189 }
190 
191 void GalleryThemeEntry::SetId( sal_uInt32 nNewId, bool bResetThemeName )
192 {
193  nId = nNewId;
194  SetModified( true );
195  bThemeNameFromResource = ( nId && bResetThemeName );
196 }
197 
198 
200 {
201 private:
202 
204  std::unique_ptr<GalleryTheme> mpTheme;
205 
206 public:
207 
208  GalleryThemeCacheEntry( const GalleryThemeEntry* pThemeEntry, std::unique_ptr<GalleryTheme> pTheme ) :
209  mpThemeEntry( pThemeEntry ), mpTheme( std::move(pTheme) ) {}
210 
211  const GalleryThemeEntry* GetThemeEntry() const { return mpThemeEntry; }
212  GalleryTheme* GetTheme() const { return mpTheme.get(); }
213 };
214 
215 
216 Gallery::Gallery( const OUString& rMultiPath )
217 : bMultiPath ( false )
218 {
219  ImplLoad( rMultiPath );
220 }
221 
223 {
224 }
225 
227 {
228  // note: this would deadlock if it used osl::Mutex::getGlobalMutex()
229  static Gallery *const s_pGallery(
230  utl::ConfigManager::IsFuzzing() ? nullptr :
231  new Gallery(SvtPathOptions().GetGalleryPath()));
232 
233  return s_pGallery;
234 }
235 
236 void Gallery::ImplLoad( const OUString& rMultiPath )
237 {
238  bool bIsReadOnlyDir {false};
239 
240  bMultiPath = !rMultiPath.isEmpty();
241 
242  INetURLObject aCurURL(SvtPathOptions().GetConfigPath());
243  ImplLoadSubDirs( aCurURL, bIsReadOnlyDir );
244 
245  if( !bIsReadOnlyDir )
246  aUserURL = aCurURL;
247 
248  if( bMultiPath )
249  {
250  bool bIsRelURL {true};
251  sal_Int32 nIdx {0};
252  do
253  {
254  aCurURL = INetURLObject(rMultiPath.getToken(0, ';', nIdx));
255  if (bIsRelURL)
256  {
257  aRelURL = aCurURL;
258  bIsRelURL = false;
259  }
260 
261  ImplLoadSubDirs( aCurURL, bIsReadOnlyDir );
262 
263  if( !bIsReadOnlyDir )
264  aUserURL = aCurURL;
265  }
266  while (nIdx>0);
267  }
268  else
269  aRelURL = INetURLObject( rMultiPath );
270 
271  DBG_ASSERT( aUserURL.GetProtocol() != INetProtocol::NotValid, "no writable Gallery user directory available" );
272  DBG_ASSERT( aRelURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
273 }
274 
275 void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, bool& rbDirIsReadOnly )
276 {
277  rbDirIsReadOnly = false;
278 
279  try
280  {
281  uno::Reference< ucb::XCommandEnvironment > xEnv;
283 
284  uno::Sequence<OUString> aProps { "Url" };
285 
286  uno::Reference< sdbc::XResultSet > xResultSet( aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) );
287 
288 #if defined(MACOSX) && HAVE_FEATURE_READONLY_INSTALLSET
289  if( rBaseURL.GetProtocol() == INetProtocol::File )
290  {
291  const char *appBundle = [[[NSBundle mainBundle] bundlePath] UTF8String];
292  OUString path = rBaseURL.GetURLPath();
293  if( path.startsWith( OUString( appBundle, strlen( appBundle ), RTL_TEXTENCODING_UTF8 ) + "/" ) )
294  rbDirIsReadOnly = true;
295  }
296 #else
297  try
298  {
299  // check readonlyness the very hard way
300  INetURLObject aTestURL( rBaseURL );
301 
302  aTestURL.Append( "cdefghij.klm" );
303  std::unique_ptr<SvStream> pTestStm(::utl::UcbStreamHelper::CreateStream( aTestURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE ));
304 
305  if( pTestStm )
306  {
307  pTestStm->WriteInt32( sal_Int32(1) );
308 
309  if( pTestStm->GetError() )
310  rbDirIsReadOnly = true;
311 
312  pTestStm.reset();
313  KillFile( aTestURL );
314  }
315  else
316  rbDirIsReadOnly = true;
317  }
318  catch( const ucb::ContentCreationException& )
319  {
320  }
321  catch( const uno::RuntimeException& )
322  {
323  }
324  catch( const uno::Exception& )
325  {
326  }
327 #endif
328  if( xResultSet.is() )
329  {
330  uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
331 
332  if( xContentAccess.is() )
333  {
334  static const char s_sTitle[] = "Title";
335  static const char s_sIsReadOnly[] = "IsReadOnly";
336 
337  while( xResultSet->next() )
338  {
339  INetURLObject aThmURL( xContentAccess->queryContentIdentifierString() );
340 
341  if (aThmURL.GetFileExtension().equalsIgnoreAsciiCase("thm"))
342  {
343  INetURLObject aSdgURL( aThmURL); aSdgURL.SetExtension( "sdg" );
344  INetURLObject aSdvURL( aThmURL ); aSdvURL.SetExtension( "sdv" );
345  OUString aTitle;
346 
347  try
348  {
352 
353  try
354  {
355  aThmCnt.getPropertyValue( s_sTitle ) >>= aTitle;
356  }
357  catch( const uno::RuntimeException& )
358  {
359  }
360  catch( const uno::Exception& )
361  {
362  }
363 
364  if( !aTitle.isEmpty() )
365  {
366  bool bReadOnly = false;
367 
368  try
369  {
370  aThmCnt.getPropertyValue( s_sIsReadOnly ) >>= bReadOnly;
371  }
372  catch( const uno::RuntimeException& )
373  {
374  }
375  catch( const uno::Exception& )
376  {
377  }
378 
379  if( !bReadOnly )
380  {
381  try
382  {
383  aSdgCnt.getPropertyValue( s_sTitle ) >>= aTitle;
384  }
385  catch( const css::uno::RuntimeException& )
386  {
387  }
388  catch( const css::uno::Exception& )
389  {
390  }
391 
392  if( !aTitle.isEmpty() )
393  {
394  try
395  {
396  aSdgCnt.getPropertyValue( s_sIsReadOnly ) >>= bReadOnly;
397  }
398  catch( const uno::RuntimeException& )
399  {
400  }
401  catch( const uno::Exception& )
402  {
403  }
404  }
405  }
406 
407  if( !bReadOnly )
408  {
409  try
410  {
411  aSdvCnt.getPropertyValue( s_sTitle ) >>= aTitle;
412  }
413  catch( const css::uno::RuntimeException& )
414  {
415  }
416  catch( const css::uno::Exception& )
417  {
418  }
419 
420  if( !aTitle.isEmpty() )
421  {
422  try
423  {
424  aSdvCnt.getPropertyValue( s_sIsReadOnly ) >>= bReadOnly;
425  }
426  catch( const uno::RuntimeException& )
427  {
428  }
429  catch( const uno::Exception& )
430  {
431  }
432  }
433  }
434 
435  GalleryThemeEntry* pEntry = GalleryTheme::CreateThemeEntry( aThmURL, rbDirIsReadOnly || bReadOnly );
436 
437  if( pEntry )
438  aThemeList.emplace_back( pEntry );
439  }
440  }
441  catch( const ucb::ContentCreationException& )
442  {
443  }
444  catch( const uno::RuntimeException& )
445  {
446  }
447  catch( const uno::Exception& )
448  {
449  }
450  }
451  }
452  }
453  }
454  }
455  catch( const ucb::ContentCreationException& )
456  {
457  }
458  catch( const uno::RuntimeException& )
459  {
460  }
461  catch( const uno::Exception& )
462  {
463  }
464 }
465 
466 GalleryThemeEntry* Gallery::ImplGetThemeEntry( const OUString& rThemeName )
467 {
468  if( !rThemeName.isEmpty() )
469  {
470  for ( size_t i = 0, n = aThemeList.size(); i < n; ++i )
471  if( rThemeName == aThemeList[ i ]->GetThemeName() )
472  return aThemeList[ i ].get();
473  }
474 
475  return nullptr;
476 }
477 
478 OUString Gallery::GetThemeName( sal_uInt32 nThemeId ) const
479 {
480  GalleryThemeEntry* pFound = nullptr;
481 
482  for ( size_t i = 0, n = aThemeList.size(); i < n && !pFound; ++i )
483  {
484  GalleryThemeEntry* pEntry = aThemeList[ i ].get();
485  if( nThemeId == pEntry->GetId() )
486  pFound = pEntry;
487  }
488 
489  // try fallback, if no entry was found
490  if( !pFound )
491  {
492  OUString aFallback;
493 
494  switch( nThemeId )
495  {
496  case GALLERY_THEME_3D:
497  aFallback = SvxResId(RID_GALLERYSTR_THEME_3D);
498  break;
500  aFallback = SvxResId(RID_GALLERYSTR_THEME_BULLETS);
501  break;
503  aFallback = SvxResId(RID_GALLERYSTR_THEME_HOMEPAGE);
504  break;
507  break;
509  aFallback = RID_GALLERYSTR_THEME_FONTWORK;
510  break;
513  break;
515  aFallback = SvxResId(RID_GALLERYSTR_THEME_SOUNDS);
516  break;
518  aFallback = SvxResId(RID_GALLERYSTR_THEME_ARROWS);
519  break;
521  aFallback = SvxResId(RID_GALLERYSTR_THEME_COMPUTERS);
522  break;
524  aFallback = SvxResId(RID_GALLERYSTR_THEME_DIAGRAMS);
525  break;
527  aFallback = SvxResId(RID_GALLERYSTR_THEME_EDUCATION);
528  break;
530  aFallback = SvxResId(RID_GALLERYSTR_THEME_ENVIRONMENT);
531  break;
533  aFallback = SvxResId(RID_GALLERYSTR_THEME_FINANCE);
534  break;
536  aFallback = SvxResId(RID_GALLERYSTR_THEME_PEOPLE);
537  break;
539  aFallback = SvxResId(RID_GALLERYSTR_THEME_SYMBOLS);
540  break;
542  aFallback = SvxResId(RID_GALLERYSTR_THEME_TRANSPORT);
543  break;
545  aFallback = SvxResId(RID_GALLERYSTR_THEME_TXTSHAPES);
546  break;
547  default:
548  break;
549  }
550 
551  pFound = const_cast<Gallery*>(this)->ImplGetThemeEntry(aFallback);
552  }
553 
554  return( pFound ? pFound->GetThemeName() : OUString() );
555 }
556 
557 bool Gallery::HasTheme( const OUString& rThemeName )
558 {
559  return( ImplGetThemeEntry( rThemeName ) != nullptr );
560 }
561 
562 bool Gallery::CreateTheme( const OUString& rThemeName )
563 {
564  bool bRet = false;
565 
566  if( !HasTheme( rThemeName ) && ( GetUserURL().GetProtocol() != INetProtocol::NotValid ) )
567  {
569  aURL.Append( rThemeName );
570  GalleryThemeEntry* pNewEntry = new GalleryThemeEntry(
571  true, aURL, rThemeName,
572  false, true, 0, false );
573 
574  aThemeList.emplace_back( pNewEntry );
575  delete new GalleryTheme( this, pNewEntry );
577  bRet = true;
578  }
579 
580  return bRet;
581 }
582 
583 void Gallery::RenameTheme( const OUString& rOldName, const OUString& rNewName )
584 {
585  GalleryThemeEntry* pThemeEntry = ImplGetThemeEntry( rOldName );
586 
587  // check if the new theme name is already present
588  if( pThemeEntry && !HasTheme( rNewName ) && !pThemeEntry->IsReadOnly() )
589  {
590  SfxListener aListener;
591  GalleryTheme* pThm = AcquireTheme( rOldName, aListener );
592 
593  if( pThm )
594  {
595  pThemeEntry->SetName( rNewName );
596  if (pThm->pThm->IsModified())
597  if (!pThm->pThm->getGalleryBinaryEngine()->implWrite(*pThm))
598  pThm->ImplSetModified(false);
599 
601  ReleaseTheme( pThm, aListener );
602  }
603  }
604 }
605 
606 bool Gallery::RemoveTheme( const OUString& rThemeName )
607 {
608  GalleryThemeEntry* pThemeEntry = ImplGetThemeEntry( rThemeName );
609  bool bRet = false;
610 
611  if( pThemeEntry && !pThemeEntry->IsReadOnly() )
612  {
614 
615  SfxListener aListener;
616  GalleryTheme* pThm = AcquireTheme( rThemeName, aListener );
617 
618  if( pThm )
619  {
620  INetURLObject aThmURL( pThm->GetThmURL() );
621  INetURLObject aSdgURL( pThm->GetSdgURL() );
622  INetURLObject aSdvURL( pThm->GetSdvURL() );
623  INetURLObject aStrURL( pThm->GetStrURL() );
624 
625  ReleaseTheme( pThm, aListener );
626 
627  KillFile( aThmURL );
628  KillFile( aSdgURL );
629  KillFile( aSdvURL );
630  KillFile( aStrURL );
631  }
632 
633  auto it = std::find_if(aThemeList.begin(), aThemeList.end(),
634  [&pThemeEntry](const std::unique_ptr<GalleryThemeEntry>& rpEntry) { return pThemeEntry == rpEntry.get(); });
635  if (it != aThemeList.end())
636  aThemeList.erase( it );
637 
639 
640  bRet = true;
641  }
642 
643  return bRet;
644 }
645 
647 {
648  GalleryTheme* pTheme = nullptr;
649 
650  if( pThemeEntry )
651  {
652  auto it = std::find_if(aThemeCache.begin(), aThemeCache.end(),
653  [&pThemeEntry](const GalleryThemeCacheEntry* pEntry) { return pThemeEntry == pEntry->GetThemeEntry(); });
654  if (it != aThemeCache.end())
655  pTheme = (*it)->GetTheme();
656 
657  if( !pTheme )
658  {
659  INetURLObject aURL = pThemeEntry->GetThmURL();
660 
661  DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
662 
663  std::unique_ptr<GalleryTheme> pNewTheme;
664  if( FileExists( aURL ) )
665  {
666  std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ ));
667 
668  if( pIStm )
669  {
670  try
671  {
672  pNewTheme.reset( new GalleryTheme( this, const_cast<GalleryThemeEntry*>(pThemeEntry) ) );
673  ReadGalleryTheme( *pIStm, *pNewTheme );
674 
675  if( pIStm->GetError() )
676  pNewTheme.reset();
677  }
678  catch (const css::ucb::ContentCreationException&)
679  {
680  }
681  }
682  }
683 
684  if (pNewTheme)
685  {
686  aThemeCache.push_back( new GalleryThemeCacheEntry( pThemeEntry, std::move(pNewTheme) ));
687  pTheme = aThemeCache.back()->GetTheme();
688  }
689  }
690  }
691 
692  return pTheme;
693 }
694 
696 {
697  auto it = std::find_if(aThemeCache.begin(), aThemeCache.end(),
698  [&pTheme](const GalleryThemeCacheEntry* pEntry) { return pTheme == pEntry->GetTheme(); });
699  if (it != aThemeCache.end())
700  {
701  delete *it;
702  aThemeCache.erase(it);
703  }
704 }
705 
706 GalleryTheme* Gallery::AcquireTheme( const OUString& rThemeName, SfxListener& rListener )
707 {
708  GalleryTheme* pTheme = nullptr;
709  GalleryThemeEntry* pThemeEntry = ImplGetThemeEntry( rThemeName );
710 
711  if( pThemeEntry )
712  {
713  pTheme = ImplGetCachedTheme( pThemeEntry );
714  if (pTheme)
715  rListener.StartListening(*pTheme, DuplicateHandling::Prevent);
716  }
717  return pTheme;
718 }
719 
720 void Gallery::ReleaseTheme( GalleryTheme* pTheme, SfxListener& rListener )
721 {
722  if( pTheme )
723  {
724  rListener.EndListening( *pTheme );
725 
726  if( !pTheme->HasListeners() )
727  ImplDeleteCachedTheme( pTheme );
728  }
729 }
730 
732 {
733  return nId > 0 && nId != GALLERY_THEME_MYTHEME;
734 }
735 
736 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const GalleryThemeEntry * GetThemeEntry() const
Definition: gallery1.cxx:211
URL aURL
bool HasListeners() const
bool IsModified() const
Definition: gallery1.hxx:68
std::unique_ptr< GalleryBinaryEngine > mpGalleryBinaryEngine
Definition: gallery1.hxx:39
GalleryTheme * AcquireTheme(const OUString &rThemeName, SfxListener &rListener)
Definition: gallery1.cxx:706
#define RID_GALLERYSTR_THEME_FONTWORK
Definition: strings.hxx:18
static SAL_DLLPRIVATE GalleryThemeEntry * CreateThemeEntry(const INetURLObject &rURL, bool bReadOnly)
Definition: galtheme.cxx:446
OUString GetURLPath(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
const INetURLObject & GetSdgURL() const
Definition: galtheme.cxx:1250
css::uno::Any getPropertyValue(const OUString &rPropertyName)
SAL_DLLPRIVATE void ImplLoad(const OUString &rMultiPath)
Definition: gallery1.cxx:236
sal_Int64 n
std::unique_ptr< GalleryTheme > mpTheme
Definition: gallery1.cxx:204
const std::unique_ptr< GalleryBinaryEngine > & getGalleryBinaryEngine() const
Definition: gallery1.hxx:54
sal_Int16 nId
static void InsertAllThemes(weld::ComboBox &rListBox)
Definition: gallery1.cxx:172
bool IsReadOnly() const
Definition: gallery1.hxx:63
bool bReadOnly
INetURLObject aUserURL
Definition: gallery1.hxx:92
SAL_DLLPRIVATE OUString GetThemeName(sal_uInt32 nThemeId) const
Definition: gallery1.cxx:478
GalleryThemeEntry * ImplGetThemeEntry(const OUString &rThemeName)
Definition: gallery1.cxx:466
SvStream & ReadGalleryTheme(SvStream &rIn, GalleryTheme &rTheme)
Definition: galtheme.cxx:1239
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
void RenameTheme(const OUString &rOldName, const OUString &rNewName)
Definition: gallery1.cxx:583
static bool IsFuzzing()
static Gallery * GetGalleryInstance()
Definition: gallery1.cxx:226
#define RID_GALLERYSTR_THEME_DUMMY5
Definition: strings.hxx:17
GalleryThemeEntry * pThm
Definition: galtheme.hxx:81
SAL_DLLPRIVATE void ImplLoadSubDirs(const INetURLObject &rBaseURL, bool &rbIsReadOnly)
Definition: gallery1.cxx:275
sal_uInt32 nId
Definition: gallery1.hxx:41
const GalleryThemeEntry * mpThemeEntry
Definition: gallery1.cxx:203
void SetExtension(OUString const &rTheExtension)
bool bThemeNameFromResource
Definition: gallery1.hxx:44
#define RID_GALLERYSTR_THEME_HTMLBUTTONS
Definition: strings.hxx:13
bool RemoveTheme(const OUString &rThemeName)
Definition: gallery1.cxx:606
SAL_DLLPRIVATE const INetURLObject & GetStrURL() const
Definition: galtheme.cxx:1252
SAL_DLLPRIVATE void ImplDeleteCachedTheme(GalleryTheme const *pTheme)
Definition: gallery1.cxx:695
static std::unique_ptr< GalleryBinaryEngine > createGalleryBinaryEngine()
Definition: gallery1.cxx:166
#define RID_GALLERYSTR_THEME_FONTWORK_VERTICAL
Definition: strings.hxx:19
#define SAL_N_ELEMENTS(arr)
GalleryTheme * GetTheme() const
Definition: gallery1.cxx:212
sal_uInt32 GetId() const
Definition: gallery1.hxx:74
SAL_DLLPRIVATE const INetURLObject & GetUserURL() const
Definition: gallery1.hxx:130
#define DBG_ASSERT(sCon, aError)
int i
bool Append(OUString const &rTheSegment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
void SetModified(bool bSet)
Definition: gallery1.hxx:69
const std::pair< sal_uInt16, const char * > aLocalized[]
Definition: gallery1.cxx:65
#define RID_GALLERYSTR_THEME_POWERPOINT
Definition: strings.hxx:14
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
#define RID_GALLERYSTR_THEME_RULERS
Definition: strings.hxx:15
bool KillFile(const INetURLObject &rURL)
Definition: galmisc.cxx:287
Gallery(Gallery const &)=delete
bool IsDefault() const
Definition: gallery1.cxx:731
bool HasTheme(const OUString &rThemeName)
Definition: gallery1.cxx:557
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
void Broadcast(const SfxHint &rHint)
void ReleaseTheme(GalleryTheme *pTheme, SfxListener &rListener)
Definition: gallery1.cxx:720
void SetName(const OUString &rNewName)
Definition: gallery1.cxx:181
const std::pair< sal_uInt16, const char * > aUnlocalized[]
Definition: gallery1.cxx:54
static bool FileExists(const INetURLObject &rURL, const OUString &rExt)
INetURLObject aRelURL
Definition: gallery1.hxx:91
GalleryThemeCacheEntry(const GalleryThemeEntry *pThemeEntry, std::unique_ptr< GalleryTheme > pTheme)
Definition: gallery1.cxx:208
bool bMultiPath
Definition: gallery1.hxx:93
INetProtocol GetProtocol() const
void SetId(sal_uInt32 nNewId, bool bResetThemeName)
Definition: gallery1.cxx:191
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
#define RID_GALLERYSTR_THEME_USERSOUNDS
Definition: strings.hxx:16
Reference< XComponentContext > getProcessComponentContext()
GalleryCacheThemeList aThemeCache
Definition: gallery1.hxx:90
SAL_DLLPRIVATE const INetURLObject & GetThmURL() const
Definition: galtheme.cxx:1249
GalleryThemeEntry(bool bCreateUniqueURL, const INetURLObject &rBaseURL, const OUString &rName, bool bReadOnly, bool bNewFile, sal_uInt32 nId, bool bThemeNameFromResource)
Definition: gallery1.cxx:109
OUString aName
Definition: gallery1.hxx:40
SAL_DLLPRIVATE void ImplSetModified(bool bModified)
Definition: galtheme.cxx:1244
void append_text(const OUString &rStr)
const OUString & GetName() const
Definition: galtheme.cxx:1263
static void CreateUniqueURL(const INetURLObject &rBaseURL, INetURLObject &aURL)
virtual ~Gallery() override
Definition: gallery1.cxx:222
bool CreateTheme(const OUString &rThemeName)
Definition: gallery1.cxx:562
INCLUDE_DOCUMENTS_ONLY
SAL_DLLPRIVATE GalleryTheme * ImplGetCachedTheme(const GalleryThemeEntry *pThemeEntry)
Definition: gallery1.cxx:646
const OUString & GetThemeName() const
Definition: gallery1.hxx:56
SAL_DLLPRIVATE const INetURLObject & GetSdvURL() const
Definition: galtheme.cxx:1251
const char first[]
std::vector< std::unique_ptr< GalleryThemeEntry > > aThemeList
Definition: gallery1.hxx:89
const INetURLObject & GetThmURL() const
Definition: gallery1.hxx:58