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.h"
23 #include "dp_gui_theextmgr.hxx"
24 #include <osl/diagnose.h>
25 #include <cppuhelper/implbase.hxx>
27 #include <unotools/configmgr.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>
38 
39 #include <boost/optional.hpp>
40 #include "license_dialog.hxx"
41 #include "dp_gui_dialog2.hxx"
43 
44 using namespace ::dp_misc;
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::uno;
47 
49 
50 namespace dp_gui {
51 
52 
53 class MyApp : public Application
54 {
55 public:
56  MyApp();
57 
58  MyApp(const MyApp&) = delete;
59  const MyApp& operator=(const MyApp&) = delete;
60 
61  // Application
62  virtual int Main() override;
63  virtual void DeInit() override;
64 };
65 
67 {
68 }
69 
70 
72 {
73  return EXIT_SUCCESS;
74 }
75 
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 namespace
87 {
88  struct ProductName
89  : public rtl::Static< OUString, ProductName > {};
90  struct Version
91  : public rtl::Static< OUString, Version > {};
92  struct AboutBoxVersion
93  : public rtl::Static< OUString, AboutBoxVersion > {};
94  struct AboutBoxVersionSuffix
95  : public rtl::Static< OUString, AboutBoxVersionSuffix > {};
96  struct OOOVendor
97  : public rtl::Static< OUString, OOOVendor > {};
98  struct Extension
99  : public rtl::Static< OUString, Extension > {};
100 }
101 
102 static OUString ReplaceProductNameHookProc( const OUString& rStr )
103 {
104  if (rStr.indexOf( "%PRODUCT" ) == -1)
105  return rStr;
106 
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();
113 
114  if ( sProductName.isEmpty() )
115  {
116  sProductName = utl::ConfigManager::getProductName();
119  sAboutBoxVersionSuffix = utl::ConfigManager::getAboutBoxProductVersionSuffix();
120  sOOOVendor = utl::ConfigManager::getVendor();
121  if ( sExtension.isEmpty() )
122  {
124  }
125  }
126 
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 );
133  return sRet;
134 }
135 
136 
138  : public ::cppu::WeakImplHelper<ui::dialogs::XAsynchronousExecutableDialog,
139  task::XJobExecutor>
140 {
144  OUString m_initialTitle;
146 
147 public:
148  ServiceImpl( Sequence<Any> const & args,
149  Reference<XComponentContext> const & xComponentContext );
150 
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;
155 
156  // XJobExecutor
157  virtual void SAL_CALL trigger( OUString const & event ) override;
158 };
159 
160 
161 ServiceImpl::ServiceImpl( Sequence<Any> const& args,
162  Reference<XComponentContext> const& xComponentContext)
163  : m_xComponentContext(xComponentContext),
164  m_bShowUpdateOnly( false )
165 {
166  /* if true then this service is running in a unopkg process and not in an office process */
169  try {
170  comphelper::unwrapArgs( args, m_parent, view, unopkg );
171  return;
172  } catch ( const css::lang::IllegalArgumentException & ) {
173  }
174  try {
176  } catch ( const css::lang::IllegalArgumentException & ) {
177  }
178 
180  if ( !pProc )
182 }
183 
184 // XAsynchronousExecutableDialog
185 
186 void ServiceImpl::setDialogTitle( OUString const & title )
187 {
189  {
190  const SolarMutexGuard guard;
193  m_parent ? *m_parent : Reference<awt::XWindow>(),
194  m_extensionURL ? *m_extensionURL : OUString() ) );
195  dialog->SetText( title );
196  }
197  else
198  m_initialTitle = title;
199 }
200 
201 
203  Reference< ui::dialogs::XDialogClosedListener > const & xListener )
204 {
205  bool bCloseDialog = true; // only used if m_bShowUpdateOnly is true
206  std::unique_ptr<Application> app;
207  //ToDo: synchronize access to s_dialog !!!
209  {
210  const bool bAppUp = (GetpApp() != nullptr);
211  bool bOfficePipePresent;
212  try {
213  bOfficePipePresent = dp_misc::office_is_running();
214  }
215  catch (const Exception & exc) {
216  if (bAppUp) {
217  const SolarMutexGuard guard;
219  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pWin ? pWin->GetFrameWeld() : nullptr,
220  VclMessageType::Warning, VclButtonsType::Ok, exc.Message));
221  xBox->run();
222  }
223  throw;
224  }
225 
226  if (! bOfficePipePresent) {
227  OSL_ASSERT( ! bAppUp );
228  app.reset( new MyApp );
229  if (! InitVCL() )
230  throw RuntimeException( "Cannot initialize VCL!",
231  static_cast<OWeakObject *>(this) );
234  " " +
237  }
238  }
239  else
240  {
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();
246  }
247 
248  {
249  const SolarMutexGuard guard;
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();
259  }
260  if ( m_bShowUpdateOnly )
261  {
262  myExtMgr->checkUpdates();
263  if ( bCloseDialog )
264  myExtMgr->Close();
265  else
266  myExtMgr->ToTop();
267  }
268  else
269  {
270  myExtMgr->Show();
271  myExtMgr->ToTop();
272  }
273  }
274 
275  if (app != nullptr)
276  {
278  DeInitVCL();
279  }
280 
281  if (xListener.is())
282  xListener->dialogClosed(
283  ui::dialogs::DialogClosedEvent(
284  static_cast< ::cppu::OWeakObject * >(this),
285  sal_Int16(0)) );
286 }
287 
288 // XJobExecutor
289 
290 void ServiceImpl::trigger( OUString const &rEvent )
291 {
292  if ( rEvent == "SHOW_UPDATE_DIALOG" )
293  m_bShowUpdateOnly = true;
294  else
295  m_bShowUpdateOnly = false;
296 
297  startExecuteModal( Reference< ui::dialogs::XDialogClosedListener >() );
298 }
299 
302  serviceSI,
303  "com.sun.star.comp.deployment.ui.PackageManagerDialog",
304  "com.sun.star.deployment.ui.PackageManagerDialog" );
305 
308  licenseSI,
309  "com.sun.star.comp.deployment.ui.LicenseDialog",
310  "com.sun.star.deployment.ui.LicenseDialog" );
311 
314  updateSI,
315  "com.sun.star.comp.deployment.ui.UpdateRequiredDialog",
316  "com.sun.star.deployment.ui.UpdateRequiredDialog" );
317 } // namespace dp_gui
318 
319 extern "C" {
320 
321 SAL_DLLPUBLIC_EXPORT void * deploymentgui_component_getFactory(
322  sal_Char const * pImplName, void *, void *)
323 {
324  return sdecl::component_getFactoryHelper(
325  pImplName,
327 }
328 
329 } // extern "C"
330 
331 /* 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
boost::optional< Reference< awt::XWindow > > m_parent
virtual void SAL_CALL setDialogTitle(OUString const &aTitle) override
virtual int Main() override
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:348
sdecl::ServiceDecl const licenseDecl(licenseSI,"com.sun.star.comp.deployment.ui.LicenseDialog","com.sun.star.deployment.ui.LicenseDialog")
const char * app
virtual void SAL_CALL trigger(OUString const &event) override
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
char sal_Char
sdecl::class_< ServiceImpl, sdecl::with_args< true > > const serviceSI
Application * GetpApp()
static OUString getProductVersion()
SAL_DLLPUBLIC_EXPORT void * deploymentgui_component_getFactory(sal_Char const *pImplName, void *, void *)
VCL_DLLPUBLIC bool InitVCL()
static OUString getProductName()
static::rtl::Reference< TheExtensionManager > s_ExtMgr
const MyApp & operator=(const MyApp &)=delete
Reference< XComponentContext > const m_xComponentContext
static OUString getAboutBoxProductVersion()
static vcl::Window * GetActiveTopWindow()
boost::optional< OUString > m_extensionURL
virtual void DeInit() override
void setProcessServiceFactory(const Reference< XMultiServiceFactory > &xSMgr)
static void syncRepositories(const css::uno::Reference< css::uno::XComponentContext > &xContext)
static OUString getVendor()
void disposeBridges(Reference< css::uno::XComponentContext > const &ctx)
Definition: dp_misc.cxx:569
static OUString ReplaceProductNameHookProc(const OUString &rStr)
Reference< XComponentContext > getProcessComponentContext()
void unwrapArgs(const css::uno::Sequence< css::uno::Any > &seq, Args &...args)
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()
ServiceImpl(Sequence< Any > const &args, Reference< XComponentContext > const &xComponentContext)
Definition: dp_gui.h:50
static OUString getProductExtension()
virtual void SAL_CALL startExecuteModal(Reference< ui::dialogs::XDialogClosedListener > const &xListener) override
OUString(* ResHookProc)(const OUString &rStr)
static void SetDisplayName(const OUString &rDisplayName)
static void Execute()