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