1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __FRAMEWORK_JOBS_HELPONSTARTUP_HXX_
29 #define __FRAMEWORK_JOBS_HELPONSTARTUP_HXX_
30 
31 //_______________________________________________
32 // my own includes
33 
34 #include <threadhelp/threadhelpbase.hxx>
35 #include <macros/xinterface.hxx>
36 #include <macros/xtypeprovider.hxx>
37 #include <macros/xserviceinfo.hxx>
38 
39 //_______________________________________________
40 // other includes
41 #include <cppuhelper/implbase3.hxx>
42 
43 //_______________________________________________
44 // uno includes
45 #include <com/sun/star/frame/XFrame.hpp>
46 #include <com/sun/star/task/XJob.hpp>
47 #include <com/sun/star/lang/XEventListener.hpp>
48 #include <com/sun/star/container/XNameAccess.hpp>
49 #include <com/sun/star/frame/XModuleManager.hpp>
50 
51 //_______________________________________________
52 // namespace
53 
54 namespace framework{
55 
56 //_______________________________________________
57 // declarations
58 
59 //_______________________________________________
60 /** @short  implements a job component, which handle the special
61             feature to show a suitable help page for every (visible!)
62             loaded document.
63 
64     @author as96863
65  */
66 class HelpOnStartup : private ThreadHelpBase
67                       ,public ::cppu::WeakImplHelper3< ::com::sun::star::lang::XServiceInfo,::com::sun::star::lang::XEventListener,::com::sun::star::task::XJob >
68 {
69     //-------------------------------------------
70     // member
71     private:
72 
73         //.......................................
74         /** @short  reference to an uno service manager. */
75         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
76 
77         //.......................................
78         /** @short  such module manager is used to classify new opened documents. */
79         css::uno::Reference< css::frame::XModuleManager > m_xModuleManager;
80 
81         //.......................................
82         /** @short  is needed to locate a might open help frame. */
83         css::uno::Reference< css::frame::XFrame > m_xDesktop;
84 
85         //.......................................
86         /** @short  provides read access to the underlying configuration. */
87         css::uno::Reference< css::container::XNameAccess > m_xConfig;
88 
89         //.......................................
90         /** @short  knows the current locale of this office session,
91                     which is needed to build complete help URLs.
92          */
93         ::rtl::OUString m_sLocale;
94 
95         //.......................................
96         /** @short  knows the current operating system of this office session,
97                     which is needed to build complete help URLs.
98          */
99         ::rtl::OUString m_sSystem;
100 
101     //-------------------------------------------
102     // native interface
103     public:
104 
105         //---------------------------------------
106         /** @short  create new instance of this class.
107 
108             @param  xSMGR
109                     reference to the uno service manager, which created this instance.
110                     Can be used later to create own needed uno resources on demand.
111          */
112         HelpOnStartup(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
113 
114         //---------------------------------------
115         /** @short  does nothing real ...
116 
117             @descr  But it should exists as virtual function,
118                     so this class cant make trouble
119                     related to inline/symbols etcpp.!
120          */
121         virtual ~HelpOnStartup();
122 
123     //-------------------------------------------
124     // uno interface
125     public:
126 
127         //---------------------------------------
128         // css.lang.XServiceInfo
129         DECLARE_XSERVICEINFO
130 
131         // css.task.XJob
132         virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments)
133             throw(css::lang::IllegalArgumentException,
134                   css::uno::Exception                ,
135                   css::uno::RuntimeException         );
136 
137         // css.lang.XEventListener
138         virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
139             throw(css::uno::RuntimeException);
140 
141     //-------------------------------------------
142     // helper
143     private:
144 
145         //---------------------------------------
146         /** @short  analyze the given job arguments, try to locate a model reference
147                     and try to classify this model.
148 
149             @descr  As a result of this operation a module identifier will be returned.
150                     It can be used against the module configuration then to retrieve further informations.
151 
152             @param  lArguments
153                     the list of job arguments which is given on our interface method execute().
154 
155             @return [string]
156                     a module identifier ... or an empty value if no model could be located ...
157                     or if it could not be classified successfully.
158          */
159         ::rtl::OUString its_getModuleIdFromEnv(const css::uno::Sequence< css::beans::NamedValue >& lArguments);
160 
161         //---------------------------------------
162         /** @short  tries to locate the open help module and return
163                     the url of the currently shown help content.
164 
165             @descr  It returns an empty string, if the help isnt still
166                     open at calling time.
167 
168             @return The URL of the current shown help content;
169                     or an empty value if the help isnt still open.
170          */
171         ::rtl::OUString its_getCurrentHelpURL();
172 
173         //---------------------------------------
174         /** @short  checks if the given help url match to a default help url
175                     of any office module.
176 
177             @param  sHelpURL
178                     the help url for checking.
179 
180             @return [bool]
181                     sal_True if the given URL is any default one ...
182                     sal_False otherwise.
183          */
184         ::sal_Bool its_isHelpUrlADefaultOne(const ::rtl::OUString& sHelpURL);
185 
186         //---------------------------------------
187         /** @short  checks, if the help module should be shown automaticly for the
188                     currently opened office module.
189 
190             @descr  This value is readed from the module configuration.
191                     In case the help should be shown, this method returns
192                     a help URL, which can be used to show the right help content.
193 
194             @param  sModule
195                     identifies the used office module.
196 
197             @return [string]
198                     A valid help URL in case the help content should be shown;
199                     an empty value if such automatism was disabled for the specified office module.
200          */
201         ::rtl::OUString its_checkIfHelpEnabledAndGetURL(const ::rtl::OUString& sModule);
202 
203         //---------------------------------------
204         /** @short  create a help URL for the given parameters.
205 
206             @param  sBaseURL
207                     must be the base URL for a requested help content
208                     e.g. "vnd.sun.star.help://swriter/"
209                     or   "vnd.sun.star.help://swriter/67351"
210 
211             @param  sLocale
212                     the current office locale
213                     e.g. "en-US"
214 
215             @param  sSystem
216                     the current operating system
217                     e.g. "WIN"
218 
219             @return The URL which was generated.
220                     e.g.
221                     e.g. "vnd.sun.star.help://swriter/?Language=en-US&System=WIN"
222                     or   "vnd.sun.star.help://swriter/67351?Language=en-US&System=WIN"
223          */
224         static ::rtl::OUString ist_createHelpURL(const ::rtl::OUString& sBaseURL,
225                                                  const ::rtl::OUString& sLocale ,
226                                                  const ::rtl::OUString& sSystem );
227 };
228 
229 } // namespace framework
230 
231 #endif // __FRAMEWORK_JOBS_HELPONSTARTUP_HXX_
232