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

Generated by: LCOV version 1.10