1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_PRESETHANDLER_HXX
21 #define INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_PRESETHANDLER_HXX
23 #include <accelerators/storageholder.hxx>
27 #include <com/sun/star/embed/XStorage.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <comphelper/processfactory.hxx>
32 #include <salhelper/singletonref.hxx>
33 #include <i18nlangtag/languagetag.hxx>
40 <layer>/global/<resourcetype>/<preset>.xml
41 <layer>/modules/<moduleid>/<resourcetype>/<preset>.xml
43 RESOURCETYPE PRESET TARGET
45 "accelerator" "default" "current"
49 "menubar" "default" "menubar"
56 /** @short this handler can provide different
57 types of configuration.
59 @descr Means: a global or a module dependent
71 /** @short because a concurrent access to the same storage from different implementations
72 isn't supported, we have to share it with others.
74 @descr This struct makes it possible to use any shared storage
75 in combination with a SingletonRef<> template ...
77 This struct is allegedly shared and must be used within a
78 synchronized section. But it isn't.
80 struct TSharedStorages
84 StorageHolder m_lStoragesShare
;
85 StorageHolder m_lStoragesUser
;
92 virtual ~TSharedStorages() {};
99 /** @short can be used to create on needed uno resources. */
100 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
102 /** @short knows the type of provided configuration.
104 @descr e.g. global, modules, ...
106 EConfigType m_eConfigType
;
108 /** @short specify the type of resource, which configuration sets
109 must be provided here.
111 @descr e.g. menubars, toolbars, accelerators
113 OUString m_sResourceType
;
115 /** @short specify the application module for a module
116 dependent configuration.
118 @descr Will be used only, if m_sResourceType is set to
119 "module". Further it must be a valid module identifier
124 /** @short provides access to the:
125 a) shared root storages
126 b) shared "inbetween" storages
127 of the share and user layer. */
128 ::salhelper::SingletonRef
< TSharedStorages
> m_aSharedStorages
;
130 /** @short if we run in document mode, we can't use the global root storages!
131 We have to use a special document storage explicitly. */
132 StorageHolder m_lDocumentStorages
;
134 /** @short holds the folder storage of the share layer alive,
135 where the current configuration set exists.
137 @descr Note: If this preset handler works in document mode
138 this member is meaned relative to the document root ...
139 not to the share layer root!
141 Further is defined, that m_xWorkingStorageUser
142 is equals to m_xWorkingStorageShare then!
144 css::uno::Reference
< css::embed::XStorage
> m_xWorkingStorageShare
;
146 /** @short global language-independent storage
148 css::uno::Reference
< css::embed::XStorage
> m_xWorkingStorageNoLang
;
150 /** @short holds the folder storage of the user layer alive,
151 where the current configuration set exists.
153 @descr Note: If this preset handler works in document mode
154 this member is meaned relative to the document root ...
155 not to the user layer root!
157 Further is defined, that m_xWorkingStorageUser
158 is equals to m_xWorkingStorageShare then!
160 css::uno::Reference
< css::embed::XStorage
> m_xWorkingStorageUser
;
162 /** @short knows the names of all presets inside the current
163 working storage of the share layer. */
164 OUStringList m_lPresets
;
166 /** @short knows the names of all targets inside the current
167 working storage of the user layer. */
168 OUStringList m_lTargets
;
170 /** @short its the current office locale and will be used
171 to handle localized presets.
173 @descr Default is "x-no-translate" which disable any
174 localized handling inside this class! */
175 LanguageTag m_aLanguageTag
;
177 /** @short knows the relative path from the root. */
178 OUString m_sRelPathShare
;
179 OUString m_sRelPathNoLang
;
180 OUString m_sRelPathUser
;
186 /** @short does nothing real.
188 @descr Because this class should be useable in combination
189 with ::salhelper::SingletonRef template this ctor
190 can't have any special parameters!
193 points to an uno service manager, which is used internally
194 to create own needed uno resources.
196 PresetHandler(const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
198 /** @short copy ctor */
199 PresetHandler(const PresetHandler
& rCopy
);
201 /** @short closes all open storages ... if user forgot that .-) */
202 virtual ~PresetHandler();
204 /** @short free all currently cache(!) storages. */
205 void forgetCachedStorages();
207 /** @short return access to the internally used and cached root storage.
209 @descr These root storages are the base of all further opened
210 presets and targets. They are provided here only, to support
211 older implementations, which base on them ...
213 getOrCreate...() - What does it mean?
214 Such root storage will be created one times only and
215 cached then internally till the last instance of such PresetHandler
218 @return com::sun::star::embed::XStorage
219 which represent a root storage.
221 css::uno::Reference
< css::embed::XStorage
> getOrCreateRootStorageShare();
222 css::uno::Reference
< css::embed::XStorage
> getOrCreateRootStorageUser();
224 /** @short provides access to the current working storages.
226 @descr Working storages are the "lowest" storages, where the
227 preset and target files exists.
229 @return com::sun::star::embed::XStorage
230 which the current working storage.
232 css::uno::Reference
< css::embed::XStorage
> getWorkingStorageShare();
233 css::uno::Reference
< css::embed::XStorage
> getWorkingStorageUser();
235 /** @short check if there is a parent storage well known for
236 the specified child storage and return it.
239 the child storage where a paranet storage should be searched for.
241 @return com::sun::star::embed::XStorage
242 A valid storage if a paranet exists. NULL otherwise.
244 css::uno::Reference
< css::embed::XStorage
> getParentStorageShare(const css::uno::Reference
< css::embed::XStorage
>& xChild
);
245 css::uno::Reference
< css::embed::XStorage
> getParentStorageUser (const css::uno::Reference
< css::embed::XStorage
>& xChild
);
247 /** @short free all internal structures and let this handler
248 work on a new type of configuration sets.
251 differ between global or module dependent configuration.
254 differ between menubar/toolbar/accelerator/... configuration.
257 if sResourceType is set to a module dependent configuration,
258 it address the current application module.
261 if sResourceType is set to E_DOCUMENT, this value points to the
262 root storage inside the document, where we can save our
263 configuration files. Note: Thats not the real root of the document ...
264 its only a sub storage. But we interpret it as our root storage.
267 in case this configuration supports localized entries,
268 the current locale must be set.
270 Localzation will be represented as directory structure
271 of provided presets. Means: you call us with a preset name "default";
272 and we use e.g. "/en-US/default.xml" internally.
274 If no localization exists for this preset set, this class
275 will work in default mode - means "no locale" - automatically.
278 @throw com::sun::star::uno::RuntimeException(!)
279 if the specified resource couldn't be located.
281 void connectToResource( EConfigType eConfigType
,
282 const OUString
& sResourceType
,
283 const OUString
& sModule
,
284 const css::uno::Reference
< css::embed::XStorage
>& xDocumentRoot
,
285 const LanguageTag
& rLanguageTag
= LanguageTag(LANGUAGE_USER_PRIV_NOTRANSLATE
));
287 /** @short try to copy the specified preset from the share
288 layer to the user layer and establish it as the
291 @descr Means: copy share/.../<preset>.xml user/.../<target>.xml
292 Note: The target will be overwritten completely or
293 created as new by this operation!
296 the ALIAS name of an existing preset.
299 the ALIAS name of the target.
301 @throw com::sun::star::container::NoSuchElementException
302 if the specified preset does not exists.
304 @throw com::sun::star::io::IOException
307 void copyPresetToTarget(const OUString
& sPreset
,
308 const OUString
& sTarget
);
310 /** @short open the specified preset as stream object
313 @descr Note: Because presets resist inside the share
314 layer, they will be opened readonly every time.
317 the ALIAS name of an existing preset.
320 access the global language-independent storage instead of the preset storage
322 @return The opened preset stream ... or NULL if the preset does not exists.
324 css::uno::Reference
< css::io::XStream
> openPreset(const OUString
& sPreset
,
325 bool bUseNoLangGlobal
= false);
327 /** @short open the specified target as stream object
330 @descr Note: Targets resist inside the user
331 layer. Normally they are opened in read/write mode.
332 But it will be opened readonly automatically if that isn't possible
333 (may be the file is write protected on the system ...).
336 the ALIAS name of the target.
338 @param bCreateIfMissing
339 create target file, if it does not still exists.
340 Note: That does not means reseting of an existing file!
342 @return The opened target stream ... or NULL if the target does not exists
343 or couldnt be created as new one.
345 css::uno::Reference
< css::io::XStream
> openTarget(const OUString
& sTarget
,
346 bool bCreateIfMissing
);
348 /** @short do anything which is necessary to flush all changes
351 @descr We have to call commit on all cached sub storages on the
352 path from the root storage upside down to the working storage
353 (which are not really used, but required to be holded alive!).
355 void commitUserChanges();
358 void addStorageListener(IStorageListener
* pListener
);
359 void removeStorageListener(IStorageListener
* pListener
);
365 /** @short open a config path ignoring errors (catching exceptions).
367 @descr We catch only normal exceptions here - no runtime exceptions.
370 the configuration path, which should be opened.
373 the open mode (READ/READWRITE)
376 force using of the share layer instead of the user layer.
378 @return An opened storage in case method was successfully - null otherwise.
380 css::uno::Reference
< css::embed::XStorage
> impl_openPathIgnoringErrors(const OUString
& sPath
,
384 /** @short try to find the specified locale inside list of possible ones.
386 @descr The lits of possible locale values was e.g. retrieved from the system
387 (configuration, directory listing etcpp). The locale normally represent
388 the current office locale. This method search for a suitable item by using
391 b) search with using fallbacks
393 @param lLocalizedValues
394 list of BCP47 language tags / locale codes
397 [IN ] the current office locale, which should be searched inside lLocalizedValues.
398 [OUT] in case fallbacks was allowed, it contains afterwards the fallback locale.
400 @param bAllowFallbacks
401 enable/disable using of fallbacks
403 @return An iterator, which points directly into lLocalizedValue list.
404 As a negative result the special iterator lLocalizedValues.end() will be returned.
406 ::std::vector
< OUString
>::const_iterator
impl_findMatchingLocalizedValue(const ::std::vector
< OUString
>& lLocalizedValues
,
407 OUString
& rLanguageTag
,
408 bool bAllowFallbacks
);
410 /** @short open a config path ignoring errors (catching exceptions).
412 @descr We catch only normal exceptions here - no runtime exceptions.
413 Further the path itself is tries in different versions (using locale
414 specific attributes).
415 e.g. "path/e-US" => "path/en" => "path/de"
418 the configuration path, which should be opened.
419 Its further used as out parameter too, so we can return the localized
423 the open mode (READ/READWRITE)
426 force using of the share layer instead of the user layer.
429 [IN ] contains the start locale for searching localized sub dirs.
430 [OUT] contains the locale of a found localized sub dir
432 @param bAllowFallback
433 enable/disable fallback handling for locales
435 @return An opened storage in case method was successfully - null otherwise.
437 css::uno::Reference
< css::embed::XStorage
> impl_openLocalizedPathIgnoringErrors(OUString
& sPath
,
440 OUString
& rLanguageTag
,
441 bool bAllowFallback
);
443 /** @short returns the names of all sub storages of specified storage.
446 the base storage for this operation.
448 @return [vector< string >]
449 a list of folder names.
451 ::std::vector
< OUString
> impl_getSubFolderNames(const css::uno::Reference
< css::embed::XStorage
>& xFolder
);
454 } // namespace framework
456 #endif // INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_PRESETHANDLER_HXX
458 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */