fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / config / helpopt.cxx
bloba51ed04b7d15c70a5fafb7cc3fab01a4fcf9e866
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 .
21 #include <svtools/helpopt.hxx>
22 #include <unotools/configmgr.hxx>
23 #include <unotools/configitem.hxx>
24 #include <tools/debug.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <vcl/help.hxx>
28 #include <osl/mutex.hxx>
29 #include <comphelper/stl_types.hxx>
31 #include <rtl/logfile.hxx>
32 #include "itemholder2.hxx"
34 using namespace utl;
35 using namespace com::sun::star::uno;
36 using namespace com::sun::star;
39 static SvtHelpOptions_Impl* pOptions = NULL;
40 static sal_Int32 nRefCount = 0;
42 #define EXTENDEDHELP 0
43 #define HELPTIPS 1
44 #define LOCALE 2
45 #define SYSTEM 3
46 #define STYLESHEET 4
48 class SvtHelpOptions_Impl : public utl::ConfigItem
50 sal_Bool bExtendedHelp;
51 sal_Bool bHelpTips;
52 sal_Bool bWelcomeScreen;
53 String aLocale;
54 String aSystem;
55 String sHelpStyleSheet;
57 DECLARE_STL_USTRINGACCESS_MAP( sal_Int32, MapString2Int );
58 MapString2Int aURLIgnoreCounters;
59 ::osl::Mutex aIgnoreCounterSafety;
61 Sequence< OUString > GetPropertyNames();
63 public:
64 SvtHelpOptions_Impl();
66 virtual void Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames );
67 void Load( const ::com::sun::star::uno::Sequence< OUString>& aPropertyNames);
68 virtual void Commit();
70 void SetExtendedHelp( sal_Bool b ) { bExtendedHelp= b; SetModified(); }
71 sal_Bool IsExtendedHelp() const { return bExtendedHelp; }
72 void SetHelpTips( sal_Bool b ) { bHelpTips = b; SetModified(); }
73 sal_Bool IsHelpTips() const { return bHelpTips; }
75 void SetWelcomeScreen( sal_Bool b ) { bWelcomeScreen = b; SetModified(); }
76 sal_Bool IsWelcomeScreen() const { return bWelcomeScreen; }
77 String GetLocale() const { return aLocale; }
78 String GetSystem() const { return aSystem; }
80 const String& GetHelpStyleSheet()const{return sHelpStyleSheet;}
81 void SetHelpStyleSheet(const String& rStyleSheet){sHelpStyleSheet = rStyleSheet; SetModified();}
83 static ::osl::Mutex & getInitMutex();
86 Sequence< OUString > SvtHelpOptions_Impl::GetPropertyNames()
88 static const char* aPropNames[] =
90 "ExtendedTip",
91 "Tip",
92 "Locale",
93 "System",
94 "HelpStyleSheet"
97 const int nCount = sizeof( aPropNames ) / sizeof( const char* );
98 Sequence< OUString > aNames( nCount );
99 OUString* pNames = aNames.getArray();
100 for ( int i = 0; i < nCount; i++ )
101 pNames[i] = OUString::createFromAscii( aPropNames[i] );
103 return aNames;
106 ::osl::Mutex & SvtHelpOptions_Impl::getInitMutex()
108 static ::osl::Mutex *pMutex = 0;
110 if( ! pMutex )
112 ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
113 if( ! pMutex )
115 static ::osl::Mutex mutex;
116 pMutex = &mutex;
119 return *pMutex;
123 // -----------------------------------------------------------------------
125 SvtHelpOptions_Impl::SvtHelpOptions_Impl()
126 : ConfigItem( OUString( "Office.Common/Help" ) )
127 , bExtendedHelp( sal_False )
128 , bHelpTips( sal_True )
129 , bWelcomeScreen( sal_False )
131 Sequence< OUString > aNames = GetPropertyNames();
132 Load( aNames );
133 EnableNotification( aNames );
136 // -----------------------------------------------------------------------
137 static int lcl_MapPropertyName( const OUString rCompare,
138 const uno::Sequence< OUString>& aInternalPropertyNames)
140 for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
142 if( aInternalPropertyNames[nProp] == rCompare )
143 return nProp;
145 return -1;
148 void SvtHelpOptions_Impl::Load(const uno::Sequence< OUString>& rPropertyNames)
150 const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
151 Sequence< Any > aValues = GetProperties( rPropertyNames );
152 const Any* pValues = aValues.getConstArray();
153 DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" );
154 if ( aValues.getLength() == rPropertyNames.getLength() )
156 for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ )
158 #if OSL_DEBUG_LEVEL > 1
159 DBG_ASSERT( pValues[nProp].hasValue(), "property value missing" );
160 #endif
161 if ( pValues[nProp].hasValue() )
163 sal_Bool bTmp = sal_Bool();
164 OUString aTmpStr;
165 sal_Int32 nTmpInt = 0;
166 if ( pValues[nProp] >>= bTmp )
168 switch ( lcl_MapPropertyName(rPropertyNames[nProp], aInternalPropertyNames) )
170 case EXTENDEDHELP :
171 bExtendedHelp = bTmp;
172 break;
173 case HELPTIPS :
174 bHelpTips = bTmp;
175 break;
176 default:
177 SAL_WARN( "svtools.config", "Wrong Member!" );
178 break;
181 else if ( pValues[nProp] >>= aTmpStr )
183 switch ( nProp )
185 case LOCALE:
186 aLocale = aTmpStr;
187 break;
189 case SYSTEM:
190 aSystem = aTmpStr;
191 break;
192 case STYLESHEET :
193 sHelpStyleSheet = aTmpStr;
194 break;
195 default:
196 SAL_WARN( "svtools.config", "Wrong Member!" );
197 break;
200 else if ( pValues[nProp] >>= nTmpInt )
202 SAL_WARN( "svtools.config", "Wrong Member!" );
204 else
206 SAL_WARN( "svtools.config", "Wrong Type!" );
210 if ( IsHelpTips() != Help::IsQuickHelpEnabled() )
211 IsHelpTips() ? Help::EnableQuickHelp() : Help::DisableQuickHelp();
212 if ( IsExtendedHelp() != Help::IsBalloonHelpEnabled() )
213 IsExtendedHelp() ? Help::EnableBalloonHelp() : Help::DisableBalloonHelp();
217 // -----------------------------------------------------------------------
219 void SvtHelpOptions_Impl::Commit()
221 Sequence< OUString > aNames = GetPropertyNames();
222 Sequence< Any > aValues( aNames.getLength() );
223 Any* pValues = aValues.getArray();
224 for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
226 switch ( nProp )
228 case EXTENDEDHELP :
229 pValues[nProp] <<= bExtendedHelp;
230 break;
232 case HELPTIPS :
233 pValues[nProp] <<= bHelpTips;
234 break;
236 case LOCALE:
237 pValues[nProp] <<= OUString(aLocale);
238 break;
240 case SYSTEM:
241 pValues[nProp] <<= OUString(aSystem);
242 break;
243 case STYLESHEET :
244 pValues[nProp] <<= OUString(sHelpStyleSheet);
245 break;
250 PutProperties( aNames, aValues );
253 // -----------------------------------------------------------------------
255 void SvtHelpOptions_Impl::Notify( const Sequence<OUString>& aPropertyNames )
257 Load( aPropertyNames );
260 SvtHelpOptions::SvtHelpOptions()
262 // Global access, must be guarded (multithreading)
263 ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
264 ++nRefCount;
265 if ( !pOptions )
267 RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? ) ::SvtHelpOptions_Impl::ctor()");
268 pOptions = new SvtHelpOptions_Impl;
270 svtools::ItemHolder2::holdConfigItem(E_HELPOPTIONS);
272 pImp = pOptions;
275 // -----------------------------------------------------------------------
277 SvtHelpOptions::~SvtHelpOptions()
279 // Global access, must be guarded (multithreading)
280 ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
281 if ( !--nRefCount )
283 if ( pOptions->IsModified() )
284 pOptions->Commit();
285 DELETEZ( pOptions );
289 void SvtHelpOptions::SetExtendedHelp( sal_Bool b )
291 pImp->SetExtendedHelp( b );
294 sal_Bool SvtHelpOptions::IsExtendedHelp() const
296 return pImp->IsExtendedHelp();
299 void SvtHelpOptions::SetHelpTips( sal_Bool b )
301 pImp->SetHelpTips( b );
304 sal_Bool SvtHelpOptions::IsHelpTips() const
306 return pImp->IsHelpTips();
309 // -----------------------------------------------------------------------
311 void SvtHelpOptions::SetWelcomeScreen( sal_Bool b )
313 pImp->SetWelcomeScreen( b );
316 sal_Bool SvtHelpOptions::IsWelcomeScreen() const
318 return pImp->IsWelcomeScreen();
321 String SvtHelpOptions::GetSystem() const
323 return pImp->GetSystem();
326 const String& SvtHelpOptions::GetHelpStyleSheet()const
328 return pImp->GetHelpStyleSheet();
331 void SvtHelpOptions::SetHelpStyleSheet(const String& rStyleSheet)
333 pImp->SetHelpStyleSheet(rStyleSheet);
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */