LCOV - code coverage report
Current view: top level - unotools/source/config - misccfg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 103 52.4 %
Date: 2012-08-25 Functions: 16 26 61.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 43 114 37.7 %

           Branch data     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                 :        106 :     sal_Bool        IsNotFoundWarning()     const {return bNotFound;}
      61                 :            :     void        SetNotFoundWarning( sal_Bool bSet);
      62                 :            : 
      63                 :        106 :     sal_Bool        IsPaperSizeWarning()    const {return bPaperSize;}
      64                 :            :     void        SetPaperSizeWarning(sal_Bool bSet);
      65                 :            : 
      66                 :        106 :     sal_Bool        IsPaperOrientationWarning()     const {return bPaperOrientation;}
      67                 :            :     void        SetPaperOrientationWarning( sal_Bool bSet);
      68                 :            : 
      69                 :            :                 // 0 ... 99
      70                 :       7457 :     sal_Int32   GetYear2000()           const { return nYear2000; }
      71                 :            :     void        SetYear2000( sal_Int32 nSet );
      72                 :            : 
      73                 :            : };
      74                 :            : 
      75                 :        123 : SfxMiscCfg::SfxMiscCfg() :
      76                 :            :     ConfigItem(OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common")) ),
      77                 :            :     bPaperSize(sal_False),
      78                 :            :     bPaperOrientation (sal_False),
      79                 :            :     bNotFound (sal_False),
      80         [ +  - ]:        123 :     nYear2000( 1930 )
      81                 :            : {
      82                 :            :     RTL_LOGFILE_CONTEXT(aLog, "svl SfxMiscCfg::SfxMiscCfg()");
      83                 :            : 
      84         [ +  - ]:        123 :     Load();
      85                 :        123 : }
      86                 :            : 
      87                 :        123 : SfxMiscCfg::~SfxMiscCfg()
      88                 :            : {
      89         [ -  + ]:        246 : }
      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                 :        123 : 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 [ +  - ][ +  - ]:        615 :     };
         [ +  - ][ +  - ]
           [ #  #  #  # ]
     128         [ +  - ]:        123 :     const Sequence< OUString > seqPropertyNames( pProperties, 4 );
     129 [ +  + ][ #  # ]:        615 :     return seqPropertyNames;
     130                 :            : }
     131                 :            : 
     132                 :        123 : void SfxMiscCfg::Load()
     133                 :            : {
     134         [ +  - ]:        123 :     const Sequence<OUString>& rNames = GetPropertyNames();
     135         [ +  - ]:        123 :     Sequence<Any> aValues = GetProperties(rNames);
     136         [ +  - ]:        123 :     EnableNotification(rNames);
     137                 :        123 :     const Any* pValues = aValues.getConstArray();
     138                 :            :     DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
     139         [ +  - ]:        123 :     if(aValues.getLength() == rNames.getLength())
     140                 :            :     {
     141         [ +  + ]:        615 :         for(int nProp = 0; nProp < rNames.getLength(); nProp++)
     142                 :            :         {
     143         [ +  - ]:        492 :             if(pValues[nProp].hasValue())
     144                 :            :             {
     145   [ +  +  +  +  :        492 :                 switch(nProp)
                      - ]
     146                 :            :                 {
     147                 :        123 :                     case  0: bPaperSize        = *(sal_Bool*)pValues[nProp].getValue(); break;      //"Print/Warning/PaperSize",
     148                 :        123 :                     case  1: bPaperOrientation = *(sal_Bool*)pValues[nProp].getValue();  break;     //"Print/Warning/PaperOrientation",
     149                 :        123 :                     case  2: bNotFound         = *(sal_Bool*)pValues[nProp].getValue()  ;  break;   //"Print/Warning/NotFound",
     150                 :        492 :                     case  3: pValues[nProp] >>= nYear2000;break;                                    //"DateFormat/TwoDigitYear",
     151                 :            :                 }
     152                 :            :             }
     153                 :            :         }
     154 [ +  - ][ +  - ]:        123 :     }
     155                 :        123 : }
     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                 :       7686 : MiscCfg::MiscCfg( )
     190                 :            : {
     191                 :            :     // Global access, must be guarded (multithreading)
     192 [ +  - ][ +  - ]:       7686 :     ::osl::MutexGuard aGuard( LocalSingleton::get() );
     193         [ +  + ]:       7686 :     if ( !pOptions )
     194                 :            :     {
     195                 :            :         RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) SfxMiscCfg::ctor()");
     196 [ +  - ][ +  - ]:        123 :         pOptions = new SfxMiscCfg;
     197                 :            : 
     198         [ +  - ]:        123 :         ItemHolder1::holdConfigItem(E_MISCCFG);
     199                 :            :     }
     200                 :            : 
     201                 :       7686 :     ++nRefCount;
     202                 :       7686 :     pImpl = pOptions;
     203 [ +  - ][ +  - ]:       7686 :     pImpl->AddListener(this);
     204                 :       7686 : }
     205                 :            : 
     206                 :       7686 : MiscCfg::~MiscCfg( )
     207                 :            : {
     208                 :            :     // Global access, must be guarded (multithreading)
     209 [ +  - ][ +  - ]:       7686 :     ::osl::MutexGuard aGuard( LocalSingleton::get() );
     210         [ +  - ]:       7686 :     pImpl->RemoveListener(this);
     211         [ +  + ]:       7686 :     if ( !--nRefCount )
     212                 :            :     {
     213 [ +  - ][ -  + ]:        123 :         if ( pOptions->IsModified() )
     214         [ #  # ]:          0 :             pOptions->Commit();
     215 [ +  - ][ +  - ]:        123 :         DELETEZ( pOptions );
     216         [ +  - ]:       7686 :     }
     217         [ -  + ]:       7809 : }
     218                 :            : 
     219                 :        106 : sal_Bool MiscCfg::IsNotFoundWarning()   const
     220                 :            : {
     221                 :        106 :     return pImpl->IsNotFoundWarning();
     222                 :            : }
     223                 :            : 
     224                 :          0 : void MiscCfg::SetNotFoundWarning(   sal_Bool bSet)
     225                 :            : {
     226                 :          0 :     pImpl->SetNotFoundWarning( bSet );
     227                 :          0 : }
     228                 :            : 
     229                 :        106 : sal_Bool MiscCfg::IsPaperSizeWarning()  const
     230                 :            : {
     231                 :        106 :     return pImpl->IsPaperSizeWarning();
     232                 :            : }
     233                 :            : 
     234                 :          0 : void MiscCfg::SetPaperSizeWarning(sal_Bool bSet)
     235                 :            : {
     236                 :          0 :     pImpl->SetPaperSizeWarning( bSet );
     237                 :          0 : }
     238                 :            : 
     239                 :        106 : sal_Bool MiscCfg::IsPaperOrientationWarning()   const
     240                 :            : {
     241                 :        106 :     return pImpl->IsPaperOrientationWarning();
     242                 :            : }
     243                 :            : 
     244                 :          0 : void MiscCfg::SetPaperOrientationWarning(   sal_Bool bSet)
     245                 :            : {
     246                 :          0 :     pImpl->SetPaperOrientationWarning( bSet );
     247                 :          0 : }
     248                 :            : 
     249                 :       7457 : sal_Int32 MiscCfg::GetYear2000() const
     250                 :            : {
     251                 :       7457 :     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