bump product version to 4.1.6.2
[LibreOffice.git] / unotools / source / config / optionsdlg.cxx
blobf204d203fc976b6c61ef535446152131d3b328ec
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 .
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>
29 #include <boost/unordered_map.hpp>
30 #include "itemholder1.hxx"
32 using namespace utl;
33 using namespace com::sun::star::beans ;
34 using namespace com::sun::star::uno;
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" )
43 static SvtOptionsDlgOptions_Impl* pOptions = NULL;
44 static sal_Int32 nRefCount = 0;
46 class SvtOptionsDlgOptions_Impl : public utl::ConfigItem
48 private:
49 struct OUStringHashCode
51 size_t operator()( const OUString& sString ) const
53 return sString.hashCode();
57 typedef boost::unordered_map< OUString, sal_Bool, OUStringHashCode, ::std::equal_to< OUString > > OptionNodeList;
59 OUString m_sPathDelimiter;
60 OptionNodeList m_aOptionNodeList;
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;
66 public:
67 SvtOptionsDlgOptions_Impl();
69 virtual void Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames );
70 virtual void Commit();
72 static ::osl::Mutex & getInitMutex();
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;
82 namespace
84 class theOptionsDlgOptions_ImplMutex : public rtl::Static<osl::Mutex, theOptionsDlgOptions_ImplMutex>{};
87 ::osl::Mutex & SvtOptionsDlgOptions_Impl::getInitMutex()
89 return theOptionsDlgOptions_ImplMutex::get();
92 // -----------------------------------------------------------------------
94 SvtOptionsDlgOptions_Impl::SvtOptionsDlgOptions_Impl()
95 : ConfigItem( OUString( CFG_FILENAME ) ),
97 m_sPathDelimiter( "/" ),
98 m_aOptionNodeList( OptionNodeList() )
101 OUString sRootNode( ROOT_NODE );
102 Sequence< OUString > aNodeSeq = GetNodeNames( sRootNode );
103 OUString sNode( sRootNode + m_sPathDelimiter );
104 sal_uInt32 nCount = aNodeSeq.getLength();
105 for ( sal_uInt32 n = 0; n < nCount; n++ )
107 OUString sSubNode( sNode + aNodeSeq[n] );
108 ReadNode( sSubNode, NT_Group );
112 // -----------------------------------------------------------------------
114 void SvtOptionsDlgOptions_Impl::Commit()
116 // nothing to commit
119 // -----------------------------------------------------------------------
121 void SvtOptionsDlgOptions_Impl::Notify( const Sequence< OUString >& )
123 // nothing to notify
126 void SvtOptionsDlgOptions_Impl::ReadNode( const OUString& _rNode, NodeType _eType )
128 OUString sNode( _rNode + m_sPathDelimiter );
129 OUString sSet;
130 sal_Int32 nLen = 0;
131 switch ( _eType )
133 case NT_Group :
135 sSet = PAGES_NODE;
136 nLen = 2;
137 break;
140 case NT_Page :
142 sSet = OPTIONS_NODE;
143 nLen = 2;
144 break;
147 case NT_Option :
149 nLen = 1;
150 break;
154 Sequence< OUString > lResult( nLen );
155 lResult[0] = OUString( sNode + PROPERTY_HIDE );
156 if ( _eType != NT_Option )
157 lResult[1] = OUString( sNode + sSet );
159 Sequence< Any > aValues;
160 aValues = GetProperties( lResult );
161 sal_Bool bHide = sal_False;
162 if ( aValues[0] >>= bHide )
163 m_aOptionNodeList.insert( OptionNodeList::value_type( sNode, bHide ) );
165 if ( _eType != NT_Option )
167 OUString sNodes( sNode + sSet );
168 Sequence< OUString > aNodes = GetNodeNames( sNodes );
169 if ( aNodes.getLength() > 0 )
171 for ( sal_uInt32 n = 0; n < (sal_uInt32)aNodes.getLength(); ++n )
173 OUString sSubNodeName( sNodes + m_sPathDelimiter + aNodes[n] );
174 ReadNode( sSubNodeName, _eType == NT_Group ? NT_Page : NT_Option );
180 // -----------------------------------------------------------------------
182 OUString getGroupPath( const OUString& _rGroup )
184 return OUString( ROOT_NODE + OUString('/') + _rGroup + OUString('/') );
186 OUString getPagePath( const OUString& _rPage )
188 return OUString( PAGES_NODE + OUString('/') + _rPage + OUString('/') );
190 OUString getOptionPath( const OUString& _rOption )
192 return OUString( OPTIONS_NODE + OUString('/') + _rOption + OUString('/') );
195 // -----------------------------------------------------------------------
197 sal_Bool SvtOptionsDlgOptions_Impl::IsHidden( const OUString& _rPath ) const
199 sal_Bool bRet = sal_False;
200 OptionNodeList::const_iterator pIter = m_aOptionNodeList.find( _rPath );
201 if ( pIter != m_aOptionNodeList.end() )
202 bRet = pIter->second;
203 return bRet;
206 // -----------------------------------------------------------------------
208 sal_Bool SvtOptionsDlgOptions_Impl::IsGroupHidden( const OUString& _rGroup ) const
210 return IsHidden( getGroupPath( _rGroup ) );
213 // -----------------------------------------------------------------------
215 sal_Bool SvtOptionsDlgOptions_Impl::IsPageHidden( const OUString& _rPage, const OUString& _rGroup ) const
217 return IsHidden( getGroupPath( _rGroup ) + getPagePath( _rPage ) );
220 // -----------------------------------------------------------------------
222 sal_Bool SvtOptionsDlgOptions_Impl::IsOptionHidden(
223 const OUString& _rOption, const OUString& _rPage, const OUString& _rGroup ) const
225 return IsHidden( getGroupPath( _rGroup ) + getPagePath( _rPage ) + getOptionPath( _rOption ) );
228 // -----------------------------------------------------------------------
230 SvtOptionsDialogOptions::SvtOptionsDialogOptions()
232 // Global access, must be guarded (multithreading)
233 ::osl::MutexGuard aGuard( SvtOptionsDlgOptions_Impl::getInitMutex() );
234 ++nRefCount;
235 if ( !pOptions )
237 pOptions = new SvtOptionsDlgOptions_Impl;
239 ItemHolder1::holdConfigItem( E_OPTIONSDLGOPTIONS );
241 m_pImp = pOptions;
244 // -----------------------------------------------------------------------
246 SvtOptionsDialogOptions::~SvtOptionsDialogOptions()
248 // Global access, must be guarded (multithreading)
249 ::osl::MutexGuard aGuard( SvtOptionsDlgOptions_Impl::getInitMutex() );
250 if ( !--nRefCount )
252 if ( pOptions->IsModified() )
253 pOptions->Commit();
254 delete pOptions;
255 pOptions = NULL;
259 sal_Bool SvtOptionsDialogOptions::IsGroupHidden( const OUString& _rGroup ) const
261 return m_pImp->IsGroupHidden( _rGroup );
264 sal_Bool SvtOptionsDialogOptions::IsPageHidden( const OUString& _rPage, const OUString& _rGroup ) const
266 return m_pImp->IsPageHidden( _rPage, _rGroup );
269 sal_Bool SvtOptionsDialogOptions::IsOptionHidden(
270 const OUString& _rOption, const OUString& _rPage, const OUString& _rGroup ) const
272 return m_pImp->IsOptionHidden( _rOption, _rPage, _rGroup );
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */