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