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/configitem.hxx>
22 #include <unotools/configmgr.hxx>
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
28 using namespace com::sun::star::beans
;
29 using namespace com::sun::star::uno
;
31 constexpr OUString ROOT_NODE
= u
"OptionsDialogGroups"_ustr
;
32 constexpr OUString PAGES_NODE
= u
"Pages"_ustr
;
35 enum NodeType
{ NT_Group
, NT_Option
};
37 constexpr OUString g_sPathDelimiter
= u
"/"_ustr
;
39 const Reference
<css::container::XHierarchicalNameAccess
>& xHierarchyAccess
,
40 SvtOptionsDialogOptions::OptionNodeList
& aOptionNodeList
,
41 std::u16string_view _rNode
, NodeType _eType
);
44 SvtOptionsDialogOptions::SvtOptionsDialogOptions()
46 Reference
<css::container::XHierarchicalNameAccess
> xHierarchyAccess
= utl::ConfigManager::acquireTree(u
"Office.OptionsDialog");
47 const Sequence
< OUString
> aNodeSeq
= utl::ConfigItem::GetNodeNames( xHierarchyAccess
, ROOT_NODE
, utl::ConfigNameFormat::LocalNode
);
48 OUString
sNode( ROOT_NODE
+ g_sPathDelimiter
);
49 for ( const auto& rNode
: aNodeSeq
)
51 OUString
sSubNode( sNode
+ rNode
);
52 ReadNode( xHierarchyAccess
, m_aOptionNodeList
, sSubNode
, NT_Group
);
58 const Reference
<css::container::XHierarchicalNameAccess
>& xHierarchyAccess
,
59 SvtOptionsDialogOptions::OptionNodeList
& aOptionNodeList
,
60 std::u16string_view _rNode
, NodeType _eType
)
62 OUString
sNode( _rNode
+ g_sPathDelimiter
);
83 Sequence
< OUString
> lResult( nLen
);
84 auto plResult
= lResult
.getArray();
85 plResult
[0] = sNode
+ "Hide";
86 if ( _eType
!= NT_Option
)
87 plResult
[1] = sNode
+ sSet
;
89 Sequence
< Any
> aValues
= utl::ConfigItem::GetProperties( xHierarchyAccess
, lResult
, /*bAllLocales*/false );
91 if ( aValues
[0] >>= bHide
)
92 aOptionNodeList
.emplace( sNode
, bHide
);
94 if ( _eType
!= NT_Option
)
96 OUString
sNodes( sNode
+ sSet
);
97 const Sequence
< OUString
> aNodes
= utl::ConfigItem::GetNodeNames( xHierarchyAccess
, sNodes
, utl::ConfigNameFormat::LocalNode
);
98 for ( const auto& rNode
: aNodes
)
100 OUString
sSubNodeName( sNodes
+ g_sPathDelimiter
+ rNode
);
101 ReadNode( xHierarchyAccess
, aOptionNodeList
, sSubNodeName
, NT_Option
);
106 static OUString
getGroupPath( std::u16string_view _rGroup
)
108 return OUString( OUString::Concat(ROOT_NODE
) + "/" + _rGroup
+ "/" );
110 static OUString
getPagePath( std::u16string_view _rPage
)
112 return OUString( OUString::Concat(PAGES_NODE
) + "/" + _rPage
+ "/" );
115 bool SvtOptionsDialogOptions::IsHidden( const OUString
& _rPath
) const
118 OptionNodeList::const_iterator pIter
= m_aOptionNodeList
.find( _rPath
);
119 if ( pIter
!= m_aOptionNodeList
.end() )
120 bRet
= pIter
->second
;
124 bool SvtOptionsDialogOptions::IsGroupHidden( std::u16string_view _rGroup
) const
126 return IsHidden( getGroupPath( _rGroup
) );
129 bool SvtOptionsDialogOptions::IsPageHidden( std::u16string_view _rPage
, std::u16string_view _rGroup
) const
131 return IsHidden( getGroupPath( _rGroup
) + getPagePath( _rPage
) );
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */