1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir //_______________________________________________
32*cdf0e10cSrcweir // include own header
33*cdf0e10cSrcweir #include <jobs/helponstartup.hxx>
34*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
35*cdf0e10cSrcweir #include <loadenv/targethelper.hxx>
36*cdf0e10cSrcweir #include <services.h>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir //_______________________________________________
39*cdf0e10cSrcweir // include others
40*cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
41*cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
42*cdf0e10cSrcweir #include <unotools/configmgr.hxx>
43*cdf0e10cSrcweir #include <vcl/svapp.hxx>
44*cdf0e10cSrcweir #include <vcl/help.hxx>
45*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir //_______________________________________________
48*cdf0e10cSrcweir // include interfaces
49*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir //_______________________________________________
54*cdf0e10cSrcweir // namespace
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir namespace framework{
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir //_______________________________________________
59*cdf0e10cSrcweir // definitions
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir // path to module config
62*cdf0e10cSrcweir static ::rtl::OUString CFG_PACKAGE_MODULES      = ::rtl::OUString::createFromAscii("/org.openoffice.Setup/Office/Factories");
63*cdf0e10cSrcweir static ::rtl::OUString CFG_PACKAGE_SETUP        = ::rtl::OUString::createFromAscii("/org.openoffice.Setup"             );
64*cdf0e10cSrcweir static ::rtl::OUString CFG_PACKAGE_COMMON       = ::rtl::OUString::createFromAscii("/org.openoffice.Office.Common"     );
65*cdf0e10cSrcweir static ::rtl::OUString CFG_PATH_L10N            = ::rtl::OUString::createFromAscii("L10N"                              );
66*cdf0e10cSrcweir static ::rtl::OUString CFG_PATH_HELP            = ::rtl::OUString::createFromAscii("Help"                              );
67*cdf0e10cSrcweir static ::rtl::OUString CFG_KEY_LOCALE           = ::rtl::OUString::createFromAscii("ooLocale"                          );
68*cdf0e10cSrcweir static ::rtl::OUString CFG_KEY_HELPSYSTEM       = ::rtl::OUString::createFromAscii("System"                            );
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir // props of job environment
71*cdf0e10cSrcweir static ::rtl::OUString PROP_ENVIRONMENT         = ::rtl::OUString::createFromAscii("Environment"                       );
72*cdf0e10cSrcweir static ::rtl::OUString PROP_JOBCONFIG           = ::rtl::OUString::createFromAscii("JobConfig"                         );
73*cdf0e10cSrcweir static ::rtl::OUString PROP_ENVTYPE             = ::rtl::OUString::createFromAscii("EnvType"                           );
74*cdf0e10cSrcweir static ::rtl::OUString PROP_MODEL               = ::rtl::OUString::createFromAscii("Model"                             );
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir // props of module config
77*cdf0e10cSrcweir static ::rtl::OUString PROP_HELP_BASEURL        = ::rtl::OUString::createFromAscii("ooSetupFactoryHelpBaseURL"         );
78*cdf0e10cSrcweir static ::rtl::OUString PROP_AUTOMATIC_HELP      = ::rtl::OUString::createFromAscii("ooSetupFactoryHelpOnOpen"          );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir // special value of job environment
81*cdf0e10cSrcweir static ::rtl::OUString ENVTYPE_DOCUMENTEVENT    = ::rtl::OUString::createFromAscii("DOCUMENTEVENT"                     );
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir //-----------------------------------------------
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE(HelpOnStartup                   ,
86*cdf0e10cSrcweir                                       ::cppu::OWeakObject             ,
87*cdf0e10cSrcweir                                       SERVICENAME_JOB                 ,
88*cdf0e10cSrcweir                                       IMPLEMENTATIONNAME_HELPONSTARTUP)
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir DEFINE_INIT_SERVICE(HelpOnStartup,
91*cdf0e10cSrcweir                     {
92*cdf0e10cSrcweir                         /*  Attention
93*cdf0e10cSrcweir                             I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
94*cdf0e10cSrcweir                             to create a new instance of this class by our own supported service factory.
95*cdf0e10cSrcweir                             see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
96*cdf0e10cSrcweir                         */
97*cdf0e10cSrcweir                         // create some needed uno services and cache it
98*cdf0e10cSrcweir                         m_xModuleManager = css::uno::Reference< css::frame::XModuleManager >(
99*cdf0e10cSrcweir                             m_xSMGR->createInstance(SERVICENAME_MODULEMANAGER),
100*cdf0e10cSrcweir                             css::uno::UNO_QUERY_THROW);
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir                         m_xDesktop = css::uno::Reference< css::frame::XFrame >(
103*cdf0e10cSrcweir                             m_xSMGR->createInstance(SERVICENAME_DESKTOP),
104*cdf0e10cSrcweir                             css::uno::UNO_QUERY_THROW);
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir                         m_xConfig = css::uno::Reference< css::container::XNameAccess >(
107*cdf0e10cSrcweir                             ::comphelper::ConfigurationHelper::openConfig(
108*cdf0e10cSrcweir                                 m_xSMGR,
109*cdf0e10cSrcweir                                 CFG_PACKAGE_MODULES,
110*cdf0e10cSrcweir                                 ::comphelper::ConfigurationHelper::E_READONLY),
111*cdf0e10cSrcweir                             css::uno::UNO_QUERY_THROW);
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir                         // ask for office locale
114*cdf0e10cSrcweir                         ::comphelper::ConfigurationHelper::readDirectKey(
115*cdf0e10cSrcweir                             m_xSMGR,
116*cdf0e10cSrcweir                             CFG_PACKAGE_SETUP,
117*cdf0e10cSrcweir                             CFG_PATH_L10N,
118*cdf0e10cSrcweir                             CFG_KEY_LOCALE,
119*cdf0e10cSrcweir                             ::comphelper::ConfigurationHelper::E_READONLY) >>= m_sLocale;
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir                         // detect system
122*cdf0e10cSrcweir                         ::comphelper::ConfigurationHelper::readDirectKey(
123*cdf0e10cSrcweir                             m_xSMGR,
124*cdf0e10cSrcweir                             CFG_PACKAGE_COMMON,
125*cdf0e10cSrcweir                             CFG_PATH_HELP,
126*cdf0e10cSrcweir                             CFG_KEY_HELPSYSTEM,
127*cdf0e10cSrcweir                             ::comphelper::ConfigurationHelper::E_READONLY) >>= m_sSystem;
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir                         // Start listening for disposing events of these services,
130*cdf0e10cSrcweir                         // so we can react e.g. for an office shutdown
131*cdf0e10cSrcweir                         css::uno::Reference< css::lang::XComponent > xComponent;
132*cdf0e10cSrcweir                         xComponent = css::uno::Reference< css::lang::XComponent >(m_xModuleManager, css::uno::UNO_QUERY);
133*cdf0e10cSrcweir                         if (xComponent.is())
134*cdf0e10cSrcweir                             xComponent->addEventListener(static_cast< css::lang::XEventListener* >(this));
135*cdf0e10cSrcweir                         xComponent = css::uno::Reference< css::lang::XComponent >(m_xDesktop, css::uno::UNO_QUERY);
136*cdf0e10cSrcweir                         if (xComponent.is())
137*cdf0e10cSrcweir                             xComponent->addEventListener(static_cast< css::lang::XEventListener* >(this));
138*cdf0e10cSrcweir                         xComponent = css::uno::Reference< css::lang::XComponent >(m_xConfig, css::uno::UNO_QUERY);
139*cdf0e10cSrcweir                         if (xComponent.is())
140*cdf0e10cSrcweir                             xComponent->addEventListener(static_cast< css::lang::XEventListener* >(this));
141*cdf0e10cSrcweir                     }
142*cdf0e10cSrcweir                    )
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir //-----------------------------------------------
145*cdf0e10cSrcweir HelpOnStartup::HelpOnStartup(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
146*cdf0e10cSrcweir     : ThreadHelpBase(     )
147*cdf0e10cSrcweir     , m_xSMGR       (xSMGR)
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir //-----------------------------------------------
152*cdf0e10cSrcweir HelpOnStartup::~HelpOnStartup()
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir //-----------------------------------------------
157*cdf0e10cSrcweir // css.task.XJob
158*cdf0e10cSrcweir css::uno::Any SAL_CALL HelpOnStartup::execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments)
159*cdf0e10cSrcweir     throw(css::lang::IllegalArgumentException,
160*cdf0e10cSrcweir           css::uno::Exception                ,
161*cdf0e10cSrcweir           css::uno::RuntimeException         )
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir     // Analyze the given arguments; try to locate a model there and
164*cdf0e10cSrcweir     // classify it's used application module.
165*cdf0e10cSrcweir     ::rtl::OUString sModule = its_getModuleIdFromEnv(lArguments);
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     // Attention: We are bound to events for openeing any document inside the office.
168*cdf0e10cSrcweir     // That includes e.g. the help module itself. But we have to do nothing then!
169*cdf0e10cSrcweir     if (!sModule.getLength())
170*cdf0e10cSrcweir         return css::uno::Any();
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     // check current state of the help module
173*cdf0e10cSrcweir     // a) help isnt open                       => show default page for the detected module
174*cdf0e10cSrcweir     // b) help shows any other default page(!) => show default page for the detected module
175*cdf0e10cSrcweir     // c) help shows any other content         => do nothing (user travelled to any other content and leaved the set of default pages)
176*cdf0e10cSrcweir     ::rtl::OUString sCurrentHelpURL                = its_getCurrentHelpURL();
177*cdf0e10cSrcweir     sal_Bool        bCurrentHelpURLIsAnyDefaultURL = its_isHelpUrlADefaultOne(sCurrentHelpURL);
178*cdf0e10cSrcweir     sal_Bool        bShowIt                        = sal_False;
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     // a)
181*cdf0e10cSrcweir     if (!sCurrentHelpURL.getLength())
182*cdf0e10cSrcweir         bShowIt = sal_True;
183*cdf0e10cSrcweir     else
184*cdf0e10cSrcweir     // b)
185*cdf0e10cSrcweir     if (bCurrentHelpURLIsAnyDefaultURL)
186*cdf0e10cSrcweir         bShowIt = sal_True;
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir     if (bShowIt)
189*cdf0e10cSrcweir     {
190*cdf0e10cSrcweir         // retrieve the help URL for the detected application module
191*cdf0e10cSrcweir         ::rtl::OUString sModuleDependendHelpURL = its_checkIfHelpEnabledAndGetURL(sModule);
192*cdf0e10cSrcweir         if (sModuleDependendHelpURL.getLength())
193*cdf0e10cSrcweir         {
194*cdf0e10cSrcweir             // Show this help page.
195*cdf0e10cSrcweir             // Note: The help window brings itself to front ...
196*cdf0e10cSrcweir             Help* pHelp = Application::GetHelp();
197*cdf0e10cSrcweir             if (pHelp)
198*cdf0e10cSrcweir                 pHelp->Start(sModuleDependendHelpURL, 0);
199*cdf0e10cSrcweir         }
200*cdf0e10cSrcweir     }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir     return css::uno::Any();
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir //-----------------------------------------------
206*cdf0e10cSrcweir void SAL_CALL HelpOnStartup::disposing(const css::lang::EventObject& aEvent)
207*cdf0e10cSrcweir     throw(css::uno::RuntimeException)
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir     // SAFE ->
210*cdf0e10cSrcweir     ResetableGuard aLock(m_aLock);
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     if (aEvent.Source == m_xModuleManager)
213*cdf0e10cSrcweir         m_xModuleManager.clear();
214*cdf0e10cSrcweir     else
215*cdf0e10cSrcweir     if (aEvent.Source == m_xDesktop)
216*cdf0e10cSrcweir         m_xDesktop.clear();
217*cdf0e10cSrcweir     else
218*cdf0e10cSrcweir     if (aEvent.Source == m_xConfig)
219*cdf0e10cSrcweir         m_xConfig.clear();
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     aLock.unlock();
222*cdf0e10cSrcweir     // <- SAFE
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir //-----------------------------------------------
226*cdf0e10cSrcweir ::rtl::OUString HelpOnStartup::its_getModuleIdFromEnv(const css::uno::Sequence< css::beans::NamedValue >& lArguments)
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir     ::comphelper::SequenceAsHashMap lArgs        (lArguments);
229*cdf0e10cSrcweir     ::comphelper::SequenceAsHashMap lEnvironment = lArgs.getUnpackedValueOrDefault(PROP_ENVIRONMENT, css::uno::Sequence< css::beans::NamedValue >());
230*cdf0e10cSrcweir     ::comphelper::SequenceAsHashMap lJobConfig   = lArgs.getUnpackedValueOrDefault(PROP_JOBCONFIG  , css::uno::Sequence< css::beans::NamedValue >());
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir     // check for right environment.
233*cdf0e10cSrcweir     // If its not a DocumentEvent, which triggered this job,
234*cdf0e10cSrcweir     // we cant work correctly! => return immediatly and do nothing
235*cdf0e10cSrcweir     ::rtl::OUString sEnvType = lEnvironment.getUnpackedValueOrDefault(PROP_ENVTYPE, ::rtl::OUString());
236*cdf0e10cSrcweir     if (!sEnvType.equals(ENVTYPE_DOCUMENTEVENT))
237*cdf0e10cSrcweir         return ::rtl::OUString();
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     css::uno::Reference< css::frame::XModel > xDoc = lEnvironment.getUnpackedValueOrDefault(PROP_MODEL, css::uno::Reference< css::frame::XModel >());
240*cdf0e10cSrcweir     if (!xDoc.is())
241*cdf0e10cSrcweir         return ::rtl::OUString();
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     // be sure that we work on top level documents only, which are registered
244*cdf0e10cSrcweir     // on the desktop instance. Ignore e.g. life previews, which are top frames too ...
245*cdf0e10cSrcweir     // but not registered at this global desktop instance.
246*cdf0e10cSrcweir     css::uno::Reference< css::frame::XDesktop >    xDesktopCheck;
247*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame >      xFrame       ;
248*cdf0e10cSrcweir     css::uno::Reference< css::frame::XController > xController  = xDoc->getCurrentController();
249*cdf0e10cSrcweir     if (xController.is())
250*cdf0e10cSrcweir         xFrame = xController->getFrame();
251*cdf0e10cSrcweir     if (xFrame.is() && xFrame->isTop())
252*cdf0e10cSrcweir         xDesktopCheck = css::uno::Reference< css::frame::XDesktop >(xFrame->getCreator(), css::uno::UNO_QUERY);
253*cdf0e10cSrcweir     if (!xDesktopCheck.is())
254*cdf0e10cSrcweir         return ::rtl::OUString();
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir     // OK - now we are sure this document is a top level document.
257*cdf0e10cSrcweir     // Classify it.
258*cdf0e10cSrcweir     // SAFE ->
259*cdf0e10cSrcweir     ResetableGuard aLock(m_aLock);
260*cdf0e10cSrcweir     css::uno::Reference< css::frame::XModuleManager > xModuleManager = m_xModuleManager;
261*cdf0e10cSrcweir     aLock.unlock();
262*cdf0e10cSrcweir     // <- SAFE
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     if (!xModuleManager.is())
265*cdf0e10cSrcweir         return ::rtl::OUString();
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     ::rtl::OUString sModuleId;
268*cdf0e10cSrcweir     try
269*cdf0e10cSrcweir     {
270*cdf0e10cSrcweir         sModuleId = xModuleManager->identify(xDoc);
271*cdf0e10cSrcweir     }
272*cdf0e10cSrcweir     catch(const css::uno::RuntimeException& exRun)
273*cdf0e10cSrcweir         { throw exRun; }
274*cdf0e10cSrcweir     catch(const css::uno::Exception&)
275*cdf0e10cSrcweir         { sModuleId = ::rtl::OUString(); }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir     return sModuleId;
278*cdf0e10cSrcweir }
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir //-----------------------------------------------
281*cdf0e10cSrcweir ::rtl::OUString HelpOnStartup::its_getCurrentHelpURL()
282*cdf0e10cSrcweir {
283*cdf0e10cSrcweir     // SAFE ->
284*cdf0e10cSrcweir     ResetableGuard aLock(m_aLock);
285*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame > xDesktop = m_xDesktop;
286*cdf0e10cSrcweir     aLock.unlock();
287*cdf0e10cSrcweir     // <- SAFE
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir     if (!xDesktop.is())
290*cdf0e10cSrcweir         return ::rtl::OUString();
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame > xHelp = xDesktop->findFrame(SPECIALTARGET_HELPTASK, css::frame::FrameSearchFlag::CHILDREN);
293*cdf0e10cSrcweir     if (!xHelp.is())
294*cdf0e10cSrcweir         return ::rtl::OUString();
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     ::rtl::OUString sCurrentHelpURL;
297*cdf0e10cSrcweir     try
298*cdf0e10cSrcweir     {
299*cdf0e10cSrcweir         css::uno::Reference< css::frame::XFramesSupplier >  xHelpRoot  (xHelp                 , css::uno::UNO_QUERY_THROW);
300*cdf0e10cSrcweir         css::uno::Reference< css::container::XIndexAccess > xHelpChilds(xHelpRoot->getFrames(), css::uno::UNO_QUERY_THROW);
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir         css::uno::Reference< css::frame::XFrame >      xHelpChild  ;
303*cdf0e10cSrcweir         css::uno::Reference< css::frame::XController > xHelpView   ;
304*cdf0e10cSrcweir         css::uno::Reference< css::frame::XModel >      xHelpContent;
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir         xHelpChilds->getByIndex(0) >>= xHelpChild;
307*cdf0e10cSrcweir         if (xHelpChild.is())
308*cdf0e10cSrcweir             xHelpView = xHelpChild->getController();
309*cdf0e10cSrcweir         if (xHelpView.is())
310*cdf0e10cSrcweir             xHelpContent = xHelpView->getModel();
311*cdf0e10cSrcweir         if (xHelpContent.is())
312*cdf0e10cSrcweir             sCurrentHelpURL = xHelpContent->getURL();
313*cdf0e10cSrcweir     }
314*cdf0e10cSrcweir     catch(css::uno::RuntimeException& exRun)
315*cdf0e10cSrcweir         { throw exRun; }
316*cdf0e10cSrcweir     catch(css::uno::Exception&)
317*cdf0e10cSrcweir         { sCurrentHelpURL = ::rtl::OUString(); }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir     return sCurrentHelpURL;
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir //-----------------------------------------------
323*cdf0e10cSrcweir ::sal_Bool HelpOnStartup::its_isHelpUrlADefaultOne(const ::rtl::OUString& sHelpURL)
324*cdf0e10cSrcweir {
325*cdf0e10cSrcweir     if (!sHelpURL.getLength())
326*cdf0e10cSrcweir         return sal_False;
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     // SAFE ->
329*cdf0e10cSrcweir     ResetableGuard aLock(m_aLock);
330*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR   (m_xSMGR, css::uno::UNO_QUERY_THROW);
331*cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess >     xConfig = m_xConfig;
332*cdf0e10cSrcweir     ::rtl::OUString                                        sLocale = m_sLocale;
333*cdf0e10cSrcweir     ::rtl::OUString                                        sSystem = m_sSystem;
334*cdf0e10cSrcweir     aLock.unlock();
335*cdf0e10cSrcweir     // <- SAFE
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir     if (!xConfig.is())
338*cdf0e10cSrcweir         return sal_False;
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir     // check given help url against all default ones
341*cdf0e10cSrcweir     const css::uno::Sequence< ::rtl::OUString > lModules = xConfig->getElementNames();
342*cdf0e10cSrcweir     const ::rtl::OUString*                      pModules = lModules.getConstArray();
343*cdf0e10cSrcweir           ::sal_Int32                           c        = lModules.getLength();
344*cdf0e10cSrcweir           ::sal_Int32                           i        = 0;
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     for (i=0; i<c; ++i)
347*cdf0e10cSrcweir     {
348*cdf0e10cSrcweir         try
349*cdf0e10cSrcweir         {
350*cdf0e10cSrcweir             css::uno::Reference< css::container::XNameAccess > xModuleConfig;
351*cdf0e10cSrcweir             xConfig->getByName(pModules[i]) >>= xModuleConfig;
352*cdf0e10cSrcweir             if (!xModuleConfig.is())
353*cdf0e10cSrcweir                 continue;
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir             ::rtl::OUString sHelpBaseURL;
356*cdf0e10cSrcweir             xModuleConfig->getByName(PROP_HELP_BASEURL) >>= sHelpBaseURL;
357*cdf0e10cSrcweir             ::rtl::OUString sHelpURLForModule = HelpOnStartup::ist_createHelpURL(sHelpBaseURL, sLocale, sSystem);
358*cdf0e10cSrcweir             if (sHelpURL.equals(sHelpURLForModule))
359*cdf0e10cSrcweir                 return sal_True;
360*cdf0e10cSrcweir         }
361*cdf0e10cSrcweir         catch(const css::uno::RuntimeException& exRun)
362*cdf0e10cSrcweir             { throw exRun; }
363*cdf0e10cSrcweir         catch(const css::uno::Exception&)
364*cdf0e10cSrcweir             {}
365*cdf0e10cSrcweir     }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir     return sal_False;
368*cdf0e10cSrcweir }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir //-----------------------------------------------
371*cdf0e10cSrcweir ::rtl::OUString HelpOnStartup::its_checkIfHelpEnabledAndGetURL(const ::rtl::OUString& sModule)
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir     // SAFE ->
374*cdf0e10cSrcweir     ResetableGuard aLock(m_aLock);
375*cdf0e10cSrcweir     css::uno::Reference< css::container::XNameAccess > xConfig = m_xConfig;
376*cdf0e10cSrcweir     ::rtl::OUString                                    sLocale = m_sLocale;
377*cdf0e10cSrcweir     ::rtl::OUString                                    sSystem = m_sSystem;
378*cdf0e10cSrcweir     aLock.unlock();
379*cdf0e10cSrcweir     // <- SAFE
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir     ::rtl::OUString sHelpURL;
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir     try
384*cdf0e10cSrcweir     {
385*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > xModuleConfig;
386*cdf0e10cSrcweir         if (xConfig.is())
387*cdf0e10cSrcweir             xConfig->getByName(sModule) >>= xModuleConfig;
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir         sal_Bool bHelpEnabled = sal_False;
390*cdf0e10cSrcweir         if (xModuleConfig.is())
391*cdf0e10cSrcweir             xModuleConfig->getByName(PROP_AUTOMATIC_HELP) >>= bHelpEnabled;
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir         if (bHelpEnabled)
394*cdf0e10cSrcweir         {
395*cdf0e10cSrcweir             ::rtl::OUString sHelpBaseURL;
396*cdf0e10cSrcweir             xModuleConfig->getByName(PROP_HELP_BASEURL) >>= sHelpBaseURL;
397*cdf0e10cSrcweir             sHelpURL = HelpOnStartup::ist_createHelpURL(sHelpBaseURL, sLocale, sSystem);
398*cdf0e10cSrcweir         }
399*cdf0e10cSrcweir     }
400*cdf0e10cSrcweir     catch(const css::uno::RuntimeException& exRun)
401*cdf0e10cSrcweir         { throw exRun; }
402*cdf0e10cSrcweir     catch(const css::uno::Exception&)
403*cdf0e10cSrcweir         { sHelpURL = ::rtl::OUString(); }
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir     return sHelpURL;
406*cdf0e10cSrcweir }
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir //-----------------------------------------------
409*cdf0e10cSrcweir ::rtl::OUString HelpOnStartup::ist_createHelpURL(const ::rtl::OUString& sBaseURL,
410*cdf0e10cSrcweir                                                  const ::rtl::OUString& sLocale ,
411*cdf0e10cSrcweir                                                  const ::rtl::OUString& sSystem )
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir     ::rtl::OUStringBuffer sHelpURL(256);
414*cdf0e10cSrcweir     sHelpURL.append     (sBaseURL    );
415*cdf0e10cSrcweir     sHelpURL.appendAscii("?Language=");
416*cdf0e10cSrcweir     sHelpURL.append     (sLocale     );
417*cdf0e10cSrcweir     sHelpURL.appendAscii("&System="  );
418*cdf0e10cSrcweir     sHelpURL.append     (sSystem     );
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir     return sHelpURL.makeStringAndClear();
421*cdf0e10cSrcweir }
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir } // namespace framework
424