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 .
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"
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
48 class SvtHelpOptions_Impl
: public utl::ConfigItem
50 sal_Bool bExtendedHelp
;
52 sal_Bool bWelcomeScreen
;
55 String sHelpStyleSheet
;
57 DECLARE_STL_USTRINGACCESS_MAP( sal_Int32
, MapString2Int
);
58 MapString2Int aURLIgnoreCounters
;
59 ::osl::Mutex aIgnoreCounterSafety
;
61 Sequence
< OUString
> GetPropertyNames();
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
[] =
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
;
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();
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
)
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() )
163 sal_Bool bTmp
= sal_Bool();
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();
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
++ )
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
);
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() );
267 RTL_LOGFILE_CONTEXT(aLog
, "svtools ( ??? ) ::SvtHelpOptions_Impl::ctor()");
268 pOptions
= new SvtHelpOptions_Impl
;
270 svtools::ItemHolder2::holdConfigItem(E_HELPOPTIONS
);
275 // -----------------------------------------------------------------------
277 SvtHelpOptions::~SvtHelpOptions()
279 // Global access, must be guarded (multithreading)
280 ::osl::MutexGuard
aGuard( SvtHelpOptions_Impl::getInitMutex() );
283 if ( pOptions
->IsModified() )
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: */