/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/** @short because a concurrent access to the same storage from different implementations isn't supported, we have to share it with others.
@descr This struct is allegedly shared and must be used within a synchronized section. But it isn't.
*/ struct TSharedStorages final
{
StorageHolder m_lStoragesShare;
StorageHolder m_lStoragesUser;
TSharedStorages()
{};
};
/** @short provides access to the: a) shared root storages b) shared "inbetween" storages
of the share and user layer. */
TSharedStorages& SharedStorages()
{ static TSharedStorages theStorages; return theStorages;
}
/* #i46497# Don't call forgetCachedStorages() here for shared storages. Because we opened different sub storages by using openPath(). And every already open path was reused and referenced (means it's ref count was increased!) So now we have to release our ref counts to these shared storages only ... and not to free all used storages. Otherwise we will disconnect all other open configuration access objects which base on these storages.
*/ auto & sharedStorages = SharedStorages();
sharedStorages.m_lStoragesShare.closePath(m_sRelPathShare);
sharedStorages.m_lStoragesUser.closePath (m_sRelPathUser );
/* On the other side closePath() is not needed for our special handled document storage. Because it's not shared with others ... so we can free it.
*/
m_lDocumentStorages.forgetCachedStorages();
}
// "UIConfig" is a "multi path" ... use first part only here!
sal_Int32 nPos = sShareLayer.indexOf(';'); if (nPos > 0)
sShareLayer = sShareLayer.copy(0, nPos);
// Note: May be an user uses URLs without a final slash! Check it ...
nPos = sShareLayer.lastIndexOf('/'); if (nPos != sShareLayer.getLength()-1)
sShareLayer += "/";
sShareLayer += "soffice.cfg"; /* // TODO remove me! // Attention: This is temp. workaround ... We create a temp. storage file // based of a system directory. This must be used so, till the storage implementation // can work on directories too.
*/
css::uno::Sequence< css::uno::Any > lArgs{
css::uno::Any(sShareLayer),
css::uno::Any(css::embed::ElementModes::READ | css::embed::ElementModes::NOCREATE)
};
// Note: May be an user uses URLs without a final slash! Check it ...
sal_Int32 nPos = sUserLayer.lastIndexOf('/'); if (nPos != sUserLayer.getLength()-1)
sUserLayer += "/";
// special case for documents // use outside root storage, if we run in E_DOCUMENT mode! if (eConfigType == E_DOCUMENT)
{ if (!xDocumentRoot.is()) throw css::uno::RuntimeException(
u"There is valid root storage, where the UI configuration can work on."_ustr);
m_lDocumentStorages.setRootStorage(xDocumentRoot);
xShare = xDocumentRoot;
xUser = xDocumentRoot;
} else
{
xShare = getOrCreateRootStorageShare();
xUser = getOrCreateRootStorageUser();
}
// #...# try
{
// a) inside share layer we should not create any new structures... We have to use // existing ones only! // b) inside user layer we can (SOFT mode!) but sometimes we should not (HARD mode!) // create new empty structures. We should prefer using of any existing structure. // c) in document mode we first open the storage as readonly and later reopen it as // readwrite if we need to store to it
sal_Int32 eShareMode = css::embed::ElementModes::READ;
sal_Int32 eUserMode = css::embed::ElementModes::READWRITE;
sal_Int32 eDocMode = css::embed::ElementModes::READ;
case E_DOCUMENT :
{ // A document does not have a share layer in real. // It has one layer only, and this one should be opened READ_WRITE. // So we open the user layer here only and set the share layer equals to it .-)
// We initially open the layer as readonly to avoid creating the subdirectory // for files that don't need it. We will reopen it as readwrite if needed.
if (
(rLanguageTag != LanguageTag(LANGUAGE_USER_PRIV_NOTRANSLATE)) && // localized level?
(eConfigType != E_DOCUMENT ) // no localization in document mode!
)
{ // First try to find the right localized set inside share layer. // Fallbacks are allowed there.
OUString aShareLocale( rLanguageTag.getBcp47());
OUString sLocalizedSharePath(sRelPathShare); bool bAllowFallbacks = true;
xShare = impl_openLocalizedPathIgnoringErrors(sLocalizedSharePath, eShareMode, true , aShareLocale, bAllowFallbacks);
// The try to locate the right sub dir inside user layer ... without using fallbacks! // Normally the corresponding sub dir should be created matching the specified locale. // Because we allow creation of storages inside user layer by default.
OUString aUserLocale( rLanguageTag.getBcp47());
OUString sLocalizedUserPath(sRelPathUser);
bAllowFallbacks = false;
xUser = impl_openLocalizedPathIgnoringErrors(sLocalizedUserPath, eUserMode, false, aUserLocale, bAllowFallbacks);
void PresetHandler::copyPresetToTarget(std::u16string_view sPreset,
std::u16string_view sTarget)
{ // don't check our preset list, if element exists // We try to open it and forward all errors to the user!
// remove existing elements before you try to copy the preset to that location ... // Otherwise w will get an ElementExistException inside copyElementTo()!
css::uno::Reference< css::container::XNameAccess > xCheckingUser(xWorkingUser, css::uno::UNO_QUERY_THROW); if (xCheckingUser->hasByName(sTargetFile))
xWorkingUser->removeElement(sTargetFile);
void PresetHandler::addStorageListener(XMLBasedAcceleratorConfiguration* pListener)
{
OUString sRelPath;
EConfigType eCfgType;
{
SolarMutexGuard g;
sRelPath = m_sRelPathUser; // use user path ... because we don't work directly on the share layer!
eCfgType = m_eConfigType;
}
if (sRelPath.isEmpty()) return;
switch(eCfgType)
{ case E_GLOBAL : case E_MODULES :
{
SharedStorages().m_lStoragesUser.addStorageListener(pListener, sRelPath);
} break;
case E_DOCUMENT :
{
m_lDocumentStorages.addStorageListener(pListener, sRelPath);
} break;
}
}
void PresetHandler::removeStorageListener(XMLBasedAcceleratorConfiguration* pListener)
{
OUString sRelPath;
EConfigType eCfgType;
{
SolarMutexGuard g;
sRelPath = m_sRelPathUser; // use user path ... because we don't work directly on the share layer!
eCfgType = m_eConfigType;
}
if (sRelPath.isEmpty()) return;
switch(eCfgType)
{ case E_GLOBAL : case E_MODULES :
{
SharedStorages().m_lStoragesUser.removeStorageListener(pListener, sRelPath);
} break;
case E_DOCUMENT :
{
m_lDocumentStorages.removeStorageListener(pListener, sRelPath);
} break;
}
}
// no fallback ... creation not allowed => no storage if (
(pLocaleFolder == lSubFolders.end() ) &&
((eMode & css::embed::ElementModes::NOCREATE) == css::embed::ElementModes::NOCREATE)
) return css::uno::Reference< css::embed::XStorage >();
// it doesn't matter, if there is a locale fallback or not // If creation of storages is allowed, we do it anyway. // Otherwise we have no acc config at all, which can make other trouble.
OUString sLocalizedPath = sPath + "/"; if (pLocaleFolder != lSubFolders.end())
sLocalizedPath += *pLocaleFolder; else
sLocalizedPath += rLanguageTag;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.