LCOV - code coverage report
Current view: top level - svl/source/config - asiancfg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 16 65 24.6 %
Date: 2014-11-03 Functions: 7 13 53.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <sal/config.h>
      21             : 
      22             : #include <cassert>
      23             : 
      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>
      45             : 
      46             : namespace {
      47             : 
      48           0 : 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           0 :     return LanguageTag::convertToBcp47( locale, false);
      54             : }
      55             : 
      56             : }
      57             : 
      58        6648 : struct SvxAsianConfig::Impl: private boost::noncopyable {
      59        6648 :     Impl():
      60             :         context(comphelper::getProcessComponentContext()),
      61        6648 :         batch(comphelper::ConfigurationChanges::create(context))
      62        6648 :     {}
      63             : 
      64             :     css::uno::Reference< css::uno::XComponentContext > context;
      65             : 
      66             :     boost::shared_ptr< comphelper::ConfigurationChanges > batch;
      67             : };
      68             : 
      69        6648 : SvxAsianConfig::SvxAsianConfig(): impl_(new Impl) {}
      70             : 
      71        6648 : SvxAsianConfig::~SvxAsianConfig() {}
      72             : 
      73           0 : void SvxAsianConfig::Commit() {
      74           0 :     impl_->batch->commit();
      75           0 : }
      76             : 
      77        5422 : bool SvxAsianConfig::IsKerningWesternTextOnly() const {
      78             :     return
      79             :         officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::get(
      80        5422 :             impl_->context);
      81             : }
      82             : 
      83           0 : void SvxAsianConfig::SetKerningWesternTextOnly(bool value) {
      84             :     officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::set(
      85           0 :         value, impl_->batch, impl_->context);
      86           0 : }
      87             : 
      88        5422 : sal_Int16 SvxAsianConfig::GetCharDistanceCompression() const {
      89             :     return
      90             :         officecfg::Office::Common::AsianLayout::CompressCharacterDistance::get(
      91        5422 :             impl_->context);
      92             : }
      93             : 
      94           0 : void SvxAsianConfig::SetCharDistanceCompression(sal_Int16 value) {
      95             :     officecfg::Office::Common::AsianLayout::CompressCharacterDistance::set(
      96           0 :         value, impl_->batch, impl_->context);
      97           0 : }
      98             : 
      99        6648 : css::uno::Sequence< css::lang::Locale > SvxAsianConfig::GetStartEndCharLocales()
     100             :     const
     101             : {
     102             :     css::uno::Sequence< OUString > ns(
     103             :         officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
     104       13296 :             impl_->context)->
     105        6648 :         getElementNames());
     106        6648 :     css::uno::Sequence< css::lang::Locale > ls(ns.getLength());
     107        6648 :     for (sal_Int32 i = 0; i < ns.getLength(); ++i) {
     108           0 :         ls[i] = LanguageTag::convertToLocale( ns[i], false);
     109             :     }
     110        6648 :     return ls;
     111             : }
     112             : 
     113           0 : bool SvxAsianConfig::GetStartEndChars(
     114             :     css::lang::Locale const & locale, OUString & startChars,
     115             :     OUString & endChars) const
     116             : {
     117             :     css::uno::Reference< css::container::XNameAccess > set(
     118             :         officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
     119           0 :             impl_->context));
     120           0 :     css::uno::Any v;
     121             :     try {
     122           0 :         v = set->getByName(toString(locale));
     123           0 :     } catch (css::container::NoSuchElementException &) {
     124           0 :         return false;
     125             :     }
     126             :     css::uno::Reference< css::beans::XPropertySet > el(
     127             :         v.get< css::uno::Reference< css::beans::XPropertySet > >(),
     128           0 :         css::uno::UNO_SET_THROW);
     129           0 :     startChars = el->getPropertyValue("StartCharacters").get< OUString >();
     130           0 :     endChars = el->getPropertyValue("EndCharacters").get< OUString >();
     131           0 :     return true;
     132             : }
     133             : 
     134           0 : void SvxAsianConfig::SetStartEndChars(
     135             :     css::lang::Locale const & locale, OUString const * startChars,
     136             :     OUString const * endChars)
     137             : {
     138             :     assert((startChars == 0) == (endChars == 0));
     139             :     css::uno::Reference< css::container::XNameContainer > set(
     140             :         officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
     141           0 :             impl_->batch, impl_->context));
     142           0 :     OUString name(toString(locale));
     143           0 :     if (startChars == 0) {
     144             :         try {
     145           0 :             set->removeByName(name);
     146           0 :         } catch (css::container::NoSuchElementException &) {}
     147             :     } else {
     148             :         bool found;
     149           0 :         css::uno::Any v;
     150             :         try {
     151           0 :             v = set->getByName(name);
     152           0 :             found = true;
     153           0 :         } catch (css::container::NoSuchElementException &) {
     154           0 :             found = false;
     155             :         }
     156           0 :         if (found) {
     157             :             css::uno::Reference< css::beans::XPropertySet > el(
     158             :                 v.get< css::uno::Reference< css::beans::XPropertySet > >(),
     159           0 :                 css::uno::UNO_SET_THROW);
     160           0 :             el->setPropertyValue("StartCharacters", css::uno::makeAny(*startChars));
     161           0 :             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           0 :                     set, css::uno::UNO_QUERY_THROW)->
     166           0 :                  createInstance()),
     167           0 :                 css::uno::UNO_QUERY_THROW);
     168           0 :             el->setPropertyValue("StartCharacters", css::uno::makeAny(*startChars));
     169           0 :             el->setPropertyValue("EndCharacters", css::uno::makeAny(*endChars));
     170           0 :             css::uno::Any v2(css::uno::makeAny(el));
     171             :             try {
     172           0 :                 set->insertByName(name, v2);
     173           0 :             } catch (css::container::ElementExistException &) {
     174             :                 SAL_INFO("svl", "Concurrent update race for \"" << name << '"');
     175           0 :             }
     176           0 :         }
     177           0 :     }
     178           0 : }
     179             : 
     180             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10