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

Generated by: LCOV version 1.10