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 "dp_gui_shared.hxx"
22 : #include "dp_gui.h"
23 : #include "dp_gui_theextmgr.hxx"
24 : #include "cppuhelper/implbase2.hxx"
25 : #include "cppuhelper/implementationentry.hxx"
26 : #include "unotools/configmgr.hxx"
27 : #include "comphelper/processfactory.hxx"
28 : #include "comphelper/servicedecl.hxx"
29 : #include "comphelper/unwrapargs.hxx"
30 : #include <i18nlangtag/languagetag.hxx>
31 : #include "vcl/svapp.hxx"
32 : #include "vcl/msgbox.hxx"
33 : #include "com/sun/star/lang/XServiceInfo.hpp"
34 : #include "com/sun/star/task/XJobExecutor.hpp"
35 : #include "com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp"
36 :
37 : #include <boost/optional.hpp>
38 : #include <boost/utility.hpp>
39 : #include "license_dialog.hxx"
40 : #include "dp_gui_dialog2.hxx"
41 : #include "dp_gui_extensioncmdqueue.hxx"
42 :
43 : using namespace ::dp_misc;
44 : using namespace ::com::sun::star;
45 : using namespace ::com::sun::star::uno;
46 :
47 :
48 : namespace dp_gui {
49 :
50 : //==============================================================================
51 : class MyApp : public Application, private boost::noncopyable
52 : {
53 : public:
54 : MyApp();
55 : virtual ~MyApp();
56 :
57 : // Application
58 : virtual int Main();
59 : virtual void DeInit();
60 : };
61 :
62 : //______________________________________________________________________________
63 0 : MyApp::~MyApp()
64 : {
65 0 : }
66 :
67 : //______________________________________________________________________________
68 0 : MyApp::MyApp()
69 : {
70 0 : }
71 :
72 : //______________________________________________________________________________
73 0 : int MyApp::Main()
74 : {
75 0 : return EXIT_SUCCESS;
76 : }
77 :
78 0 : void MyApp::DeInit()
79 : {
80 : css::uno::Reference< css::uno::XComponentContext > context(
81 0 : comphelper::getProcessComponentContext());
82 0 : dp_misc::disposeBridges(context);
83 : css::uno::Reference< css::lang::XComponent >(
84 0 : context, css::uno::UNO_QUERY_THROW)->dispose();
85 0 : comphelper::setProcessServiceFactory(0);
86 0 : }
87 :
88 : namespace
89 : {
90 : struct ProductName
91 : : public rtl::Static< String, ProductName > {};
92 : struct Version
93 : : public rtl::Static< String, Version > {};
94 : struct AboutBoxVersion
95 : : public rtl::Static< String, AboutBoxVersion > {};
96 : struct AboutBoxVersionSuffix
97 : : public rtl::Static< String, AboutBoxVersionSuffix > {};
98 : struct OOOVendor
99 : : public rtl::Static< String, OOOVendor > {};
100 : struct Extension
101 : : public rtl::Static< String, Extension > {};
102 : }
103 :
104 0 : OUString ReplaceProductNameHookProc( const OUString& rStr )
105 : {
106 0 : if (rStr.indexOf( "%PRODUCT" ) == -1)
107 0 : return rStr;
108 :
109 0 : OUString sProductName = ProductName::get();
110 0 : OUString sVersion = Version::get();
111 0 : OUString sAboutBoxVersion = AboutBoxVersion::get();
112 0 : OUString sAboutBoxVersionSuffix = AboutBoxVersionSuffix::get();
113 0 : OUString sExtension = Extension::get();
114 0 : OUString sOOOVendor = OOOVendor::get();
115 :
116 0 : if ( sProductName.isEmpty() )
117 : {
118 0 : sProductName = utl::ConfigManager::getProductName();
119 0 : sVersion = utl::ConfigManager::getProductVersion();
120 0 : sAboutBoxVersion = utl::ConfigManager::getAboutBoxProductVersion();
121 0 : sAboutBoxVersionSuffix = utl::ConfigManager::getAboutBoxProductVersionSuffix();
122 0 : sOOOVendor = utl::ConfigManager::getVendor();
123 0 : if ( sExtension.isEmpty() )
124 : {
125 0 : sExtension = utl::ConfigManager::getProductExtension();
126 : }
127 : }
128 :
129 0 : OUString sRet = rStr.replaceAll( "%PRODUCTNAME", sProductName );
130 0 : sRet = sRet.replaceAll( "%PRODUCTVERSION", sVersion );
131 0 : sRet = sRet.replaceAll( "%ABOUTBOXPRODUCTVERSIONSUFFIX", sAboutBoxVersionSuffix );
132 0 : sRet = sRet.replaceAll( "%ABOUTBOXPRODUCTVERSION", sAboutBoxVersion );
133 0 : sRet = sRet.replaceAll( "%OOOVENDOR", sOOOVendor );
134 0 : sRet = sRet.replaceAll( "%PRODUCTEXTENSION", sExtension );
135 0 : return sRet;
136 : }
137 :
138 : //==============================================================================
139 0 : class ServiceImpl
140 : : public ::cppu::WeakImplHelper2<ui::dialogs::XAsynchronousExecutableDialog,
141 : task::XJobExecutor>
142 : {
143 : Reference<XComponentContext> const m_xComponentContext;
144 : boost::optional< Reference<awt::XWindow> > /* const */ m_parent;
145 : boost::optional<OUString> /* const */ m_view;
146 : /* if true then this service is running in an unopkg process and not in an office process */
147 : boost::optional<sal_Bool> /* const */ m_unopkg;
148 : boost::optional<OUString> m_extensionURL;
149 : OUString m_initialTitle;
150 : bool m_bShowUpdateOnly;
151 :
152 : public:
153 : ServiceImpl( Sequence<Any> const & args,
154 : Reference<XComponentContext> const & xComponentContext );
155 :
156 : // XAsynchronousExecutableDialog
157 : virtual void SAL_CALL setDialogTitle( OUString const & aTitle )
158 : throw (RuntimeException);
159 : virtual void SAL_CALL startExecuteModal(
160 : Reference< ui::dialogs::XDialogClosedListener > const & xListener )
161 : throw (RuntimeException);
162 :
163 : // XJobExecutor
164 : virtual void SAL_CALL trigger( OUString const & event )
165 : throw (RuntimeException);
166 : };
167 :
168 : //______________________________________________________________________________
169 0 : ServiceImpl::ServiceImpl( Sequence<Any> const& args,
170 : Reference<XComponentContext> const& xComponentContext)
171 : : m_xComponentContext(xComponentContext),
172 0 : m_bShowUpdateOnly( false )
173 : {
174 : try {
175 0 : comphelper::unwrapArgs( args, m_parent, m_view, m_unopkg );
176 0 : return;
177 0 : } catch ( const css::lang::IllegalArgumentException & ) {
178 : }
179 : try {
180 0 : comphelper::unwrapArgs( args, m_extensionURL);
181 0 : } catch ( const css::lang::IllegalArgumentException & ) {
182 : }
183 :
184 0 : ResHookProc pProc = ResMgr::GetReadStringHook();
185 0 : if ( !pProc )
186 0 : ResMgr::SetReadStringHook( ReplaceProductNameHookProc );
187 : }
188 :
189 : // XAsynchronousExecutableDialog
190 : //______________________________________________________________________________
191 0 : void ServiceImpl::setDialogTitle( OUString const & title )
192 : throw (RuntimeException)
193 : {
194 0 : if ( dp_gui::TheExtensionManager::s_ExtMgr.is() )
195 : {
196 0 : const SolarMutexGuard guard;
197 : ::rtl::Reference< ::dp_gui::TheExtensionManager > dialog(
198 : ::dp_gui::TheExtensionManager::get( m_xComponentContext,
199 0 : m_parent ? *m_parent : Reference<awt::XWindow>(),
200 0 : m_extensionURL ? *m_extensionURL : OUString() ) );
201 0 : dialog->SetText( title );
202 : }
203 : else
204 0 : m_initialTitle = title;
205 0 : }
206 :
207 : //______________________________________________________________________________
208 0 : void ServiceImpl::startExecuteModal(
209 : Reference< ui::dialogs::XDialogClosedListener > const & xListener )
210 : throw (RuntimeException)
211 : {
212 0 : bool bCloseDialog = true; // only used if m_bShowUpdateOnly is true
213 0 : ::std::auto_ptr<Application> app;
214 : //ToDo: synchronize access to s_dialog !!!
215 0 : if (! dp_gui::TheExtensionManager::s_ExtMgr.is())
216 : {
217 0 : const bool bAppUp = (GetpApp() != 0);
218 : bool bOfficePipePresent;
219 : try {
220 0 : bOfficePipePresent = dp_misc::office_is_running();
221 : }
222 0 : catch (const Exception & exc) {
223 0 : if (bAppUp) {
224 0 : const SolarMutexGuard guard;
225 : std::auto_ptr<ErrorBox> box(
226 : new ErrorBox( Application::GetActiveTopWindow(),
227 0 : WB_OK, exc.Message ) );
228 0 : box->Execute();
229 : }
230 0 : throw;
231 : }
232 :
233 0 : if (! bOfficePipePresent) {
234 : OSL_ASSERT( ! bAppUp );
235 0 : app.reset( new MyApp );
236 0 : if (! InitVCL() )
237 : throw RuntimeException( "Cannot initialize VCL!",
238 0 : static_cast<OWeakObject *>(this) );
239 0 : AllSettings as = app->GetSettings();
240 0 : as.SetUILanguageTag( LanguageTag( utl::ConfigManager::getLocale() ) );
241 0 : app->SetSettings( as );
242 0 : app->SetDisplayName(
243 0 : utl::ConfigManager::getProductName() +
244 0 : OUString(" ") +
245 0 : utl::ConfigManager::getProductVersion());
246 0 : ExtensionCmdQueue::syncRepositories( m_xComponentContext );
247 : }
248 : }
249 : else
250 : {
251 : // When m_bShowUpdateOnly is set, we are inside the office and the user clicked
252 : // the update notification icon in the menu bar. We must not close the extensions
253 : // dialog after displaying the update dialog when it has been visible before
254 0 : if ( m_bShowUpdateOnly )
255 0 : bCloseDialog = ! dp_gui::TheExtensionManager::s_ExtMgr->isVisible();
256 : }
257 :
258 : {
259 0 : const SolarMutexGuard guard;
260 : ::rtl::Reference< ::dp_gui::TheExtensionManager > myExtMgr(
261 : ::dp_gui::TheExtensionManager::get(
262 : m_xComponentContext,
263 0 : m_parent ? *m_parent : Reference<awt::XWindow>(),
264 0 : m_extensionURL ? *m_extensionURL : OUString() ) );
265 0 : myExtMgr->createDialog( false );
266 0 : if (!m_initialTitle.isEmpty()) {
267 0 : myExtMgr->SetText( m_initialTitle );
268 0 : m_initialTitle = OUString();
269 : }
270 0 : if ( m_bShowUpdateOnly )
271 : {
272 0 : myExtMgr->checkUpdates( true, !bCloseDialog );
273 0 : if ( bCloseDialog )
274 0 : myExtMgr->Close();
275 : else
276 0 : myExtMgr->ToTop( TOTOP_RESTOREWHENMIN );
277 : }
278 : else
279 : {
280 0 : myExtMgr->Show();
281 0 : myExtMgr->ToTop( TOTOP_RESTOREWHENMIN );
282 0 : }
283 : }
284 :
285 0 : if (app.get() != 0) {
286 0 : Application::Execute();
287 0 : DeInitVCL();
288 : }
289 :
290 0 : if (xListener.is())
291 0 : xListener->dialogClosed(
292 : ui::dialogs::DialogClosedEvent(
293 : static_cast< ::cppu::OWeakObject * >(this),
294 0 : sal_Int16(0)) );
295 0 : }
296 :
297 : // XJobExecutor
298 : //______________________________________________________________________________
299 0 : void ServiceImpl::trigger( OUString const &rEvent ) throw (RuntimeException)
300 : {
301 0 : if ( rEvent == "SHOW_UPDATE_DIALOG" )
302 0 : m_bShowUpdateOnly = true;
303 : else
304 0 : m_bShowUpdateOnly = false;
305 :
306 0 : startExecuteModal( Reference< ui::dialogs::XDialogClosedListener >() );
307 0 : }
308 :
309 : namespace sdecl = comphelper::service_decl;
310 0 : sdecl::class_<ServiceImpl, sdecl::with_args<true> > serviceSI;
311 0 : sdecl::ServiceDecl const serviceDecl(
312 : serviceSI,
313 : "com.sun.star.comp.deployment.ui.PackageManagerDialog",
314 : "com.sun.star.deployment.ui.PackageManagerDialog" );
315 :
316 0 : sdecl::class_<LicenseDialog, sdecl::with_args<true> > licenseSI;
317 0 : sdecl::ServiceDecl const licenseDecl(
318 : licenseSI,
319 : "com.sun.star.comp.deployment.ui.LicenseDialog",
320 : "com.sun.star.deployment.ui.LicenseDialog" );
321 :
322 0 : sdecl::class_<UpdateRequiredDialogService, sdecl::with_args<true> > updateSI;
323 0 : sdecl::ServiceDecl const updateDecl(
324 : updateSI,
325 : "com.sun.star.comp.deployment.ui.UpdateRequiredDialog",
326 : "com.sun.star.deployment.ui.UpdateRequiredDialog" );
327 : } // namespace dp_gui
328 :
329 : extern "C" {
330 :
331 0 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL deploymentgui_component_getFactory(
332 : sal_Char const * pImplName,
333 : lang::XMultiServiceFactory * pServiceManager,
334 : registry::XRegistryKey * pRegistryKey )
335 : {
336 : return component_getFactoryHelper(
337 0 : pImplName, pServiceManager, pRegistryKey, dp_gui::serviceDecl, dp_gui::licenseDecl, dp_gui::updateDecl );
338 : }
339 :
340 0 : } // extern "C"
341 :
342 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|