LCOV - code coverage report
Current view: top level - svl/source/config - asiancfg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 75 21.3 %
Date: 2012-08-25 Functions: 7 13 53.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 150 8.0 %

           Branch data     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/oustringostreaminserter.hxx"
      39                 :            : #include "rtl/ustrbuf.hxx"
      40                 :            : #include "rtl/ustring.h"
      41                 :            : #include "rtl/ustring.hxx"
      42                 :            : #include "sal/log.hxx"
      43                 :            : #include "sal/types.h"
      44                 :            : #include "svl/asiancfg.hxx"
      45                 :            : 
      46                 :            : namespace {
      47                 :            : 
      48                 :            : namespace css = com::sun::star;
      49                 :            : 
      50                 :          0 : rtl::OUString toString(css::lang::Locale const & locale) {
      51                 :            :     SAL_WARN_IF(
      52                 :            :         locale.Language.indexOf('-') != -1, "svl",
      53                 :            :         "Locale language \"" << locale.Language << "\" contains \"-\"");
      54         [ #  # ]:          0 :     rtl::OUStringBuffer buf(locale.Language);
      55                 :            :     SAL_WARN_IF(
      56                 :            :         locale.Country.isEmpty() && !locale.Variant.isEmpty(), "svl",
      57                 :            :         "Locale has empty country but non-empty variant \"" << locale.Variant
      58                 :            :             << '"');
      59         [ #  # ]:          0 :     if (!locale.Country.isEmpty()) {
      60         [ #  # ]:          0 :         buf.append('-');
      61                 :            :         SAL_WARN_IF(
      62                 :            :             locale.Country.indexOf('-') != -1, "svl",
      63                 :            :             "Locale country \"" << locale.Country << "\" contains \"-\"");
      64         [ #  # ]:          0 :         buf.append(locale.Country);
      65         [ #  # ]:          0 :         if (!locale.Variant.isEmpty()) {
      66         [ #  # ]:          0 :             buf.append('-');
      67         [ #  # ]:          0 :             buf.append(locale.Variant);
      68                 :            :         }
      69                 :            :     }
      70         [ #  # ]:          0 :     return buf.makeStringAndClear();
      71                 :            : }
      72                 :            : 
      73                 :            : }
      74                 :            : 
      75         [ +  - ]:       2297 : struct SvxAsianConfig::Impl: private boost::noncopyable {
      76                 :       2297 :     Impl():
      77                 :            :         context(comphelper::getProcessComponentContext()),
      78 [ +  - ][ +  - ]:       2297 :         batch(comphelper::ConfigurationChanges::create(context))
      79                 :       2297 :     {}
      80                 :            : 
      81                 :            :     css::uno::Reference< css::uno::XComponentContext > context;
      82                 :            : 
      83                 :            :     boost::shared_ptr< comphelper::ConfigurationChanges > batch;
      84                 :            : };
      85                 :            : 
      86 [ +  - ][ +  - ]:       2297 : SvxAsianConfig::SvxAsianConfig(): impl_(new Impl) {}
      87                 :            : 
      88         [ +  - ]:       2297 : SvxAsianConfig::~SvxAsianConfig() {}
      89                 :            : 
      90                 :          0 : void SvxAsianConfig::Commit() {
      91                 :          0 :     impl_->batch->commit();
      92                 :          0 : }
      93                 :            : 
      94                 :       1803 : bool SvxAsianConfig::IsKerningWesternTextOnly() const {
      95                 :            :     return
      96                 :            :         officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::get(
      97                 :       1803 :             impl_->context);
      98                 :            : }
      99                 :            : 
     100                 :          0 : void SvxAsianConfig::SetKerningWesternTextOnly(bool value) {
     101                 :            :     officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::set(
     102                 :          0 :         value, impl_->batch, impl_->context);
     103                 :          0 : }
     104                 :            : 
     105                 :       1803 : sal_Int16 SvxAsianConfig::GetCharDistanceCompression() const {
     106                 :            :     return
     107                 :            :         officecfg::Office::Common::AsianLayout::CompressCharacterDistance::get(
     108                 :       1803 :             impl_->context);
     109                 :            : }
     110                 :            : 
     111                 :          0 : void SvxAsianConfig::SetCharDistanceCompression(sal_Int16 value) {
     112                 :            :     officecfg::Office::Common::AsianLayout::CompressCharacterDistance::set(
     113                 :          0 :         value, impl_->batch, impl_->context);
     114                 :          0 : }
     115                 :            : 
     116                 :       2297 : css::uno::Sequence< css::lang::Locale > SvxAsianConfig::GetStartEndCharLocales()
     117                 :            :     const
     118                 :            : {
     119                 :            :     css::uno::Sequence< rtl::OUString > ns(
     120                 :            :         officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
     121 [ +  - ][ +  - ]:       4594 :             impl_->context)->
     122         [ +  - ]:       2297 :         getElementNames());
     123         [ +  - ]:       2297 :     css::uno::Sequence< css::lang::Locale > ls(ns.getLength());
     124         [ -  + ]:       2297 :     for (sal_Int32 i = 0; i < ns.getLength(); ++i) {
     125                 :          0 :         sal_Int32 n = 0;
     126 [ #  # ][ #  # ]:          0 :         ls[i].Language = ns[i].getToken(0, '-', n);
     127 [ #  # ][ #  # ]:          0 :         ls[i].Country = ns[i].getToken(0, '-', n);
     128 [ #  # ][ #  # ]:          0 :         ls[i].Variant = ns[i].getToken(0, '-', n);
     129                 :            :     }
     130         [ +  - ]:       2297 :     return ls;
     131                 :            : }
     132                 :            : 
     133                 :          0 : bool SvxAsianConfig::GetStartEndChars(
     134                 :            :     css::lang::Locale const & locale, rtl::OUString & startChars,
     135                 :            :     rtl::OUString & endChars) const
     136                 :            : {
     137                 :            :     css::uno::Reference< css::container::XNameAccess > set(
     138                 :            :         officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
     139         [ #  # ]:          0 :             impl_->context));
     140                 :          0 :     css::uno::Any v;
     141                 :            :     try {
     142 [ #  # ][ #  # ]:          0 :         v = set->getByName(toString(locale));
         [ #  # ][ #  # ]
     143         [ #  # ]:          0 :     } catch (css::container::NoSuchElementException &) {
     144                 :          0 :         return false;
     145                 :            :     }
     146                 :            :     css::uno::Reference< css::beans::XPropertySet > el(
     147                 :            :         v.get< css::uno::Reference< css::beans::XPropertySet > >(),
     148 [ #  # ][ #  # ]:          0 :         css::uno::UNO_SET_THROW);
     149 [ #  # ][ #  # ]:          0 :     startChars = el->getPropertyValue("StartCharacters").get< rtl::OUString >();
                 [ #  # ]
     150 [ #  # ][ #  # ]:          0 :     endChars = el->getPropertyValue("EndCharacters").get< rtl::OUString >();
                 [ #  # ]
     151                 :          0 :     return true;
     152                 :            : }
     153                 :            : 
     154                 :          0 : void SvxAsianConfig::SetStartEndChars(
     155                 :            :     css::lang::Locale const & locale, rtl::OUString const * startChars,
     156                 :            :     rtl::OUString const * endChars)
     157                 :            : {
     158                 :            :     assert((startChars == 0) == (endChars == 0));
     159                 :            :     css::uno::Reference< css::container::XNameContainer > set(
     160                 :            :         officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
     161         [ #  # ]:          0 :             impl_->batch, impl_->context));
     162         [ #  # ]:          0 :     rtl::OUString name(toString(locale));
     163         [ #  # ]:          0 :     if (startChars == 0) {
     164                 :            :         try {
     165 [ #  # ][ #  # ]:          0 :             set->removeByName(name);
     166   [ #  #  #  # ]:          0 :         } catch (css::container::NoSuchElementException &) {}
     167                 :            :     } else {
     168                 :            :         bool found;
     169                 :          0 :         css::uno::Any v;
     170                 :            :         try {
     171 [ #  # ][ #  # ]:          0 :             v = set->getByName(name);
     172                 :          0 :             found = true;
     173         [ #  # ]:          0 :         } catch (css::container::NoSuchElementException &) {
     174                 :          0 :             found = false;
     175                 :            :         }
     176         [ #  # ]:          0 :         if (found) {
     177                 :            :             css::uno::Reference< css::beans::XPropertySet > el(
     178                 :            :                 v.get< css::uno::Reference< css::beans::XPropertySet > >(),
     179 [ #  # ][ #  # ]:          0 :                 css::uno::UNO_SET_THROW);
     180 [ #  # ][ #  # ]:          0 :             el->setPropertyValue("StartCharacters", css::uno::makeAny(*startChars));
                 [ #  # ]
     181 [ #  # ][ #  # ]:          0 :             el->setPropertyValue("EndCharacters", css::uno::makeAny(*endChars));
                 [ #  # ]
     182                 :            :         } else {
     183                 :            :             css::uno::Reference< css::beans::XPropertySet > el(
     184                 :            :                 (css::uno::Reference< css::lang::XSingleServiceFactory >(
     185 [ #  # ][ #  # ]:          0 :                     set, css::uno::UNO_QUERY_THROW)->
     186                 :          0 :                  createInstance()),
     187 [ #  # ][ #  # ]:          0 :                 css::uno::UNO_QUERY_THROW);
     188 [ #  # ][ #  # ]:          0 :             el->setPropertyValue("StartCharacters", css::uno::makeAny(*startChars));
                 [ #  # ]
     189 [ #  # ][ #  # ]:          0 :             el->setPropertyValue("EndCharacters", css::uno::makeAny(*endChars));
         [ #  # ][ #  # ]
     190         [ #  # ]:          0 :             css::uno::Any v2(css::uno::makeAny(el));
     191                 :            :             try {
     192 [ #  # ][ #  # ]:          0 :                 set->insertByName(name, v2);
     193         [ #  # ]:          0 :             } catch (css::container::ElementExistException &) {
     194                 :            :                 SAL_INFO("svl", "Concurrent update race for \"" << name << '"');
     195                 :          0 :             }
     196                 :          0 :         }
     197                 :          0 :     }
     198         [ #  # ]:          0 : }
     199                 :            : 
     200                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10