LCOV - code coverage report
Current view: top level - unotools/source/config - optionsdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 94 0.0 %
Date: 2012-08-25 Functions: 0 21 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 134 0.0 %

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

Generated by: LCOV version 1.10