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 OUStringLiteral ROOT_NODE
= u
"OptionsDialogGroups";
32 constexpr OUStringLiteral PAGES_NODE
= u
"Pages";
33 constexpr OUStringLiteral OPTIONS_NODE
= u
"Options";
36 enum NodeType
{ NT_Group
, NT_Page
, NT_Option
};
38 constexpr OUStringLiteral g_sPathDelimiter
= u
"/";
40 const Reference
<css::container::XHierarchicalNameAccess
>& xHierarchyAccess
,
41 SvtOptionsDialogOptions::OptionNodeList
& aOptionNodeList
,
42 std::u16string_view _rNode
, NodeType _eType
);
45 SvtOptionsDialogOptions::SvtOptionsDialogOptions()
47 Reference
<css::container::XHierarchicalNameAccess
> xHierarchyAccess
= utl::ConfigManager::acquireTree(u
"Office.OptionsDialog");
48 const Sequence
< OUString
> aNodeSeq
= utl::ConfigItem::GetNodeNames( xHierarchyAccess
, ROOT_NODE
, utl::ConfigNameFormat::LocalPath
);
49 OUString
sNode( ROOT_NODE
+ g_sPathDelimiter
);
50 for ( const auto& rNode
: aNodeSeq
)
52 OUString
sSubNode( sNode
+ rNode
);
53 ReadNode( xHierarchyAccess
, m_aOptionNodeList
, sSubNode
, NT_Group
);
59 const Reference
<css::container::XHierarchicalNameAccess
>& xHierarchyAccess
,
60 SvtOptionsDialogOptions::OptionNodeList
& aOptionNodeList
,
61 std::u16string_view _rNode
, NodeType _eType
)
63 OUString
sNode( _rNode
+ g_sPathDelimiter
);
91 Sequence
< OUString
> lResult( nLen
);
92 auto plResult
= lResult
.getArray();
93 plResult
[0] = sNode
+ "Hide";
94 if ( _eType
!= NT_Option
)
95 plResult
[1] = sNode
+ sSet
;
97 Sequence
< Any
> aValues
= utl::ConfigItem::GetProperties( xHierarchyAccess
, lResult
, /*bAllLocales*/false );
99 if ( aValues
[0] >>= bHide
)
100 aOptionNodeList
.emplace( sNode
, bHide
);
102 if ( _eType
!= NT_Option
)
104 OUString
sNodes( sNode
+ sSet
);
105 const Sequence
< OUString
> aNodes
= utl::ConfigItem::GetNodeNames( xHierarchyAccess
, sNodes
, utl::ConfigNameFormat::LocalPath
);
106 for ( const auto& rNode
: aNodes
)
108 OUString
sSubNodeName( sNodes
+ g_sPathDelimiter
+ rNode
);
109 ReadNode( xHierarchyAccess
, aOptionNodeList
, sSubNodeName
, _eType
== NT_Group
? NT_Page
: NT_Option
);
114 static OUString
getGroupPath( std::u16string_view _rGroup
)
116 return OUString( OUString::Concat(ROOT_NODE
) + "/" + _rGroup
+ "/" );
118 static OUString
getPagePath( std::u16string_view _rPage
)
120 return OUString( OUString::Concat(PAGES_NODE
) + "/" + _rPage
+ "/" );
122 static OUString
getOptionPath( std::u16string_view _rOption
)
124 return OUString( OUString::Concat(OPTIONS_NODE
) + "/" + _rOption
+ "/" );
127 bool SvtOptionsDialogOptions::IsHidden( const OUString
& _rPath
) const
130 OptionNodeList::const_iterator pIter
= m_aOptionNodeList
.find( _rPath
);
131 if ( pIter
!= m_aOptionNodeList
.end() )
132 bRet
= pIter
->second
;
136 bool SvtOptionsDialogOptions::IsGroupHidden( std::u16string_view _rGroup
) const
138 return IsHidden( getGroupPath( _rGroup
) );
141 bool SvtOptionsDialogOptions::IsPageHidden( std::u16string_view _rPage
, std::u16string_view _rGroup
) const
143 return IsHidden( getGroupPath( _rGroup
) + getPagePath( _rPage
) );
146 bool SvtOptionsDialogOptions::IsOptionHidden(
147 std::u16string_view _rOption
, std::u16string_view _rPage
, std::u16string_view _rGroup
) const
149 return IsHidden( getGroupPath( _rGroup
) + getPagePath( _rPage
) + getOptionPath( _rOption
) );
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */