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

Generated by: LCOV version 1.11