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 <sal/config.h>
24 #include <svtools/helpopt.hxx>
25 #include <unotools/configmgr.hxx>
26 #include <unotools/configitem.hxx>
27 #include <tools/debug.hxx>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <vcl/help.hxx>
31 #include <osl/mutex.hxx>
33 #include "itemholder2.hxx"
36 using namespace com::sun::star::uno
;
37 using namespace com::sun::star
;
40 static SvtHelpOptions_Impl
* pOptions
= NULL
;
41 static sal_Int32 nRefCount
= 0;
43 #define EXTENDEDHELP 0
49 class SvtHelpOptions_Impl
: public utl::ConfigItem
56 OUString sHelpStyleSheet
;
58 typedef std::map
<OUString
, sal_Int32
> MapString2Int
;
59 MapString2Int aURLIgnoreCounters
;
61 static Sequence
< OUString
> GetPropertyNames();
63 virtual void ImplCommit() SAL_OVERRIDE
;
66 SvtHelpOptions_Impl();
68 virtual void Notify( const com::sun::star::uno::Sequence
< OUString
>& aPropertyNames
) SAL_OVERRIDE
;
69 void Load( const ::com::sun::star::uno::Sequence
< OUString
>& aPropertyNames
);
71 void SetExtendedHelp( bool b
) { bExtendedHelp
= b
; SetModified(); }
72 bool IsExtendedHelp() const { return bExtendedHelp
; }
73 void SetHelpTips( bool b
) { bHelpTips
= b
; SetModified(); }
74 bool IsHelpTips() const { return bHelpTips
; }
76 void SetWelcomeScreen( bool b
) { bWelcomeScreen
= b
; SetModified(); }
77 bool IsWelcomeScreen() const { return bWelcomeScreen
; }
78 OUString
GetSystem() const { return aSystem
; }
80 const OUString
& GetHelpStyleSheet()const{return sHelpStyleSheet
;}
81 void SetHelpStyleSheet(const OUString
& rStyleSheet
){sHelpStyleSheet
= rStyleSheet
; SetModified();}
83 static ::osl::Mutex
& getInitMutex();
86 Sequence
< OUString
> SvtHelpOptions_Impl::GetPropertyNames()
88 static const char* aPropNames
[] =
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
] );
106 ::osl::Mutex
& SvtHelpOptions_Impl::getInitMutex()
108 static ::osl::Mutex
*pMutex
= 0;
112 ::osl::MutexGuard
guard( ::osl::Mutex::getGlobalMutex() );
115 static ::osl::Mutex mutex
;
125 SvtHelpOptions_Impl::SvtHelpOptions_Impl()
126 : ConfigItem( OUString( "Office.Common/Help" ) )
127 , bExtendedHelp( false )
129 , bWelcomeScreen( false )
131 Sequence
< OUString
> aNames
= GetPropertyNames();
133 EnableNotification( aNames
);
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
)
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" );
161 if ( pValues
[nProp
].hasValue() )
165 sal_Int32 nTmpInt
= 0;
166 if ( pValues
[nProp
] >>= bTmp
)
168 switch ( lcl_MapPropertyName(rPropertyNames
[nProp
], aInternalPropertyNames
) )
171 bExtendedHelp
= bTmp
;
177 SAL_WARN( "svtools.config", "Wrong Member!" );
181 else if ( pValues
[nProp
] >>= aTmpStr
)
193 sHelpStyleSheet
= aTmpStr
;
196 SAL_WARN( "svtools.config", "Wrong Member!" );
200 else if ( pValues
[nProp
] >>= nTmpInt
)
202 SAL_WARN( "svtools.config", "Wrong Member!" );
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();
219 void SvtHelpOptions_Impl::ImplCommit()
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
++ )
229 pValues
[nProp
] <<= bExtendedHelp
;
233 pValues
[nProp
] <<= bHelpTips
;
237 pValues
[nProp
] <<= OUString(aLocale
);
241 pValues
[nProp
] <<= OUString(aSystem
);
244 pValues
[nProp
] <<= OUString(sHelpStyleSheet
);
250 PutProperties( aNames
, aValues
);
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() );
267 pOptions
= new SvtHelpOptions_Impl
;
269 svtools::ItemHolder2::holdConfigItem(E_HELPOPTIONS
);
276 SvtHelpOptions::~SvtHelpOptions()
278 // Global access, must be guarded (multithreading)
279 ::osl::MutexGuard
aGuard( SvtHelpOptions_Impl::getInitMutex() );
282 if ( pOptions
->IsModified() )
288 void SvtHelpOptions::SetExtendedHelp( bool b
)
290 pImp
->SetExtendedHelp( b
);
293 bool SvtHelpOptions::IsExtendedHelp() const
295 return pImp
->IsExtendedHelp();
298 void SvtHelpOptions::SetHelpTips( bool b
)
300 pImp
->SetHelpTips( b
);
303 bool SvtHelpOptions::IsHelpTips() const
305 return pImp
->IsHelpTips();
310 void SvtHelpOptions::SetWelcomeScreen( bool b
)
312 pImp
->SetWelcomeScreen( b
);
315 bool SvtHelpOptions::IsWelcomeScreen() const
317 return pImp
->IsWelcomeScreen();
320 OUString
SvtHelpOptions::GetSystem() const
322 return pImp
->GetSystem();
325 const OUString
& SvtHelpOptions::GetHelpStyleSheet()const
327 return pImp
->GetHelpStyleSheet();
330 void SvtHelpOptions::SetHelpStyleSheet(const OUString
& rStyleSheet
)
332 pImp
->SetHelpStyleSheet(rStyleSheet
);
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */