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

Generated by: LCOV version 1.10