LCOV - code coverage report
Current view: top level - vcl/source/gdi - configsettings.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 74 0.0 %
Date: 2014-04-14 Functions: 0 9 0.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 <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           0 : SettingsConfigItem* SettingsConfigItem::get()
      38             : {
      39           0 :     ImplSVData* pSVData = ImplGetSVData();
      40           0 :     if( ! pSVData->mpSettingsConfigItem )
      41           0 :         pSVData->mpSettingsConfigItem = new SettingsConfigItem();
      42           0 :     return pSVData->mpSettingsConfigItem;
      43             : }
      44             : 
      45           0 : SettingsConfigItem::SettingsConfigItem()
      46             :         :
      47             :         ConfigItem( OUString( SETTINGS_CONFIGNODE ),
      48             :                     CONFIG_MODE_DELAYED_UPDATE ),
      49           0 :     m_aSettings( 0 )
      50             : {
      51           0 :     getValues();
      52           0 : }
      53             : 
      54           0 : SettingsConfigItem::~SettingsConfigItem()
      55             : {
      56           0 :     if( IsModified() )
      57           0 :         Commit();
      58           0 : }
      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           0 : void SettingsConfigItem::getValues()
      93             : {
      94           0 :     m_aSettings.clear();
      95             : 
      96           0 :     Sequence< OUString > aNames( GetNodeNames( OUString() ) );
      97             : 
      98           0 :     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           0 :         OUString aKeyName( aNames.getConstArray()[j] );
     106           0 :         Sequence< OUString > aKeys( GetNodeNames( aKeyName ) );
     107           0 :         Sequence< OUString > aSettingsKeys( aKeys.getLength() );
     108           0 :         const OUString* pFrom = aKeys.getConstArray();
     109           0 :         OUString* pTo = aSettingsKeys.getArray();
     110           0 :         for( int m = 0; m < aKeys.getLength(); m++ )
     111             :         {
     112           0 :             OUString aName( aKeyName );
     113           0 :             aName += OUString('/');
     114           0 :             aName += pFrom[m];
     115           0 :             pTo[m] = aName;
     116           0 :         }
     117           0 :         Sequence< Any > aValues( GetProperties( aSettingsKeys ) );
     118           0 :         const Any* pValue = aValues.getConstArray();
     119           0 :         for( int i = 0; i < aValues.getLength(); i++, pValue++ )
     120             :         {
     121           0 :             if( pValue->getValueTypeClass() == TypeClass_STRING )
     122             :             {
     123           0 :                 const OUString* pLine = (const OUString*)pValue->getValue();
     124           0 :                 if( !pLine->isEmpty() )
     125           0 :                     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           0 :     }
     135           0 : }
     136             : 
     137           0 : const OUString& SettingsConfigItem::getValue( const OUString& rGroup, const OUString& rKey ) const
     138             : {
     139           0 :     ::boost::unordered_map< OUString, SmallOUStrMap, OUStringHash >::const_iterator group = m_aSettings.find( rGroup );
     140           0 :     if( group == m_aSettings.end() || group->second.find( rKey ) == group->second.end() )
     141             :     {
     142           0 :         static OUString aEmpty;
     143           0 :         return aEmpty;
     144             :     }
     145           0 :     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           0 : }
     157             : 
     158             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10