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