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