LCOV - code coverage report
Current view: top level - vcl/source/gdi - configsettings.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 41 74 55.4 %
Date: 2014-11-03 Functions: 8 11 72.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 <vcl/configsettings.hxx>
      21             : 
      22             : #include <svdata.hxx>
      23             : 
      24             : #include <com/sun/star/uno/Any.hxx>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : #include <com/sun/star/beans/PropertyValue.hpp>
      27             : 
      28             : using namespace utl;
      29             : using namespace vcl;
      30             : using namespace com::sun::star::uno;
      31             : using namespace com::sun::star::lang;
      32             : using namespace com::sun::star::beans;
      33             : using namespace com::sun::star::container;
      34             : 
      35             : #define SETTINGS_CONFIGNODE "VCL/Settings"
      36             : 
      37         314 : SettingsConfigItem* SettingsConfigItem::get()
      38             : {
      39         314 :     ImplSVData* pSVData = ImplGetSVData();
      40         314 :     if( ! pSVData->mpSettingsConfigItem )
      41         260 :         pSVData->mpSettingsConfigItem = new SettingsConfigItem();
      42         314 :     return pSVData->mpSettingsConfigItem;
      43             : }
      44             : 
      45         260 : SettingsConfigItem::SettingsConfigItem()
      46             :         :
      47             :         ConfigItem( OUString( SETTINGS_CONFIGNODE ),
      48             :                     CONFIG_MODE_DELAYED_UPDATE ),
      49         260 :     m_aSettings( 0 )
      50             : {
      51         260 :     getValues();
      52         260 : }
      53             : 
      54         774 : SettingsConfigItem::~SettingsConfigItem()
      55             : {
      56         258 :     if( IsModified() )
      57           0 :         Commit();
      58         516 : }
      59             : 
      60           0 : void SettingsConfigItem::Commit()
      61             : {
      62           0 :     boost::unordered_map< OUString, SmallOUStrMap, OUStringHash >::const_iterator group;
      63             : 
      64           0 :     for( group = m_aSettings.begin(); group != m_aSettings.end(); ++group )
      65             :     {
      66           0 :         OUString aKeyName( group->first );
      67           0 :         /*bool bAdded =*/ AddNode( OUString(), aKeyName );
      68           0 :         Sequence< PropertyValue > aValues( group->second.size() );
      69           0 :         PropertyValue* pValues = aValues.getArray();
      70           0 :         int nIndex = 0;
      71           0 :         SmallOUStrMap::const_iterator it;
      72           0 :         for( it = group->second.begin(); it != group->second.end(); ++it )
      73             :         {
      74           0 :             OUString aName( aKeyName );
      75           0 :             aName +=  OUString('/');
      76           0 :             aName += it->first;
      77           0 :             pValues[nIndex].Name    = aName;
      78           0 :             pValues[nIndex].Handle  = 0;
      79           0 :             pValues[nIndex].Value <<= it->second;
      80           0 :             pValues[nIndex].State   = PropertyState_DIRECT_VALUE;
      81           0 :             nIndex++;
      82           0 :         }
      83           0 :         ReplaceSetProperties( aKeyName, aValues );
      84           0 :     }
      85           0 : }
      86             : 
      87           0 : void SettingsConfigItem::Notify( const Sequence< OUString >& )
      88             : {
      89           0 :     getValues();
      90           0 : }
      91             : 
      92         260 : void SettingsConfigItem::getValues()
      93             : {
      94         260 :     m_aSettings.clear();
      95             : 
      96         260 :     Sequence< OUString > aNames( GetNodeNames( OUString() ) );
      97             : 
      98        1820 :     for( int j = 0; j < aNames.getLength(); j++ )
      99             :     {
     100             : #if OSL_DEBUG_LEVEL > 2
     101             :         OSL_TRACE( "found settings data for \"%s\"\n",
     102             :                  OUStringToOString( aNames.getConstArray()[j], RTL_TEXTENCODING_ASCII_US ).getStr()
     103             :                  );
     104             : #endif
     105        1560 :         OUString aKeyName( aNames.getConstArray()[j] );
     106        3120 :         Sequence< OUString > aKeys( GetNodeNames( aKeyName ) );
     107        3120 :         Sequence< OUString > aSettingsKeys( aKeys.getLength() );
     108        1560 :         const OUString* pFrom = aKeys.getConstArray();
     109        1560 :         OUString* pTo = aSettingsKeys.getArray();
     110        3380 :         for( int m = 0; m < aKeys.getLength(); m++ )
     111             :         {
     112        1820 :             OUString aName( aKeyName );
     113        1820 :             aName += OUString('/');
     114        1820 :             aName += pFrom[m];
     115        1820 :             pTo[m] = aName;
     116        1820 :         }
     117        3120 :         Sequence< Any > aValues( GetProperties( aSettingsKeys ) );
     118        1560 :         const Any* pValue = aValues.getConstArray();
     119        3380 :         for( int i = 0; i < aValues.getLength(); i++, pValue++ )
     120             :         {
     121        1820 :             if( pValue->getValueTypeClass() == TypeClass_STRING )
     122             :             {
     123        1820 :                 const OUString* pLine = (const OUString*)pValue->getValue();
     124        1820 :                 if( !pLine->isEmpty() )
     125        1560 :                     m_aSettings[ aKeyName ][ pFrom[i] ] = *pLine;
     126             : #if OSL_DEBUG_LEVEL > 2
     127             :                 OSL_TRACE( "   \"%s\"=\"%.30s\"\n",
     128             :                          OUStringToOString( aKeys.getConstArray()[i], RTL_TEXTENCODING_ASCII_US ).getStr(),
     129             :                          OUStringToOString( *pLine, RTL_TEXTENCODING_ASCII_US ).getStr()
     130             :                          );
     131             : #endif
     132             :             }
     133             :         }
     134        1820 :     }
     135         260 : }
     136             : 
     137         314 : const OUString& SettingsConfigItem::getValue( const OUString& rGroup, const OUString& rKey ) const
     138             : {
     139         314 :     ::boost::unordered_map< OUString, SmallOUStrMap, OUStringHash >::const_iterator group = m_aSettings.find( rGroup );
     140         314 :     if( group == m_aSettings.end() || group->second.find( rKey ) == group->second.end() )
     141             :     {
     142           0 :         static OUString aEmpty;
     143           0 :         return aEmpty;
     144             :     }
     145         314 :     return group->second.find(rKey)->second;
     146             : }
     147             : 
     148           0 : void SettingsConfigItem::setValue( const OUString& rGroup, const OUString& rKey, const OUString& rValue )
     149             : {
     150           0 :     bool bModified = m_aSettings[ rGroup ][ rKey ] != rValue;
     151           0 :     if( bModified )
     152             :     {
     153           0 :         m_aSettings[ rGroup ][ rKey ] = rValue;
     154           0 :         SetModified();
     155             :     }
     156        1233 : }
     157             : 
     158             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10