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