Bump version to 4.3-4
[LibreOffice.git] / unotools / source / config / optionsdlg.cxx
blobc318e6f1c70ed4f29ce89d2831f69cf034af6519
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
27 #include <boost/unordered_map.hpp>
28 #include "itemholder1.hxx"
30 using namespace utl;
31 using namespace com::sun::star::beans;
32 using namespace com::sun::star::uno;
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" )
40 static SvtOptionsDlgOptions_Impl* pOptions = NULL;
41 static sal_Int32 nRefCount = 0;
43 class SvtOptionsDlgOptions_Impl : public utl::ConfigItem
45 private:
46 typedef boost::unordered_map< OUString, sal_Bool, OUStringHash, ::std::equal_to< OUString > > OptionNodeList;
48 OUString m_sPathDelimiter;
49 OptionNodeList m_aOptionNodeList;
51 enum NodeType{ NT_Group, NT_Page, NT_Option };
52 void ReadNode( const OUString& _rNode, NodeType _eType );
53 bool IsHidden( const OUString& _rPath ) const;
55 public:
56 SvtOptionsDlgOptions_Impl();
58 virtual void Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames ) SAL_OVERRIDE;
59 virtual void Commit() SAL_OVERRIDE;
61 static ::osl::Mutex & getInitMutex();
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;
71 namespace
73 class theOptionsDlgOptions_ImplMutex : public rtl::Static<osl::Mutex, theOptionsDlgOptions_ImplMutex>{};
76 ::osl::Mutex & SvtOptionsDlgOptions_Impl::getInitMutex()
78 return theOptionsDlgOptions_ImplMutex::get();
81 SvtOptionsDlgOptions_Impl::SvtOptionsDlgOptions_Impl()
82 : ConfigItem( OUString( CFG_FILENAME ) ),
84 m_sPathDelimiter( "/" ),
85 m_aOptionNodeList( OptionNodeList() )
88 OUString sRootNode( ROOT_NODE );
89 Sequence< OUString > aNodeSeq = GetNodeNames( sRootNode );
90 OUString sNode( sRootNode + m_sPathDelimiter );
91 sal_uInt32 nCount = aNodeSeq.getLength();
92 for ( sal_uInt32 n = 0; n < nCount; n++ )
94 OUString sSubNode( sNode + aNodeSeq[n] );
95 ReadNode( sSubNode, NT_Group );
99 void SvtOptionsDlgOptions_Impl::Commit()
101 // nothing to commit
104 void SvtOptionsDlgOptions_Impl::Notify( const Sequence< OUString >& )
106 // nothing to notify
109 void SvtOptionsDlgOptions_Impl::ReadNode( const OUString& _rNode, NodeType _eType )
111 OUString sNode( _rNode + m_sPathDelimiter );
112 OUString sSet;
113 sal_Int32 nLen = 0;
114 switch ( _eType )
116 case NT_Group :
118 sSet = PAGES_NODE;
119 nLen = 2;
120 break;
123 case NT_Page :
125 sSet = OPTIONS_NODE;
126 nLen = 2;
127 break;
130 case NT_Option :
132 nLen = 1;
133 break;
137 Sequence< OUString > lResult( nLen );
138 lResult[0] = OUString( sNode + PROPERTY_HIDE );
139 if ( _eType != NT_Option )
140 lResult[1] = OUString( sNode + sSet );
142 Sequence< Any > aValues;
143 aValues = GetProperties( lResult );
144 bool bHide = false;
145 if ( aValues[0] >>= bHide )
146 m_aOptionNodeList.insert( OptionNodeList::value_type( sNode, bHide ) );
148 if ( _eType != NT_Option )
150 OUString sNodes( sNode + sSet );
151 Sequence< OUString > aNodes = GetNodeNames( sNodes );
152 if ( aNodes.getLength() > 0 )
154 for ( sal_uInt32 n = 0; n < (sal_uInt32)aNodes.getLength(); ++n )
156 OUString sSubNodeName( sNodes + m_sPathDelimiter + aNodes[n] );
157 ReadNode( sSubNodeName, _eType == NT_Group ? NT_Page : NT_Option );
163 OUString getGroupPath( const OUString& _rGroup )
165 return OUString( ROOT_NODE + OUString('/') + _rGroup + OUString('/') );
167 OUString getPagePath( const OUString& _rPage )
169 return OUString( PAGES_NODE + OUString('/') + _rPage + OUString('/') );
171 OUString getOptionPath( const OUString& _rOption )
173 return OUString( OPTIONS_NODE + OUString('/') + _rOption + OUString('/') );
176 bool SvtOptionsDlgOptions_Impl::IsHidden( const OUString& _rPath ) const
178 bool bRet = false;
179 OptionNodeList::const_iterator pIter = m_aOptionNodeList.find( _rPath );
180 if ( pIter != m_aOptionNodeList.end() )
181 bRet = pIter->second;
182 return bRet;
185 bool SvtOptionsDlgOptions_Impl::IsGroupHidden( const OUString& _rGroup ) const
187 return IsHidden( getGroupPath( _rGroup ) );
190 bool SvtOptionsDlgOptions_Impl::IsPageHidden( const OUString& _rPage, const OUString& _rGroup ) const
192 return IsHidden( getGroupPath( _rGroup ) + getPagePath( _rPage ) );
195 bool SvtOptionsDlgOptions_Impl::IsOptionHidden(
196 const OUString& _rOption, const OUString& _rPage, const OUString& _rGroup ) const
198 return IsHidden( getGroupPath( _rGroup ) + getPagePath( _rPage ) + getOptionPath( _rOption ) );
201 SvtOptionsDialogOptions::SvtOptionsDialogOptions()
203 // Global access, must be guarded (multithreading)
204 ::osl::MutexGuard aGuard( SvtOptionsDlgOptions_Impl::getInitMutex() );
205 ++nRefCount;
206 if ( !pOptions )
208 pOptions = new SvtOptionsDlgOptions_Impl;
210 ItemHolder1::holdConfigItem( E_OPTIONSDLGOPTIONS );
212 m_pImp = pOptions;
215 SvtOptionsDialogOptions::~SvtOptionsDialogOptions()
217 // Global access, must be guarded (multithreading)
218 ::osl::MutexGuard aGuard( SvtOptionsDlgOptions_Impl::getInitMutex() );
219 if ( !--nRefCount )
221 if ( pOptions->IsModified() )
222 pOptions->Commit();
223 delete pOptions;
224 pOptions = NULL;
228 bool SvtOptionsDialogOptions::IsGroupHidden( const OUString& _rGroup ) const
230 return m_pImp->IsGroupHidden( _rGroup );
233 bool SvtOptionsDialogOptions::IsPageHidden( const OUString& _rPage, const OUString& _rGroup ) const
235 return m_pImp->IsPageHidden( _rPage, _rGroup );
238 bool SvtOptionsDialogOptions::IsOptionHidden(
239 const OUString& _rOption, const OUString& _rPage, const OUString& _rGroup ) const
241 return m_pImp->IsOptionHidden( _rOption, _rPage, _rGroup );
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */