1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SFX2_TEMPLATEFOLDERCACHE_HXX
25 #define SFX2_TEMPLATEFOLDERCACHE_HXX
26 
27 #include "svtools/svtdllapi.h"
28 #include <sal/types.h>
29 
30 //.........................................................................
31 namespace svt
32 {
33 //.........................................................................
34 
35 	//=====================================================================
36 	//= TemplateFolderCache
37 	//=====================================================================
38 	class TemplateFolderCacheImpl;
39 	/** allows to cache the state of the template directories of OOo
40 		<p>Usually, this class is used together with an instance of a the
41 		<service scope="com.sun.star.frame">DocumentTemplates</service> service. It allows to scan the template folders
42 		of the Office, and updates the configuration so that it reflects the most recent state of the folders.<br/>
43 		As this is an expensive, the TemplateFolderCache has been introduced. It caches the state of the template
44 		folders, and allows to determine if the DocumentTemplates service needs to be invoked to do the (much more expensive)
45 		update.</p>
46 	@example C++
47 	<listing>
48 		TemplateFolderCache aTemplateFolders;
49 		if ( aTemplateFolders.needsUpdate() )
50 		{
51 			// store the current state
52 			aCache.storeState();
53 
54 			// create the DocumentTemplates instance
55 			Reference< XDocumentTemplates > xTemplates = ...;
56 
57 			// update the templates configuration
58 			xTemplates->update();
59 		}
60 
61 		// do anything which relies on a up-to-date template configuration
62 	</listing>
63 	*/
64 	class SVT_DLLPUBLIC TemplateFolderCache
65 	{
66 	private:
67 		TemplateFolderCacheImpl*		m_pImpl;
68 
69 	public:
70 		/** ctor.
71 		@param _bAutoStoreState
72 			Set this to <TRUE/> if you want the instance to automatically store the state of the template folders upon
73 			destruction.<br/>
74 			If set to <FALSE/>, you would epplicitly need to call <method>storeState</method> to do this.<br/>
75 			If the current state is not known (e.g. because you did not call needsUpdate, which retrieves it),
76 			it is not retrieved in the dtor, regardless of the <arg>_bAutoStoreState</arg> flag.
77 		*/
78 		TemplateFolderCache( sal_Bool _bAutoStoreState = sal_False );
79 		~TemplateFolderCache( );
80 
81 		/** determines whether or not the template configuration needs to be updated
82 		@param _bForceCheck
83 			set this to <TRUE/> if you want the object to rescan the template folders in every case. The default (<FALSE/>)
84 			means that once the information has been retrieved in a first call, every second call returns the same result
85 			as the first one, even if in the meantime the template folders changed.
86 		@return
87 			<TRUE/> if the template configuration needs to be updated
88 		*/
89 		sal_Bool	needsUpdate( sal_Bool _bForceCheck = sal_False );
90 
91 		/** stores the current state of the template folders in the cache
92 		@param _bForceRetrieval
93 			if set to <TRUE/>, the current state of the template folders is retrieved again, even if it is already known.
94 			Usually, you set this to <FALSE/>: After calling <method>needsUpdate</method>, the state is know and does not
95 			need to be read again.
96 		*/
97 		void		storeState( sal_Bool _bForceRetrieval = sal_False );
98 	};
99 
100 //.........................................................................
101 }	// namespace svt
102 //.........................................................................
103 
104 #endif // SFX2_TEMPLATEFOLDERCACHE_HXX
105