xref: /aoo41x/main/svx/source/gallery2/gallery1.cxx (revision 02c50d82)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define ENABLE_BYTESTRING_STREAM_OPERATORS
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/vcompat.hxx>
30cdf0e10cSrcweir #include <ucbhelper/content.hxx>
31cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
32cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
33cdf0e10cSrcweir #include <sfx2/docfile.hxx>
34cdf0e10cSrcweir #include "svx/gallery.hxx"
35cdf0e10cSrcweir #include "gallery.hrc"
36cdf0e10cSrcweir #include "svx/galmisc.hxx"
37cdf0e10cSrcweir #include "svx/galtheme.hxx"
38cdf0e10cSrcweir #include "svx/gallery1.hxx"
39cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
40cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #define ENABLE_BYTESTRING_STREAM_OPERATORS
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // --------------
45cdf0e10cSrcweir // - Namespaces -
46cdf0e10cSrcweir // --------------
47cdf0e10cSrcweir 
48cdf0e10cSrcweir using namespace ::rtl;
49cdf0e10cSrcweir using namespace ::com::sun::star;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // ---------------------
52cdf0e10cSrcweir // - GalleryThemeEntry -
53cdf0e10cSrcweir // ---------------------
54cdf0e10cSrcweir 
GalleryThemeEntry(const INetURLObject & rBaseURL,const String & rName,sal_uInt32 _nFileNumber,sal_Bool _bReadOnly,sal_Bool _bImported,sal_Bool _bNewFile,sal_uInt32 _nId,sal_Bool _bThemeNameFromResource)55cdf0e10cSrcweir GalleryThemeEntry::GalleryThemeEntry( const INetURLObject& rBaseURL, const String& rName,
56cdf0e10cSrcweir 									  sal_uInt32 _nFileNumber, sal_Bool _bReadOnly, sal_Bool _bImported,
57cdf0e10cSrcweir 									  sal_Bool _bNewFile, sal_uInt32 _nId, sal_Bool _bThemeNameFromResource ) :
58cdf0e10cSrcweir 		nFileNumber                             ( _nFileNumber ),
59cdf0e10cSrcweir 		nId                                     ( _nId ),
60cdf0e10cSrcweir 		bReadOnly                               ( _bReadOnly || _bImported ),
61cdf0e10cSrcweir 		bImported                               ( _bImported ),
62cdf0e10cSrcweir 		bThemeNameFromResource  ( _bThemeNameFromResource )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir 	INetURLObject aURL( rBaseURL );
65cdf0e10cSrcweir 	DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
66cdf0e10cSrcweir 	String aFileName( String( RTL_CONSTASCII_USTRINGPARAM( "sg" ) ) );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	aURL.Append( ( aFileName += String::CreateFromInt32( nFileNumber ) ) += String( RTL_CONSTASCII_USTRINGPARAM( ".thm" ) ) );
69cdf0e10cSrcweir 	aThmURL = ImplGetURLIgnoreCase( aURL );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	aURL.setExtension( String( RTL_CONSTASCII_USTRINGPARAM( "sdg" ) ) );
72cdf0e10cSrcweir 	aSdgURL = ImplGetURLIgnoreCase( aURL );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	aURL.setExtension( String( RTL_CONSTASCII_USTRINGPARAM( "sdv" ) ) );
75cdf0e10cSrcweir 	aSdvURL = ImplGetURLIgnoreCase( aURL );
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	SetModified( _bNewFile );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	if( nId && bThemeNameFromResource )
80*02c50d82SAndre Fischer     {
81*02c50d82SAndre Fischer         const ResId aId (GAL_RESID( RID_GALLERYSTR_THEME_START + (sal_uInt16) nId));
82*02c50d82SAndre Fischer         if (aId.GetpResource() == NULL)
83*02c50d82SAndre Fischer             OSL_TRACE("");
84*02c50d82SAndre Fischer         aName = String(aId);
85*02c50d82SAndre Fischer     }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	if( !aName.Len() )
88cdf0e10cSrcweir 		aName = rName;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir // -----------------------------------------------------------------------------
92cdf0e10cSrcweir 
ImplGetURLIgnoreCase(const INetURLObject & rURL) const93cdf0e10cSrcweir INetURLObject GalleryThemeEntry::ImplGetURLIgnoreCase( const INetURLObject& rURL ) const
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	INetURLObject	aURL( rURL );
96cdf0e10cSrcweir 	String			aFileName;
97cdf0e10cSrcweir 	sal_Bool			bExists = sal_False;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	// check original file name
100cdf0e10cSrcweir 	if( FileExists( aURL ) )
101cdf0e10cSrcweir 		bExists = sal_True;
102cdf0e10cSrcweir 	else
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir 		// check upper case file name
105cdf0e10cSrcweir 		aURL.setName( aURL.getName().toAsciiUpperCase() );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 		if( FileExists( aURL ) )
108cdf0e10cSrcweir 			bExists = sal_True;
109cdf0e10cSrcweir 		else
110cdf0e10cSrcweir 		{
111cdf0e10cSrcweir 			// check lower case file name
112cdf0e10cSrcweir 			aURL.setName( aURL.getName().toAsciiLowerCase() );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 			if( FileExists( aURL ) )
115cdf0e10cSrcweir 				bExists = sal_True;
116cdf0e10cSrcweir 		}
117cdf0e10cSrcweir 	}
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	return aURL;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir // -----------------------------------------------------------------------------
123cdf0e10cSrcweir 
SetName(const String & rNewName)124cdf0e10cSrcweir void GalleryThemeEntry::SetName( const String& rNewName )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	if( aName != rNewName )
127cdf0e10cSrcweir 	{
128cdf0e10cSrcweir 		aName = rNewName;
129cdf0e10cSrcweir 		SetModified( sal_True );
130cdf0e10cSrcweir 		bThemeNameFromResource = sal_False;
131cdf0e10cSrcweir 	}
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir // -----------------------------------------------------------------------------
135cdf0e10cSrcweir 
SetId(sal_uInt32 nNewId,sal_Bool bResetThemeName)136cdf0e10cSrcweir void GalleryThemeEntry::SetId( sal_uInt32 nNewId, sal_Bool bResetThemeName )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	nId = nNewId;
139cdf0e10cSrcweir 	SetModified( sal_True );
140cdf0e10cSrcweir 	bThemeNameFromResource = ( nId && bResetThemeName );
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir // ---------------------------
144cdf0e10cSrcweir // - GalleryImportThemeEntry -
145cdf0e10cSrcweir // ---------------------------
146cdf0e10cSrcweir 
operator <<(SvStream & rOut,const GalleryImportThemeEntry & rEntry)147cdf0e10cSrcweir SvStream& operator<<( SvStream& rOut, const GalleryImportThemeEntry& rEntry )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	ByteString aDummy;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	rOut << ByteString( rEntry.aThemeName, RTL_TEXTENCODING_UTF8 ) <<
152cdf0e10cSrcweir 			ByteString( rEntry.aUIName, RTL_TEXTENCODING_UTF8 ) <<
153cdf0e10cSrcweir 			ByteString( String(rEntry.aURL.GetMainURL( INetURLObject::NO_DECODE )), RTL_TEXTENCODING_UTF8 ) <<
154cdf0e10cSrcweir 			ByteString( rEntry.aImportName, RTL_TEXTENCODING_UTF8 ) <<
155cdf0e10cSrcweir 			aDummy;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	return rOut;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir // ------------------------------------------------------------------------
161cdf0e10cSrcweir 
operator >>(SvStream & rIn,GalleryImportThemeEntry & rEntry)162cdf0e10cSrcweir SvStream& operator>>( SvStream& rIn, GalleryImportThemeEntry& rEntry )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir 	ByteString aTmpStr;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 	rIn >> aTmpStr; rEntry.aThemeName = String( aTmpStr, RTL_TEXTENCODING_UTF8 );
167cdf0e10cSrcweir 	rIn >> aTmpStr; rEntry.aUIName = String( aTmpStr, RTL_TEXTENCODING_UTF8 );
168cdf0e10cSrcweir 	rIn >> aTmpStr; rEntry.aURL = INetURLObject( String( aTmpStr, RTL_TEXTENCODING_UTF8 ) );
169cdf0e10cSrcweir 	rIn >> aTmpStr; rEntry.aImportName = String( aTmpStr, RTL_TEXTENCODING_UTF8 );
170cdf0e10cSrcweir 	rIn >> aTmpStr;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	return rIn;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir // --------------------------
176cdf0e10cSrcweir // - GalleryThemeCacheEntry -
177cdf0e10cSrcweir // --------------------------
178cdf0e10cSrcweir 
179cdf0e10cSrcweir class GalleryThemeCacheEntry;
180cdf0e10cSrcweir DBG_NAME(GalleryThemeCacheEntry)
181cdf0e10cSrcweir class GalleryThemeCacheEntry
182cdf0e10cSrcweir {
183cdf0e10cSrcweir private:
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 	const GalleryThemeEntry*        mpThemeEntry;
186cdf0e10cSrcweir 	GalleryTheme*                           mpTheme;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir public:
189cdf0e10cSrcweir 
GalleryThemeCacheEntry(const GalleryThemeEntry * pThemeEntry,GalleryTheme * pTheme)190cdf0e10cSrcweir 								GalleryThemeCacheEntry( const GalleryThemeEntry* pThemeEntry, GalleryTheme* pTheme ) :
191cdf0e10cSrcweir 									mpThemeEntry( pThemeEntry ), mpTheme( pTheme ) {DBG_CTOR(GalleryThemeCacheEntry,NULL);}
~GalleryThemeCacheEntry()192cdf0e10cSrcweir 								~GalleryThemeCacheEntry() { delete mpTheme;DBG_DTOR(GalleryThemeCacheEntry,NULL); }
193cdf0e10cSrcweir 
GetThemeEntry() const194cdf0e10cSrcweir 	const GalleryThemeEntry*        GetThemeEntry() const { return mpThemeEntry; }
GetTheme() const195cdf0e10cSrcweir 	GalleryTheme*                           GetTheme() const { return mpTheme; }
196cdf0e10cSrcweir };
197cdf0e10cSrcweir 
198cdf0e10cSrcweir // -----------
199cdf0e10cSrcweir // - Gallery -
200cdf0e10cSrcweir // -----------
Gallery(const String & rMultiPath)201cdf0e10cSrcweir Gallery::Gallery( const String& rMultiPath )
202cdf0e10cSrcweir :		nReadTextEncoding	( gsl_getSystemTextEncoding() )
203cdf0e10cSrcweir ,		nLastFileNumber		( 0 )
204cdf0e10cSrcweir ,		bMultiPath			( sal_False )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir 	ImplLoad( rMultiPath );
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir // ------------------------------------------------------------------------
210cdf0e10cSrcweir 
~Gallery()211cdf0e10cSrcweir Gallery::~Gallery()
212cdf0e10cSrcweir {
213cdf0e10cSrcweir 	// Themen-Liste loeschen
214cdf0e10cSrcweir 	for( GalleryThemeEntry* pThemeEntry = aThemeList.First(); pThemeEntry; pThemeEntry = aThemeList.Next() )
215cdf0e10cSrcweir 		delete pThemeEntry;
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 	// Import-Liste loeschen
218cdf0e10cSrcweir 	for( GalleryImportThemeEntry* pImportEntry = aImportList.First(); pImportEntry; pImportEntry = aImportList.Next() )
219cdf0e10cSrcweir 		delete pImportEntry;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir // ------------------------------------------------------------------------
223cdf0e10cSrcweir 
GetGalleryInstance()224cdf0e10cSrcweir Gallery* Gallery::GetGalleryInstance()
225cdf0e10cSrcweir {
226cdf0e10cSrcweir 	static Gallery* pGallery = NULL;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	if( !pGallery )
229cdf0e10cSrcweir 	{
230cdf0e10cSrcweir 	    ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
231cdf0e10cSrcweir 		if( !pGallery )
232cdf0e10cSrcweir 		{
233cdf0e10cSrcweir 			pGallery = new Gallery( SvtPathOptions().GetGalleryPath() );
234cdf0e10cSrcweir 		}
235cdf0e10cSrcweir 	}
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	return pGallery;
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir // ------------------------------------------------------------------------
241cdf0e10cSrcweir 
ImplLoad(const String & rMultiPath)242cdf0e10cSrcweir void Gallery::ImplLoad( const String& rMultiPath )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir 	const sal_uInt16    nTokenCount = rMultiPath.GetTokenCount( ';' );
245cdf0e10cSrcweir     sal_Bool        bIsReadOnlyDir;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 	bMultiPath = ( nTokenCount > 0 );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     INetURLObject aCurURL(SvtPathOptions().GetConfigPath());
250cdf0e10cSrcweir 	ImplLoadSubDirs( aCurURL, bIsReadOnlyDir );
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	if( !bIsReadOnlyDir )
253cdf0e10cSrcweir 	    aUserURL = aCurURL;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	if( bMultiPath )
256cdf0e10cSrcweir 	{
257cdf0e10cSrcweir 		aRelURL = INetURLObject( rMultiPath.GetToken( 0, ';' ) );
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 		for( sal_uInt16 i = 0UL; i < nTokenCount; i++ )
260cdf0e10cSrcweir 		{
261cdf0e10cSrcweir 		    aCurURL = INetURLObject(rMultiPath.GetToken( i, ';' ));
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 			ImplLoadSubDirs( aCurURL, bIsReadOnlyDir );
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 			if( !bIsReadOnlyDir )
266cdf0e10cSrcweir 			    aUserURL = aCurURL;
267cdf0e10cSrcweir 	    }
268cdf0e10cSrcweir 	}
269cdf0e10cSrcweir 	else
270cdf0e10cSrcweir 		aRelURL = INetURLObject( rMultiPath );
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 	DBG_ASSERT( aUserURL.GetProtocol() != INET_PROT_NOT_VALID, "no writable Gallery user directory available" );
273cdf0e10cSrcweir 	DBG_ASSERT( aRelURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 	ImplLoadImports();
276cdf0e10cSrcweir }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir // ------------------------------------------------------------------------
279cdf0e10cSrcweir 
ImplLoadSubDirs(const INetURLObject & rBaseURL,sal_Bool & rbDirIsReadOnly)280cdf0e10cSrcweir void Gallery::ImplLoadSubDirs( const INetURLObject& rBaseURL, sal_Bool& rbDirIsReadOnly )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir     rbDirIsReadOnly = sal_False;
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 	try
285cdf0e10cSrcweir 	{
286cdf0e10cSrcweir 		uno::Reference< ucb::XCommandEnvironment > xEnv;
287cdf0e10cSrcweir 		::ucbhelper::Content					   aCnt( rBaseURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv );
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 		uno::Sequence< OUString > aProps( 1 );
290cdf0e10cSrcweir 		aProps.getArray()[ 0 ] = OUString::createFromAscii( "Url" );
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 		uno::Reference< sdbc::XResultSet > xResultSet( aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) );
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 		try
295cdf0e10cSrcweir 		{
296cdf0e10cSrcweir 		    // check readonlyness the very hard way
297cdf0e10cSrcweir         	INetURLObject   aTestURL( rBaseURL );
298cdf0e10cSrcweir 	        String          aTestFile( RTL_CONSTASCII_USTRINGPARAM( "cdefghij.klm" ) );
299cdf0e10cSrcweir 
300cdf0e10cSrcweir     	    aTestURL.Append( aTestFile );
301cdf0e10cSrcweir 	        SvStream* pTestStm = ::utl::UcbStreamHelper::CreateStream( aTestURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 	        if( pTestStm )
304cdf0e10cSrcweir 	        {
305cdf0e10cSrcweir 	            *pTestStm << 1;
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 	            if( pTestStm->GetError() )
308cdf0e10cSrcweir 	                rbDirIsReadOnly = sal_True;
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 	            delete pTestStm;
311cdf0e10cSrcweir 	            KillFile( aTestURL );
312cdf0e10cSrcweir 	        }
313cdf0e10cSrcweir 	        else
314cdf0e10cSrcweir 	            rbDirIsReadOnly = sal_True;
315cdf0e10cSrcweir 	    }
316cdf0e10cSrcweir 	    catch( const ucb::ContentCreationException& )
317cdf0e10cSrcweir 	    {
318cdf0e10cSrcweir 	    }
319cdf0e10cSrcweir 	    catch( const uno::RuntimeException& )
320cdf0e10cSrcweir 	    {
321cdf0e10cSrcweir 	    }
322cdf0e10cSrcweir 	    catch( const uno::Exception& )
323cdf0e10cSrcweir 	    {
324cdf0e10cSrcweir 	    }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 		if( xResultSet.is() )
327cdf0e10cSrcweir 		{
328cdf0e10cSrcweir 			uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 			if( xContentAccess.is() )
331cdf0e10cSrcweir 			{
332cdf0e10cSrcweir                 static const ::rtl::OUString s_sTitle(RTL_CONSTASCII_USTRINGPARAM("Title"));
333cdf0e10cSrcweir                 static const ::rtl::OUString s_sIsReadOnly(RTL_CONSTASCII_USTRINGPARAM("IsReadOnly"));
334cdf0e10cSrcweir                 static const ::rtl::OUString s_sSDG_EXT(RTL_CONSTASCII_USTRINGPARAM("sdg"));
335cdf0e10cSrcweir                 static const ::rtl::OUString s_sSDV_EXT(RTL_CONSTASCII_USTRINGPARAM("sdv"));
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 				while( xResultSet->next() )
338cdf0e10cSrcweir 				{
339cdf0e10cSrcweir 					INetURLObject aThmURL( xContentAccess->queryContentIdentifierString() );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 					if(aThmURL.GetExtension().equalsIgnoreAsciiCaseAscii("thm"))
342cdf0e10cSrcweir 					{
343cdf0e10cSrcweir 						INetURLObject	aSdgURL( aThmURL); aSdgURL.SetExtension( s_sSDG_EXT );
344cdf0e10cSrcweir 						INetURLObject	aSdvURL( aThmURL ); aSdvURL.SetExtension( s_sSDV_EXT );
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 						OUString		aTitle;
347cdf0e10cSrcweir 						sal_Bool		bReadOnly = sal_False;
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 						try
350cdf0e10cSrcweir 						{
351cdf0e10cSrcweir 						    ::ucbhelper::Content aThmCnt( aThmURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv );
352cdf0e10cSrcweir 						    ::ucbhelper::Content aSdgCnt( aSdgURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv );
353cdf0e10cSrcweir 						    ::ucbhelper::Content aSdvCnt( aSdvURL.GetMainURL( INetURLObject::NO_DECODE ), xEnv );
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 						    try
356cdf0e10cSrcweir 						    {
357cdf0e10cSrcweir 						        aThmCnt.getPropertyValue( s_sTitle ) >>= aTitle;
358cdf0e10cSrcweir 						    }
359cdf0e10cSrcweir 	                        catch( const uno::RuntimeException& )
360cdf0e10cSrcweir 	                        {
361cdf0e10cSrcweir 	                        }
362cdf0e10cSrcweir 	                        catch( const uno::Exception& )
363cdf0e10cSrcweir 	                        {
364cdf0e10cSrcweir 	                        }
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 						    if( aTitle.getLength() )
367cdf0e10cSrcweir 						    {
368cdf0e10cSrcweir 						        try
369cdf0e10cSrcweir 						        {
370cdf0e10cSrcweir 							        aThmCnt.getPropertyValue( s_sIsReadOnly ) >>= bReadOnly;
371cdf0e10cSrcweir 						        }
372cdf0e10cSrcweir 	                            catch( const uno::RuntimeException& )
373cdf0e10cSrcweir 	                            {
374cdf0e10cSrcweir 	                            }
375cdf0e10cSrcweir 	                            catch( const uno::Exception& )
376cdf0e10cSrcweir 	                            {
377cdf0e10cSrcweir 	                            }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 							    if( !bReadOnly )
380cdf0e10cSrcweir 							    {
381cdf0e10cSrcweir 							        try
382cdf0e10cSrcweir 							        {
383cdf0e10cSrcweir 								        aSdgCnt.getPropertyValue( s_sTitle ) >>= aTitle;
384cdf0e10cSrcweir 						            }
385cdf0e10cSrcweir 	                                catch( const ::com::sun::star::uno::RuntimeException& )
386cdf0e10cSrcweir 	                                {
387cdf0e10cSrcweir 	                                }
388cdf0e10cSrcweir 	                                catch( const ::com::sun::star::uno::Exception& )
389cdf0e10cSrcweir 	                                {
390cdf0e10cSrcweir 	                                }
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 								    if( aTitle.getLength() )
393cdf0e10cSrcweir 								    {
394cdf0e10cSrcweir 								        try
395cdf0e10cSrcweir 								        {
396cdf0e10cSrcweir 	    								    aSdgCnt.getPropertyValue( s_sIsReadOnly ) >>= bReadOnly;
397cdf0e10cSrcweir     					                }
398cdf0e10cSrcweir 	                                    catch( const uno::RuntimeException& )
399cdf0e10cSrcweir 	                                    {
400cdf0e10cSrcweir 	                                    }
401cdf0e10cSrcweir 	                                    catch( const uno::Exception& )
402cdf0e10cSrcweir 	                                    {
403cdf0e10cSrcweir 	                                    }
404cdf0e10cSrcweir 							        }
405cdf0e10cSrcweir 							    }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir 							    if( !bReadOnly )
408cdf0e10cSrcweir 							    {
409cdf0e10cSrcweir 							        try
410cdf0e10cSrcweir 							        {
411cdf0e10cSrcweir 								        aSdvCnt.getPropertyValue( s_sTitle ) >>= aTitle;
412cdf0e10cSrcweir     					            }
413cdf0e10cSrcweir 	                                catch( const ::com::sun::star::uno::RuntimeException& )
414cdf0e10cSrcweir 	                                {
415cdf0e10cSrcweir 	                                }
416cdf0e10cSrcweir 	                                catch( const ::com::sun::star::uno::Exception& )
417cdf0e10cSrcweir 	                                {
418cdf0e10cSrcweir 	                                }
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 								    if( aTitle.getLength() )
421cdf0e10cSrcweir 								    {
422cdf0e10cSrcweir 								        try
423cdf0e10cSrcweir 								        {
424cdf0e10cSrcweir     									    aSdvCnt.getPropertyValue( s_sIsReadOnly ) >>= bReadOnly;
425cdf0e10cSrcweir     					                }
426cdf0e10cSrcweir 	                                    catch( const uno::RuntimeException& )
427cdf0e10cSrcweir 	                                    {
428cdf0e10cSrcweir 	                                    }
429cdf0e10cSrcweir 	                                    catch( const uno::Exception& )
430cdf0e10cSrcweir 	                                    {
431cdf0e10cSrcweir 	                                    }
432cdf0e10cSrcweir 								    }
433cdf0e10cSrcweir 							    }
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 							    GalleryThemeEntry* pEntry = GalleryTheme::CreateThemeEntry( aThmURL, rbDirIsReadOnly || bReadOnly );
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 							    if( pEntry )
438cdf0e10cSrcweir 							    {
439cdf0e10cSrcweir 								    const sal_uIntPtr nFileNumber = (sal_uIntPtr) String(aThmURL.GetBase()).Erase( 0, 2 ).Erase( 6 ).ToInt32();
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 								    aThemeList.Insert( pEntry, LIST_APPEND );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 								    if( nFileNumber > nLastFileNumber )
444cdf0e10cSrcweir 									    nLastFileNumber = nFileNumber;
445cdf0e10cSrcweir 							    }
446cdf0e10cSrcweir 						    }
447cdf0e10cSrcweir 						}
448cdf0e10cSrcweir 	                    catch( const ucb::ContentCreationException& )
449cdf0e10cSrcweir 	                    {
450cdf0e10cSrcweir 	                    }
451cdf0e10cSrcweir 	                    catch( const uno::RuntimeException& )
452cdf0e10cSrcweir 	                    {
453cdf0e10cSrcweir 	                    }
454cdf0e10cSrcweir 	                    catch( const uno::Exception& )
455cdf0e10cSrcweir 	                    {
456cdf0e10cSrcweir 	                    }
457cdf0e10cSrcweir 					}
458cdf0e10cSrcweir 				}
459cdf0e10cSrcweir 			}
460cdf0e10cSrcweir 		}
461cdf0e10cSrcweir 	}
462cdf0e10cSrcweir 	catch( const ucb::ContentCreationException& )
463cdf0e10cSrcweir 	{
464cdf0e10cSrcweir 	}
465cdf0e10cSrcweir 	catch( const uno::RuntimeException& )
466cdf0e10cSrcweir 	{
467cdf0e10cSrcweir 	}
468cdf0e10cSrcweir 	catch( const uno::Exception& )
469cdf0e10cSrcweir 	{
470cdf0e10cSrcweir 	}
471cdf0e10cSrcweir }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir // ------------------------------------------------------------------------
474cdf0e10cSrcweir 
ImplLoadImports()475cdf0e10cSrcweir void Gallery::ImplLoadImports()
476cdf0e10cSrcweir {
477cdf0e10cSrcweir 	INetURLObject aURL( GetUserURL() );
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 	aURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( "gallery.sdi" ) ) );
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 	if( FileExists( aURL ) )
482cdf0e10cSrcweir 	{
483cdf0e10cSrcweir 		SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 		if( pIStm )
486cdf0e10cSrcweir 		{
487cdf0e10cSrcweir 			GalleryThemeEntry*			pThemeEntry;
488cdf0e10cSrcweir 			GalleryImportThemeEntry*	pImportEntry;
489cdf0e10cSrcweir 			INetURLObject               aFile;
490cdf0e10cSrcweir 			sal_uInt32                      nInventor;
491cdf0e10cSrcweir 			sal_uInt32                      nCount;
492cdf0e10cSrcweir 			sal_uInt16                      nId;
493cdf0e10cSrcweir 			sal_uInt16                      i;
494cdf0e10cSrcweir 			sal_uInt16                      nTempCharSet;
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 			for( pImportEntry = aImportList.First(); pImportEntry; pImportEntry = aImportList.Next() )
497cdf0e10cSrcweir 				delete pImportEntry;
498cdf0e10cSrcweir 
499cdf0e10cSrcweir 			aImportList.Clear();
500cdf0e10cSrcweir 			*pIStm >> nInventor;
501cdf0e10cSrcweir 
502cdf0e10cSrcweir 			if( nInventor == COMPAT_FORMAT( 'S', 'G', 'A', '3' ) )
503cdf0e10cSrcweir 			{
504cdf0e10cSrcweir 				*pIStm >> nId >> nCount >> nTempCharSet;
505cdf0e10cSrcweir 
506cdf0e10cSrcweir 				for( i = 0; i < nCount; i++ )
507cdf0e10cSrcweir 				{
508cdf0e10cSrcweir 					pImportEntry = new GalleryImportThemeEntry;
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 					*pIStm >> *pImportEntry;
511cdf0e10cSrcweir 					aImportList.Insert( pImportEntry, LIST_APPEND );
512cdf0e10cSrcweir 					aFile = INetURLObject( pImportEntry->aURL );
513cdf0e10cSrcweir 					pThemeEntry = new GalleryThemeEntry( aFile,
514cdf0e10cSrcweir 														 pImportEntry->aUIName,
515cdf0e10cSrcweir 														 String(aFile.GetBase()).Erase( 0, 2 ).Erase( 6 ).ToInt32(),
516cdf0e10cSrcweir 														 sal_True, sal_True, sal_False, 0, sal_False );
517cdf0e10cSrcweir 
518cdf0e10cSrcweir 					aThemeList.Insert( pThemeEntry, LIST_APPEND );
519cdf0e10cSrcweir 				}
520cdf0e10cSrcweir 			}
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 			delete pIStm;
523cdf0e10cSrcweir 		}
524cdf0e10cSrcweir 	}
525cdf0e10cSrcweir }
526cdf0e10cSrcweir 
527cdf0e10cSrcweir // ------------------------------------------------------------------------
528cdf0e10cSrcweir 
ImplWriteImportList()529cdf0e10cSrcweir void Gallery::ImplWriteImportList()
530cdf0e10cSrcweir {
531cdf0e10cSrcweir 	INetURLObject aURL( GetUserURL() );
532cdf0e10cSrcweir 	aURL.Append( ( String( "gallery.sdi", RTL_TEXTENCODING_UTF8 ) ) );
533cdf0e10cSrcweir 	SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 	if( pOStm )
536cdf0e10cSrcweir 	{
537cdf0e10cSrcweir 		const sal_uInt32 nInventor = (sal_uInt32) COMPAT_FORMAT( 'S', 'G', 'A', '3' );
538cdf0e10cSrcweir 		const sal_uInt16 nId = 0x0004;
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 		*pOStm << nInventor << nId << (sal_uInt32) aImportList.Count() << (sal_uInt16) gsl_getSystemTextEncoding();
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 		for( GalleryImportThemeEntry* pImportEntry = aImportList.First(); pImportEntry; pImportEntry = aImportList.Next() )
543cdf0e10cSrcweir 			*pOStm << *pImportEntry;
544cdf0e10cSrcweir 
545cdf0e10cSrcweir 		if( pOStm->GetError() )
546cdf0e10cSrcweir 			ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 		delete pOStm;
549cdf0e10cSrcweir 	}
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir // ------------------------------------------------------------------------
553cdf0e10cSrcweir 
ImplGetThemeEntry(const String & rThemeName)554cdf0e10cSrcweir GalleryThemeEntry* Gallery::ImplGetThemeEntry( const String& rThemeName )
555cdf0e10cSrcweir {
556cdf0e10cSrcweir 	GalleryThemeEntry* pFound = NULL;
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 	if( rThemeName.Len() )
559cdf0e10cSrcweir 		for( GalleryThemeEntry* pEntry = aThemeList.First(); pEntry && !pFound; pEntry = aThemeList.Next() )
560cdf0e10cSrcweir 			if( rThemeName == pEntry->GetThemeName() )
561cdf0e10cSrcweir 				pFound = pEntry;
562cdf0e10cSrcweir 
563cdf0e10cSrcweir 	return pFound;
564cdf0e10cSrcweir }
565cdf0e10cSrcweir 
566cdf0e10cSrcweir // ------------------------------------------------------------------------
567cdf0e10cSrcweir 
ImplGetImportThemeEntry(const String & rImportName)568cdf0e10cSrcweir GalleryImportThemeEntry* Gallery::ImplGetImportThemeEntry( const String& rImportName )
569cdf0e10cSrcweir {
570cdf0e10cSrcweir 	GalleryImportThemeEntry* pFound = NULL;
571cdf0e10cSrcweir 
572cdf0e10cSrcweir 	for( GalleryImportThemeEntry* pImportEntry = aImportList.First(); pImportEntry && !pFound; pImportEntry = aImportList.Next() )
573cdf0e10cSrcweir 		if ( rImportName == pImportEntry->aUIName )
574cdf0e10cSrcweir 			pFound = pImportEntry;
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 	return pFound;
577cdf0e10cSrcweir }
578cdf0e10cSrcweir 
579cdf0e10cSrcweir // ------------------------------------------------------------------------
580cdf0e10cSrcweir 
GetThemeName(sal_uIntPtr nThemeId) const581cdf0e10cSrcweir String Gallery::GetThemeName( sal_uIntPtr nThemeId ) const
582cdf0e10cSrcweir {
583cdf0e10cSrcweir 	GalleryThemeEntry* pFound = NULL;
584cdf0e10cSrcweir 
585cdf0e10cSrcweir 	for( sal_uIntPtr n = 0, nCount = aThemeList.Count(); n < nCount; n++ )
586cdf0e10cSrcweir 	{
587cdf0e10cSrcweir 		GalleryThemeEntry* pEntry = aThemeList.GetObject( n );
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 		if( nThemeId == pEntry->GetId() )
590cdf0e10cSrcweir 			pFound = pEntry;
591cdf0e10cSrcweir 	}
592cdf0e10cSrcweir 
593cdf0e10cSrcweir 	// try fallback, if no entry was found
594cdf0e10cSrcweir 	if( !pFound )
595cdf0e10cSrcweir 	{
596cdf0e10cSrcweir 		ByteString      aFallback;
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 		switch( nThemeId )
599cdf0e10cSrcweir 		{
600cdf0e10cSrcweir 			case( GALLERY_THEME_3D ): aFallback = "3D"; break;
601cdf0e10cSrcweir 			case( GALLERY_THEME_BULLETS ): aFallback = "Bullets"; break;
602cdf0e10cSrcweir 			case( GALLERY_THEME_HOMEPAGE ): aFallback = "Homepage"; break;
603cdf0e10cSrcweir 			case( GALLERY_THEME_POWERPOINT ): aFallback = "private://gallery/hidden/imgppt"; break;
604cdf0e10cSrcweir 			case( GALLERY_THEME_FONTWORK ): aFallback = "private://gallery/hidden/fontwork"; break;
605cdf0e10cSrcweir 			case( GALLERY_THEME_FONTWORK_VERTICAL ): aFallback = "private://gallery/hidden/fontworkvertical"; break;
606cdf0e10cSrcweir 			case( GALLERY_THEME_RULERS ): aFallback = "Rulers"; break;
607cdf0e10cSrcweir 			case( GALLERY_THEME_SOUNDS ): aFallback = "Sounds"; break;
608cdf0e10cSrcweir 
609cdf0e10cSrcweir             case( RID_GALLERYSTR_THEME_ARROWS ): aFallback = "Arrows"; break;
610cdf0e10cSrcweir             case( RID_GALLERYSTR_THEME_COMPUTERS ): aFallback = "Computers"; break;
611cdf0e10cSrcweir             case( RID_GALLERYSTR_THEME_DIAGRAMS ): aFallback = "Diagrams"; break;
612cdf0e10cSrcweir             case( RID_GALLERYSTR_THEME_EDUCATION ): aFallback = "Education"; break;
613cdf0e10cSrcweir             case( RID_GALLERYSTR_THEME_ENVIRONMENT ): aFallback = "Environment"; break;
614cdf0e10cSrcweir             case( RID_GALLERYSTR_THEME_FINANCE ): aFallback = "Finance"; break;
615cdf0e10cSrcweir             case( RID_GALLERYSTR_THEME_PEOPLE ): aFallback = "People"; break;
616cdf0e10cSrcweir             case( RID_GALLERYSTR_THEME_SYMBOLS ): aFallback = "Symbols"; break;
617cdf0e10cSrcweir             case( RID_GALLERYSTR_THEME_TRANSPORT ): aFallback = "Transport"; break;
618cdf0e10cSrcweir             case( RID_GALLERYSTR_THEME_TXTSHAPES ): aFallback = "Textshapes"; break;
619cdf0e10cSrcweir 
620cdf0e10cSrcweir             default:
621cdf0e10cSrcweir 			break;
622cdf0e10cSrcweir 		}
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 		pFound = ( (Gallery*) this )->ImplGetThemeEntry( String::CreateFromAscii( aFallback.GetBuffer() ) );
625cdf0e10cSrcweir 	}
626cdf0e10cSrcweir 
627cdf0e10cSrcweir 	return( pFound ? pFound->GetThemeName() : String() );
628cdf0e10cSrcweir }
629cdf0e10cSrcweir 
630cdf0e10cSrcweir // ------------------------------------------------------------------------
631cdf0e10cSrcweir 
HasTheme(const String & rThemeName)632cdf0e10cSrcweir sal_Bool Gallery::HasTheme( const String& rThemeName )
633cdf0e10cSrcweir {
634cdf0e10cSrcweir 	return( ImplGetThemeEntry( rThemeName ) != NULL );
635cdf0e10cSrcweir }
636cdf0e10cSrcweir 
637cdf0e10cSrcweir // ------------------------------------------------------------------------
638cdf0e10cSrcweir 
CreateTheme(const String & rThemeName,sal_uInt32 nNumFrom)639cdf0e10cSrcweir sal_Bool Gallery::CreateTheme( const String& rThemeName, sal_uInt32 nNumFrom )
640cdf0e10cSrcweir {
641cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
642cdf0e10cSrcweir 
643cdf0e10cSrcweir 	if( !HasTheme( rThemeName ) && ( GetUserURL().GetProtocol() != INET_PROT_NOT_VALID ) )
644cdf0e10cSrcweir 	{
645cdf0e10cSrcweir 		nLastFileNumber = nNumFrom > nLastFileNumber ? nNumFrom : nLastFileNumber + 1;
646cdf0e10cSrcweir 		GalleryThemeEntry* pNewEntry = new GalleryThemeEntry( GetUserURL(), rThemeName,
647cdf0e10cSrcweir 															  nLastFileNumber,
648cdf0e10cSrcweir 															  sal_False, sal_False, sal_True, 0, sal_False );
649cdf0e10cSrcweir 
650cdf0e10cSrcweir 		aThemeList.Insert( pNewEntry, LIST_APPEND );
651cdf0e10cSrcweir 		delete( new GalleryTheme( this, pNewEntry ) );
652cdf0e10cSrcweir 		Broadcast( GalleryHint( GALLERY_HINT_THEME_CREATED, rThemeName ) );
653cdf0e10cSrcweir 		bRet = sal_True;
654cdf0e10cSrcweir 	}
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 	return bRet;
657cdf0e10cSrcweir }
658cdf0e10cSrcweir 
659cdf0e10cSrcweir // ------------------------------------------------------------------------
660cdf0e10cSrcweir 
CreateImportTheme(const INetURLObject & rURL,const String & rImportName)661cdf0e10cSrcweir sal_Bool Gallery::CreateImportTheme( const INetURLObject& rURL, const String& rImportName )
662cdf0e10cSrcweir {
663cdf0e10cSrcweir 	INetURLObject	aURL( rURL );
664cdf0e10cSrcweir 	sal_Bool			bRet = sal_False;
665cdf0e10cSrcweir 
666cdf0e10cSrcweir 	DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
667cdf0e10cSrcweir 
668cdf0e10cSrcweir 	if( FileExists( aURL ) )
669cdf0e10cSrcweir 	{
670cdf0e10cSrcweir 		SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
671cdf0e10cSrcweir 
672cdf0e10cSrcweir 		if( pIStm )
673cdf0e10cSrcweir 		{
674cdf0e10cSrcweir 			sal_uIntPtr   nStmErr;
675cdf0e10cSrcweir 			sal_uInt16  nId;
676cdf0e10cSrcweir 
677cdf0e10cSrcweir 			*pIStm >> nId;
678cdf0e10cSrcweir 
679cdf0e10cSrcweir 			if( nId > 0x0004 )
680cdf0e10cSrcweir 				ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
681cdf0e10cSrcweir 			else
682cdf0e10cSrcweir 			{
683cdf0e10cSrcweir 				ByteString				aTmpStr;
684cdf0e10cSrcweir 				String                  aThemeName; *pIStm >> aTmpStr; aThemeName = String( aTmpStr, RTL_TEXTENCODING_UTF8 );
685cdf0e10cSrcweir 				GalleryThemeEntry*      pThemeEntry = new GalleryThemeEntry( aURL, rImportName,
686cdf0e10cSrcweir 																			 String(aURL.GetBase()).Erase( 0, 2 ).Erase( 6 ).ToInt32(),
687cdf0e10cSrcweir 																			 sal_True, sal_True, sal_True, 0, sal_False );
688cdf0e10cSrcweir 				GalleryTheme*           pImportTheme = new GalleryTheme( this, pThemeEntry );
689cdf0e10cSrcweir 
690cdf0e10cSrcweir 				pIStm->Seek( STREAM_SEEK_TO_BEGIN );
691cdf0e10cSrcweir 				*pIStm >> *pImportTheme;
692cdf0e10cSrcweir 				nStmErr = pIStm->GetError();
693cdf0e10cSrcweir 
694cdf0e10cSrcweir 				if( nStmErr )
695cdf0e10cSrcweir 				{
696cdf0e10cSrcweir 					delete pThemeEntry;
697cdf0e10cSrcweir 					ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
698cdf0e10cSrcweir 				}
699cdf0e10cSrcweir 				else
700cdf0e10cSrcweir 				{
701cdf0e10cSrcweir 					String  aName( rImportName );
702cdf0e10cSrcweir 					String  aNewName( aName );
703cdf0e10cSrcweir 					sal_uIntPtr   nCount = 0;
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 					aName += ' ';
706cdf0e10cSrcweir 
707cdf0e10cSrcweir 					while ( HasTheme( aNewName ) && ( nCount++ < 16000 ) )
708cdf0e10cSrcweir 					{
709cdf0e10cSrcweir 						aNewName = aName;
710cdf0e10cSrcweir 						aNewName += String::CreateFromInt32( nCount );
711cdf0e10cSrcweir 					}
712cdf0e10cSrcweir 
713cdf0e10cSrcweir 					pImportTheme->SetImportName( aNewName );
714cdf0e10cSrcweir 					aThemeList.Insert( pThemeEntry, LIST_APPEND );
715cdf0e10cSrcweir 
716cdf0e10cSrcweir 					// Thema in Import-Liste eintragen und Import-Liste     speichern
717cdf0e10cSrcweir 					GalleryImportThemeEntry* pImportEntry = new GalleryImportThemeEntry;
718cdf0e10cSrcweir 					pImportEntry->aThemeName = pImportEntry->aUIName = aNewName;
719cdf0e10cSrcweir 					pImportEntry->aURL = rURL;
720cdf0e10cSrcweir 					pImportEntry->aImportName = rImportName;
721cdf0e10cSrcweir 					aImportList.Insert( pImportEntry, LIST_APPEND );
722cdf0e10cSrcweir 					ImplWriteImportList();
723cdf0e10cSrcweir 					bRet = sal_True;
724cdf0e10cSrcweir 				}
725cdf0e10cSrcweir 
726cdf0e10cSrcweir 				delete pImportTheme;
727cdf0e10cSrcweir 			}
728cdf0e10cSrcweir 
729cdf0e10cSrcweir 			delete pIStm;
730cdf0e10cSrcweir 		}
731cdf0e10cSrcweir 	}
732cdf0e10cSrcweir 
733cdf0e10cSrcweir 	return bRet;
734cdf0e10cSrcweir }
735cdf0e10cSrcweir 
736cdf0e10cSrcweir // ------------------------------------------------------------------------
737cdf0e10cSrcweir 
RenameTheme(const String & rOldName,const String & rNewName)738cdf0e10cSrcweir sal_Bool Gallery::RenameTheme( const String& rOldName, const String& rNewName )
739cdf0e10cSrcweir {
740cdf0e10cSrcweir 	GalleryThemeEntry*      pThemeEntry = ImplGetThemeEntry( rOldName );
741cdf0e10cSrcweir 	sal_Bool                            bRet = sal_False;
742cdf0e10cSrcweir 
743cdf0e10cSrcweir 	// Ueberpruefen, ob neuer Themenname schon vorhanden ist
744cdf0e10cSrcweir 	if( pThemeEntry && !HasTheme( rNewName ) && ( !pThemeEntry->IsReadOnly() || pThemeEntry->IsImported() ) )
745cdf0e10cSrcweir 	{
746cdf0e10cSrcweir 		SfxListener   aListener;
747cdf0e10cSrcweir 		GalleryTheme* pThm = AcquireTheme( rOldName, aListener );
748cdf0e10cSrcweir 
749cdf0e10cSrcweir 		if( pThm )
750cdf0e10cSrcweir 		{
751cdf0e10cSrcweir 			const String aOldName( rOldName );
752cdf0e10cSrcweir 
753cdf0e10cSrcweir 			pThemeEntry->SetName( rNewName );
754cdf0e10cSrcweir 			pThm->ImplWrite();
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 			if( pThemeEntry->IsImported() )
757cdf0e10cSrcweir 			{
758cdf0e10cSrcweir 				pThm->SetImportName( rNewName );
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 				GalleryImportThemeEntry* pImportEntry = ImplGetImportThemeEntry( rOldName );
761cdf0e10cSrcweir 
762cdf0e10cSrcweir 				if( pImportEntry )
763cdf0e10cSrcweir 				{
764cdf0e10cSrcweir 					pImportEntry->aUIName = rNewName;
765cdf0e10cSrcweir 					ImplWriteImportList();
766cdf0e10cSrcweir 				}
767cdf0e10cSrcweir 			}
768cdf0e10cSrcweir 
769cdf0e10cSrcweir 			Broadcast( GalleryHint( GALLERY_HINT_THEME_RENAMED, aOldName, pThm->GetName() ) );
770cdf0e10cSrcweir 			ReleaseTheme( pThm, aListener );
771cdf0e10cSrcweir 			bRet = sal_True;
772cdf0e10cSrcweir 		}
773cdf0e10cSrcweir 	}
774cdf0e10cSrcweir 
775cdf0e10cSrcweir 	return bRet;
776cdf0e10cSrcweir }
777cdf0e10cSrcweir 
778cdf0e10cSrcweir // ------------------------------------------------------------------------
779cdf0e10cSrcweir 
RemoveTheme(const String & rThemeName)780cdf0e10cSrcweir sal_Bool Gallery::RemoveTheme( const String& rThemeName )
781cdf0e10cSrcweir {
782cdf0e10cSrcweir 	GalleryThemeEntry*	pThemeEntry = ImplGetThemeEntry( rThemeName );
783cdf0e10cSrcweir 	sal_Bool                bRet = sal_False;
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 	if( pThemeEntry && ( !pThemeEntry->IsReadOnly() || pThemeEntry->IsImported() ) )
786cdf0e10cSrcweir 	{
787cdf0e10cSrcweir 		Broadcast( GalleryHint( GALLERY_HINT_CLOSE_THEME, rThemeName ) );
788cdf0e10cSrcweir 
789cdf0e10cSrcweir 		if( pThemeEntry->IsImported() )
790cdf0e10cSrcweir 		{
791cdf0e10cSrcweir 			GalleryImportThemeEntry* pImportEntry = ImplGetImportThemeEntry( rThemeName );
792cdf0e10cSrcweir 
793cdf0e10cSrcweir 			if( pImportEntry )
794cdf0e10cSrcweir 			{
795cdf0e10cSrcweir 				delete aImportList.Remove( pImportEntry );
796cdf0e10cSrcweir 				ImplWriteImportList();
797cdf0e10cSrcweir 			}
798cdf0e10cSrcweir 		}
799cdf0e10cSrcweir 		else
800cdf0e10cSrcweir 		{
801cdf0e10cSrcweir 			SfxListener		aListener;
802cdf0e10cSrcweir 			GalleryTheme*	pThm = AcquireTheme( rThemeName, aListener );
803cdf0e10cSrcweir 
804cdf0e10cSrcweir             if( pThm )
805cdf0e10cSrcweir             {
806cdf0e10cSrcweir                 INetURLObject	aThmURL( pThm->GetThmURL() );
807cdf0e10cSrcweir                 INetURLObject	aSdgURL( pThm->GetSdgURL() );
808cdf0e10cSrcweir                 INetURLObject	aSdvURL( pThm->GetSdvURL() );
809cdf0e10cSrcweir 
810cdf0e10cSrcweir                 ReleaseTheme( pThm, aListener );
811cdf0e10cSrcweir 
812cdf0e10cSrcweir                 KillFile( aThmURL );
813cdf0e10cSrcweir                 KillFile( aSdgURL );
814cdf0e10cSrcweir                 KillFile( aSdvURL );
815cdf0e10cSrcweir             }
816cdf0e10cSrcweir 		}
817cdf0e10cSrcweir 
818cdf0e10cSrcweir 		delete aThemeList.Remove( pThemeEntry );
819cdf0e10cSrcweir 		Broadcast( GalleryHint( GALLERY_HINT_THEME_REMOVED, rThemeName ) );
820cdf0e10cSrcweir 
821cdf0e10cSrcweir 		bRet = sal_True;
822cdf0e10cSrcweir 	}
823cdf0e10cSrcweir 
824cdf0e10cSrcweir 	return bRet;
825cdf0e10cSrcweir }
826cdf0e10cSrcweir 
827cdf0e10cSrcweir // ------------------------------------------------------------------------
828cdf0e10cSrcweir 
GetImportURL(const String & rThemeName)829cdf0e10cSrcweir INetURLObject Gallery::GetImportURL( const String& rThemeName )
830cdf0e10cSrcweir {
831cdf0e10cSrcweir 	INetURLObject				aURL;
832cdf0e10cSrcweir 	GalleryImportThemeEntry*	pImportEntry = ImplGetImportThemeEntry( rThemeName );
833cdf0e10cSrcweir 
834cdf0e10cSrcweir 	if( pImportEntry )
835cdf0e10cSrcweir 	{
836cdf0e10cSrcweir 		aURL = pImportEntry->aURL;
837cdf0e10cSrcweir 		DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
838cdf0e10cSrcweir 	}
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 	return aURL;
841cdf0e10cSrcweir }
842cdf0e10cSrcweir 
843cdf0e10cSrcweir // ------------------------------------------------------------------------
844cdf0e10cSrcweir 
ImplGetCachedTheme(const GalleryThemeEntry * pThemeEntry)845cdf0e10cSrcweir GalleryTheme* Gallery::ImplGetCachedTheme( const GalleryThemeEntry* pThemeEntry )
846cdf0e10cSrcweir {
847cdf0e10cSrcweir 	GalleryTheme* pTheme = NULL;
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 	if( pThemeEntry )
850cdf0e10cSrcweir 	{
851cdf0e10cSrcweir 		GalleryThemeCacheEntry* pEntry;
852cdf0e10cSrcweir 
853cdf0e10cSrcweir 		for( pEntry = (GalleryThemeCacheEntry*) aThemeCache.First(); pEntry && !pTheme; pEntry = (GalleryThemeCacheEntry*) aThemeCache.Next() )
854cdf0e10cSrcweir 			if( pThemeEntry == pEntry->GetThemeEntry() )
855cdf0e10cSrcweir 				pTheme = pEntry->GetTheme();
856cdf0e10cSrcweir 
857cdf0e10cSrcweir 		if( !pTheme )
858cdf0e10cSrcweir 		{
859cdf0e10cSrcweir 			INetURLObject aURL;
860cdf0e10cSrcweir 
861cdf0e10cSrcweir 			if( !pThemeEntry->IsImported() )
862cdf0e10cSrcweir 				aURL = pThemeEntry->GetThmURL();
863cdf0e10cSrcweir 			else
864cdf0e10cSrcweir 				aURL = GetImportURL( pThemeEntry->GetThemeName() );
865cdf0e10cSrcweir 
866cdf0e10cSrcweir 			DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
867cdf0e10cSrcweir 
868cdf0e10cSrcweir 			if( FileExists( aURL ) )
869cdf0e10cSrcweir 			{
870cdf0e10cSrcweir 				SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
871cdf0e10cSrcweir 
872cdf0e10cSrcweir 				if( pIStm )
873cdf0e10cSrcweir 				{
874cdf0e10cSrcweir 					pTheme = new GalleryTheme( this, (GalleryThemeEntry*) pThemeEntry );
875cdf0e10cSrcweir 					*pIStm >> *pTheme;
876cdf0e10cSrcweir 
877cdf0e10cSrcweir 					if( pIStm->GetError() )
878cdf0e10cSrcweir 						delete pTheme, pTheme = NULL;
879cdf0e10cSrcweir 					else if( pThemeEntry->IsImported() )
880cdf0e10cSrcweir 						pTheme->SetImportName( pThemeEntry->GetThemeName() );
881cdf0e10cSrcweir 
882cdf0e10cSrcweir 					delete pIStm;
883cdf0e10cSrcweir 				}
884cdf0e10cSrcweir 			}
885cdf0e10cSrcweir 
886cdf0e10cSrcweir 			if( pTheme )
887cdf0e10cSrcweir 				aThemeCache.Insert( new GalleryThemeCacheEntry( pThemeEntry, pTheme ), LIST_APPEND );
888cdf0e10cSrcweir 		}
889cdf0e10cSrcweir 	}
890cdf0e10cSrcweir 
891cdf0e10cSrcweir 	return pTheme;
892cdf0e10cSrcweir }
893cdf0e10cSrcweir 
894cdf0e10cSrcweir // ------------------------------------------------------------------------
895cdf0e10cSrcweir 
ImplDeleteCachedTheme(GalleryTheme * pTheme)896cdf0e10cSrcweir void Gallery::ImplDeleteCachedTheme( GalleryTheme* pTheme )
897cdf0e10cSrcweir {
898cdf0e10cSrcweir 	GalleryThemeCacheEntry* pEntry;
899cdf0e10cSrcweir 	sal_Bool                                    bDone = sal_False;
900cdf0e10cSrcweir 
901cdf0e10cSrcweir 	for( pEntry = (GalleryThemeCacheEntry*) aThemeCache.First(); pEntry && !bDone; pEntry = (GalleryThemeCacheEntry*) aThemeCache.Next() )
902cdf0e10cSrcweir 	{
903cdf0e10cSrcweir 		if( pTheme == pEntry->GetTheme() )
904cdf0e10cSrcweir 		{
905cdf0e10cSrcweir 			delete (GalleryThemeCacheEntry*) aThemeCache.Remove( pEntry );
906cdf0e10cSrcweir 			bDone = sal_True;
907cdf0e10cSrcweir 		}
908cdf0e10cSrcweir 	}
909cdf0e10cSrcweir }
910cdf0e10cSrcweir 
911cdf0e10cSrcweir // ------------------------------------------------------------------------
912cdf0e10cSrcweir 
AcquireTheme(const String & rThemeName,SfxListener & rListener)913cdf0e10cSrcweir GalleryTheme* Gallery::AcquireTheme( const String& rThemeName, SfxListener& rListener )
914cdf0e10cSrcweir {
915cdf0e10cSrcweir 	GalleryTheme*           pTheme = NULL;
916cdf0e10cSrcweir 	GalleryThemeEntry*      pThemeEntry = ImplGetThemeEntry( rThemeName );
917cdf0e10cSrcweir 
918cdf0e10cSrcweir 	if( pThemeEntry && ( ( pTheme = ImplGetCachedTheme( pThemeEntry ) ) != NULL ) )
919cdf0e10cSrcweir 		rListener.StartListening( *pTheme );
920cdf0e10cSrcweir 
921cdf0e10cSrcweir 	return pTheme;
922cdf0e10cSrcweir }
923cdf0e10cSrcweir 
924cdf0e10cSrcweir // ------------------------------------------------------------------------
925cdf0e10cSrcweir 
ReleaseTheme(GalleryTheme * pTheme,SfxListener & rListener)926cdf0e10cSrcweir void Gallery::ReleaseTheme( GalleryTheme* pTheme, SfxListener& rListener )
927cdf0e10cSrcweir {
928cdf0e10cSrcweir 	if( pTheme )
929 	{
930 		rListener.EndListening( *pTheme );
931 
932 		if( !pTheme->HasListeners() )
933 			ImplDeleteCachedTheme( pTheme );
934 	}
935 }
936 
IsDefault() const937 sal_Bool GalleryThemeEntry::IsDefault() const
938 { return( ( nId > 0 ) && ( nId != ( RID_GALLERYSTR_THEME_MYTHEME - RID_GALLERYSTR_THEME_START ) ) ); }
939 
940