update emoji autocorrect entries from po-files
[LibreOffice.git] / unotools / source / config / optionsdlg.cxx
blob2683a8870acba281bbac7af21d8b23f03ef90f0f
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 .
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>
31 using namespace utl;
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
45 private:
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;
57 public:
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;
72 namespace
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()
102 // nothing to commit
105 void SvtOptionsDlgOptions_Impl::Notify( const Sequence< OUString >& )
107 // nothing to notify
110 void SvtOptionsDlgOptions_Impl::ReadNode( const OUString& _rNode, NodeType _eType )
112 OUString sNode( _rNode + m_sPathDelimiter );
113 OUString sSet;
114 sal_Int32 nLen = 0;
115 switch ( _eType )
117 case NT_Group :
119 sSet = PAGES_NODE;
120 nLen = 2;
121 break;
124 case NT_Page :
126 sSet = OPTIONS_NODE;
127 nLen = 2;
128 break;
131 case NT_Option :
133 nLen = 1;
134 break;
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 );
145 bool bHide = false;
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
179 bool bRet = false;
180 OptionNodeList::const_iterator pIter = m_aOptionNodeList.find( _rPath );
181 if ( pIter != m_aOptionNodeList.end() )
182 bRet = pIter->second;
183 return bRet;
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() );
206 ++nRefCount;
207 if ( !pOptions )
209 pOptions = new SvtOptionsDlgOptions_Impl;
211 ItemHolder1::holdConfigItem( E_OPTIONSDLGOPTIONS );
213 m_pImp = pOptions;
216 SvtOptionsDialogOptions::~SvtOptionsDialogOptions()
218 // Global access, must be guarded (multithreading)
219 ::osl::MutexGuard aGuard( SvtOptionsDlgOptions_Impl::getInitMutex() );
220 if ( !--nRefCount )
222 if ( pOptions->IsModified() )
223 pOptions->Commit();
224 delete pOptions;
225 pOptions = NULL;
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: */