1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "itemholder1.hxx"
29 #include <unordered_map>
32 using namespace com::sun::star::beans
;
33 using namespace com::sun::star::uno
;
35 #define CFG_FILENAME OUString( "Office.OptionsDialog" )
36 #define ROOT_NODE "OptionsDialogGroups"
37 #define PAGES_NODE "Pages"
38 #define OPTIONS_NODE "Options"
40 static SvtOptionsDlgOptions_Impl
* pOptions
= NULL
;
41 static sal_Int32 nRefCount
= 0;
43 class SvtOptionsDlgOptions_Impl
: public utl::ConfigItem
46 typedef std::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 virtual void ImplCommit() SAL_OVERRIDE
;
58 SvtOptionsDlgOptions_Impl();
60 virtual void Notify( const com::sun::star::uno::Sequence
< OUString
>& aPropertyNames
) SAL_OVERRIDE
;
62 static ::osl::Mutex
& getInitMutex();
64 bool IsGroupHidden ( const OUString
& _rGroup
) const;
65 bool IsPageHidden ( const OUString
& _rPage
,
66 const OUString
& _rGroup
) const;
67 bool IsOptionHidden ( const OUString
& _rOption
,
68 const OUString
& _rPage
,
69 const OUString
& _rGroup
) const;
74 class theOptionsDlgOptions_ImplMutex
: public rtl::Static
<osl::Mutex
, theOptionsDlgOptions_ImplMutex
>{};
77 ::osl::Mutex
& SvtOptionsDlgOptions_Impl::getInitMutex()
79 return theOptionsDlgOptions_ImplMutex::get();
82 SvtOptionsDlgOptions_Impl::SvtOptionsDlgOptions_Impl()
83 : ConfigItem( OUString( CFG_FILENAME
) ),
85 m_sPathDelimiter( "/" ),
86 m_aOptionNodeList( OptionNodeList() )
89 OUString
sRootNode( ROOT_NODE
);
90 Sequence
< OUString
> aNodeSeq
= GetNodeNames( sRootNode
);
91 OUString
sNode( sRootNode
+ m_sPathDelimiter
);
92 sal_uInt32 nCount
= aNodeSeq
.getLength();
93 for ( sal_uInt32 n
= 0; n
< nCount
; n
++ )
95 OUString
sSubNode( sNode
+ aNodeSeq
[n
] );
96 ReadNode( sSubNode
, NT_Group
);
100 void SvtOptionsDlgOptions_Impl::ImplCommit()
105 void SvtOptionsDlgOptions_Impl::Notify( const Sequence
< OUString
>& )
110 void SvtOptionsDlgOptions_Impl::ReadNode( const OUString
& _rNode
, NodeType _eType
)
112 OUString
sNode( _rNode
+ m_sPathDelimiter
);
138 Sequence
< OUString
> lResult( nLen
);
139 lResult
[0] = OUString( sNode
+ "Hide" );
140 if ( _eType
!= NT_Option
)
141 lResult
[1] = OUString( sNode
+ sSet
);
143 Sequence
< Any
> aValues
;
144 aValues
= GetProperties( lResult
);
146 if ( aValues
[0] >>= bHide
)
147 m_aOptionNodeList
.insert( OptionNodeList::value_type( sNode
, bHide
) );
149 if ( _eType
!= NT_Option
)
151 OUString
sNodes( sNode
+ sSet
);
152 Sequence
< OUString
> aNodes
= GetNodeNames( sNodes
);
153 if ( aNodes
.getLength() > 0 )
155 for ( sal_uInt32 n
= 0; n
< (sal_uInt32
)aNodes
.getLength(); ++n
)
157 OUString
sSubNodeName( sNodes
+ m_sPathDelimiter
+ aNodes
[n
] );
158 ReadNode( sSubNodeName
, _eType
== NT_Group
? NT_Page
: NT_Option
);
164 OUString
getGroupPath( const OUString
& _rGroup
)
166 return OUString( ROOT_NODE
"/" + _rGroup
+ "/" );
168 OUString
getPagePath( const OUString
& _rPage
)
170 return OUString( PAGES_NODE
"/" + _rPage
+ "/" );
172 OUString
getOptionPath( const OUString
& _rOption
)
174 return OUString( OPTIONS_NODE
"/" + _rOption
+ "/" );
177 bool SvtOptionsDlgOptions_Impl::IsHidden( const OUString
& _rPath
) const
180 OptionNodeList::const_iterator pIter
= m_aOptionNodeList
.find( _rPath
);
181 if ( pIter
!= m_aOptionNodeList
.end() )
182 bRet
= pIter
->second
;
186 bool SvtOptionsDlgOptions_Impl::IsGroupHidden( const OUString
& _rGroup
) const
188 return IsHidden( getGroupPath( _rGroup
) );
191 bool SvtOptionsDlgOptions_Impl::IsPageHidden( const OUString
& _rPage
, const OUString
& _rGroup
) const
193 return IsHidden( getGroupPath( _rGroup
) + getPagePath( _rPage
) );
196 bool SvtOptionsDlgOptions_Impl::IsOptionHidden(
197 const OUString
& _rOption
, const OUString
& _rPage
, const OUString
& _rGroup
) const
199 return IsHidden( getGroupPath( _rGroup
) + getPagePath( _rPage
) + getOptionPath( _rOption
) );
202 SvtOptionsDialogOptions::SvtOptionsDialogOptions()
204 // Global access, must be guarded (multithreading)
205 ::osl::MutexGuard
aGuard( SvtOptionsDlgOptions_Impl::getInitMutex() );
209 pOptions
= new SvtOptionsDlgOptions_Impl
;
211 ItemHolder1::holdConfigItem( E_OPTIONSDLGOPTIONS
);
216 SvtOptionsDialogOptions::~SvtOptionsDialogOptions()
218 // Global access, must be guarded (multithreading)
219 ::osl::MutexGuard
aGuard( SvtOptionsDlgOptions_Impl::getInitMutex() );
222 if ( pOptions
->IsModified() )
229 bool SvtOptionsDialogOptions::IsGroupHidden( const OUString
& _rGroup
) const
231 return m_pImp
->IsGroupHidden( _rGroup
);
234 bool SvtOptionsDialogOptions::IsPageHidden( const OUString
& _rPage
, const OUString
& _rGroup
) const
236 return m_pImp
->IsPageHidden( _rPage
, _rGroup
);
239 bool SvtOptionsDialogOptions::IsOptionHidden(
240 const OUString
& _rOption
, const OUString
& _rPage
, const OUString
& _rGroup
) const
242 return m_pImp
->IsOptionHidden( _rOption
, _rPage
, _rGroup
);
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */