LCOV - code coverage report
Current view: top level - libreoffice/unotools/source/config - configmgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 57 82 69.5 %
Date: 2012-12-27 Functions: 16 25 64.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        1557 :     RegisterConfigItemHelper(
      45             :         utl::ConfigManager & manager, utl::ConfigItem & item):
      46        1557 :             manager_(manager), item_(&item)
      47             :     {
      48        1557 :         manager.registerConfigItem(item_);
      49        1557 :     }
      50             : 
      51        3114 :     ~RegisterConfigItemHelper() {
      52        1557 :         if (item_ != 0) {
      53           0 :             manager_.removeConfigItem(*item_);
      54             :         }
      55        1557 :     }
      56             : 
      57        1557 :     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        4208 : getConfigurationProvider() {
      66        4208 :     return css::configuration::theDefaultProvider::get( comphelper::getProcessComponentContext() );
      67             : }
      68             : 
      69        2500 : rtl::OUString getConfigurationString(
      70             :     rtl::OUString const & module, rtl::OUString const & path)
      71             : {
      72        2500 :     css::uno::Sequence< css::uno::Any > args(1);
      73        2500 :     args[0] <<= css::beans::NamedValue(
      74             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
      75        5000 :         css::uno::makeAny(module));
      76             :     return
      77             :         css::uno::Reference< css::container::XHierarchicalNameAccess >(
      78        5000 :             getConfigurationProvider()->createInstanceWithArguments(
      79             :                 rtl::OUString(
      80             :                     RTL_CONSTASCII_USTRINGPARAM(
      81             :                         "com.sun.star.configuration.ConfigurationAccess")),
      82        2500 :                 args),
      83        5000 :             css::uno::UNO_QUERY_THROW)->
      84        5000 :         getByHierarchicalName(path).get< rtl::OUString >();
      85             : }
      86             : 
      87             : struct theConfigManager:
      88             :     public rtl::Static< utl::ConfigManager, theConfigManager >
      89             : {};
      90             : 
      91             : }
      92             : 
      93           0 : rtl::OUString utl::ConfigManager::getAboutBoxProductVersion() {
      94             :     return getConfigurationString(
      95             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
      96             :         rtl::OUString(
      97           0 :             RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupVersionAboutBox")));
      98             : }
      99             : 
     100           0 : rtl::OUString utl::ConfigManager::getAboutBoxProductVersionSuffix() {
     101             :     return getConfigurationString(
     102             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     103             :         rtl::OUString(
     104           0 :             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          61 : rtl::OUString utl::ConfigManager::getLocale() {
     114             :     return getConfigurationString(
     115             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     116          61 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooLocale")));
     117             : }
     118             : 
     119         898 : rtl::OUString utl::ConfigManager::getProductExtension() {
     120             :     return getConfigurationString(
     121             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     122         898 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupExtension")));
     123             : }
     124             : 
     125        1230 : rtl::OUString utl::ConfigManager::getProductName() {
     126             :     return getConfigurationString(
     127             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     128        1230 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooName")));
     129             : }
     130             : 
     131         311 : rtl::OUString utl::ConfigManager::getProductVersion() {
     132             :     return getConfigurationString(
     133             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     134         311 :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupVersion")));
     135             : }
     136             : 
     137           0 : rtl::OUString utl::ConfigManager::getProductXmlFileFormat() {
     138             :     return getConfigurationString(
     139             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     140             :         rtl::OUString(
     141           0 :             RTL_CONSTASCII_USTRINGPARAM("Product/ooXMLFileFormatName")));
     142             : }
     143             : 
     144           0 : rtl::OUString utl::ConfigManager::getProductXmlFileFormatVersion() {
     145             :     return getConfigurationString(
     146             :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
     147             :         rtl::OUString(
     148           0 :             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           0 : void utl::ConfigManager::storeConfigItems() {
     167           0 :     getConfigManager().doStoreConfigItems();
     168           0 : }
     169             : 
     170        1557 : utl::ConfigManager & utl::ConfigManager::getConfigManager() {
     171        1557 :     return theConfigManager::get();
     172             : }
     173             : 
     174             : css::uno::Reference< css::container::XHierarchicalNameAccess >
     175        1708 : utl::ConfigManager::acquireTree(utl::ConfigItem & item) {
     176        1708 :     css::uno::Sequence< css::uno::Any > args(1);
     177        1708 :     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        3416 :             item.GetSubTreeName()));
     182        1708 :     if ((item.GetMode() & CONFIG_MODE_ALL_LOCALES) != 0) {
     183           4 :         args.realloc(2);
     184           4 :         args[1] <<= css::beans::NamedValue(
     185             :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("locale")),
     186           8 :             css::uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*"))));
     187             :     }
     188             :     return css::uno::Reference< css::container::XHierarchicalNameAccess >(
     189        3416 :         getConfigurationProvider()->createInstanceWithArguments(
     190             :             rtl::OUString(
     191             :                 RTL_CONSTASCII_USTRINGPARAM(
     192             :                     "com.sun.star.configuration.ConfigurationUpdateAccess")),
     193        1708 :             args),
     194        3416 :         css::uno::UNO_QUERY_THROW);
     195             : }
     196             : 
     197          32 : utl::ConfigManager::ConfigManager() {}
     198             : 
     199          32 : utl::ConfigManager::~ConfigManager() {
     200             :     OSL_ASSERT(items_.empty());
     201          32 : }
     202             : 
     203             : css::uno::Reference< css::container::XHierarchicalNameAccess >
     204        1557 : utl::ConfigManager::addConfigItem(utl::ConfigItem & item) {
     205        1557 :     RegisterConfigItemHelper reg(*this, item);
     206             :     css::uno::Reference< css::container::XHierarchicalNameAccess > tree(
     207        1557 :         acquireTree(item));
     208        1557 :     reg.keep();
     209        1557 :     return tree;
     210             : }
     211             : 
     212         819 : void utl::ConfigManager::removeConfigItem(utl::ConfigItem & item) {
     213      121014 :     for (std::list< ConfigItem * >::iterator i(items_.begin());
     214       80676 :          i != items_.end(); ++i)
     215             :     {
     216       40338 :         if (*i == &item) {
     217         819 :             items_.erase(i);
     218         819 :             break;
     219             :         }
     220             :     }
     221         819 : }
     222             : 
     223        1557 : void utl::ConfigManager::registerConfigItem(utl::ConfigItem * item) {
     224             :     OSL_ASSERT(item != 0);
     225        1557 :     items_.push_back(item);
     226        1557 : }
     227             : 
     228           0 : void utl::ConfigManager::doStoreConfigItems() {
     229           0 :     for (std::list< ConfigItem * >::iterator i(items_.begin());
     230           0 :          i != items_.end(); ++i)
     231             :     {
     232           0 :         if ((*i)->IsModified()) {
     233           0 :             (*i)->Commit();
     234           0 :             (*i)->ClearModified();
     235             :         }
     236             :     }
     237           0 : }
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10