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

Generated by: LCOV version 1.10