LCOV - code coverage report
Current view: top level - unotools/source/config - printwarningoptions.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 101 0.0 %
Date: 2014-11-03 Functions: 0 26 0.0 %
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/printwarningoptions.hxx>
      21             : #include <unotools/configmgr.hxx>
      22             : #include <unotools/configitem.hxx>
      23             : #include <tools/debug.hxx>
      24             : #include <com/sun/star/uno/Any.hxx>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : 
      27             : #include "itemholder1.hxx"
      28             : 
      29             : //  namespaces
      30             : 
      31             : using namespace ::utl;
      32             : using namespace ::osl;
      33             : using namespace ::com::sun::star::uno;
      34             : 
      35             : #define ROOTNODE_START                  OUString("Office.Common/Print")
      36             : 
      37             : #define PROPERTYNAME_PAPERSIZE          OUString("Warning/PaperSize")
      38             : #define PROPERTYNAME_PAPERORIENTATION   OUString("Warning/PaperOrientation")
      39             : #define PROPERTYNAME_NOTFOUND           OUString("Warning/NotFound")
      40             : #define PROPERTYNAME_TRANSPARENCY       OUString("Warning/Transparency")
      41             : #define PROPERTYNAME_PRINTINGMODIFIESDOCUMENT  OUString("PrintingModifiesDocument")
      42             : 
      43             : #define PROPERTYHANDLE_PAPERSIZE        0
      44             : #define PROPERTYHANDLE_PAPERORIENTATION 1
      45             : #define PROPERTYHANDLE_NOTFOUND         2
      46             : #define PROPERTYHANDLE_TRANSPARENCY     3
      47             : #define PROPERTYHDL_PRINTINGMODIFIESDOCUMENT            4
      48             : 
      49             : #define PROPERTYCOUNT                   5
      50             : 
      51             : class SvtPrintWarningOptions_Impl : public ConfigItem
      52             : {
      53             : public:
      54             : 
      55             : //  constructor / destructor
      56             : 
      57             :      SvtPrintWarningOptions_Impl();
      58             :     virtual ~SvtPrintWarningOptions_Impl();
      59             : 
      60             : //  overloaded methods of baseclass
      61             : 
      62             :     virtual void Commit() SAL_OVERRIDE;
      63             :     virtual void    Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames ) SAL_OVERRIDE;
      64             : 
      65             : //  public interface
      66             : 
      67           0 :     bool    IsPaperSize() const { return m_bPaperSize; }
      68           0 :     bool    IsPaperOrientation() const { return m_bPaperOrientation; }
      69           0 :     bool    IsTransparency() const { return m_bTransparency; }
      70           0 :     bool    IsModifyDocumentOnPrintingAllowed() const { return m_bModifyDocumentOnPrintingAllowed; }
      71             : 
      72           0 :     void        SetPaperSize( bool bState ) { m_bPaperSize = bState; SetModified(); }
      73           0 :     void        SetPaperOrientation( bool bState ) { m_bPaperOrientation = bState; SetModified(); }
      74           0 :     void        SetTransparency( bool bState ) { m_bTransparency = bState; SetModified(); }
      75           0 :     void        SetModifyDocumentOnPrintingAllowed( bool bState ) { m_bModifyDocumentOnPrintingAllowed = bState; SetModified(); }
      76             : 
      77             : //  private methods
      78             : 
      79             : private:
      80             : 
      81             :     static Sequence< OUString > impl_GetPropertyNames();
      82             : 
      83             : //  private member
      84             : 
      85             : private:
      86             : 
      87             :     bool    m_bPaperSize;
      88             :     bool    m_bPaperOrientation;
      89             :     bool    m_bNotFound;
      90             :     bool    m_bTransparency;
      91             :     bool    m_bModifyDocumentOnPrintingAllowed;
      92             : };
      93             : 
      94             : //  constructor
      95             : 
      96           0 : SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl() :
      97             :     ConfigItem( ROOTNODE_START  ),
      98             :     m_bPaperSize( false ),
      99             :     m_bPaperOrientation( false ),
     100             :     m_bNotFound( false ),
     101             :     m_bTransparency( true ),
     102           0 :     m_bModifyDocumentOnPrintingAllowed( true )
     103             : {
     104           0 :     Sequence< OUString >    seqNames( impl_GetPropertyNames() );
     105           0 :     Sequence< Any >         seqValues( GetProperties( seqNames ) );
     106             : 
     107             :     DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nI miss some values of configuration keys!\n" );
     108             : 
     109             :     // Copy values from list in right order to our internal member.
     110           0 :     sal_Int32 nPropertyCount = seqValues.getLength();
     111           0 :     sal_Int32 nProperty = 0;
     112             : 
     113           0 :     for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
     114             :     {
     115             :         DBG_ASSERT( seqValues[nProperty].hasValue(), "SvtPrintWarningOptions_Impl::SvtPrintWarningOptions_Impl()\nInvalid property value for property detected!\n" );
     116             : 
     117           0 :         switch( nProperty )
     118             :         {
     119             :             case PROPERTYHANDLE_PAPERSIZE:
     120             :             {
     121             :                 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
     122           0 :                 seqValues[nProperty] >>= m_bPaperSize;
     123             :             }
     124           0 :             break;
     125             : 
     126             :             case PROPERTYHANDLE_PAPERORIENTATION:
     127             :             {
     128             :                 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
     129           0 :                 seqValues[nProperty] >>= m_bPaperOrientation;
     130             :             }
     131           0 :             break;
     132             : 
     133             :             case PROPERTYHANDLE_NOTFOUND:
     134             :             {
     135             :                 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
     136           0 :                 seqValues[nProperty] >>= m_bNotFound;
     137             :             }
     138           0 :             break;
     139             : 
     140             :             case PROPERTYHANDLE_TRANSPARENCY:
     141             :             {
     142             :                 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
     143           0 :                 seqValues[nProperty] >>= m_bTransparency;
     144             :             }
     145           0 :             break;
     146             :             case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT:
     147             :             {
     148             :                 DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "Invalid type" );
     149           0 :                 seqValues[nProperty] >>= m_bModifyDocumentOnPrintingAllowed;
     150             :             }
     151           0 :             break;
     152             : 
     153             :         }
     154           0 :     }
     155           0 : }
     156             : 
     157             : //  destructor
     158             : 
     159           0 : SvtPrintWarningOptions_Impl::~SvtPrintWarningOptions_Impl()
     160             : {
     161           0 :     if( IsModified() )
     162           0 :         Commit();
     163           0 : }
     164             : 
     165             : //  Commit
     166             : 
     167           0 : void SvtPrintWarningOptions_Impl::Commit()
     168             : {
     169           0 :     Sequence< OUString >    aSeqNames( impl_GetPropertyNames() );
     170           0 :     Sequence< Any >         aSeqValues( aSeqNames.getLength() );
     171             : 
     172           0 :     for( sal_Int32 nProperty = 0, nCount = aSeqNames.getLength(); nProperty < nCount; ++nProperty )
     173             :     {
     174           0 :         switch( nProperty )
     175             :         {
     176             :             case PROPERTYHANDLE_PAPERSIZE:
     177           0 :                 aSeqValues[nProperty] <<= m_bPaperSize;
     178           0 :             break;
     179             : 
     180             :             case PROPERTYHANDLE_PAPERORIENTATION:
     181           0 :                 aSeqValues[nProperty] <<= m_bPaperOrientation;
     182           0 :             break;
     183             : 
     184             :             case PROPERTYHANDLE_NOTFOUND:
     185           0 :                 aSeqValues[nProperty] <<= m_bNotFound;
     186           0 :             break;
     187             : 
     188             :             case PROPERTYHANDLE_TRANSPARENCY:
     189           0 :                 aSeqValues[nProperty] <<= m_bTransparency;
     190           0 :             break;
     191             :             case PROPERTYHDL_PRINTINGMODIFIESDOCUMENT:
     192           0 :                 aSeqValues[nProperty] <<= m_bModifyDocumentOnPrintingAllowed;
     193           0 :             break;
     194             :         }
     195             :     }
     196             : 
     197           0 :     PutProperties( aSeqNames, aSeqValues );
     198           0 : }
     199             : 
     200           0 : void SvtPrintWarningOptions_Impl::Notify( const Sequence< OUString >&  )
     201             : {
     202           0 : }
     203             : 
     204             : //  private method
     205             : 
     206           0 : Sequence< OUString > SvtPrintWarningOptions_Impl::impl_GetPropertyNames()
     207             : {
     208             :     // Build list of configuration key names.
     209             :     const OUString pProperties[] =
     210             :     {
     211             :         PROPERTYNAME_PAPERSIZE,
     212             :         PROPERTYNAME_PAPERORIENTATION,
     213             :         PROPERTYNAME_NOTFOUND,
     214             :         PROPERTYNAME_TRANSPARENCY,
     215             :         PROPERTYNAME_PRINTINGMODIFIESDOCUMENT
     216           0 :     };
     217             : 
     218             :     // Initialize return sequence with these list ...
     219           0 :     const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
     220             : 
     221           0 :     return seqPropertyNames;
     222             : }
     223             : 
     224             : //  initialize static member
     225             : //  DON'T DO IT IN YOUR HEADER!
     226             : //  see definition for further information
     227             : 
     228             : SvtPrintWarningOptions_Impl*    SvtPrintWarningOptions::m_pDataContainer = NULL;
     229             : sal_Int32                       SvtPrintWarningOptions::m_nRefCount = 0;
     230             : 
     231             : //  constructor
     232             : 
     233           0 : SvtPrintWarningOptions::SvtPrintWarningOptions()
     234             : {
     235             :     // Global access, must be guarded (multithreading!).
     236           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     237             :     // Increase our refcount ...
     238           0 :     ++m_nRefCount;
     239             :     // ... and initialize our data container only if it not already!
     240           0 :     if( m_pDataContainer == NULL )
     241             :     {
     242           0 :         m_pDataContainer = new SvtPrintWarningOptions_Impl();
     243           0 :         ItemHolder1::holdConfigItem(E_PRINTWARNINGOPTIONS);
     244           0 :     }
     245           0 : }
     246             : 
     247             : //  destructor
     248             : 
     249           0 : SvtPrintWarningOptions::~SvtPrintWarningOptions()
     250             : {
     251             :     // Global access, must be guarded (multithreading!)
     252           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     253             :     // Decrease our refcount.
     254           0 :     --m_nRefCount;
     255             :     // If last instance was deleted ...
     256             :     // we must destroy our static data container!
     257           0 :     if( m_nRefCount <= 0 )
     258             :     {
     259           0 :         delete m_pDataContainer;
     260           0 :         m_pDataContainer = NULL;
     261           0 :     }
     262           0 : }
     263             : 
     264             : //  public method
     265             : 
     266           0 : bool SvtPrintWarningOptions::IsPaperSize() const
     267             : {
     268           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     269           0 :     return m_pDataContainer->IsPaperSize();
     270             : }
     271             : 
     272             : //  public method
     273             : 
     274           0 : bool SvtPrintWarningOptions::IsPaperOrientation() const
     275             : {
     276           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     277           0 :     return m_pDataContainer->IsPaperOrientation();
     278             : }
     279             : 
     280             : //  public method
     281             : 
     282           0 : bool SvtPrintWarningOptions::IsTransparency() const
     283             : {
     284           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     285           0 :     return m_pDataContainer->IsTransparency();
     286             : }
     287             : 
     288             : //  public method
     289             : 
     290           0 : void SvtPrintWarningOptions::SetPaperSize( bool bState )
     291             : {
     292           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     293           0 :     m_pDataContainer->SetPaperSize( bState );
     294           0 : }
     295             : 
     296             : //  public method
     297             : 
     298           0 : void SvtPrintWarningOptions::SetPaperOrientation( bool bState )
     299             : {
     300           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     301           0 :     m_pDataContainer->SetPaperOrientation( bState );
     302           0 : }
     303             : 
     304             : //  public method
     305             : 
     306           0 : void SvtPrintWarningOptions::SetTransparency( bool bState )
     307             : {
     308           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     309           0 :     m_pDataContainer->SetTransparency( bState );
     310           0 : }
     311             : 
     312           0 : bool SvtPrintWarningOptions::IsModifyDocumentOnPrintingAllowed() const
     313             : {
     314           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     315           0 :     return m_pDataContainer->IsModifyDocumentOnPrintingAllowed();
     316             : }
     317             : 
     318           0 : void SvtPrintWarningOptions::SetModifyDocumentOnPrintingAllowed( bool bState )
     319             : {
     320           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     321           0 :     m_pDataContainer->SetModifyDocumentOnPrintingAllowed( bState );
     322           0 : }
     323             : 
     324             : namespace
     325             : {
     326             :     class thePrintWarningOptionsMutex : public rtl::Static<osl::Mutex, thePrintWarningOptionsMutex>{};
     327             : }
     328             : 
     329             : //  private method
     330             : 
     331           0 : Mutex& SvtPrintWarningOptions::GetOwnStaticMutex()
     332             : {
     333           0 :     return thePrintWarningOptionsMutex::get();
     334             : }
     335             : 
     336             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10