LibreOffice Module desktop (master) 1
dp_gui_service.cxx
Go to the documentation of this file.
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 <memory>
22#include "dp_gui_theextmgr.hxx"
23#include <osl/diagnose.h>
29#include <unotools/resmgr.hxx>
30#include <vcl/weld.hxx>
31#include <vcl/window.hxx>
32#include <vcl/svapp.hxx>
33#include <com/sun/star/task/XJobExecutor.hpp>
34#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
35
36#include <optional>
37#include "license_dialog.hxx"
38#include "dp_gui_dialog2.hxx"
40#include <dp_misc.h>
41
42using namespace ::dp_misc;
43using namespace ::com::sun::star;
44using namespace ::com::sun::star::uno;
45
46namespace dp_gui {
47
48namespace {
49
50class MyApp : public Application
51{
52public:
53 MyApp();
54
55 MyApp(const MyApp&) = delete;
56 const MyApp& operator=(const MyApp&) = delete;
57
58 // Application
59 virtual int Main() override;
60 virtual void DeInit() override;
61};
62
63}
64
65MyApp::MyApp()
66{
67}
68
69
70int MyApp::Main()
71{
72 return EXIT_SUCCESS;
73}
74
75void MyApp::DeInit()
76{
77 css::uno::Reference< css::uno::XComponentContext > context(
80 css::uno::Reference< css::lang::XComponent >(
81 context, css::uno::UNO_QUERY_THROW)->dispose();
83}
84
85static OUString ReplaceProductNameHookProc( const OUString& rStr )
86{
87 if (rStr.indexOf( "%PRODUCT" ) == -1)
88 return rStr;
89
90 static const OUString sProductName = utl::ConfigManager::getProductName();
91 static const OUString sVersion = utl::ConfigManager::getProductVersion();
92 static const OUString sAboutBoxVersion = utl::ConfigManager::getAboutBoxProductVersion();
93 static const OUString sAboutBoxVersionSuffix = utl::ConfigManager::getAboutBoxProductVersionSuffix();
94 static const OUString sExtension = utl::ConfigManager::getProductExtension();
95 static const OUString sOOOVendor = utl::ConfigManager::getVendor();
96
97 OUString sRet = rStr.replaceAll( "%PRODUCTNAME", sProductName );
98 sRet = sRet.replaceAll( "%PRODUCTVERSION", sVersion );
99 sRet = sRet.replaceAll( "%ABOUTBOXPRODUCTVERSIONSUFFIX", sAboutBoxVersionSuffix );
100 sRet = sRet.replaceAll( "%ABOUTBOXPRODUCTVERSION", sAboutBoxVersion );
101 sRet = sRet.replaceAll( "%OOOVENDOR", sOOOVendor );
102 sRet = sRet.replaceAll( "%PRODUCTEXTENSION", sExtension );
103 return sRet;
104}
105
106namespace {
107
108class ServiceImpl
109 : public ::cppu::WeakImplHelper<ui::dialogs::XAsynchronousExecutableDialog,
110 task::XJobExecutor, css::lang::XServiceInfo>
111{
112 Reference<XComponentContext> const m_xComponentContext;
113 std::optional< Reference<awt::XWindow> > /* const */ m_parent;
114 std::optional<OUString> m_extensionURL;
117
118public:
119 ServiceImpl( Sequence<Any> const & args,
120 Reference<XComponentContext> const & xComponentContext );
121
122 // XServiceInfo
123 virtual OUString SAL_CALL getImplementationName() override;
124 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
125 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
126
127 // XAsynchronousExecutableDialog
128 virtual void SAL_CALL setDialogTitle( OUString const & aTitle ) override;
129 virtual void SAL_CALL startExecuteModal(
130 Reference< ui::dialogs::XDialogClosedListener > const & xListener ) override;
131
132 // XJobExecutor
133 virtual void SAL_CALL trigger( OUString const & event ) override;
134};
135
136}
137
138ServiceImpl::ServiceImpl( Sequence<Any> const& args,
139 Reference<XComponentContext> const& xComponentContext)
140 : m_xComponentContext(xComponentContext),
141 m_bShowUpdateOnly( false )
142{
143 /* if true then this service is running in a unopkg process and not in an office process */
144 std::optional<OUString> view;
145 try {
146 std::optional<sal_Bool> unopkg;
147 comphelper::unwrapArgs( args, m_parent, view, unopkg );
148 return;
149 } catch ( const css::lang::IllegalArgumentException & ) {
150 }
151 try {
153 } catch ( const css::lang::IllegalArgumentException & ) {
154 }
155
157 if ( !pProc )
159}
160
161// XServiceInfo
162OUString ServiceImpl::getImplementationName()
163{
164 return "com.sun.star.comp.deployment.ui.PackageManagerDialog";
165}
166
167sal_Bool ServiceImpl::supportsService( const OUString& ServiceName )
168{
169 return cppu::supportsService(this, ServiceName);
170}
171
172css::uno::Sequence< OUString > ServiceImpl::getSupportedServiceNames()
173{
174 return { "com.sun.star.deployment.ui.PackageManagerDialog" };
175}
176
177// XAsynchronousExecutableDialog
178
179void ServiceImpl::setDialogTitle( OUString const & title )
180{
182 {
183 const SolarMutexGuard guard;
186 m_parent ? *m_parent : Reference<awt::XWindow>(),
187 m_extensionURL ? *m_extensionURL : OUString() ) );
188 dialog->SetText( title );
189 }
190 else
191 m_initialTitle = title;
192}
193
194
195void ServiceImpl::startExecuteModal(
196 Reference< ui::dialogs::XDialogClosedListener > const & xListener )
197{
198 bool bCloseDialog = true; // only used if m_bShowUpdateOnly is true
199 std::unique_ptr<Application> app;
200 //ToDo: synchronize access to s_dialog !!!
202 {
203 const bool bAppUp = (GetpApp() != nullptr);
204 bool bOfficePipePresent;
205 try {
206 bOfficePipePresent = dp_misc::office_is_running();
207 }
208 catch (const Exception & exc) {
209 if (bAppUp) {
210 const SolarMutexGuard guard;
212 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pWin ? pWin->GetFrameWeld() : nullptr,
213 VclMessageType::Warning, VclButtonsType::Ok, exc.Message));
214 xBox->run();
215 }
216 throw;
217 }
218
219 if (! bOfficePipePresent) {
220 OSL_ASSERT( ! bAppUp );
221 app.reset( new MyApp );
222 if (! InitVCL() )
223 throw RuntimeException( "Cannot initialize VCL!",
224 static_cast<OWeakObject *>(this) );
227 " " +
230 }
231 }
232 else
233 {
234 // When m_bShowUpdateOnly is set, we are inside the office and the user clicked
235 // the update notification icon in the menu bar. We must not close the extensions
236 // dialog after displaying the update dialog when it has been visible before
237 if ( m_bShowUpdateOnly )
238 bCloseDialog = ! dp_gui::TheExtensionManager::s_ExtMgr->isVisible();
239 }
240
241 {
242 const SolarMutexGuard guard;
246 m_parent ? *m_parent : Reference<awt::XWindow>(),
247 m_extensionURL ? *m_extensionURL : OUString() ) );
248 myExtMgr->createDialog( false );
249 if (!m_initialTitle.isEmpty()) {
250 myExtMgr->SetText( m_initialTitle );
251 m_initialTitle.clear();
252 }
253 if ( m_bShowUpdateOnly )
254 {
255 myExtMgr->checkUpdates();
256 if ( bCloseDialog )
257 myExtMgr->Close();
258 else
259 myExtMgr->ToTop();
260 }
261 else
262 {
263 myExtMgr->Show();
264 myExtMgr->ToTop();
265 }
266 }
267
268 if (app != nullptr)
269 {
271 DeInitVCL();
272 }
273
274 if (xListener.is())
275 xListener->dialogClosed(
276 ui::dialogs::DialogClosedEvent(
277 static_cast< ::cppu::OWeakObject * >(this),
278 sal_Int16(0)) );
279}
280
281// XJobExecutor
282
283void ServiceImpl::trigger( OUString const &rEvent )
284{
285 if ( rEvent == "SHOW_UPDATE_DIALOG" )
286 m_bShowUpdateOnly = true;
287 else
288 m_bShowUpdateOnly = false;
289
290 startExecuteModal( Reference< ui::dialogs::XDialogClosedListener >() );
291}
292
293} // namespace dp_gui
294
295extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
297 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
298{
299 return cppu::acquire(new dp_gui::LicenseDialog(args, context));
300}
301
302extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
304 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
305{
306 return cppu::acquire(new dp_gui::ServiceImpl(args, context));
307}
308
309extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
311 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
312{
313 return cppu::acquire(new dp_gui::UpdateRequiredDialogService(args, context));
314}
315
316/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void Execute()
static void SetDisplayName(const OUString &rDisplayName)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
static vcl::Window * GetActiveTopWindow()
static ::rtl::Reference< TheExtensionManager > get(css::uno::Reference< css::uno::XComponentContext > const &xContext, css::uno::Reference< css::awt::XWindow > const &xParent=nullptr, OUString const &view=OUString())
static ::rtl::Reference< TheExtensionManager > s_ExtMgr
static OUString getProductVersion()
static OUString getAboutBoxProductVersionSuffix()
static OUString getProductExtension()
static OUString getAboutBoxProductVersion()
static OUString getVendor()
static OUString getProductName()
weld::Window * GetFrameWeld() const
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * desktop_LicenseDialog_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
Reference< XComponentContext > const m_xComponentContext
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * desktop_ServiceImpl_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * desktop_UpdateRequiredDialogService_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
OUString m_initialTitle
bool m_bShowUpdateOnly
std::optional< Reference< awt::XWindow > > m_parent
std::optional< OUString > m_extensionURL
ResHookProc GetReadStringHook()
void SetReadStringHook(ResHookProc pProc)
void unwrapArgs(const css::uno::Sequence< css::uno::Any > &seq, Args &... args)
void setProcessServiceFactory(const Reference< XMultiServiceFactory > &xSMgr)
Reference< XComponentContext > getProcessComponentContext()
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Definition: dp_gui.h:22
static OUString ReplaceProductNameHookProc(const OUString &rStr)
void syncRepositories(bool force, Reference< ucb::XCommandEnvironment > const &xCmdEnv)
Definition: dp_misc.cxx:491
bool office_is_running()
Definition: dp_misc.cxx:331
void disposeBridges(Reference< css::uno::XComponentContext > const &ctx)
Definition: dp_misc.cxx:530
args
OUString(* ResHookProc)(const OUString &rStr)
VCL_DLLPUBLIC bool InitVCL()
VCL_DLLPUBLIC Application * GetpApp()
VCL_DLLPUBLIC void DeInitVCL()
unsigned char sal_Bool