LCOV - code coverage report
Current view: top level - unotools/source/config - configmgr.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 12 75 16.0 %
Date: 2014-04-14 Functions: 5 22 22.7 %
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           0 :     RegisterConfigItemHelper(
      45             :         utl::ConfigManager & manager, utl::ConfigItem & item):
      46           0 :             manager_(manager), item_(&item)
      47             :     {
      48           0 :         manager.registerConfigItem(item_);
      49           0 :     }
      50             : 
      51           0 :     ~RegisterConfigItemHelper() {
      52           0 :         if (item_ != 0) {
      53           0 :             manager_.removeConfigItem(*item_);
      54             :         }
      55           0 :     }
      56             : 
      57           0 :     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           0 : getConfigurationProvider() {
      66           0 :     return css::configuration::theDefaultProvider::get( comphelper::getProcessComponentContext() );
      67             : }
      68             : 
      69           0 : OUString getConfigurationString(OUString const & module, OUString const & path)
      70             : {
      71           0 :     css::uno::Sequence< css::uno::Any > args(1);
      72           0 :     args[0] <<= css::beans::NamedValue(
      73             :         OUString("nodepath"),
      74           0 :         css::uno::makeAny(module));
      75             :     return
      76             :         css::uno::Reference< css::container::XHierarchicalNameAccess >(
      77           0 :             getConfigurationProvider()->createInstanceWithArguments(
      78             :                 OUString("com.sun.star.configuration.ConfigurationAccess"),
      79           0 :                 args),
      80           0 :             css::uno::UNO_QUERY_THROW)->
      81           0 :         getByHierarchicalName(path).get< OUString >();
      82             : }
      83             : 
      84             : struct theConfigManager:
      85             :     public rtl::Static< utl::ConfigManager, theConfigManager >
      86             : {};
      87             : 
      88             : }
      89             : 
      90           0 : OUString utl::ConfigManager::getAboutBoxProductVersion() {
      91             :     return getConfigurationString(
      92             :         OUString("/org.openoffice.Setup"),
      93           0 :         OUString("Product/ooSetupVersionAboutBox"));
      94             : }
      95             : 
      96           0 : OUString utl::ConfigManager::getAboutBoxProductVersionSuffix() {
      97             :     return getConfigurationString(
      98             :         OUString("/org.openoffice.Setup"),
      99           0 :         OUString("Product/ooSetupVersionAboutBoxSuffix"));
     100             : }
     101             : 
     102           0 : OUString utl::ConfigManager::getDefaultCurrency() {
     103             :     return getConfigurationString(
     104             :         OUString("/org.openoffice.Setup"),
     105           0 :         OUString("L10N/ooSetupCurrency"));
     106             : }
     107             : 
     108           0 : OUString utl::ConfigManager::getLocale() {
     109             :     return getConfigurationString(
     110             :         OUString("/org.openoffice.Setup"),
     111           0 :         OUString("L10N/ooLocale"));
     112             : }
     113             : 
     114           0 : OUString utl::ConfigManager::getProductExtension() {
     115             :     return getConfigurationString(
     116             :         OUString("/org.openoffice.Setup"),
     117           0 :         OUString("Product/ooSetupExtension"));
     118             : }
     119             : 
     120           0 : OUString utl::ConfigManager::getProductName() {
     121             :     return getConfigurationString(
     122             :         OUString("/org.openoffice.Setup"),
     123           0 :         OUString("Product/ooName"));
     124             : }
     125             : 
     126           0 : OUString utl::ConfigManager::getProductVersion() {
     127             :     return getConfigurationString(
     128             :         OUString("/org.openoffice.Setup"),
     129           0 :         OUString("Product/ooSetupVersion"));
     130             : }
     131             : 
     132           0 : OUString utl::ConfigManager::getVendor() {
     133             :     return getConfigurationString(
     134             :         OUString("/org.openoffice.Setup"),
     135           0 :         OUString("Product/ooVendor"));
     136             : }
     137             : 
     138           1 : void utl::ConfigManager::storeConfigItems() {
     139           1 :     getConfigManager().doStoreConfigItems();
     140           1 : }
     141             : 
     142           1 : utl::ConfigManager & utl::ConfigManager::getConfigManager() {
     143           1 :     return theConfigManager::get();
     144             : }
     145             : 
     146             : css::uno::Reference< css::container::XHierarchicalNameAccess >
     147           0 : utl::ConfigManager::acquireTree(utl::ConfigItem & item) {
     148           0 :     css::uno::Sequence< css::uno::Any > args(1);
     149           0 :     args[0] <<= css::beans::NamedValue(
     150             :         OUString("nodepath"),
     151             :         css::uno::makeAny(
     152           0 :             OUString("/org.openoffice.") + item.GetSubTreeName()));
     153           0 :     if ((item.GetMode() & CONFIG_MODE_ALL_LOCALES) != 0) {
     154           0 :         args.realloc(2);
     155           0 :         args[1] <<= css::beans::NamedValue(OUString("locale"), css::uno::makeAny(OUString("*")));
     156             :     }
     157             :     return css::uno::Reference< css::container::XHierarchicalNameAccess >(
     158           0 :         getConfigurationProvider()->createInstanceWithArguments(
     159             :             OUString("com.sun.star.configuration.ConfigurationUpdateAccess"),
     160           0 :             args),
     161           0 :         css::uno::UNO_QUERY_THROW);
     162             : }
     163             : 
     164           1 : utl::ConfigManager::ConfigManager() {}
     165             : 
     166           1 : utl::ConfigManager::~ConfigManager() {
     167             :     OSL_ASSERT(items_.empty());
     168           1 : }
     169             : 
     170             : css::uno::Reference< css::container::XHierarchicalNameAccess >
     171           0 : utl::ConfigManager::addConfigItem(utl::ConfigItem & item) {
     172           0 :     RegisterConfigItemHelper reg(*this, item);
     173             :     css::uno::Reference< css::container::XHierarchicalNameAccess > tree(
     174           0 :         acquireTree(item));
     175           0 :     reg.keep();
     176           0 :     return tree;
     177             : }
     178             : 
     179           0 : void utl::ConfigManager::removeConfigItem(utl::ConfigItem & item) {
     180           0 :     for (std::list< ConfigItem * >::iterator i(items_.begin());
     181           0 :          i != items_.end(); ++i)
     182             :     {
     183           0 :         if (*i == &item) {
     184           0 :             items_.erase(i);
     185           0 :             break;
     186             :         }
     187             :     }
     188           0 : }
     189             : 
     190           0 : void utl::ConfigManager::registerConfigItem(utl::ConfigItem * item) {
     191             :     OSL_ASSERT(item != 0);
     192           0 :     items_.push_back(item);
     193           0 : }
     194             : 
     195           1 : void utl::ConfigManager::doStoreConfigItems() {
     196           3 :     for (std::list< ConfigItem * >::iterator i(items_.begin());
     197           2 :          i != items_.end(); ++i)
     198             :     {
     199           0 :         if ((*i)->IsModified()) {
     200           0 :             (*i)->Commit();
     201           0 :             (*i)->ClearModified();
     202             :         }
     203             :     }
     204           1 : }
     205             : 
     206             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10