LCOV - code coverage report
Current view: top level - vcl/source/gdi - configsettings.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 41 76 53.9 %
Date: 2012-08-25 Functions: 6 9 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 57 182 31.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <vcl/configsettings.hxx>
      31                 :            : 
      32                 :            : #include <svdata.hxx>
      33                 :            : 
      34                 :            : #include <com/sun/star/uno/Any.hxx>
      35                 :            : #include <com/sun/star/uno/Sequence.hxx>
      36                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      37                 :            : 
      38                 :            : using namespace utl;
      39                 :            : using namespace vcl;
      40                 :            : using namespace com::sun::star::uno;
      41                 :            : using namespace com::sun::star::lang;
      42                 :            : using namespace com::sun::star::beans;
      43                 :            : using namespace com::sun::star::container;
      44                 :            : 
      45                 :            : using ::rtl::OUString;
      46                 :            : 
      47                 :            : #define SETTINGS_CONFIGNODE "VCL/Settings"
      48                 :            : 
      49                 :            : /*
      50                 :            :  *  SettingsConfigItem::get
      51                 :            :  */
      52                 :            : 
      53                 :        269 : SettingsConfigItem* SettingsConfigItem::get()
      54                 :            : {
      55                 :        269 :     ImplSVData* pSVData = ImplGetSVData();
      56         [ +  + ]:        269 :     if( ! pSVData->mpSettingsConfigItem )
      57         [ +  - ]:        209 :         pSVData->mpSettingsConfigItem = new SettingsConfigItem();
      58                 :        269 :     return pSVData->mpSettingsConfigItem;
      59                 :            : }
      60                 :            : 
      61                 :            : /*
      62                 :            :  *  SettignsConfigItem constructor
      63                 :            :  */
      64                 :            : 
      65                 :        209 : SettingsConfigItem::SettingsConfigItem()
      66                 :            :         :
      67                 :            :         ConfigItem( OUString( RTL_CONSTASCII_USTRINGPARAM( SETTINGS_CONFIGNODE ) ),
      68                 :            :                     CONFIG_MODE_DELAYED_UPDATE ),
      69 [ +  - ][ +  - ]:        209 :     m_aSettings( 0 )
      70                 :            : {
      71         [ +  - ]:        209 :     getValues();
      72                 :        209 : }
      73                 :            : 
      74                 :            : /*
      75                 :            :  *  SettingsConfigItem destructor
      76                 :            :  */
      77                 :            : 
      78         [ +  - ]:        158 : SettingsConfigItem::~SettingsConfigItem()
      79                 :            : {
      80 [ +  - ][ -  + ]:        158 :     if( IsModified() )
      81         [ #  # ]:          0 :         Commit();
      82         [ -  + ]:        316 : }
      83                 :            : 
      84                 :            : /*
      85                 :            :  *  SettingsConfigItem::Commit
      86                 :            :  */
      87                 :            : 
      88                 :          0 : void SettingsConfigItem::Commit()
      89                 :            : {
      90 [ #  # ][ #  # ]:          0 :     if( ! IsValidConfigMgr() )
      91                 :          0 :         return;
      92                 :            : 
      93                 :          0 :     boost::unordered_map< OUString, SmallOUStrMap, rtl::OUStringHash >::const_iterator group;
      94                 :            : 
      95 [ #  # ][ #  # ]:          0 :     for( group = m_aSettings.begin(); group != m_aSettings.end(); ++group )
                 [ #  # ]
      96                 :            :     {
      97 [ #  # ][ #  # ]:          0 :         String aKeyName( group->first );
      98 [ #  # ][ #  # ]:          0 :         /*sal_Bool bAdded =*/ AddNode( OUString(), aKeyName );
      99 [ #  # ][ #  # ]:          0 :         Sequence< PropertyValue > aValues( group->second.size() );
     100         [ #  # ]:          0 :         PropertyValue* pValues = aValues.getArray();
     101                 :          0 :         int nIndex = 0;
     102                 :          0 :         SmallOUStrMap::const_iterator it;
     103 [ #  # ][ #  # ]:          0 :         for( it = group->second.begin(); it != group->second.end(); ++it )
         [ #  # ][ #  # ]
     104                 :            :         {
     105         [ #  # ]:          0 :             String aName( aKeyName );
     106         [ #  # ]:          0 :             aName.Append( '/' );
     107 [ #  # ][ #  # ]:          0 :             aName.Append( String( it->first ) );
         [ #  # ][ #  # ]
     108         [ #  # ]:          0 :             pValues[nIndex].Name    = aName;
     109                 :          0 :             pValues[nIndex].Handle  = 0;
     110 [ #  # ][ #  # ]:          0 :             pValues[nIndex].Value <<= it->second;
     111                 :          0 :             pValues[nIndex].State   = PropertyState_DIRECT_VALUE;
     112                 :          0 :             nIndex++;
     113         [ #  # ]:          0 :         }
     114 [ #  # ][ #  # ]:          0 :         ReplaceSetProperties( aKeyName, aValues );
         [ #  # ][ #  # ]
     115 [ #  # ][ #  # ]:          0 :     }
     116                 :            : }
     117                 :            : 
     118                 :            : /*
     119                 :            :  *  SettingsConfigItem::Notify
     120                 :            :  */
     121                 :            : 
     122                 :          0 : void SettingsConfigItem::Notify( const Sequence< OUString >& )
     123                 :            : {
     124                 :          0 :     getValues();
     125                 :          0 : }
     126                 :            : 
     127                 :            : /*
     128                 :            :  *  SettingsConfigItem::getValues
     129                 :            :  */
     130                 :        209 : void SettingsConfigItem::getValues()
     131                 :            : {
     132 [ +  - ][ +  - ]:        209 :     if( ! IsValidConfigMgr() )
     133                 :        209 :         return;
     134                 :            : 
     135         [ +  - ]:        209 :     m_aSettings.clear();
     136                 :            : 
     137         [ +  - ]:        209 :     Sequence< OUString > aNames( GetNodeNames( OUString() ) );
     138                 :            : 
     139         [ +  + ]:       1463 :     for( int j = 0; j < aNames.getLength(); j++ )
     140                 :            :     {
     141                 :            : #if OSL_DEBUG_LEVEL > 2
     142                 :            :         OSL_TRACE( "found settings data for \"%s\"\n",
     143                 :            :                  OUStringToOString( aNames.getConstArray()[j], RTL_TEXTENCODING_ASCII_US ).getStr()
     144                 :            :                  );
     145                 :            : #endif
     146         [ +  - ]:       1254 :         String aKeyName( aNames.getConstArray()[j] );
     147 [ +  - ][ +  - ]:       1254 :         Sequence< OUString > aKeys( GetNodeNames( aKeyName ) );
     148         [ +  - ]:       1254 :         Sequence< OUString > aSettingsKeys( aKeys.getLength() );
     149                 :       1254 :         const OUString* pFrom = aKeys.getConstArray();
     150         [ +  - ]:       1254 :         OUString* pTo = aSettingsKeys.getArray();
     151         [ +  + ]:       2717 :         for( int m = 0; m < aKeys.getLength(); m++ )
     152                 :            :         {
     153         [ +  - ]:       1463 :             String aName( aKeyName );
     154         [ +  - ]:       1463 :             aName.Append( '/' );
     155 [ +  - ][ +  - ]:       1463 :             aName.Append( String( pFrom[m] ) );
                 [ +  - ]
     156         [ +  - ]:       1463 :             pTo[m] = aName;
     157         [ +  - ]:       1463 :         }
     158         [ +  - ]:       1254 :         Sequence< Any > aValues( GetProperties( aSettingsKeys ) );
     159                 :       1254 :         const Any* pValue = aValues.getConstArray();
     160         [ +  + ]:       2717 :         for( int i = 0; i < aValues.getLength(); i++, pValue++ )
     161                 :            :         {
     162         [ +  - ]:       1463 :             if( pValue->getValueTypeClass() == TypeClass_STRING )
     163                 :            :             {
     164                 :       1463 :                 const OUString* pLine = (const OUString*)pValue->getValue();
     165         [ +  + ]:       1463 :                 if( !pLine->isEmpty() )
     166 [ +  - ][ +  - ]:       1254 :                     m_aSettings[ aKeyName ][ pFrom[i] ] = *pLine;
                 [ +  - ]
     167                 :            : #if OSL_DEBUG_LEVEL > 2
     168                 :            :                 OSL_TRACE( "   \"%s\"=\"%.30s\"\n",
     169                 :            :                          OUStringToOString( aKeys.getConstArray()[i], RTL_TEXTENCODING_ASCII_US ).getStr(),
     170                 :            :                          OUStringToOString( *pLine, RTL_TEXTENCODING_ASCII_US ).getStr()
     171                 :            :                          );
     172                 :            : #endif
     173                 :            :             }
     174                 :            :         }
     175 [ +  - ][ +  - ]:       1463 :     }
         [ +  - ][ +  - ]
                 [ +  - ]
     176                 :            : }
     177                 :            : 
     178                 :            : /*
     179                 :            :  *  SettingsConfigItem::getDefaultFont
     180                 :            :  */
     181                 :            : 
     182                 :        269 : const OUString& SettingsConfigItem::getValue( const OUString& rGroup, const OUString& rKey ) const
     183                 :            : {
     184         [ +  - ]:        269 :     ::boost::unordered_map< OUString, SmallOUStrMap, rtl::OUStringHash >::const_iterator group = m_aSettings.find( rGroup );
     185 [ +  - ][ +  - ]:        269 :     if( group == m_aSettings.end() || group->second.find( rKey ) == group->second.end() )
         [ +  - ][ +  - ]
         [ -  + ][ +  - ]
         [ +  - ][ +  - ]
           [ -  +  #  #  
             #  #  #  # ]
     186                 :            :     {
     187 [ #  # ][ #  # ]:          0 :         static OUString aEmpty;
     188                 :          0 :         return aEmpty;
     189                 :            :     }
     190 [ +  - ][ +  - ]:        269 :     return group->second.find(rKey)->second;
                 [ +  - ]
     191                 :            : }
     192                 :            : 
     193                 :            : /*
     194                 :            :  *  SettingsConfigItem::setDefaultFont
     195                 :            :  */
     196                 :            : 
     197                 :          0 : void SettingsConfigItem::setValue( const OUString& rGroup, const OUString& rKey, const OUString& rValue )
     198                 :            : {
     199                 :          0 :     bool bModified = m_aSettings[ rGroup ][ rKey ] != rValue;
     200         [ #  # ]:          0 :     if( bModified )
     201                 :            :     {
     202                 :          0 :         m_aSettings[ rGroup ][ rKey ] = rValue;
     203                 :          0 :         SetModified();
     204                 :            :     }
     205                 :          0 : }
     206                 :            : 
     207                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10