LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/unotools/source/config - misccfg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 103 52.4 %
Date: 2013-07-09 Functions: 16 26 61.5 %
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 <unotools/misccfg.hxx>
      22             : #include "rtl/instance.hxx"
      23             : #include <unotools/configmgr.hxx>
      24             : #include <unotools/configitem.hxx>
      25             : #include <tools/debug.hxx>
      26             : #include <com/sun/star/uno/Any.hxx>
      27             : #include <com/sun/star/uno/Sequence.hxx>
      28             : #include <osl/mutex.hxx>
      29             : #include <rtl/logfile.hxx>
      30             : #include "itemholder1.hxx"
      31             : 
      32             : using namespace com::sun::star::uno;
      33             : 
      34             : 
      35             : namespace utl
      36             : {
      37             : 
      38             : static SfxMiscCfg* pOptions = NULL;
      39             : static sal_Int32 nRefCount = 0;
      40             : 
      41             : class SfxMiscCfg : public utl::ConfigItem
      42             : {
      43             :     sal_Bool            bPaperSize;     // printer warnings
      44             :     sal_Bool            bPaperOrientation;
      45             :     sal_Bool            bNotFound;
      46             :     sal_Int32       nYear2000;      // two digit year representation
      47             : 
      48             :     const com::sun::star::uno::Sequence<OUString> GetPropertyNames();
      49             :     void                    Load();
      50             : 
      51             : public:
      52             :     SfxMiscCfg( );
      53             :     ~SfxMiscCfg( );
      54             : 
      55             :     virtual void            Notify( const com::sun::star::uno::Sequence<OUString>& aPropertyNames);
      56             :     virtual void            Commit();
      57             : 
      58         188 :     sal_Bool        IsNotFoundWarning()     const {return bNotFound;}
      59             :     void        SetNotFoundWarning( sal_Bool bSet);
      60             : 
      61         188 :     sal_Bool        IsPaperSizeWarning()    const {return bPaperSize;}
      62             :     void        SetPaperSizeWarning(sal_Bool bSet);
      63             : 
      64         188 :     sal_Bool        IsPaperOrientationWarning()     const {return bPaperOrientation;}
      65             :     void        SetPaperOrientationWarning( sal_Bool bSet);
      66             : 
      67             :                 // 0 ... 99
      68        5072 :     sal_Int32   GetYear2000()           const { return nYear2000; }
      69             :     void        SetYear2000( sal_Int32 nSet );
      70             : 
      71             : };
      72             : 
      73          69 : SfxMiscCfg::SfxMiscCfg() :
      74             :     ConfigItem(OUString("Office.Common") ),
      75             :     bPaperSize(sal_False),
      76             :     bPaperOrientation (sal_False),
      77             :     bNotFound (sal_False),
      78          69 :     nYear2000( 1930 )
      79             : {
      80             :     RTL_LOGFILE_CONTEXT(aLog, "svl SfxMiscCfg::SfxMiscCfg()");
      81             : 
      82          69 :     Load();
      83          69 : }
      84             : 
      85         136 : SfxMiscCfg::~SfxMiscCfg()
      86             : {
      87         136 : }
      88             : 
      89           0 : void SfxMiscCfg::SetNotFoundWarning( sal_Bool bSet)
      90             : {
      91           0 :     if(bNotFound != bSet)
      92           0 :         SetModified();
      93           0 :     bNotFound = bSet;
      94           0 : }
      95             : 
      96           0 : void SfxMiscCfg::SetPaperSizeWarning( sal_Bool bSet)
      97             : {
      98           0 :     if(bPaperSize != bSet)
      99           0 :         SetModified();
     100           0 :     bPaperSize = bSet;
     101           0 : }
     102             : 
     103           0 : void SfxMiscCfg::SetPaperOrientationWarning( sal_Bool bSet)
     104             : {
     105           0 :     if(bPaperOrientation != bSet)
     106           0 :         SetModified();
     107           0 :     bPaperOrientation = bSet;
     108           0 : }
     109             : 
     110           0 : void SfxMiscCfg::SetYear2000( sal_Int32 nSet )
     111             : {
     112           0 :     if(nYear2000 != nSet)
     113           0 :         SetModified();
     114           0 :     nYear2000 = nSet;
     115           0 : }
     116             : 
     117          69 : const Sequence<OUString> SfxMiscCfg::GetPropertyNames()
     118             : {
     119             :     const OUString pProperties[] =
     120             :     {
     121             :         OUString("Print/Warning/PaperSize"),
     122             :         OUString("Print/Warning/PaperOrientation"),
     123             :         OUString("Print/Warning/NotFound"),
     124             :         OUString("DateFormat/TwoDigitYear")
     125         345 :     };
     126          69 :     const Sequence< OUString > seqPropertyNames( pProperties, 4 );
     127         345 :     return seqPropertyNames;
     128             : }
     129             : 
     130          69 : void SfxMiscCfg::Load()
     131             : {
     132          69 :     const Sequence<OUString>& rNames = GetPropertyNames();
     133         138 :     Sequence<Any> aValues = GetProperties(rNames);
     134          69 :     EnableNotification(rNames);
     135          69 :     const Any* pValues = aValues.getConstArray();
     136             :     DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
     137          69 :     if(aValues.getLength() == rNames.getLength())
     138             :     {
     139         345 :         for(int nProp = 0; nProp < rNames.getLength(); nProp++)
     140             :         {
     141         276 :             if(pValues[nProp].hasValue())
     142             :             {
     143         276 :                 switch(nProp)
     144             :                 {
     145          69 :                     case  0: bPaperSize        = *(sal_Bool*)pValues[nProp].getValue(); break;      //"Print/Warning/PaperSize",
     146          69 :                     case  1: bPaperOrientation = *(sal_Bool*)pValues[nProp].getValue();  break;     //"Print/Warning/PaperOrientation",
     147          69 :                     case  2: bNotFound         = *(sal_Bool*)pValues[nProp].getValue()  ;  break;   //"Print/Warning/NotFound",
     148          69 :                     case  3: pValues[nProp] >>= nYear2000;break;                                    //"DateFormat/TwoDigitYear",
     149             :                 }
     150             :             }
     151             :         }
     152          69 :     }
     153          69 : }
     154             : 
     155           0 : void SfxMiscCfg::Notify( const com::sun::star::uno::Sequence<OUString>& )
     156             : {
     157           0 :     Load();
     158           0 : }
     159             : 
     160           0 : void SfxMiscCfg::Commit()
     161             : {
     162           0 :     const Sequence<OUString>& rNames = GetPropertyNames();
     163           0 :     Sequence<Any> aValues(rNames.getLength());
     164           0 :     Any* pValues = aValues.getArray();
     165             : 
     166           0 :     const Type& rType = ::getBooleanCppuType();
     167           0 :     for(int nProp = 0; nProp < rNames.getLength(); nProp++)
     168             :     {
     169           0 :         switch(nProp)
     170             :         {
     171           0 :             case  0: pValues[nProp].setValue(&bPaperSize, rType);break;  //"Print/Warning/PaperSize",
     172           0 :             case  1: pValues[nProp].setValue(&bPaperOrientation, rType);break;     //"Print/Warning/PaperOrientation",
     173           0 :             case  2: pValues[nProp].setValue(&bNotFound, rType);break;   //"Print/Warning/NotFound",
     174           0 :             case  3: pValues[nProp] <<= nYear2000;break;                 //"DateFormat/TwoDigitYear",
     175             :         }
     176             :     }
     177           0 :     PutProperties(rNames, aValues);
     178           0 : }
     179             : // -----------------------------------------------------------------------
     180             : namespace
     181             : {
     182             :     class LocalSingleton : public rtl::Static< osl::Mutex, LocalSingleton >
     183             :     {
     184             :     };
     185             : }
     186             : 
     187        5329 : MiscCfg::MiscCfg( )
     188             : {
     189             :     // Global access, must be guarded (multithreading)
     190        5329 :     ::osl::MutexGuard aGuard( LocalSingleton::get() );
     191        5329 :     if ( !pOptions )
     192             :     {
     193             :         RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) SfxMiscCfg::ctor()");
     194          69 :         pOptions = new SfxMiscCfg;
     195             : 
     196          69 :         ItemHolder1::holdConfigItem(E_MISCCFG);
     197             :     }
     198             : 
     199        5329 :     ++nRefCount;
     200        5329 :     pImpl = pOptions;
     201        5329 :     pImpl->AddListener(this);
     202        5329 : }
     203             : 
     204       10724 : MiscCfg::~MiscCfg( )
     205             : {
     206             :     // Global access, must be guarded (multithreading)
     207        5328 :     ::osl::MutexGuard aGuard( LocalSingleton::get() );
     208        5328 :     pImpl->RemoveListener(this);
     209        5328 :     if ( !--nRefCount )
     210             :     {
     211          68 :         if ( pOptions->IsModified() )
     212           0 :             pOptions->Commit();
     213          68 :         DELETEZ( pOptions );
     214        5328 :     }
     215        5396 : }
     216             : 
     217         188 : sal_Bool MiscCfg::IsNotFoundWarning()   const
     218             : {
     219         188 :     return pImpl->IsNotFoundWarning();
     220             : }
     221             : 
     222           0 : void MiscCfg::SetNotFoundWarning(   sal_Bool bSet)
     223             : {
     224           0 :     pImpl->SetNotFoundWarning( bSet );
     225           0 : }
     226             : 
     227         188 : sal_Bool MiscCfg::IsPaperSizeWarning()  const
     228             : {
     229         188 :     return pImpl->IsPaperSizeWarning();
     230             : }
     231             : 
     232           0 : void MiscCfg::SetPaperSizeWarning(sal_Bool bSet)
     233             : {
     234           0 :     pImpl->SetPaperSizeWarning( bSet );
     235           0 : }
     236             : 
     237         188 : sal_Bool MiscCfg::IsPaperOrientationWarning()   const
     238             : {
     239         188 :     return pImpl->IsPaperOrientationWarning();
     240             : }
     241             : 
     242           0 : void MiscCfg::SetPaperOrientationWarning(   sal_Bool bSet)
     243             : {
     244           0 :     pImpl->SetPaperOrientationWarning( bSet );
     245           0 : }
     246             : 
     247        5072 : sal_Int32 MiscCfg::GetYear2000() const
     248             : {
     249        5072 :     return pImpl->GetYear2000();
     250             : }
     251             : 
     252           0 : void MiscCfg::SetYear2000( sal_Int32 nSet )
     253             : {
     254           0 :     pImpl->SetYear2000( nSet );
     255           0 : }
     256             : 
     257             : }
     258             : 
     259             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10