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

Generated by: LCOV version 1.10