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

Generated by: LCOV version 1.10