LCOV - code coverage report
Current view: top level - libreoffice/unotools/source/config - configmgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 75 82 91.5 %
Date: 2012-12-17 Functions: 22 25 88.0 %
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 <list>
      23             : 
      24             : #include "boost/noncopyable.hpp"
      25             : #include "com/sun/star/beans/NamedValue.hpp"
      26             : #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
      27             : #include "com/sun/star/configuration/theDefaultProvider.hpp"
      28             : #include "com/sun/star/lang/XMultiServiceFactory.hpp"
      29             : #include "com/sun/star/uno/Any.hxx"
      30             : #include "com/sun/star/uno/Reference.hxx"
      31             : #include "com/sun/star/uno/Sequence.hxx"
      32             : #include "osl/diagnose.h"
      33             : #include "rtl/instance.hxx"
      34             : #include "rtl/ustring.h"
      35             : #include "rtl/ustring.hxx"
      36             : #include "unotools/configitem.hxx"
      37             : #include "unotools/configmgr.hxx"
      38             : #include "comphelper/processfactory.hxx"
      39             : 
      40             : namespace {
      41             : 
      42             : class RegisterConfigItemHelper: private boost::noncopyable {
      43             : public:
      44        4494 :     RegisterConfigItemHelper(
      45             :         utl::ConfigManager & manager, utl::ConfigItem & item):
      46        4494 :             manager_(manager), item_(&item)
      47             :     {
      48        4494 :         manager.registerConfigItem(item_);
      49        4494 :     }
      50             : 
      51        8988 :     ~RegisterConfigItemHelper() {
      52        4494 :         if (item_ != 0) {
      53           0 :             manager_.removeConfigItem(*item_);
      54             :         }
      55        4494 :     }
      56             : 
      57        4494 :     void keep() { item_ = 0; }
      58             : 
      59             : private:
      60             :     utl::ConfigManager & manager_;
      61             :     utl::ConfigItem * item_;
      62             : };
      63             : 
      64             : css::uno::Reference< css::lang::XMultiServiceFactory >
      65       10340 : getConfigurationProvider() {
      66       10340 :     return css::configuration::theDefaultProvider::get( comphelper::getProcessComponentContext() );
      67             : }
      68             : 
      69        5487 : rtl::OUString getConfigurationString(
      70             :     rtl::OUString const & module, rtl::OUString const & path)
      71             : {
      72        5487 :     css::uno::Sequence< css::uno::Any > args(1);
      73        5487 :     args[0] <<= css::beans::NamedValue(
      74             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
      75       10974 :         css::uno::makeAny(module));
      76             :     return
      77             :         css::uno::Reference< css::container::XHierarchicalNameAccess >(
      78       10974 :             getConfigurationProvider()->createInstanceWithArguments(
      79             :                 rtl::OUString(
      80             :                     RTL_CONSTASCII_USTRINGPARAM(
      81             :                         "com.sun.star.configuration.ConfigurationAccess")),
      82        5487 :                 args),
      83       10974 :             css::uno::UNO_QUERY_THROW)->
      84       10974 :         getByHierarchicalName(path).get< rtl::OUString >();
      85             : }
      86             : 
      87             : struct theConfigManager:
      88             :     public rtl::Static< utl::ConfigManager, theConfigManager >
      89             : {};
      90             : 
      91             : }
      92             : 
      93          15 : rtl::OUString utl::ConfigManager::getAboutBoxProductVersion() {
      94             :     return getConfigurationString(
      95             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
      96             :         rtl::OUString(
      97          15 :             RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupVersionAboutBox")));
      98             : }
      99             : 
     100          15 : rtl::OUString utl::ConfigManager::getAboutBoxProductVersionSuffix() {
     101             :     return getConfigurationString(
     102             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     103             :         rtl::OUString(
     104          15 :             RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupVersionAboutBoxSuffix")));
     105             : }
     106             : 
     107           0 : rtl::OUString utl::ConfigManager::getDefaultCurrency() {
     108             :     return getConfigurationString(
     109             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     110           0 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooSetupCurrency")));
     111             : }
     112             : 
     113         226 : rtl::OUString utl::ConfigManager::getLocale() {
     114             :     return getConfigurationString(
     115             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     116         226 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooLocale")));
     117             : }
     118             : 
     119        1823 : rtl::OUString utl::ConfigManager::getProductExtension() {
     120             :     return getConfigurationString(
     121             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     122        1823 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupExtension")));
     123             : }
     124             : 
     125        2719 : rtl::OUString utl::ConfigManager::getProductName() {
     126             :     return getConfigurationString(
     127             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     128        2719 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooName")));
     129             : }
     130             : 
     131         659 : rtl::OUString utl::ConfigManager::getProductVersion() {
     132             :     return getConfigurationString(
     133             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     134         659 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupVersion")));
     135             : }
     136             : 
     137          15 : rtl::OUString utl::ConfigManager::getProductXmlFileFormat() {
     138             :     return getConfigurationString(
     139             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     140             :         rtl::OUString(
     141          15 :             RTL_CONSTASCII_USTRINGPARAM("Product/ooXMLFileFormatName")));
     142             : }
     143             : 
     144          15 : rtl::OUString utl::ConfigManager::getProductXmlFileFormatVersion() {
     145             :     return getConfigurationString(
     146             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     147             :         rtl::OUString(
     148          15 :             RTL_CONSTASCII_USTRINGPARAM("Product/ooXMLFileFormatVersion")));
     149             : }
     150             : 
     151           0 : rtl::OUString utl::ConfigManager::getVendor() {
     152             :     return getConfigurationString(
     153             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     154           0 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooVendor")));
     155             : }
     156             : 
     157           0 : rtl::OUString utl::ConfigManager::getWriterCompatibilityVersionOOo_1_1() {
     158             :     return getConfigurationString(
     159             :         rtl::OUString(
     160             :             RTL_CONSTASCII_USTRINGPARAM(
     161             :                 "/org.openoffice.Office.Compatibility")),
     162             :         rtl::OUString(
     163           0 :             RTL_CONSTASCII_USTRINGPARAM("WriterCompatibilityVersion/OOo11")));
     164             : }
     165             : 
     166          16 : void utl::ConfigManager::storeConfigItems() {
     167          16 :     getConfigManager().doStoreConfigItems();
     168          16 : }
     169             : 
     170        4510 : utl::ConfigManager & utl::ConfigManager::getConfigManager() {
     171        4510 :     return theConfigManager::get();
     172             : }
     173             : 
     174             : css::uno::Reference< css::container::XHierarchicalNameAccess >
     175        4853 : utl::ConfigManager::acquireTree(utl::ConfigItem & item) {
     176        4853 :     css::uno::Sequence< css::uno::Any > args(1);
     177        4853 :     args[0] <<= css::beans::NamedValue(
     178             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
     179             :         css::uno::makeAny(
     180             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.")) +
     181        9706 :             item.GetSubTreeName()));
     182        4853 :     if ((item.GetMode() & CONFIG_MODE_ALL_LOCALES) != 0) {
     183          18 :         args.realloc(2);
     184          18 :         args[1] <<= css::beans::NamedValue(
     185             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("locale")),
     186          36 :             css::uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*"))));
     187             :     }
     188             :     return css::uno::Reference< css::container::XHierarchicalNameAccess >(
     189        9706 :         getConfigurationProvider()->createInstanceWithArguments(
     190             :             rtl::OUString(
     191             :                 RTL_CONSTASCII_USTRINGPARAM(
     192             :                     "com.sun.star.configuration.ConfigurationUpdateAccess")),
     193        4853 :             args),
     194        9706 :         css::uno::UNO_QUERY_THROW);
     195             : }
     196             : 
     197          98 : utl::ConfigManager::ConfigManager() {}
     198             : 
     199          98 : utl::ConfigManager::~ConfigManager() {
     200             :     OSL_ASSERT(items_.empty());
     201          98 : }
     202             : 
     203             : css::uno::Reference< css::container::XHierarchicalNameAccess >
     204        4494 : utl::ConfigManager::addConfigItem(utl::ConfigItem & item) {
     205        4494 :     RegisterConfigItemHelper reg(*this, item);
     206             :     css::uno::Reference< css::container::XHierarchicalNameAccess > tree(
     207        4494 :         acquireTree(item));
     208        4494 :     reg.keep();
     209        4494 :     return tree;
     210             : }
     211             : 
     212        2240 : void utl::ConfigManager::removeConfigItem(utl::ConfigItem & item) {
     213      265494 :     for (std::list< ConfigItem * >::iterator i(items_.begin());
     214      176996 :          i != items_.end(); ++i)
     215             :     {
     216       88498 :         if (*i == &item) {
     217        2240 :             items_.erase(i);
     218        2240 :             break;
     219             :         }
     220             :     }
     221        2240 : }
     222             : 
     223        4494 : void utl::ConfigManager::registerConfigItem(utl::ConfigItem * item) {
     224             :     OSL_ASSERT(item != 0);
     225        4494 :     items_.push_back(item);
     226        4494 : }
     227             : 
     228          16 : void utl::ConfigManager::doStoreConfigItems() {
     229         954 :     for (std::list< ConfigItem * >::iterator i(items_.begin());
     230         636 :          i != items_.end(); ++i)
     231             :     {
     232         302 :         if ((*i)->IsModified()) {
     233          34 :             (*i)->Commit();
     234          34 :             (*i)->ClearModified();
     235             :         }
     236             :     }
     237          16 : }
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10