bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / config / asiancfg.cxx
bloba4af225c86ba2a6edb2fe3c0340de1a6ac7ebf10
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <sal/config.h>
22 #include <cassert>
24 #include <boost/noncopyable.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/container/ElementExistException.hpp>
27 #include <com/sun/star/container/NoSuchElementException.hpp>
28 #include <com/sun/star/container/XNameAccess.hpp>
29 #include <com/sun/star/container/XNameContainer.hpp>
30 #include <com/sun/star/lang/Locale.hpp>
31 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
32 #include <com/sun/star/uno/Any.hxx>
33 #include <com/sun/star/uno/Reference.hxx>
34 #include <com/sun/star/uno/Sequence.hxx>
35 #include <comphelper/configuration.hxx>
36 #include <comphelper/processfactory.hxx>
37 #include "officecfg/Office/Common.hxx"
38 #include <rtl/ustrbuf.hxx>
39 #include <rtl/ustring.h>
40 #include <rtl/ustring.hxx>
41 #include <sal/log.hxx>
42 #include <sal/types.h>
43 #include <i18nlangtag/languagetag.hxx>
44 #include <svl/asiancfg.hxx>
46 namespace {
48 OUString toString(css::lang::Locale const & locale) {
49 SAL_WARN_IF( locale.Language.indexOf('-') != -1, "svl",
50 "Locale language \"" << locale.Language << "\" contains \"-\"");
51 SAL_WARN_IF( locale.Country.indexOf('-') != -1, "svl",
52 "Locale country \"" << locale.Country << "\" contains \"-\"");
53 return LanguageTag::convertToBcp47( locale, false);
58 struct SvxAsianConfig::Impl: private boost::noncopyable {
59 Impl():
60 context(comphelper::getProcessComponentContext()),
61 batch(comphelper::ConfigurationChanges::create(context))
64 css::uno::Reference< css::uno::XComponentContext > context;
66 std::shared_ptr< comphelper::ConfigurationChanges > batch;
69 SvxAsianConfig::SvxAsianConfig(): impl_(new Impl) {}
71 SvxAsianConfig::~SvxAsianConfig() {}
73 void SvxAsianConfig::Commit() {
74 impl_->batch->commit();
77 bool SvxAsianConfig::IsKerningWesternTextOnly() const {
78 return
79 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::get(
80 impl_->context);
83 void SvxAsianConfig::SetKerningWesternTextOnly(bool value) {
84 officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::set(
85 value, impl_->batch);
88 sal_Int16 SvxAsianConfig::GetCharDistanceCompression() const {
89 return
90 officecfg::Office::Common::AsianLayout::CompressCharacterDistance::get(
91 impl_->context);
94 void SvxAsianConfig::SetCharDistanceCompression(sal_Int16 value) {
95 officecfg::Office::Common::AsianLayout::CompressCharacterDistance::set(
96 value, impl_->batch);
99 css::uno::Sequence< css::lang::Locale > SvxAsianConfig::GetStartEndCharLocales()
100 const
102 css::uno::Sequence< OUString > ns(
103 officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
104 impl_->context)->
105 getElementNames());
106 css::uno::Sequence< css::lang::Locale > ls(ns.getLength());
107 for (sal_Int32 i = 0; i < ns.getLength(); ++i) {
108 ls[i] = LanguageTag::convertToLocale( ns[i], false);
110 return ls;
113 bool SvxAsianConfig::GetStartEndChars(
114 css::lang::Locale const & locale, OUString & startChars,
115 OUString & endChars) const
117 css::uno::Reference< css::container::XNameAccess > set(
118 officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
119 impl_->context));
120 css::uno::Any v;
121 try {
122 v = set->getByName(toString(locale));
123 } catch (css::container::NoSuchElementException &) {
124 return false;
126 css::uno::Reference< css::beans::XPropertySet > el(
127 v.get< css::uno::Reference< css::beans::XPropertySet > >(),
128 css::uno::UNO_SET_THROW);
129 startChars = el->getPropertyValue("StartCharacters").get< OUString >();
130 endChars = el->getPropertyValue("EndCharacters").get< OUString >();
131 return true;
134 void SvxAsianConfig::SetStartEndChars(
135 css::lang::Locale const & locale, OUString const * startChars,
136 OUString const * endChars)
138 assert((startChars == 0) == (endChars == 0));
139 css::uno::Reference< css::container::XNameContainer > set(
140 officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
141 impl_->batch));
142 OUString name(toString(locale));
143 if (startChars == 0) {
144 try {
145 set->removeByName(name);
146 } catch (css::container::NoSuchElementException &) {}
147 } else {
148 bool found;
149 css::uno::Any v;
150 try {
151 v = set->getByName(name);
152 found = true;
153 } catch (css::container::NoSuchElementException &) {
154 found = false;
156 if (found) {
157 css::uno::Reference< css::beans::XPropertySet > el(
158 v.get< css::uno::Reference< css::beans::XPropertySet > >(),
159 css::uno::UNO_SET_THROW);
160 el->setPropertyValue("StartCharacters", css::uno::makeAny(*startChars));
161 el->setPropertyValue("EndCharacters", css::uno::makeAny(*endChars));
162 } else {
163 css::uno::Reference< css::beans::XPropertySet > el(
164 (css::uno::Reference< css::lang::XSingleServiceFactory >(
165 set, css::uno::UNO_QUERY_THROW)->
166 createInstance()),
167 css::uno::UNO_QUERY_THROW);
168 el->setPropertyValue("StartCharacters", css::uno::makeAny(*startChars));
169 el->setPropertyValue("EndCharacters", css::uno::makeAny(*endChars));
170 css::uno::Any v2(css::uno::makeAny(el));
171 try {
172 set->insertByName(name, v2);
173 } catch (css::container::ElementExistException &) {
174 SAL_INFO("svl", "Concurrent update race for \"" << name << '"');
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */