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 .
23 #include "dp_gui_theextmgr.hxx"
24 #include <osl/diagnose.h>
25 #include <cppuhelper/implbase.hxx>
26 #include <cppuhelper/implementationentry.hxx>
27 #include <unotools/configmgr.hxx>
28 #include <comphelper/processfactory.hxx>
29 #include <comphelper/servicedecl.hxx>
30 #include <comphelper/unwrapargs.hxx>
31 #include <unotools/resmgr.hxx>
32 #include <vcl/weld.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/settings.hxx>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/task/XJobExecutor.hpp>
37 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
39 #include <boost/optional.hpp>
40 #include "license_dialog.hxx"
41 #include "dp_gui_dialog2.hxx"
42 #include "dp_gui_extensioncmdqueue.hxx"
44 using namespace ::dp_misc
;
45 using namespace ::com::sun::star
;
46 using namespace ::com::sun::star::uno
;
48 namespace sdecl
= comphelper::service_decl
;
53 class MyApp
: public Application
58 MyApp(const MyApp
&) = delete;
59 const MyApp
& operator=(const MyApp
&) = delete;
62 virtual int Main() override
;
63 virtual void DeInit() override
;
78 css::uno::Reference
< css::uno::XComponentContext
> context(
79 comphelper::getProcessComponentContext());
80 dp_misc::disposeBridges(context
);
81 css::uno::Reference
< css::lang::XComponent
>(
82 context
, css::uno::UNO_QUERY_THROW
)->dispose();
83 comphelper::setProcessServiceFactory(nullptr);
89 : public rtl::Static
< OUString
, ProductName
> {};
91 : public rtl::Static
< OUString
, Version
> {};
92 struct AboutBoxVersion
93 : public rtl::Static
< OUString
, AboutBoxVersion
> {};
94 struct AboutBoxVersionSuffix
95 : public rtl::Static
< OUString
, AboutBoxVersionSuffix
> {};
97 : public rtl::Static
< OUString
, OOOVendor
> {};
99 : public rtl::Static
< OUString
, Extension
> {};
102 static OUString
ReplaceProductNameHookProc( const OUString
& rStr
)
104 if (rStr
.indexOf( "%PRODUCT" ) == -1)
107 OUString sProductName
= ProductName::get();
108 OUString sVersion
= Version::get();
109 OUString sAboutBoxVersion
= AboutBoxVersion::get();
110 OUString sAboutBoxVersionSuffix
= AboutBoxVersionSuffix::get();
111 OUString sExtension
= Extension::get();
112 OUString sOOOVendor
= OOOVendor::get();
114 if ( sProductName
.isEmpty() )
116 sProductName
= utl::ConfigManager::getProductName();
117 sVersion
= utl::ConfigManager::getProductVersion();
118 sAboutBoxVersion
= utl::ConfigManager::getAboutBoxProductVersion();
119 sAboutBoxVersionSuffix
= utl::ConfigManager::getAboutBoxProductVersionSuffix();
120 sOOOVendor
= utl::ConfigManager::getVendor();
121 if ( sExtension
.isEmpty() )
123 sExtension
= utl::ConfigManager::getProductExtension();
127 OUString sRet
= rStr
.replaceAll( "%PRODUCTNAME", sProductName
);
128 sRet
= sRet
.replaceAll( "%PRODUCTVERSION", sVersion
);
129 sRet
= sRet
.replaceAll( "%ABOUTBOXPRODUCTVERSIONSUFFIX", sAboutBoxVersionSuffix
);
130 sRet
= sRet
.replaceAll( "%ABOUTBOXPRODUCTVERSION", sAboutBoxVersion
);
131 sRet
= sRet
.replaceAll( "%OOOVENDOR", sOOOVendor
);
132 sRet
= sRet
.replaceAll( "%PRODUCTEXTENSION", sExtension
);
138 : public ::cppu::WeakImplHelper
<ui::dialogs::XAsynchronousExecutableDialog
,
141 Reference
<XComponentContext
> const m_xComponentContext
;
142 boost::optional
< Reference
<awt::XWindow
> > /* const */ m_parent
;
143 boost::optional
<OUString
> m_extensionURL
;
144 OUString m_initialTitle
;
145 bool m_bShowUpdateOnly
;
148 ServiceImpl( Sequence
<Any
> const & args
,
149 Reference
<XComponentContext
> const & xComponentContext
);
151 // XAsynchronousExecutableDialog
152 virtual void SAL_CALL
setDialogTitle( OUString
const & aTitle
) override
;
153 virtual void SAL_CALL
startExecuteModal(
154 Reference
< ui::dialogs::XDialogClosedListener
> const & xListener
) override
;
157 virtual void SAL_CALL
trigger( OUString
const & event
) override
;
161 ServiceImpl::ServiceImpl( Sequence
<Any
> const& args
,
162 Reference
<XComponentContext
> const& xComponentContext
)
163 : m_xComponentContext(xComponentContext
),
164 m_bShowUpdateOnly( false )
166 /* if true then this service is running in a unopkg process and not in an office process */
167 boost::optional
<sal_Bool
> unopkg
;
168 boost::optional
<OUString
> view
;
170 comphelper::unwrapArgs( args
, m_parent
, view
, unopkg
);
172 } catch ( const css::lang::IllegalArgumentException
& ) {
175 comphelper::unwrapArgs( args
, m_extensionURL
);
176 } catch ( const css::lang::IllegalArgumentException
& ) {
179 ResHookProc pProc
= Translate::GetReadStringHook();
181 Translate::SetReadStringHook(ReplaceProductNameHookProc
);
184 // XAsynchronousExecutableDialog
186 void ServiceImpl::setDialogTitle( OUString
const & title
)
188 if ( dp_gui::TheExtensionManager::s_ExtMgr
.is() )
190 const SolarMutexGuard guard
;
191 ::rtl::Reference
< ::dp_gui::TheExtensionManager
> dialog(
192 ::dp_gui::TheExtensionManager::get( m_xComponentContext
,
193 m_parent
? *m_parent
: Reference
<awt::XWindow
>(),
194 m_extensionURL
? *m_extensionURL
: OUString() ) );
195 dialog
->SetText( title
);
198 m_initialTitle
= title
;
202 void ServiceImpl::startExecuteModal(
203 Reference
< ui::dialogs::XDialogClosedListener
> const & xListener
)
205 bool bCloseDialog
= true; // only used if m_bShowUpdateOnly is true
206 std::unique_ptr
<Application
> app
;
207 //ToDo: synchronize access to s_dialog !!!
208 if (! dp_gui::TheExtensionManager::s_ExtMgr
.is())
210 const bool bAppUp
= (GetpApp() != nullptr);
211 bool bOfficePipePresent
;
213 bOfficePipePresent
= dp_misc::office_is_running();
215 catch (const Exception
& exc
) {
217 const SolarMutexGuard guard
;
218 vcl::Window
* pWin
= Application::GetActiveTopWindow();
219 std::unique_ptr
<weld::MessageDialog
> xBox(Application::CreateMessageDialog(pWin
? pWin
->GetFrameWeld() : nullptr,
220 VclMessageType::Warning
, VclButtonsType::Ok
, exc
.Message
));
226 if (! bOfficePipePresent
) {
227 OSL_ASSERT( ! bAppUp
);
228 app
.reset( new MyApp
);
230 throw RuntimeException( "Cannot initialize VCL!",
231 static_cast<OWeakObject
*>(this) );
232 Application::SetDisplayName(
233 utl::ConfigManager::getProductName() +
235 utl::ConfigManager::getProductVersion());
236 ExtensionCmdQueue::syncRepositories( m_xComponentContext
);
241 // When m_bShowUpdateOnly is set, we are inside the office and the user clicked
242 // the update notification icon in the menu bar. We must not close the extensions
243 // dialog after displaying the update dialog when it has been visible before
244 if ( m_bShowUpdateOnly
)
245 bCloseDialog
= ! dp_gui::TheExtensionManager::s_ExtMgr
->isVisible();
249 const SolarMutexGuard guard
;
250 ::rtl::Reference
< ::dp_gui::TheExtensionManager
> myExtMgr(
251 ::dp_gui::TheExtensionManager::get(
253 m_parent
? *m_parent
: Reference
<awt::XWindow
>(),
254 m_extensionURL
? *m_extensionURL
: OUString() ) );
255 myExtMgr
->createDialog( false );
256 if (!m_initialTitle
.isEmpty()) {
257 myExtMgr
->SetText( m_initialTitle
);
258 m_initialTitle
.clear();
260 if ( m_bShowUpdateOnly
)
262 myExtMgr
->checkUpdates();
277 Application::Execute();
282 xListener
->dialogClosed(
283 ui::dialogs::DialogClosedEvent(
284 static_cast< ::cppu::OWeakObject
* >(this),
290 void ServiceImpl::trigger( OUString
const &rEvent
)
292 if ( rEvent
== "SHOW_UPDATE_DIALOG" )
293 m_bShowUpdateOnly
= true;
295 m_bShowUpdateOnly
= false;
297 startExecuteModal( Reference
< ui::dialogs::XDialogClosedListener
>() );
300 sdecl::class_
<ServiceImpl
, sdecl::with_args
<true> > const serviceSI
;
301 sdecl::ServiceDecl
const serviceDecl(
303 "com.sun.star.comp.deployment.ui.PackageManagerDialog",
304 "com.sun.star.deployment.ui.PackageManagerDialog" );
306 sdecl::class_
<LicenseDialog
, sdecl::with_args
<true> > const licenseSI
;
307 sdecl::ServiceDecl
const licenseDecl(
309 "com.sun.star.comp.deployment.ui.LicenseDialog",
310 "com.sun.star.deployment.ui.LicenseDialog" );
312 sdecl::class_
<UpdateRequiredDialogService
, sdecl::with_args
<true> > const updateSI
;
313 sdecl::ServiceDecl
const updateDecl(
315 "com.sun.star.comp.deployment.ui.UpdateRequiredDialog",
316 "com.sun.star.deployment.ui.UpdateRequiredDialog" );
317 } // namespace dp_gui
321 SAL_DLLPUBLIC_EXPORT
void * deploymentgui_component_getFactory(
322 sal_Char
const * pImplName
, void *, void *)
324 return sdecl::component_getFactoryHelper(
326 {&dp_gui::serviceDecl
, &dp_gui::licenseDecl
, &dp_gui::updateDecl
});
331 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */