LCOV - code coverage report
Current view: top level - unotools/source/config - optionsdlg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 92 0.0 %
Date: 2014-11-03 Functions: 0 20 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/optionsdlg.hxx>
      21             : #include <unotools/configmgr.hxx>
      22             : #include <unotools/configitem.hxx>
      23             : #include <com/sun/star/uno/Any.hxx>
      24             : #include <com/sun/star/uno/Sequence.hxx>
      25             : #include <osl/mutex.hxx>
      26             : 
      27             : #include <boost/unordered_map.hpp>
      28             : #include "itemholder1.hxx"
      29             : 
      30             : using namespace utl;
      31             : using namespace com::sun::star::beans;
      32             : using namespace com::sun::star::uno;
      33             : 
      34             : #define CFG_FILENAME            OUString( "Office.OptionsDialog" )
      35             : #define ROOT_NODE               OUString( "OptionsDialogGroups" )
      36             : #define PAGES_NODE              OUString( "Pages" )
      37             : #define OPTIONS_NODE            OUString( "Options" )
      38             : #define PROPERTY_HIDE           OUString( "Hide" )
      39             : 
      40             : static SvtOptionsDlgOptions_Impl*   pOptions = NULL;
      41             : static sal_Int32                    nRefCount = 0;
      42             : 
      43           0 : class SvtOptionsDlgOptions_Impl : public utl::ConfigItem
      44             : {
      45             : private:
      46             :     typedef boost::unordered_map< OUString, sal_Bool, OUStringHash, ::std::equal_to< OUString > > OptionNodeList;
      47             : 
      48             :     OUString        m_sPathDelimiter;
      49             :     OptionNodeList  m_aOptionNodeList;
      50             : 
      51             :     enum NodeType{ NT_Group, NT_Page, NT_Option };
      52             :     void            ReadNode( const OUString& _rNode, NodeType _eType );
      53             :     bool        IsHidden( const OUString& _rPath ) const;
      54             : 
      55             : public:
      56             :                     SvtOptionsDlgOptions_Impl();
      57             : 
      58             :     virtual void    Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames ) SAL_OVERRIDE;
      59             :     virtual void    Commit() SAL_OVERRIDE;
      60             : 
      61             :     static ::osl::Mutex & getInitMutex();
      62             : 
      63             :     bool        IsGroupHidden   (   const OUString& _rGroup ) const;
      64             :     bool        IsPageHidden    (   const OUString& _rPage,
      65             :                                         const OUString& _rGroup ) const;
      66             :     bool        IsOptionHidden  (   const OUString& _rOption,
      67             :                                         const OUString& _rPage,
      68             :                                         const OUString& _rGroup ) const;
      69             : };
      70             : 
      71             : namespace
      72             : {
      73             :     class theOptionsDlgOptions_ImplMutex : public rtl::Static<osl::Mutex, theOptionsDlgOptions_ImplMutex>{};
      74             : }
      75             : 
      76           0 : ::osl::Mutex & SvtOptionsDlgOptions_Impl::getInitMutex()
      77             : {
      78           0 :     return theOptionsDlgOptions_ImplMutex::get();
      79             : }
      80             : 
      81           0 : SvtOptionsDlgOptions_Impl::SvtOptionsDlgOptions_Impl()
      82             :     : ConfigItem( OUString( CFG_FILENAME ) ),
      83             : 
      84             :     m_sPathDelimiter( "/" ),
      85           0 :     m_aOptionNodeList( OptionNodeList() )
      86             : 
      87             : {
      88           0 :     OUString sRootNode( ROOT_NODE );
      89           0 :     Sequence< OUString > aNodeSeq = GetNodeNames( sRootNode );
      90           0 :     OUString sNode( sRootNode + m_sPathDelimiter );
      91           0 :     sal_uInt32 nCount = aNodeSeq.getLength();
      92           0 :     for ( sal_uInt32 n = 0; n < nCount; n++ )
      93             :     {
      94           0 :         OUString sSubNode( sNode + aNodeSeq[n] );
      95           0 :         ReadNode( sSubNode, NT_Group );
      96           0 :     }
      97           0 : }
      98             : 
      99           0 : void SvtOptionsDlgOptions_Impl::Commit()
     100             : {
     101             :     // nothing to commit
     102           0 : }
     103             : 
     104           0 : void SvtOptionsDlgOptions_Impl::Notify( const Sequence< OUString >& )
     105             : {
     106             :     // nothing to notify
     107           0 : }
     108             : 
     109           0 : void SvtOptionsDlgOptions_Impl::ReadNode( const OUString& _rNode, NodeType _eType )
     110             : {
     111           0 :     OUString sNode( _rNode + m_sPathDelimiter );
     112           0 :     OUString sSet;
     113           0 :     sal_Int32 nLen = 0;
     114           0 :     switch ( _eType )
     115             :     {
     116             :         case NT_Group :
     117             :         {
     118           0 :             sSet = PAGES_NODE;
     119           0 :             nLen = 2;
     120           0 :             break;
     121             :         }
     122             : 
     123             :         case NT_Page :
     124             :         {
     125           0 :             sSet = OPTIONS_NODE;
     126           0 :             nLen = 2;
     127           0 :             break;
     128             :         }
     129             : 
     130             :         case NT_Option :
     131             :         {
     132           0 :             nLen = 1;
     133           0 :             break;
     134             :         }
     135             :     }
     136             : 
     137           0 :     Sequence< OUString > lResult( nLen );
     138           0 :     lResult[0] = OUString( sNode + PROPERTY_HIDE );
     139           0 :     if ( _eType != NT_Option )
     140           0 :         lResult[1] = OUString( sNode + sSet );
     141             : 
     142           0 :     Sequence< Any > aValues;
     143           0 :     aValues = GetProperties( lResult );
     144           0 :     bool bHide = false;
     145           0 :     if ( aValues[0] >>= bHide )
     146           0 :         m_aOptionNodeList.insert( OptionNodeList::value_type( sNode, bHide ) );
     147             : 
     148           0 :     if ( _eType != NT_Option )
     149             :     {
     150           0 :         OUString sNodes( sNode + sSet );
     151           0 :         Sequence< OUString > aNodes = GetNodeNames( sNodes );
     152           0 :         if ( aNodes.getLength() > 0 )
     153             :         {
     154           0 :             for ( sal_uInt32 n = 0; n < (sal_uInt32)aNodes.getLength(); ++n )
     155             :             {
     156           0 :                 OUString sSubNodeName( sNodes + m_sPathDelimiter + aNodes[n] );
     157           0 :                 ReadNode( sSubNodeName, _eType == NT_Group ? NT_Page : NT_Option );
     158           0 :             }
     159           0 :         }
     160           0 :     }
     161           0 : }
     162             : 
     163           0 : OUString getGroupPath( const OUString& _rGroup )
     164             : {
     165           0 :     return OUString( ROOT_NODE + OUString('/') + _rGroup + OUString('/') );
     166             : }
     167           0 : OUString getPagePath( const OUString& _rPage )
     168             : {
     169           0 :     return OUString( PAGES_NODE + OUString('/') + _rPage + OUString('/') );
     170             : }
     171           0 : OUString getOptionPath( const OUString& _rOption )
     172             : {
     173           0 :     return OUString( OPTIONS_NODE + OUString('/') + _rOption + OUString('/') );
     174             : }
     175             : 
     176           0 : bool SvtOptionsDlgOptions_Impl::IsHidden( const OUString& _rPath ) const
     177             : {
     178           0 :     bool bRet = false;
     179           0 :     OptionNodeList::const_iterator pIter = m_aOptionNodeList.find( _rPath );
     180           0 :     if ( pIter != m_aOptionNodeList.end() )
     181           0 :         bRet = pIter->second;
     182           0 :     return bRet;
     183             : }
     184             : 
     185           0 : bool SvtOptionsDlgOptions_Impl::IsGroupHidden( const OUString& _rGroup ) const
     186             : {
     187           0 :     return IsHidden( getGroupPath( _rGroup ) );
     188             : }
     189             : 
     190           0 : bool SvtOptionsDlgOptions_Impl::IsPageHidden( const OUString& _rPage, const OUString& _rGroup ) const
     191             : {
     192           0 :     return IsHidden( getGroupPath( _rGroup  ) + getPagePath( _rPage ) );
     193             : }
     194             : 
     195           0 : bool SvtOptionsDlgOptions_Impl::IsOptionHidden(
     196             :     const OUString& _rOption, const OUString& _rPage, const OUString& _rGroup ) const
     197             : {
     198           0 :     return IsHidden( getGroupPath( _rGroup  ) + getPagePath( _rPage ) + getOptionPath( _rOption ) );
     199             : }
     200             : 
     201           0 : SvtOptionsDialogOptions::SvtOptionsDialogOptions()
     202             : {
     203             :     // Global access, must be guarded (multithreading)
     204           0 :     ::osl::MutexGuard aGuard( SvtOptionsDlgOptions_Impl::getInitMutex() );
     205           0 :     ++nRefCount;
     206           0 :     if ( !pOptions )
     207             :     {
     208           0 :         pOptions = new SvtOptionsDlgOptions_Impl;
     209             : 
     210           0 :         ItemHolder1::holdConfigItem( E_OPTIONSDLGOPTIONS );
     211             :     }
     212           0 :     m_pImp = pOptions;
     213           0 : }
     214             : 
     215           0 : SvtOptionsDialogOptions::~SvtOptionsDialogOptions()
     216             : {
     217             :     // Global access, must be guarded (multithreading)
     218           0 :     ::osl::MutexGuard aGuard( SvtOptionsDlgOptions_Impl::getInitMutex() );
     219           0 :     if ( !--nRefCount )
     220             :     {
     221           0 :         if ( pOptions->IsModified() )
     222           0 :             pOptions->Commit();
     223           0 :         delete pOptions;
     224           0 :         pOptions = NULL;
     225           0 :     }
     226           0 : }
     227             : 
     228           0 : bool SvtOptionsDialogOptions::IsGroupHidden( const OUString& _rGroup ) const
     229             : {
     230           0 :     return m_pImp->IsGroupHidden( _rGroup );
     231             : }
     232             : 
     233           0 : bool SvtOptionsDialogOptions::IsPageHidden( const OUString& _rPage, const OUString& _rGroup ) const
     234             : {
     235           0 :     return m_pImp->IsPageHidden( _rPage, _rGroup );
     236             : }
     237             : 
     238           0 : bool SvtOptionsDialogOptions::IsOptionHidden(
     239             :     const OUString& _rOption, const OUString& _rPage, const OUString& _rGroup ) const
     240             : {
     241           0 :     return m_pImp->IsOptionHidden( _rOption, _rPage, _rGroup );
     242             : }
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10