2011-12-13 12:37:00 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
2013-04-19 21:10:42 +01:00
|
|
|
* This file is part of the LibreOffice project.
|
2011-12-13 12:37:00 +01:00
|
|
|
*
|
2013-04-19 21:10:42 +01:00
|
|
|
* 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/.
|
2011-12-13 12:37:00 +01:00
|
|
|
*/
|
|
|
|
|
2014-05-10 18:10:59 +02:00
|
|
|
#include <sal/config.h>
|
2011-12-13 12:37:00 +01:00
|
|
|
|
|
|
|
#include <cassert>
|
2015-02-06 09:46:57 +00:00
|
|
|
#include <memory>
|
2011-12-13 12:37:00 +01:00
|
|
|
|
2015-04-01 14:08:04 +02:00
|
|
|
#include <com/sun/star/beans/PropertyAttribute.hpp>
|
2014-05-10 18:10:59 +02:00
|
|
|
#include <com/sun/star/configuration/ReadOnlyAccess.hpp>
|
|
|
|
#include <com/sun/star/configuration/ReadWriteAccess.hpp>
|
|
|
|
#include <com/sun/star/configuration/XReadWriteAccess.hpp>
|
|
|
|
#include <com/sun/star/configuration/theDefaultProvider.hpp>
|
|
|
|
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
|
|
|
|
#include <com/sun/star/container/XHierarchicalNameReplace.hpp>
|
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
|
|
|
#include <com/sun/star/container/XNameContainer.hpp>
|
|
|
|
#include <com/sun/star/lang/Locale.hpp>
|
|
|
|
#include <com/sun/star/lang/XLocalizable.hpp>
|
|
|
|
#include <com/sun/star/uno/Any.hxx>
|
|
|
|
#include <com/sun/star/uno/Reference.hxx>
|
|
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
|
|
|
#include <comphelper/configuration.hxx>
|
|
|
|
#include <rtl/instance.hxx>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
#include <rtl/ustring.hxx>
|
|
|
|
#include <i18nlangtag/languagetag.hxx>
|
2011-12-13 12:37:00 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct TheConfigurationWrapper:
|
|
|
|
public rtl::StaticWithArg<
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::detail::ConfigurationWrapper,
|
2011-12-13 12:37:00 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext >,
|
|
|
|
TheConfigurationWrapper >
|
|
|
|
{};
|
|
|
|
|
2012-07-25 18:54:38 +02:00
|
|
|
OUString getDefaultLocale(
|
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & context)
|
|
|
|
{
|
2013-04-04 23:50:59 +02:00
|
|
|
return LanguageTag(
|
2012-07-25 18:54:38 +02:00
|
|
|
css::uno::Reference< css::lang::XLocalizable >(
|
|
|
|
css::configuration::theDefaultProvider::get(context),
|
|
|
|
css::uno::UNO_QUERY_THROW)->
|
2014-01-19 14:02:44 +01:00
|
|
|
getLocale()).getBcp47(false);
|
2012-07-25 18:54:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
OUString extendLocalizedPath(OUString const & path, OUString const & locale) {
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer buf(path);
|
2012-07-25 18:54:38 +02:00
|
|
|
buf.append("/['*");
|
|
|
|
SAL_WARN_IF(
|
|
|
|
locale.match("*"), "comphelper",
|
2013-04-04 23:50:59 +02:00
|
|
|
"Locale \"" << locale << "\" starts with \"*\"");
|
2012-07-25 18:54:38 +02:00
|
|
|
assert(locale.indexOf('&') == -1);
|
|
|
|
assert(locale.indexOf('"') == -1);
|
|
|
|
assert(locale.indexOf('\'') == -1);
|
|
|
|
buf.append(locale);
|
|
|
|
buf.append("']");
|
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
2011-12-13 12:37:00 +01:00
|
|
|
}
|
|
|
|
|
2015-02-06 09:46:57 +00:00
|
|
|
std::shared_ptr< comphelper::ConfigurationChanges >
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::ConfigurationChanges::create(
|
2011-12-13 12:37:00 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & context)
|
|
|
|
{
|
|
|
|
return TheConfigurationWrapper::get(context).createChanges();
|
|
|
|
}
|
|
|
|
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::ConfigurationChanges::~ConfigurationChanges() {}
|
2011-12-13 12:37:00 +01:00
|
|
|
|
2012-01-31 15:36:49 +01:00
|
|
|
void comphelper::ConfigurationChanges::commit() const {
|
2011-12-13 12:37:00 +01:00
|
|
|
access_->commitChanges();
|
|
|
|
}
|
|
|
|
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::ConfigurationChanges::ConfigurationChanges(
|
2011-12-13 12:37:00 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & context):
|
2012-07-25 18:54:38 +02:00
|
|
|
access_(
|
|
|
|
css::configuration::ReadWriteAccess::create(
|
|
|
|
context, getDefaultLocale(context)))
|
2011-12-13 12:37:00 +01:00
|
|
|
{}
|
|
|
|
|
2012-01-31 15:36:49 +01:00
|
|
|
void comphelper::ConfigurationChanges::setPropertyValue(
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString const & path, css::uno::Any const & value) const
|
2011-12-13 12:37:00 +01:00
|
|
|
{
|
|
|
|
access_->replaceByHierarchicalName(path, value);
|
|
|
|
}
|
|
|
|
|
2012-01-25 18:17:08 +01:00
|
|
|
css::uno::Reference< css::container::XHierarchicalNameReplace >
|
2013-04-07 12:06:47 +02:00
|
|
|
comphelper::ConfigurationChanges::getGroup(OUString const & path) const
|
2012-01-25 18:17:08 +01:00
|
|
|
{
|
|
|
|
return css::uno::Reference< css::container::XHierarchicalNameReplace >(
|
|
|
|
access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW);
|
|
|
|
}
|
|
|
|
|
2011-12-13 12:37:00 +01:00
|
|
|
css::uno::Reference< css::container::XNameContainer >
|
2013-04-07 12:06:47 +02:00
|
|
|
comphelper::ConfigurationChanges::getSet(OUString const & path) const
|
2011-12-13 12:37:00 +01:00
|
|
|
{
|
|
|
|
return css::uno::Reference< css::container::XNameContainer >(
|
|
|
|
access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW);
|
|
|
|
}
|
|
|
|
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::detail::ConfigurationWrapper const &
|
|
|
|
comphelper::detail::ConfigurationWrapper::get(
|
2011-12-13 12:37:00 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & context)
|
|
|
|
{
|
|
|
|
return TheConfigurationWrapper::get(context);
|
|
|
|
}
|
|
|
|
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::detail::ConfigurationWrapper::ConfigurationWrapper(
|
2011-12-13 12:37:00 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & context):
|
2012-07-25 18:54:38 +02:00
|
|
|
context_(context),
|
2015-04-01 14:08:04 +02:00
|
|
|
access_(css::configuration::ReadWriteAccess::create(context, "*"))
|
2011-12-13 12:37:00 +01:00
|
|
|
{}
|
|
|
|
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::detail::ConfigurationWrapper::~ConfigurationWrapper() {}
|
2011-12-13 12:37:00 +01:00
|
|
|
|
2015-04-01 14:08:04 +02:00
|
|
|
bool comphelper::detail::ConfigurationWrapper::isReadOnly(OUString const & path)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
css::beans::Property SB(access_->getPropertyByHierarchicalName(path));
|
|
|
|
return
|
|
|
|
(access_->getPropertyByHierarchicalName(path).Attributes
|
|
|
|
& css::beans::PropertyAttribute::READONLY)
|
|
|
|
!= 0;
|
|
|
|
}
|
|
|
|
|
2012-01-31 15:36:49 +01:00
|
|
|
css::uno::Any comphelper::detail::ConfigurationWrapper::getPropertyValue(
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString const & path) const
|
2011-12-13 12:37:00 +01:00
|
|
|
{
|
|
|
|
return access_->getByHierarchicalName(path);
|
|
|
|
}
|
|
|
|
|
2012-01-31 15:36:49 +01:00
|
|
|
void comphelper::detail::ConfigurationWrapper::setPropertyValue(
|
2015-02-06 09:46:57 +00:00
|
|
|
std::shared_ptr< ConfigurationChanges > const & batch,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString const & path, com::sun::star::uno::Any const & value) const
|
2011-12-13 12:37:00 +01:00
|
|
|
{
|
|
|
|
assert(batch.get() != 0);
|
|
|
|
batch->setPropertyValue(path, value);
|
|
|
|
}
|
|
|
|
|
2012-01-31 15:36:49 +01:00
|
|
|
css::uno::Any
|
|
|
|
comphelper::detail::ConfigurationWrapper::getLocalizedPropertyValue(
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString const & path) const
|
2011-12-13 12:37:00 +01:00
|
|
|
{
|
2012-07-25 18:54:38 +02:00
|
|
|
return access_->getByHierarchicalName(
|
|
|
|
extendLocalizedPath(path, getDefaultLocale(context_)));
|
2011-12-13 12:37:00 +01:00
|
|
|
}
|
|
|
|
|
2012-01-31 15:36:49 +01:00
|
|
|
void comphelper::detail::ConfigurationWrapper::setLocalizedPropertyValue(
|
2015-02-06 09:46:57 +00:00
|
|
|
std::shared_ptr< ConfigurationChanges > const & batch,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString const & path, com::sun::star::uno::Any const & value) const
|
2011-12-13 12:37:00 +01:00
|
|
|
{
|
|
|
|
assert(batch.get() != 0);
|
2012-07-25 18:54:38 +02:00
|
|
|
batch->setPropertyValue(path, value);
|
2011-12-13 12:37:00 +01:00
|
|
|
}
|
|
|
|
|
2012-01-25 18:17:08 +01:00
|
|
|
css::uno::Reference< css::container::XHierarchicalNameAccess >
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::detail::ConfigurationWrapper::getGroupReadOnly(
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString const & path) const
|
2012-01-25 18:17:08 +01:00
|
|
|
{
|
|
|
|
return css::uno::Reference< css::container::XHierarchicalNameAccess >(
|
2012-07-25 18:54:38 +02:00
|
|
|
(css::configuration::ReadOnlyAccess::create(
|
|
|
|
context_, getDefaultLocale(context_))->
|
|
|
|
getByHierarchicalName(path)),
|
|
|
|
css::uno::UNO_QUERY_THROW);
|
2012-01-25 18:17:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::container::XHierarchicalNameReplace >
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::detail::ConfigurationWrapper::getGroupReadWrite(
|
2015-02-06 09:46:57 +00:00
|
|
|
std::shared_ptr< ConfigurationChanges > const & batch,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString const & path) const
|
2012-01-25 18:17:08 +01:00
|
|
|
{
|
|
|
|
assert(batch.get() != 0);
|
|
|
|
return batch->getGroup(path);
|
|
|
|
}
|
|
|
|
|
2011-12-13 12:37:00 +01:00
|
|
|
css::uno::Reference< css::container::XNameAccess >
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::detail::ConfigurationWrapper::getSetReadOnly(
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString const & path) const
|
2011-12-13 12:37:00 +01:00
|
|
|
{
|
|
|
|
return css::uno::Reference< css::container::XNameAccess >(
|
2012-07-25 18:54:38 +02:00
|
|
|
(css::configuration::ReadOnlyAccess::create(
|
|
|
|
context_, getDefaultLocale(context_))->
|
|
|
|
getByHierarchicalName(path)),
|
|
|
|
css::uno::UNO_QUERY_THROW);
|
2011-12-13 12:37:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
css::uno::Reference< css::container::XNameContainer >
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::detail::ConfigurationWrapper::getSetReadWrite(
|
2015-02-06 09:46:57 +00:00
|
|
|
std::shared_ptr< ConfigurationChanges > const & batch,
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString const & path) const
|
2011-12-13 12:37:00 +01:00
|
|
|
{
|
|
|
|
assert(batch.get() != 0);
|
|
|
|
return batch->getSet(path);
|
|
|
|
}
|
|
|
|
|
2015-02-06 09:46:57 +00:00
|
|
|
std::shared_ptr< comphelper::ConfigurationChanges >
|
2012-01-31 15:36:49 +01:00
|
|
|
comphelper::detail::ConfigurationWrapper::createChanges() const {
|
2015-02-06 09:46:57 +00:00
|
|
|
return std::shared_ptr< ConfigurationChanges >(
|
2011-12-13 12:37:00 +01:00
|
|
|
new ConfigurationChanges(context_));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|