Line data Source code
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 :
20 :
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>
30 :
31 : #include <rtl/logfile.hxx>
32 : #include "itemholder2.hxx"
33 :
34 : using namespace utl;
35 : using namespace com::sun::star::uno;
36 : using namespace com::sun::star;
37 :
38 :
39 : static SvtHelpOptions_Impl* pOptions = NULL;
40 : static sal_Int32 nRefCount = 0;
41 :
42 : #define EXTENDEDHELP 0
43 : #define HELPTIPS 1
44 : #define LOCALE 2
45 : #define SYSTEM 3
46 : #define STYLESHEET 4
47 :
48 264 : class SvtHelpOptions_Impl : public utl::ConfigItem
49 : {
50 : sal_Bool bExtendedHelp;
51 : sal_Bool bHelpTips;
52 : sal_Bool bWelcomeScreen;
53 : String aLocale;
54 : String aSystem;
55 : String sHelpStyleSheet;
56 :
57 : DECLARE_STL_USTRINGACCESS_MAP( sal_Int32, MapString2Int );
58 : MapString2Int aURLIgnoreCounters;
59 : ::osl::Mutex aIgnoreCounterSafety;
60 :
61 : Sequence< OUString > GetPropertyNames();
62 :
63 : public:
64 : SvtHelpOptions_Impl();
65 :
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();
69 :
70 0 : void SetExtendedHelp( sal_Bool b ) { bExtendedHelp= b; SetModified(); }
71 266 : sal_Bool IsExtendedHelp() const { return bExtendedHelp; }
72 0 : void SetHelpTips( sal_Bool b ) { bHelpTips = b; SetModified(); }
73 532 : sal_Bool IsHelpTips() const { return bHelpTips; }
74 :
75 0 : void SetWelcomeScreen( sal_Bool b ) { bWelcomeScreen = b; SetModified(); }
76 0 : sal_Bool IsWelcomeScreen() const { return bWelcomeScreen; }
77 : String GetLocale() const { return aLocale; }
78 775 : String GetSystem() const { return aSystem; }
79 :
80 0 : const String& GetHelpStyleSheet()const{return sHelpStyleSheet;}
81 0 : void SetHelpStyleSheet(const String& rStyleSheet){sHelpStyleSheet = rStyleSheet; SetModified();}
82 :
83 : static ::osl::Mutex & getInitMutex();
84 : };
85 :
86 266 : Sequence< OUString > SvtHelpOptions_Impl::GetPropertyNames()
87 : {
88 : static const char* aPropNames[] =
89 : {
90 : "ExtendedTip",
91 : "Tip",
92 : "Locale",
93 : "System",
94 : "HelpStyleSheet"
95 : };
96 :
97 266 : const int nCount = sizeof( aPropNames ) / sizeof( const char* );
98 266 : Sequence< OUString > aNames( nCount );
99 266 : OUString* pNames = aNames.getArray();
100 1596 : for ( int i = 0; i < nCount; i++ )
101 1330 : pNames[i] = OUString::createFromAscii( aPropNames[i] );
102 :
103 266 : return aNames;
104 : }
105 :
106 2613 : ::osl::Mutex & SvtHelpOptions_Impl::getInitMutex()
107 : {
108 : static ::osl::Mutex *pMutex = 0;
109 :
110 2613 : if( ! pMutex )
111 : {
112 133 : ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
113 133 : if( ! pMutex )
114 : {
115 133 : static ::osl::Mutex mutex;
116 133 : pMutex = &mutex;
117 133 : }
118 : }
119 2613 : return *pMutex;
120 : }
121 :
122 :
123 : // -----------------------------------------------------------------------
124 :
125 133 : SvtHelpOptions_Impl::SvtHelpOptions_Impl()
126 : : ConfigItem( OUString( "Office.Common/Help" ) )
127 : , bExtendedHelp( sal_False )
128 : , bHelpTips( sal_True )
129 133 : , bWelcomeScreen( sal_False )
130 : {
131 133 : Sequence< OUString > aNames = GetPropertyNames();
132 133 : Load( aNames );
133 133 : EnableNotification( aNames );
134 133 : }
135 :
136 : // -----------------------------------------------------------------------
137 266 : static int lcl_MapPropertyName( const OUString rCompare,
138 : const uno::Sequence< OUString>& aInternalPropertyNames)
139 : {
140 399 : for(int nProp = 0; nProp < aInternalPropertyNames.getLength(); ++nProp)
141 : {
142 399 : if( aInternalPropertyNames[nProp] == rCompare )
143 266 : return nProp;
144 : }
145 0 : return -1;
146 : }
147 :
148 133 : void SvtHelpOptions_Impl::Load(const uno::Sequence< OUString>& rPropertyNames)
149 : {
150 133 : const uno::Sequence< OUString> aInternalPropertyNames( GetPropertyNames());
151 266 : Sequence< Any > aValues = GetProperties( rPropertyNames );
152 133 : const Any* pValues = aValues.getConstArray();
153 : DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" );
154 133 : if ( aValues.getLength() == rPropertyNames.getLength() )
155 : {
156 798 : for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ )
157 : {
158 : #if OSL_DEBUG_LEVEL > 1
159 : DBG_ASSERT( pValues[nProp].hasValue(), "property value missing" );
160 : #endif
161 665 : if ( pValues[nProp].hasValue() )
162 : {
163 665 : sal_Bool bTmp = sal_Bool();
164 665 : OUString aTmpStr;
165 665 : sal_Int32 nTmpInt = 0;
166 665 : if ( pValues[nProp] >>= bTmp )
167 : {
168 266 : switch ( lcl_MapPropertyName(rPropertyNames[nProp], aInternalPropertyNames) )
169 : {
170 : case EXTENDEDHELP :
171 133 : bExtendedHelp = bTmp;
172 133 : break;
173 : case HELPTIPS :
174 133 : bHelpTips = bTmp;
175 133 : break;
176 : default:
177 : SAL_WARN( "svtools.config", "Wrong Member!" );
178 0 : break;
179 : }
180 : }
181 399 : else if ( pValues[nProp] >>= aTmpStr )
182 : {
183 399 : switch ( nProp )
184 : {
185 : case LOCALE:
186 133 : aLocale = aTmpStr;
187 133 : break;
188 :
189 : case SYSTEM:
190 133 : aSystem = aTmpStr;
191 133 : break;
192 : case STYLESHEET :
193 133 : sHelpStyleSheet = aTmpStr;
194 133 : break;
195 : default:
196 : SAL_WARN( "svtools.config", "Wrong Member!" );
197 0 : break;
198 : }
199 : }
200 0 : else if ( pValues[nProp] >>= nTmpInt )
201 : {
202 : SAL_WARN( "svtools.config", "Wrong Member!" );
203 : }
204 : else
205 : {
206 : SAL_WARN( "svtools.config", "Wrong Type!" );
207 665 : }
208 : }
209 : }
210 133 : if ( IsHelpTips() != Help::IsQuickHelpEnabled() )
211 133 : IsHelpTips() ? Help::EnableQuickHelp() : Help::DisableQuickHelp();
212 133 : if ( IsExtendedHelp() != Help::IsBalloonHelpEnabled() )
213 0 : IsExtendedHelp() ? Help::EnableBalloonHelp() : Help::DisableBalloonHelp();
214 133 : }
215 133 : }
216 :
217 : // -----------------------------------------------------------------------
218 :
219 0 : void SvtHelpOptions_Impl::Commit()
220 : {
221 0 : Sequence< OUString > aNames = GetPropertyNames();
222 0 : Sequence< Any > aValues( aNames.getLength() );
223 0 : Any* pValues = aValues.getArray();
224 0 : for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
225 : {
226 0 : switch ( nProp )
227 : {
228 : case EXTENDEDHELP :
229 0 : pValues[nProp] <<= bExtendedHelp;
230 0 : break;
231 :
232 : case HELPTIPS :
233 0 : pValues[nProp] <<= bHelpTips;
234 0 : break;
235 :
236 : case LOCALE:
237 0 : pValues[nProp] <<= OUString(aLocale);
238 0 : break;
239 :
240 : case SYSTEM:
241 0 : pValues[nProp] <<= OUString(aSystem);
242 0 : break;
243 : case STYLESHEET :
244 0 : pValues[nProp] <<= OUString(sHelpStyleSheet);
245 0 : break;
246 :
247 : }
248 : }
249 :
250 0 : PutProperties( aNames, aValues );
251 0 : }
252 :
253 : // -----------------------------------------------------------------------
254 :
255 0 : void SvtHelpOptions_Impl::Notify( const Sequence<OUString>& aPropertyNames )
256 : {
257 0 : Load( aPropertyNames );
258 0 : }
259 :
260 1307 : SvtHelpOptions::SvtHelpOptions()
261 : {
262 : // Global access, must be guarded (multithreading)
263 1307 : ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
264 1307 : ++nRefCount;
265 1307 : if ( !pOptions )
266 : {
267 : RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? ) ::SvtHelpOptions_Impl::ctor()");
268 133 : pOptions = new SvtHelpOptions_Impl;
269 :
270 133 : svtools::ItemHolder2::holdConfigItem(E_HELPOPTIONS);
271 : }
272 1307 : pImp = pOptions;
273 1307 : }
274 :
275 : // -----------------------------------------------------------------------
276 :
277 2744 : SvtHelpOptions::~SvtHelpOptions()
278 : {
279 : // Global access, must be guarded (multithreading)
280 1306 : ::osl::MutexGuard aGuard( SvtHelpOptions_Impl::getInitMutex() );
281 1306 : if ( !--nRefCount )
282 : {
283 132 : if ( pOptions->IsModified() )
284 0 : pOptions->Commit();
285 132 : DELETEZ( pOptions );
286 1306 : }
287 1438 : }
288 :
289 0 : void SvtHelpOptions::SetExtendedHelp( sal_Bool b )
290 : {
291 0 : pImp->SetExtendedHelp( b );
292 0 : }
293 :
294 133 : sal_Bool SvtHelpOptions::IsExtendedHelp() const
295 : {
296 133 : return pImp->IsExtendedHelp();
297 : }
298 :
299 0 : void SvtHelpOptions::SetHelpTips( sal_Bool b )
300 : {
301 0 : pImp->SetHelpTips( b );
302 0 : }
303 :
304 266 : sal_Bool SvtHelpOptions::IsHelpTips() const
305 : {
306 266 : return pImp->IsHelpTips();
307 : }
308 :
309 : // -----------------------------------------------------------------------
310 :
311 0 : void SvtHelpOptions::SetWelcomeScreen( sal_Bool b )
312 : {
313 0 : pImp->SetWelcomeScreen( b );
314 0 : }
315 :
316 0 : sal_Bool SvtHelpOptions::IsWelcomeScreen() const
317 : {
318 0 : return pImp->IsWelcomeScreen();
319 : }
320 :
321 775 : String SvtHelpOptions::GetSystem() const
322 : {
323 775 : return pImp->GetSystem();
324 : }
325 :
326 0 : const String& SvtHelpOptions::GetHelpStyleSheet()const
327 : {
328 0 : return pImp->GetHelpStyleSheet();
329 : }
330 :
331 0 : void SvtHelpOptions::SetHelpStyleSheet(const String& rStyleSheet)
332 : {
333 0 : pImp->SetHelpStyleSheet(rStyleSheet);
334 0 : }
335 :
336 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|