LibreOffice Module unotools (master) 1
optionsdlg.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
23#include <com/sun/star/uno/Any.hxx>
24#include <com/sun/star/uno/Sequence.hxx>
25
26#include <cassert>
27
28using namespace com::sun::star::beans;
29using namespace com::sun::star::uno;
30
31constexpr OUStringLiteral ROOT_NODE = u"OptionsDialogGroups";
32constexpr OUStringLiteral PAGES_NODE = u"Pages";
33constexpr OUStringLiteral OPTIONS_NODE = u"Options";
34
35namespace {
36 enum NodeType{ NT_Group, NT_Page, NT_Option };
37}
38constexpr OUStringLiteral g_sPathDelimiter = u"/";
39static void ReadNode(
42 std::u16string_view _rNode, NodeType _eType );
43
44
46{
49 OUString sNode( ROOT_NODE + g_sPathDelimiter );
50 for ( const auto& rNode : aNodeSeq )
51 {
52 OUString sSubNode( sNode + rNode );
53 ReadNode( xHierarchyAccess, m_aOptionNodeList, sSubNode, NT_Group );
54 }
55}
56
57
58static void ReadNode(
61 std::u16string_view _rNode, NodeType _eType )
62{
63 OUString sNode( _rNode + g_sPathDelimiter );
64 OUString sSet;
65 sal_Int32 nLen = 0;
66 switch ( _eType )
67 {
68 case NT_Group :
69 {
70 sSet = PAGES_NODE;
71 nLen = 2;
72 break;
73 }
74
75 case NT_Page :
76 {
77 sSet = OPTIONS_NODE;
78 nLen = 2;
79 break;
80 }
81
82 case NT_Option :
83 {
84 nLen = 1;
85 break;
86 }
87 }
88
89 assert(nLen > 0);
90
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;
96
97 Sequence< Any > aValues = utl::ConfigItem::GetProperties( xHierarchyAccess, lResult, /*bAllLocales*/false );
98 bool bHide = false;
99 if ( aValues[0] >>= bHide )
100 aOptionNodeList.emplace( sNode, bHide );
101
102 if ( _eType != NT_Option )
103 {
104 OUString sNodes( sNode + sSet );
106 for ( const auto& rNode : aNodes )
107 {
108 OUString sSubNodeName( sNodes + g_sPathDelimiter + rNode );
109 ReadNode( xHierarchyAccess, aOptionNodeList, sSubNodeName, _eType == NT_Group ? NT_Page : NT_Option );
110 }
111 }
112}
113
114static OUString getGroupPath( std::u16string_view _rGroup )
115{
116 return OUString( OUString::Concat(ROOT_NODE) + "/" + _rGroup + "/" );
117}
118static OUString getPagePath( std::u16string_view _rPage )
119{
120 return OUString( OUString::Concat(PAGES_NODE) + "/" + _rPage + "/" );
121}
122static OUString getOptionPath( std::u16string_view _rOption )
123{
124 return OUString( OUString::Concat(OPTIONS_NODE) + "/" + _rOption + "/" );
125}
126
127bool SvtOptionsDialogOptions::IsHidden( const OUString& _rPath ) const
128{
129 bool bRet = false;
130 OptionNodeList::const_iterator pIter = m_aOptionNodeList.find( _rPath );
131 if ( pIter != m_aOptionNodeList.end() )
132 bRet = pIter->second;
133 return bRet;
134}
135
136bool SvtOptionsDialogOptions::IsGroupHidden( std::u16string_view _rGroup ) const
137{
138 return IsHidden( getGroupPath( _rGroup ) );
139}
140
141bool SvtOptionsDialogOptions::IsPageHidden( std::u16string_view _rPage, std::u16string_view _rGroup ) const
142{
143 return IsHidden( getGroupPath( _rGroup ) + getPagePath( _rPage ) );
144}
145
147 std::u16string_view _rOption, std::u16string_view _rPage, std::u16string_view _rGroup ) const
148{
149 return IsHidden( getGroupPath( _rGroup ) + getPagePath( _rPage ) + getOptionPath( _rOption ) );
150}
151
152/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionNodeList m_aOptionNodeList
Definition: optionsdlg.hxx:45
bool IsPageHidden(std::u16string_view _rPage, std::u16string_view _rGroup) const
Definition: optionsdlg.cxx:141
bool IsHidden(const OUString &_rPath) const
Definition: optionsdlg.cxx:127
std::unordered_map< OUString, bool > OptionNodeList
Definition: optionsdlg.hxx:32
bool IsOptionHidden(std::u16string_view _rOption, std::u16string_view _rPage, std::u16string_view _rGroup) const
Definition: optionsdlg.cxx:146
bool IsGroupHidden(std::u16string_view _rGroup) const
Definition: optionsdlg.cxx:136
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
css::uno::Sequence< OUString > GetNodeNames(const OUString &rNode)
Definition: configitem.cxx:685
static SAL_DLLPRIVATE css::uno::Reference< css::container::XHierarchicalNameAccess > acquireTree(utl::ConfigItem const &item)
Definition: configmgr.cxx:117
float u
NodeType
static void ReadNode(const Reference< css::container::XHierarchicalNameAccess > &xHierarchyAccess, SvtOptionsDialogOptions::OptionNodeList &aOptionNodeList, std::u16string_view _rNode, NodeType _eType)
Definition: optionsdlg.cxx:58
constexpr OUStringLiteral g_sPathDelimiter
Definition: optionsdlg.cxx:38
constexpr OUStringLiteral PAGES_NODE
Definition: optionsdlg.cxx:32
static OUString getGroupPath(std::u16string_view _rGroup)
Definition: optionsdlg.cxx:114
static OUString getPagePath(std::u16string_view _rPage)
Definition: optionsdlg.cxx:118
static OUString getOptionPath(std::u16string_view _rOption)
Definition: optionsdlg.cxx:122
constexpr OUStringLiteral OPTIONS_NODE
Definition: optionsdlg.cxx:33
constexpr OUStringLiteral ROOT_NODE
Definition: optionsdlg.cxx:31