LCOV - code coverage report
Current view: top level - unotools/source/config - configmgr.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 72 75 96.0 %
Date: 2015-06-13 12:38:46 Functions: 21 22 95.5 %
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 <com/sun/star/beans/NamedValue.hpp>
      25             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      26             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      27             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      28             : #include <com/sun/star/uno/Any.hxx>
      29             : #include <com/sun/star/uno/Reference.hxx>
      30             : #include <com/sun/star/uno/Sequence.hxx>
      31             : #include <osl/diagnose.h>
      32             : #include <rtl/instance.hxx>
      33             : #include <rtl/ustring.h>
      34             : #include <rtl/ustring.hxx>
      35             : #include <unotools/configitem.hxx>
      36             : #include <unotools/configmgr.hxx>
      37             : #include <comphelper/processfactory.hxx>
      38             : 
      39             : namespace {
      40             : 
      41             : class RegisterConfigItemHelper {
      42             : public:
      43       24815 :     RegisterConfigItemHelper(
      44             :         utl::ConfigManager & manager, utl::ConfigItem & item):
      45       24815 :             manager_(manager), item_(&item)
      46             :     {
      47       24815 :         manager.registerConfigItem(item_);
      48       24815 :     }
      49             : 
      50       24815 :     ~RegisterConfigItemHelper() {
      51       24815 :         if (item_ != 0) {
      52           0 :             manager_.removeConfigItem(*item_);
      53             :         }
      54       24815 :     }
      55             : 
      56       24815 :     void keep() { item_ = 0; }
      57             : 
      58             : private:
      59             :     utl::ConfigManager & manager_;
      60             :     utl::ConfigItem * item_;
      61             : 
      62             :     RegisterConfigItemHelper(const RegisterConfigItemHelper&) SAL_DELETED_FUNCTION;
      63             :     RegisterConfigItemHelper& operator=(const RegisterConfigItemHelper&) SAL_DELETED_FUNCTION;
      64             : };
      65             : 
      66             : css::uno::Reference< css::lang::XMultiServiceFactory >
      67       69241 : getConfigurationProvider() {
      68       69241 :     return css::configuration::theDefaultProvider::get( comphelper::getProcessComponentContext() );
      69             : }
      70             : 
      71       43277 : OUString getConfigurationString(OUString const & module, OUString const & path)
      72             : {
      73       43277 :     css::uno::Sequence< css::uno::Any > args(1);
      74       86554 :     args[0] <<= css::beans::NamedValue(
      75             :         OUString("nodepath"),
      76       43277 :         css::uno::makeAny(module));
      77             :     return
      78             :         css::uno::Reference< css::container::XHierarchicalNameAccess >(
      79       86554 :             getConfigurationProvider()->createInstanceWithArguments(
      80             :                 OUString("com.sun.star.configuration.ConfigurationAccess"),
      81       43277 :                 args),
      82       86554 :             css::uno::UNO_QUERY_THROW)->
      83       86554 :         getByHierarchicalName(path).get< OUString >();
      84             : }
      85             : 
      86             : struct theConfigManager:
      87             :     public rtl::Static< utl::ConfigManager, theConfigManager >
      88             : {};
      89             : 
      90             : }
      91             : 
      92         941 : OUString utl::ConfigManager::getAboutBoxProductVersion() {
      93             :     return getConfigurationString(
      94             :         OUString("/org.openoffice.Setup"),
      95         941 :         OUString("Product/ooSetupVersionAboutBox"));
      96             : }
      97             : 
      98         941 : OUString utl::ConfigManager::getAboutBoxProductVersionSuffix() {
      99             :     return getConfigurationString(
     100             :         OUString("/org.openoffice.Setup"),
     101         941 :         OUString("Product/ooSetupVersionAboutBoxSuffix"));
     102             : }
     103             : 
     104          17 : OUString utl::ConfigManager::getDefaultCurrency() {
     105             :     return getConfigurationString(
     106             :         OUString("/org.openoffice.Setup"),
     107          17 :         OUString("L10N/ooSetupCurrency"));
     108             : }
     109             : 
     110         699 : OUString utl::ConfigManager::getLocale() {
     111             :     return getConfigurationString(
     112             :         OUString("/org.openoffice.Setup"),
     113         699 :         OUString("L10N/ooLocale"));
     114             : }
     115             : 
     116        2558 : OUString utl::ConfigManager::getProductExtension() {
     117             :     return getConfigurationString(
     118             :         OUString("/org.openoffice.Setup"),
     119        2558 :         OUString("Product/ooSetupExtension"));
     120             : }
     121             : 
     122       32625 : OUString utl::ConfigManager::getProductName() {
     123             :     return getConfigurationString(
     124             :         OUString("/org.openoffice.Setup"),
     125       32625 :         OUString("Product/ooName"));
     126             : }
     127             : 
     128        5496 : OUString utl::ConfigManager::getProductVersion() {
     129             :     return getConfigurationString(
     130             :         OUString("/org.openoffice.Setup"),
     131        5496 :         OUString("Product/ooSetupVersion"));
     132             : }
     133             : 
     134           0 : OUString utl::ConfigManager::getVendor() {
     135             :     return getConfigurationString(
     136             :         OUString("/org.openoffice.Setup"),
     137           0 :         OUString("Product/ooVendor"));
     138             : }
     139             : 
     140         350 : void utl::ConfigManager::storeConfigItems() {
     141         350 :     getConfigManager().doStoreConfigItems();
     142         350 : }
     143             : 
     144       48300 : utl::ConfigManager & utl::ConfigManager::getConfigManager() {
     145       48300 :     return theConfigManager::get();
     146             : }
     147             : 
     148             : css::uno::Reference< css::container::XHierarchicalNameAccess >
     149       25964 : utl::ConfigManager::acquireTree(utl::ConfigItem & item) {
     150       25964 :     css::uno::Sequence< css::uno::Any > args(1);
     151       51928 :     args[0] <<= css::beans::NamedValue(
     152             :         OUString("nodepath"),
     153       77892 :         css::uno::makeAny("/org.openoffice." + item.GetSubTreeName()));
     154       25964 :     if (item.GetMode() & ConfigItemMode::AllLocales) {
     155          38 :         args.realloc(2);
     156          38 :         args[1] <<= css::beans::NamedValue(OUString("locale"), css::uno::makeAny(OUString("*")));
     157             :     }
     158             :     return css::uno::Reference< css::container::XHierarchicalNameAccess >(
     159       51928 :         getConfigurationProvider()->createInstanceWithArguments(
     160             :             OUString("com.sun.star.configuration.ConfigurationUpdateAccess"),
     161       25964 :             args),
     162       51928 :         css::uno::UNO_QUERY_THROW);
     163             : }
     164             : 
     165         246 : utl::ConfigManager::ConfigManager() {}
     166             : 
     167         246 : utl::ConfigManager::~ConfigManager() {
     168             :     OSL_ASSERT(items_.empty());
     169         246 : }
     170             : 
     171             : css::uno::Reference< css::container::XHierarchicalNameAccess >
     172       24815 : utl::ConfigManager::addConfigItem(utl::ConfigItem & item) {
     173       24815 :     RegisterConfigItemHelper reg(*this, item);
     174             :     css::uno::Reference< css::container::XHierarchicalNameAccess > tree(
     175       24815 :         acquireTree(item));
     176       24815 :     reg.keep();
     177       24815 :     return tree;
     178             : }
     179             : 
     180       23135 : void utl::ConfigManager::removeConfigItem(utl::ConfigItem & item) {
     181     2594382 :     for (std::list< ConfigItem * >::iterator i(items_.begin());
     182     1729588 :          i != items_.end(); ++i)
     183             :     {
     184      864794 :         if (*i == &item) {
     185       23135 :             items_.erase(i);
     186       23135 :             break;
     187             :         }
     188             :     }
     189       23135 : }
     190             : 
     191       24815 : void utl::ConfigManager::registerConfigItem(utl::ConfigItem * item) {
     192             :     OSL_ASSERT(item != 0);
     193       24815 :     items_.push_back(item);
     194       24815 : }
     195             : 
     196         350 : void utl::ConfigManager::doStoreConfigItems() {
     197       23199 :     for (std::list< ConfigItem * >::iterator i(items_.begin());
     198       15466 :          i != items_.end(); ++i)
     199             :     {
     200        7383 :         if ((*i)->IsModified()) {
     201         315 :             (*i)->Commit();
     202         315 :             (*i)->ClearModified();
     203             :         }
     204             :     }
     205         350 : }
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11