LibreOffice Module desktop (master)  1
dp_gui_updatedialog.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 <sal/config.h>
22 
23 #include <cstddef>
24 #include <limits>
25 #include <map>
26 #include <utility>
27 #include <vector>
28 
29 
30 #include <o3tl/optional.hxx>
31 #include <com/sun/star/awt/Rectangle.hpp>
32 #include <com/sun/star/awt/WindowAttribute.hpp>
33 #include <com/sun/star/awt/WindowClass.hpp>
34 #include <com/sun/star/awt/WindowDescriptor.hpp>
35 #include <com/sun/star/awt/XWindow.hpp>
36 #include <com/sun/star/awt/XWindowPeer.hpp>
37 #include <com/sun/star/beans/NamedValue.hpp>
38 #include <com/sun/star/beans/Optional.hpp>
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/configuration/theDefaultProvider.hpp>
42 #include <com/sun/star/container/XNameAccess.hpp>
43 #include <com/sun/star/container/XNameContainer.hpp>
44 #include <com/sun/star/deployment/DeploymentException.hpp>
45 #include <com/sun/star/deployment/UpdateInformationProvider.hpp>
46 #include <com/sun/star/deployment/XPackage.hpp>
47 #include <com/sun/star/deployment/XExtensionManager.hpp>
48 #include <com/sun/star/deployment/ExtensionManager.hpp>
49 #include <com/sun/star/deployment/XUpdateInformationProvider.hpp>
50 #include <com/sun/star/frame/Desktop.hpp>
51 #include <com/sun/star/frame/XDispatch.hpp>
52 #include <com/sun/star/frame/XDispatchProvider.hpp>
53 #include <com/sun/star/lang/IllegalArgumentException.hpp>
54 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
55 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
56 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
57 #include <com/sun/star/task/InteractionHandler.hpp>
58 #include <com/sun/star/task/XAbortChannel.hpp>
59 #include <com/sun/star/task/XJob.hpp>
60 #include <com/sun/star/ucb/CommandAbortedException.hpp>
61 #include <com/sun/star/ucb/CommandFailedException.hpp>
62 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
63 #include <com/sun/star/uno/Any.hxx>
64 #include <com/sun/star/uno/Exception.hpp>
65 #include <com/sun/star/uno/Reference.hxx>
66 #include <com/sun/star/uno/RuntimeException.hpp>
67 #include <com/sun/star/uno/Sequence.hxx>
68 #include <com/sun/star/uno/XInterface.hpp>
69 #include <com/sun/star/util/URL.hpp>
70 #include <com/sun/star/util/XChangesBatch.hpp>
71 #include <com/sun/star/util/URLTransformer.hpp>
72 #include <com/sun/star/util/XURLTransformer.hpp>
73 #include <com/sun/star/xml/dom/XElement.hpp>
74 #include <com/sun/star/xml/dom/XNode.hpp>
75 #include <osl/diagnose.h>
76 #include <rtl/ref.hxx>
77 #include <rtl/string.h>
78 #include <rtl/ustrbuf.hxx>
79 #include <rtl/ustring.h>
80 #include <rtl/ustring.hxx>
81 #include <sal/types.h>
82 #include <salhelper/thread.hxx>
83 #include <svtools/controldims.hxx>
84 #include <tools/gen.hxx>
85 #include <tools/link.hxx>
86 #include <tools/solar.h>
87 #include <unotools/configmgr.hxx>
88 #include <vcl/svapp.hxx>
89 
91 #include <cppuhelper/exc_hlp.hxx>
92 
93 #include <dp_dependencies.hxx>
95 #include <dp_identifier.hxx>
96 #include <dp_version.hxx>
97 #include <dp_misc.h>
98 #include <dp_update.hxx>
99 
100 #include "dp_gui.h"
101 #include <strings.hrc>
102 #include <bitmaps.hlst>
103 #include "dp_gui_updatedata.hxx"
104 #include "dp_gui_updatedialog.hxx"
105 #include <dp_shared.hxx>
106 
107 class KeyEvent;
108 class MouseEvent;
109 namespace com { namespace sun { namespace star { namespace uno {
110  class XComponentContext;
111 } } } }
112 
113 using namespace ::com::sun::star;
115 
116 namespace {
117 
118 static sal_Unicode const LF = 0x000A;
119 static sal_Unicode const CR = 0x000D;
120 
121 #define IGNORED_UPDATES OUString("/org.openoffice.Office.ExtensionManager/ExtensionUpdateData/IgnoredUpdates")
122 #define PROPERTY_VERSION "Version"
123 
124 enum Kind { ENABLED_UPDATE, DISABLED_UPDATE, SPECIFIC_ERROR };
125 
126 OUString confineToParagraph(OUString const & text) {
127  // Confine arbitrary text to a single paragraph in a VclMultiLineEdit
128  // This assumes that U+000A and U+000D are the only paragraph separators in
129  // a VclMultiLineEdit, and that replacing them with a single space
130  // each is acceptable:
131  return text.replace(LF, ' ').replace(CR, ' ');
132 }
133 }
134 
136  OUString name;
137  uno::Sequence< OUString > unsatisfiedDependencies;
138  // We also want to show release notes and publisher for disabled updates
139  css::uno::Reference< css::xml::dom::XNode > aUpdateInfo;
140 };
141 
143  OUString name;
144  OUString message;
145 };
146 
147 
149  OUString sExtensionID;
150  OUString sVersion;
151 
152  IgnoredUpdate( const OUString &rExtensionID, const OUString &rVersion );
153 };
154 
155 
156 UpdateDialog::IgnoredUpdate::IgnoredUpdate( const OUString &rExtensionID, const OUString &rVersion ):
157  sExtensionID( rExtensionID ),
158  sVersion( rVersion )
159 {}
160 
161 
163 {
166  sal_uInt16 m_nIndex;
167  OUString m_aName;
168 
169  Index( Kind theKind, sal_uInt16 nIndex, const OUString &rName ) :
170  m_eKind( theKind ),
171  m_bIgnored( false ),
172  m_nIndex( nIndex ),
173  m_aName( rName ) {}
174 };
175 
176 
178 public:
179  Thread(
180  uno::Reference< uno::XComponentContext > const & context,
181  UpdateDialog & dialog,
182  const std::vector< uno::Reference< deployment::XPackage > > & vExtensionList);
183 
184  void stop();
185 
186 private:
187  virtual ~Thread() override;
188 
189  virtual void execute() override;
190 
191  void handleSpecificError(
192  uno::Reference< deployment::XPackage > const & package,
193  uno::Any const & exception) const;
194 
195  OUString getUpdateDisplayString(
196  dp_gui::UpdateData const & data, OUString const & version = OUString()) const;
197 
198  void prepareUpdateData(
199  css::uno::Reference< css::xml::dom::XNode > const & updateInfo,
201  dp_gui::UpdateData & out_data) const;
202 
203  bool update(
204  UpdateDialog::DisabledUpdate const & du,
205  dp_gui::UpdateData const & data) const;
206 
207  uno::Reference< uno::XComponentContext > m_context;
209  std::vector< uno::Reference< deployment::XPackage > > m_vExtensionList;
210  uno::Reference< deployment::XUpdateInformationProvider > m_updateInformation;
211  uno::Reference< task::XInteractionHandler > m_xInteractionHdl;
212 
213  // guarded by Application::GetSolarMutex():
214  bool m_stop;
215 };
216 
218  uno::Reference< uno::XComponentContext > const & context,
219  UpdateDialog & dialog,
220  const std::vector< uno::Reference< deployment::XPackage > > &vExtensionList):
221  salhelper::Thread("dp_gui_updatedialog"),
222  m_context(context),
223  m_dialog(dialog),
224  m_vExtensionList(vExtensionList),
225  m_updateInformation(
226  deployment::UpdateInformationProvider::create(context)),
227  m_stop(false)
228 {
229  if( m_context.is() )
230  {
232  task::InteractionHandler::createWithParent(m_context, dialog.getDialog()->GetXWindow());
233  m_updateInformation->setInteractionHandler( m_xInteractionHdl );
234  }
235 }
236 
238  {
239  SolarMutexGuard g;
240  m_stop = true;
241  }
242  m_updateInformation->cancel();
243 }
244 
246 {
247  if ( m_xInteractionHdl.is() )
248  m_updateInformation->setInteractionHandler( uno::Reference< task::XInteractionHandler > () );
249 }
250 
252 {
253  {
254  SolarMutexGuard g;
255  if ( m_stop ) {
256  return;
257  }
258  }
259  uno::Reference<deployment::XExtensionManager> extMgr =
260  deployment::ExtensionManager::get(m_context);
261 
262  std::vector<std::pair<uno::Reference<deployment::XPackage>, uno::Any > > errors;
263 
265  m_context, extMgr, m_updateInformation, &m_vExtensionList, errors);
266 
267  for (auto const& elem : errors)
268  handleSpecificError(elem.first, elem.second);
269 
270  for (auto const& updateInfo : updateInfoMap)
271  {
272  dp_misc::UpdateInfo const & info = updateInfo.second;
273  UpdateData updateData(info.extension);
274  DisabledUpdate disableUpdate;
275  //determine if online updates meet the requirements
276  prepareUpdateData(info.info, disableUpdate, updateData);
277 
278  //determine if the update is installed in the user or shared repository
279  OUString sOnlineVersion;
280  if (info.info.is())
281  sOnlineVersion = info.version;
282  OUString sVersionUser;
283  OUString sVersionShared;
284  OUString sVersionBundled;
285  uno::Sequence< uno::Reference< deployment::XPackage> > extensions;
286  try {
287  extensions = extMgr->getExtensionsWithSameIdentifier(
288  dp_misc::getIdentifier(info.extension), info.extension->getName(),
289  uno::Reference<ucb::XCommandEnvironment>());
290  } catch ( const lang::IllegalArgumentException& ) {
291  OSL_ASSERT(false);
292  continue;
293  } catch ( const css::ucb::CommandFailedException& ) {
294  OSL_ASSERT(false);
295  continue;
296  }
297  OSL_ASSERT(extensions.getLength() == 3);
298  if (extensions[0].is() )
299  sVersionUser = extensions[0]->getVersion();
300  if (extensions[1].is() )
301  sVersionShared = extensions[1]->getVersion();
302  if (extensions[2].is() )
303  sVersionBundled = extensions[2]->getVersion();
304 
305  bool bSharedReadOnly = extMgr->isReadOnlyRepository("shared");
306 
308  bSharedReadOnly, sVersionUser, sVersionShared, sVersionBundled, sOnlineVersion);
310  bSharedReadOnly, sVersionShared, sVersionBundled, sOnlineVersion);
311 
312  if (sourceUser != dp_misc::UPDATE_SOURCE_NONE)
313  {
314  if (sourceUser == dp_misc::UPDATE_SOURCE_SHARED)
315  {
316  updateData.aUpdateSource = extensions[1];
317  updateData.updateVersion = extensions[1]->getVersion();
318  }
319  else if (sourceUser == dp_misc::UPDATE_SOURCE_BUNDLED)
320  {
321  updateData.aUpdateSource = extensions[2];
322  updateData.updateVersion = extensions[2]->getVersion();
323  }
324  if (!update(disableUpdate, updateData))
325  return;
326  }
327 
328  if (sourceShared != dp_misc::UPDATE_SOURCE_NONE)
329  {
330  if (sourceShared == dp_misc::UPDATE_SOURCE_BUNDLED)
331  {
332  updateData.aUpdateSource = extensions[2];
333  updateData.updateVersion = extensions[2]->getVersion();
334  }
335  updateData.bIsShared = true;
336  if (!update(disableUpdate, updateData))
337  return;
338  }
339  }
340 
341 
342  SolarMutexGuard g;
343  if (!m_stop) {
344  m_dialog.checkingDone();
345  }
346 }
347 
348 //Parameter package can be null
350  uno::Reference< deployment::XPackage > const & package,
351  uno::Any const & exception) const
352 {
354  if (package.is())
355  data.name = package->getDisplayName();
356  uno::Exception e;
357  if (exception >>= e) {
358  data.message = e.Message;
359  }
360  SolarMutexGuard g;
361  if (!m_stop) {
362  m_dialog.addSpecificError(data);
363  }
364 }
365 
367  dp_gui::UpdateData const & data, OUString const & version) const
368 {
369  OSL_ASSERT(data.aInstalledPackage.is());
370  OUStringBuffer b(data.aInstalledPackage->getDisplayName());
371  b.append(' ');
372  {
373  SolarMutexGuard g;
374  if(!m_stop)
375  b.append(m_dialog.m_version);
376  }
377  b.append(' ');
378  if (!version.isEmpty())
379  b.append(version);
380  else
381  b.append(data.updateVersion);
382 
383  if (!data.sWebsiteURL.isEmpty())
384  {
385  b.append(' ');
386  {
387  SolarMutexGuard g;
388  if(!m_stop)
389  b.append(m_dialog.m_browserbased);
390  }
391  }
392  return b.makeStringAndClear();
393 }
394 
398  uno::Reference< xml::dom::XNode > const & updateInfo,
400  dp_gui::UpdateData & out_data) const
401 {
402  if (!updateInfo.is())
403  return;
404  dp_misc::DescriptionInfoset infoset(m_context, updateInfo);
405  OSL_ASSERT(!infoset.getVersion().isEmpty());
406  uno::Sequence< uno::Reference< xml::dom::XElement > > ds(
408 
409  out_du.aUpdateInfo = updateInfo;
410  out_du.unsatisfiedDependencies.realloc(ds.getLength());
411  for (sal_Int32 i = 0; i < ds.getLength(); ++i) {
413  }
414 
415  const ::o3tl::optional< OUString> updateWebsiteURL(infoset.getLocalizedUpdateWebsiteURL());
416 
417  out_du.name = getUpdateDisplayString(out_data, infoset.getVersion());
418 
419  if (!out_du.unsatisfiedDependencies.hasElements())
420  {
421  out_data.aUpdateInfo = updateInfo;
422  out_data.updateVersion = infoset.getVersion();
423  if (updateWebsiteURL)
424  out_data.sWebsiteURL = *updateWebsiteURL;
425  }
426 }
427 
429  UpdateDialog::DisabledUpdate const & du,
430  dp_gui::UpdateData const & data) const
431 {
432  bool ret = false;
433  if (!du.unsatisfiedDependencies.hasElements())
434  {
435  SolarMutexGuard g;
436  if (!m_stop) {
437  m_dialog.addEnabledUpdate(getUpdateDisplayString(data), data);
438  }
439  ret = !m_stop;
440  } else {
441  SolarMutexGuard g;
442  if (!m_stop) {
443  m_dialog.addDisabledUpdate(du);
444  }
445  ret = !m_stop;
446  }
447  return ret;
448 }
449 
450 // UpdateDialog ----------------------------------------------------------
451 UpdateDialog::UpdateDialog(
452  uno::Reference< uno::XComponentContext > const & context,
453  weld::Window * parent, const std::vector<uno::Reference< deployment::XPackage > > &vExtensionList,
454  std::vector< dp_gui::UpdateData > * updateData)
455  : GenericDialogController(parent, "desktop/ui/updatedialog.ui", "UpdateDialog")
456  , m_context(context)
457  , m_none(DpResId(RID_DLG_UPDATE_NONE))
458  , m_noInstallable(DpResId(RID_DLG_UPDATE_NOINSTALLABLE))
459  , m_failure(DpResId(RID_DLG_UPDATE_FAILURE))
460  , m_unknownError(DpResId(RID_DLG_UPDATE_UNKNOWNERROR))
461  , m_noDescription(DpResId(RID_DLG_UPDATE_NODESCRIPTION))
462  , m_noInstall(DpResId(RID_DLG_UPDATE_NOINSTALL))
463  , m_noDependency(DpResId(RID_DLG_UPDATE_NODEPENDENCY))
464  , m_noDependencyCurVer(DpResId(RID_DLG_UPDATE_NODEPENDENCY_CUR_VER))
465  , m_browserbased(DpResId(RID_DLG_UPDATE_BROWSERBASED))
466  , m_version(DpResId(RID_DLG_UPDATE_VERSION))
467  , m_ignoredUpdate(DpResId(RID_DLG_UPDATE_IGNORED_UPDATE))
468  , m_updateData(*updateData)
469  , m_thread(new UpdateDialog::Thread(context, *this, vExtensionList))
470  , m_xChecking(m_xBuilder->weld_label("UPDATE_CHECKING"))
471  , m_xThrobber(m_xBuilder->weld_spinner("THROBBER"))
472  , m_xUpdate(m_xBuilder->weld_label("UPDATE_LABEL"))
473  , m_xUpdates(m_xBuilder->weld_tree_view("checklist"))
474  , m_xAll(m_xBuilder->weld_check_button("UPDATE_ALL"))
475  , m_xDescription(m_xBuilder->weld_label("DESCRIPTION_LABEL"))
476  , m_xPublisherLabel(m_xBuilder->weld_label("PUBLISHER_LABEL"))
477  , m_xPublisherLink(m_xBuilder->weld_link_button("PUBLISHER_LINK"))
478  , m_xReleaseNotesLabel(m_xBuilder->weld_label("RELEASE_NOTES_LABEL"))
479  , m_xReleaseNotesLink(m_xBuilder->weld_link_button("RELEASE_NOTES_LINK"))
480  , m_xDescriptions(m_xBuilder->weld_text_view("DESCRIPTIONS"))
481  , m_xOk(m_xBuilder->weld_button("ok"))
482  , m_xClose(m_xBuilder->weld_button("close"))
483  , m_xHelp(m_xBuilder->weld_button("help"))
484 {
485  auto nWidth = m_xDescriptions->get_approximate_digit_width() * 62;
486  auto nHeight = m_xDescriptions->get_height_rows(8);
487  m_xDescriptions->set_size_request(nWidth, nHeight);
488  m_xUpdates->set_size_request(nWidth, nHeight);
489 
490  std::vector<int> aWidths;
491  aWidths.push_back(m_xUpdates->get_checkbox_column_width());
492  m_xUpdates->set_column_fixed_widths(aWidths);
493 
494  OSL_ASSERT(updateData != nullptr);
495 
496  m_xExtensionManager = deployment::ExtensionManager::get( context );
497 
498  m_xUpdates->connect_changed(LINK(this, UpdateDialog, selectionHandler));
499  m_xUpdates->connect_toggled(LINK(this, UpdateDialog, entryToggled));
500  m_xAll->connect_toggled(LINK(this, UpdateDialog, allHandler));
501  m_xOk->connect_clicked(LINK(this, UpdateDialog, okHandler));
502  m_xClose->connect_clicked(LINK(this, UpdateDialog, closeHandler));
504  m_xHelp->set_sensitive(false);
505 
506  initDescription();
507  getIgnoredUpdates();
508 }
509 
510 UpdateDialog::~UpdateDialog()
511 {
512 }
513 
514 short UpdateDialog::run() {
515  m_xThrobber->start();
516  m_thread->launch();
517  short nRet = GenericDialogController::run();
518  m_thread->stop();
519  return nRet;
520 }
521 
522 IMPL_LINK(UpdateDialog, entryToggled, const row_col&, rRowCol, void)
523 {
524  int nRow = rRowCol.first;
525 
526  // error's can't be enabled
527  const UpdateDialog::Index* p = reinterpret_cast<UpdateDialog::Index const *>(m_xUpdates->get_id(rRowCol.first).toInt64());
528  if (p->m_eKind == SPECIFIC_ERROR)
529  m_xUpdates->set_toggle(nRow, TRISTATE_FALSE, 0);
530 
531  enableOk();
532 }
533 
534 void UpdateDialog::insertItem(UpdateDialog::Index *pEntry, bool bEnabledCheckBox)
535 {
536  int nEntry = m_xUpdates->n_children();
537  m_xUpdates->append();
538  m_xUpdates->set_toggle(nEntry, bEnabledCheckBox ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
539  m_xUpdates->set_text(nEntry, pEntry->m_aName, 1);
540  m_xUpdates->set_id(nEntry, OUString::number(reinterpret_cast<sal_Int64>(pEntry)));
541 }
542 
543 void UpdateDialog::addAdditional(UpdateDialog::Index * index, bool bEnabledCheckBox)
544 {
545  m_xAll->set_sensitive(true);
546  if (m_xAll->get_active())
547  {
548  insertItem(index, bEnabledCheckBox);
549  m_xUpdate->set_sensitive(true);
550  m_xUpdates->set_sensitive(true);
551  m_xDescription->set_sensitive(true);
552  m_xDescriptions->set_sensitive(true);
553  }
554 }
555 
556 void UpdateDialog::addEnabledUpdate( OUString const & name,
557  dp_gui::UpdateData const & data )
558 {
559  sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_enabledUpdates.size() );
560  UpdateDialog::Index *pEntry = new UpdateDialog::Index( ENABLED_UPDATE, nIndex, name );
561 
562  m_enabledUpdates.push_back( data );
563  m_ListboxEntries.emplace_back( pEntry );
564 
565  if (!isIgnoredUpdate(pEntry))
566  {
567  insertItem(pEntry, true);
568  }
569  else
570  addAdditional(pEntry, false);
571 
572  m_xUpdate->set_sensitive(true);
573  m_xUpdates->set_sensitive(true);
574  m_xDescription->set_sensitive(true);
575  m_xDescriptions->set_sensitive(true);
576 }
577 
578 void UpdateDialog::addDisabledUpdate( UpdateDialog::DisabledUpdate const & data )
579 {
580  sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_disabledUpdates.size() );
581  UpdateDialog::Index *pEntry = new UpdateDialog::Index( DISABLED_UPDATE, nIndex, data.name );
582 
583  m_disabledUpdates.push_back( data );
584  m_ListboxEntries.emplace_back( pEntry );
585 
586  isIgnoredUpdate( pEntry );
587  addAdditional(pEntry, false);
588 }
589 
590 void UpdateDialog::addSpecificError( UpdateDialog::SpecificError const & data )
591 {
592  sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_specificErrors.size() );
593  UpdateDialog::Index *pEntry = new UpdateDialog::Index( SPECIFIC_ERROR, nIndex, data.name );
594 
595  m_specificErrors.push_back( data );
596  m_ListboxEntries.emplace_back( pEntry );
597 
598  addAdditional(pEntry, false);
599 }
600 
601 void UpdateDialog::checkingDone() {
602  m_xChecking->hide();
603  m_xThrobber->stop();
604  m_xThrobber->hide();
605  if (m_xUpdates->n_children() == 0)
606  {
607  clearDescription();
608  m_xDescription->set_sensitive(true);
609  m_xDescriptions->set_sensitive(true);
610 
611  if ( m_disabledUpdates.empty() && m_specificErrors.empty() && m_ignoredUpdates.empty() )
612  showDescription( m_none );
613  else
614  showDescription( m_noInstallable );
615  }
616 
617  enableOk();
618 }
619 
620 void UpdateDialog::enableOk() {
621  if (!m_xChecking->get_visible()) {
622  int nChecked = 0;
623  for (int i = 0, nCount = m_xUpdates->n_children(); i < nCount; ++i) {
624  if (m_xUpdates->get_toggle(i, 0) == TRISTATE_TRUE)
625  ++nChecked;
626  }
627  m_xOk->set_sensitive(nChecked != 0);
628  }
629 }
630 
631 // *********************************************************************************
632 void UpdateDialog::createNotifyJob( bool bPrepareOnly,
633  uno::Sequence< uno::Sequence< OUString > > const &rItemList )
634 {
636  return;
637 
638  // notify update check job
639  try
640  {
641  uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
642  configuration::theDefaultProvider::get(
644 
645  beans::PropertyValue aProperty;
646  aProperty.Name = "nodepath";
647  aProperty.Value <<= OUString("org.openoffice.Office.Addons/AddonUI/OfficeHelp/UpdateCheckJob");
648 
649  uno::Sequence< uno::Any > aArgumentList( 1 );
650  aArgumentList[0] <<= aProperty;
651 
652  uno::Reference< container::XNameAccess > xNameAccess(
653  xConfigProvider->createInstanceWithArguments(
654  "com.sun.star.configuration.ConfigurationAccess", aArgumentList ),
655  uno::UNO_QUERY_THROW );
656 
657  util::URL aURL;
658  xNameAccess->getByName("URL") >>= aURL.Complete;
659 
660  uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
661  uno::Reference < util::XURLTransformer > xTransformer = util::URLTransformer::create(xContext);
662 
663  xTransformer->parseStrict(aURL);
664 
665  uno::Reference < frame::XDesktop2 > xDesktop = frame::Desktop::create( xContext );
666  uno::Reference< frame::XDispatchProvider > xDispatchProvider( xDesktop->getCurrentFrame(),
667  uno::UNO_QUERY_THROW );
668  uno::Reference< frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch(aURL, OUString(), 0);
669 
670  if( xDispatch.is() )
671  {
672  uno::Sequence< beans::PropertyValue > aPropList(2);
673  aProperty.Name = "updateList";
674  aProperty.Value <<= rItemList;
675  aPropList[0] = aProperty;
676  aProperty.Name = "prepareOnly";
677  aProperty.Value <<= bPrepareOnly;
678  aPropList[1] = aProperty;
679 
680  xDispatch->dispatch(aURL, aPropList );
681  }
682  }
683  catch( const uno::Exception& e )
684  {
685  dp_misc::TRACE( "Caught exception: "
686  + e.Message + "\n thread terminated.\n\n");
687  }
688 }
689 
690 // *********************************************************************************
691 void UpdateDialog::notifyMenubar( bool bPrepareOnly, bool bRecheckOnly )
692 {
694  return;
695 
696  uno::Sequence< uno::Sequence< OUString > > aItemList;
697 
698  if ( ! bRecheckOnly )
699  {
700  sal_Int32 nCount = 0;
701  for (sal_uInt16 i = 0, nItemCount = m_xUpdates->n_children(); i < nItemCount; ++i)
702  {
703  uno::Sequence< OUString > aItem(2);
704 
705  UpdateDialog::Index const * p = reinterpret_cast< UpdateDialog::Index const * >(m_xUpdates->get_id(i).toInt64());
706 
707  if ( p->m_eKind == ENABLED_UPDATE )
708  {
709  dp_gui::UpdateData aUpdData = m_enabledUpdates[ p->m_nIndex ];
710  aItem[0] = dp_misc::getIdentifier( aUpdData.aInstalledPackage );
711 
712  dp_misc::DescriptionInfoset aInfoset( m_context, aUpdData.aUpdateInfo );
713  aItem[1] = aInfoset.getVersion();
714  }
715  else
716  continue;
717 
718  aItemList.realloc( nCount + 1 );
719  aItemList[ nCount ] = aItem;
720  nCount += 1;
721  }
722  }
723 
724  createNotifyJob( bPrepareOnly, aItemList );
725 }
726 
727 // *********************************************************************************
728 
729 void UpdateDialog::initDescription()
730 {
731  m_xPublisherLabel->hide();
732  m_xPublisherLink->hide();
733  m_xReleaseNotesLabel->hide();
734  m_xReleaseNotesLink->hide();
735 }
736 
737 void UpdateDialog::clearDescription()
738 {
739  m_xPublisherLabel->hide();
740  m_xPublisherLink->hide();
741  m_xPublisherLink->set_label("");
742  m_xPublisherLink->set_uri("");
743  m_xReleaseNotesLabel->hide();
744  m_xReleaseNotesLink->hide();
745  m_xReleaseNotesLink->set_uri( "" );
746  m_xDescriptions->set_text("");
747 }
748 
749 bool UpdateDialog::showDescription(uno::Reference< xml::dom::XNode > const & aUpdateInfo)
750 {
751  dp_misc::DescriptionInfoset infoset(m_context, aUpdateInfo);
752  return showDescription(infoset.getLocalizedPublisherNameAndURL(),
753  infoset.getLocalizedReleaseNotesURL());
754 }
755 
756 bool UpdateDialog::showDescription(uno::Reference< deployment::XPackage > const & aExtension)
757 {
758  OSL_ASSERT(aExtension.is());
759  beans::StringPair pubInfo = aExtension->getPublisherInfo();
760  return showDescription(std::make_pair(pubInfo.First, pubInfo.Second),
761  "");
762 }
763 
764 bool UpdateDialog::showDescription(std::pair< OUString, OUString > const & pairPublisher,
765  OUString const & sReleaseNotes)
766 {
767  OUString sPub = pairPublisher.first;
768  OUString sURL = pairPublisher.second;
769 
770  if ( sPub.isEmpty() && sURL.isEmpty() && sReleaseNotes.isEmpty() )
771  // nothing to show
772  return false;
773 
774  if ( !sPub.isEmpty() )
775  {
776  m_xPublisherLabel->show();
777  m_xPublisherLink->show();
778  m_xPublisherLink->set_label(sPub);
779  m_xPublisherLink->set_uri(sURL);
780  }
781 
782  if ( !sReleaseNotes.isEmpty() )
783  {
784  m_xReleaseNotesLabel->show();
785  m_xReleaseNotesLink->show();
786  m_xReleaseNotesLink->set_uri( sReleaseNotes );
787  }
788  return true;
789 }
790 
791 bool UpdateDialog::showDescription( const OUString& rDescription)
792 {
793  if ( rDescription.isEmpty() )
794  // nothing to show
795  return false;
796 
797  m_xDescriptions->set_text(rDescription);
798  return true;
799 }
800 
801 void UpdateDialog::getIgnoredUpdates()
802 {
803  uno::Reference< lang::XMultiServiceFactory > xConfig(
804  configuration::theDefaultProvider::get(m_context));
805  beans::NamedValue aValue( "nodepath", uno::Any( IGNORED_UPDATES ) );
806  uno::Sequence< uno::Any > args(1);
807  args[0] <<= aValue;
808 
809  uno::Reference< container::XNameAccess > xNameAccess( xConfig->createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", args), uno::UNO_QUERY_THROW );
810  uno::Sequence< OUString > aElementNames = xNameAccess->getElementNames();
811 
812  for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
813  {
814  OUString aIdentifier = aElementNames[i];
815  OUString aVersion;
816 
817  uno::Any aPropValue( uno::Reference< beans::XPropertySet >( xNameAccess->getByName( aIdentifier ), uno::UNO_QUERY_THROW )->getPropertyValue( PROPERTY_VERSION ) );
818  aPropValue >>= aVersion;
819  IgnoredUpdate *pData = new IgnoredUpdate( aIdentifier, aVersion );
820  m_ignoredUpdates.emplace_back( pData );
821  }
822 }
823 
824 
825 bool UpdateDialog::isIgnoredUpdate( UpdateDialog::Index * index )
826 {
827  bool bIsIgnored = false;
828 
829  if (! m_ignoredUpdates.empty() )
830  {
831  OUString aExtensionID;
832  OUString aVersion;
833 
834  if ( index->m_eKind == ENABLED_UPDATE )
835  {
836  dp_gui::UpdateData aUpdData = m_enabledUpdates[ index->m_nIndex ];
837  aExtensionID = dp_misc::getIdentifier( aUpdData.aInstalledPackage );
838  aVersion = aUpdData.updateVersion;
839  }
840  else if ( index->m_eKind == DISABLED_UPDATE )
841  {
842  DisabledUpdate &rData = m_disabledUpdates[ index->m_nIndex ];
843  dp_misc::DescriptionInfoset aInfoset( m_context, rData.aUpdateInfo );
844  ::o3tl::optional< OUString > aID( aInfoset.getIdentifier() );
845  if ( aID )
846  aExtensionID = *aID;
847  aVersion = aInfoset.getVersion();
848  }
849 
850  for (auto const& ignoredUpdate : m_ignoredUpdates)
851  {
852  if ( ignoredUpdate->sExtensionID == aExtensionID )
853  {
854  if ( ( !ignoredUpdate->sVersion.isEmpty() ) || ( ignoredUpdate->sVersion == aVersion ) )
855  {
856  bIsIgnored = true;
857  index->m_bIgnored = true;
858  }
859  break;
860  }
861  }
862  }
863 
864  return bIsIgnored;
865 }
866 
867 
868 IMPL_LINK_NOARG(UpdateDialog, selectionHandler, weld::TreeView&, void)
869 {
870  OUStringBuffer b;
871  int nSelectedPos = m_xUpdates->get_selected_index();
872  clearDescription();
873 
874  const UpdateDialog::Index* p = nullptr;
875  if (nSelectedPos != -1)
876  p = reinterpret_cast<UpdateDialog::Index const *>(m_xUpdates->get_id(nSelectedPos).toInt64());
877  if (p != nullptr)
878  {
879  sal_uInt16 pos = p->m_nIndex;
880 
881  switch (p->m_eKind)
882  {
883  case ENABLED_UPDATE:
884  {
885  if ( m_enabledUpdates[ pos ].aUpdateSource.is() )
886  showDescription( m_enabledUpdates[ pos ].aUpdateSource );
887  else
888  showDescription( m_enabledUpdates[ pos ].aUpdateInfo );
889 
890  if ( p->m_bIgnored )
891  b.append( m_ignoredUpdate );
892 
893  break;
894  }
895  case DISABLED_UPDATE:
896  {
897  if ( !m_disabledUpdates.empty() )
898  showDescription( m_disabledUpdates[pos].aUpdateInfo );
899 
900  if ( p->m_bIgnored )
901  b.append( m_ignoredUpdate );
902 
903  if ( m_disabledUpdates.empty() )
904  break;
905 
906  UpdateDialog::DisabledUpdate & data = m_disabledUpdates[ pos ];
907  if (data.unsatisfiedDependencies.hasElements())
908  {
909  // create error string for version mismatch
910  OUString sVersion( "%VERSION" );
911  OUString sProductName( "%PRODUCTNAME" );
912  sal_Int32 nPos = m_noDependencyCurVer.indexOf( sVersion );
913  if ( nPos >= 0 )
914  {
915  m_noDependencyCurVer = m_noDependencyCurVer.replaceAt( nPos, sVersion.getLength(), utl::ConfigManager::getAboutBoxProductVersion() );
916  }
917  nPos = m_noDependencyCurVer.indexOf( sProductName );
918  if ( nPos >= 0 )
919  {
920  m_noDependencyCurVer = m_noDependencyCurVer.replaceAt( nPos, sProductName.getLength(), utl::ConfigManager::getProductName() );
921  }
922  nPos = m_noDependency.indexOf( sProductName );
923  if ( nPos >= 0 )
924  {
925  m_noDependency = m_noDependency.replaceAt( nPos, sProductName.getLength(), utl::ConfigManager::getProductName() );
926  }
927 
928  b.append(m_noInstall);
929  b.append(LF);
930  b.append(m_noDependency);
931  for (sal_Int32 i = 0;
932  i < data.unsatisfiedDependencies.getLength(); ++i)
933  {
934  b.append(LF);
935  b.append(" ");
936  // U+2003 EM SPACE would be better than two spaces,
937  // but some fonts do not contain it
938  b.append(
939  confineToParagraph(
940  data.unsatisfiedDependencies[i]));
941  }
942  b.append(LF);
943  b.append(" ");
944  b.append(m_noDependencyCurVer);
945  }
946  break;
947  }
948  case SPECIFIC_ERROR:
949  {
950  UpdateDialog::SpecificError & data = m_specificErrors[ pos ];
951  b.append(m_failure);
952  b.append(LF);
953  b.append( data.message.isEmpty() ? m_unknownError : data.message );
954  break;
955  }
956  default:
957  OSL_ASSERT(false);
958  break;
959  }
960  }
961 
962  if ( b.isEmpty() )
963  b.append( m_noDescription );
964 
965  showDescription( b.makeStringAndClear() );
966 }
967 
969 {
970  if (m_xAll->get_active())
971  {
972  m_xUpdate->set_sensitive(true);
973  m_xUpdates->set_sensitive(true);
974  m_xDescription->set_sensitive(true);
975  m_xDescriptions->set_sensitive(true);
976 
977  for (auto const& listboxEntry : m_ListboxEntries)
978  {
979  if ( listboxEntry->m_bIgnored || ( listboxEntry->m_eKind != ENABLED_UPDATE ) )
980  insertItem(listboxEntry.get(), false);
981  }
982  }
983  else
984  {
985  for (sal_uInt16 i = m_xUpdates->n_children(); i != 0 ;)
986  {
987  i -= 1;
988  UpdateDialog::Index const * p = reinterpret_cast< UpdateDialog::Index const * >( m_xUpdates->get_id(i).toInt64() );
989  if ( p->m_bIgnored || ( p->m_eKind != ENABLED_UPDATE ) )
990  {
991  m_xUpdates->remove(i);
992  }
993  }
994 
995  if (m_xUpdates->n_children() == 0)
996  {
997  clearDescription();
998  m_xUpdate->set_sensitive(false);
999  m_xUpdates->set_sensitive(false);
1000  if (m_xChecking->get_visible())
1001  m_xDescription->set_sensitive(false);
1002  else
1003  showDescription(m_noInstallable);
1004  }
1005  }
1006 }
1007 
1009 {
1010  //If users are going to update a shared extension then we need
1011  //to warn them
1012  for (auto const& enableUpdate : m_enabledUpdates)
1013  {
1014  OSL_ASSERT(enableUpdate.aInstalledPackage.is());
1015  //If the user has no write access to the shared folder then the update
1016  //for a shared extension is disable, that is it cannot be in m_enabledUpdates
1017  }
1018 
1019 
1020  for (sal_uInt16 i = 0, nCount = m_xUpdates->n_children(); i < nCount; ++i)
1021  {
1022  UpdateDialog::Index const * p =
1023  reinterpret_cast< UpdateDialog::Index const * >(
1024  m_xUpdates->get_id(i).toInt64());
1025  if (p->m_eKind == ENABLED_UPDATE && m_xUpdates->get_toggle(i, 0) == TRISTATE_TRUE) {
1026  m_updateData.push_back( m_enabledUpdates[ p->m_nIndex ] );
1027  }
1028  }
1029 
1030  m_xDialog->response(RET_OK);
1031 }
1032 
1034 {
1035  m_thread->stop();
1036  m_xDialog->response(RET_CANCEL);
1037 }
1038 
1039 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::o3tl::optional< OUString > getIdentifier() const
Return the identifier.
uno::Reference< task::XInteractionHandler > m_xInteractionHdl
css::uno::Reference< css::deployment::XPackage > aInstalledPackage
css::uno::Reference< css::xml::dom::XNode > aUpdateInfo
std::map< OUString, UpdateInfo > UpdateInfoMap
Definition: dp_update.hxx:102
URL aURL
sal_Int32 nIndex
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
void prepareUpdateData(css::uno::Reference< css::xml::dom::XNode > const &updateInfo, UpdateDialog::DisabledUpdate &out_du, dp_gui::UpdateData &out_data) const
out_data will only be filled if all dependencies are ok.
uno::Reference< deployment::XUpdateInformationProvider > m_updateInformation
css::uno::Reference< css::xml::dom::XNode > aUpdateInfo
bool update()
Definition: updater.cxx:284
std::shared_ptr< ContentProperties > const pData
const sal_Char LF
Definition: dp_misc.h:38
uno::Reference< uno::XComponentContext > m_context
bool office_is_running()
Definition: dp_misc.cxx:348
tuple args
const ContentProperties & rData
virtual Dialog * getDialog() override
TRISTATE_TRUE
RET_CANCEL
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
Thread(uno::Reference< uno::XComponentContext > const &context, UpdateDialog &dialog, const std::vector< uno::Reference< deployment::XPackage > > &vExtensionList)
OUString getVersion() const
Return the textual version representation.
sal_uInt16 sal_Unicode
IMPL_LINK_NOARG(UpdateDialog, selectionHandler, weld::TreeView &, void)
size_t pos
std::vector< uno::Reference< deployment::XPackage > > m_vExtensionList
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
OUString getUpdateDisplayString(dp_gui::UpdateData const &data, OUString const &version=OUString()) const
int nCount
IMPL_LINK(UpdateDialog, entryToggled, const row_col &, rRowCol, void)
std::vector< uno::Reference< deployment::XPackage > > m_vExtensionList
void handleSpecificError(uno::Reference< deployment::XPackage > const &package, uno::Any const &exception) const
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC UPDATE_SOURCE isUpdateSharedExtension(bool bReadOnlyShared, OUString const &sharedVersion, OUString const &bundledVersion, OUString const &onlineVersion)
Definition: dp_update.cxx:284
static OUString getProductName()
const sal_Char CR
Definition: dp_misc.h:37
int i
TRISTATE_FALSE
css::uno::Reference< css::xml::dom::XNode > info
Definition: dp_update.hxx:99
The modal “Check for Updates” dialog.
static OUString getAboutBoxProductVersion()
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC UPDATE_SOURCE isUpdateUserExtension(bool bReadOnlyShared, OUString const &userVersion, OUString const &sharedVersion, OUString const &bundledVersion, OUString const &onlineVersion)
Definition: dp_update.cxx:234
#define IGNORED_UPDATES
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:1882
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC UpdateInfoMap getOnlineUpdateInfos(css::uno::Reference< css::uno::XComponentContext > const &xContext, css::uno::Reference< css::deployment::XExtensionManager > const &xExtMgr, css::uno::Reference< css::deployment::XUpdateInformationProvider > const &updateInformation, std::vector< css::uno::Reference< css::deployment::XPackage > > const *extensionList, std::vector< std::pair< css::uno::Reference< css::deployment::XPackage >, css::uno::Any > > &out_errors)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > > check(dp_misc::DescriptionInfoset const &infoset)
Check for unsatisfied dependencies.
void TRACE(OUString const &sText)
print the text to the console in a debug build.
Definition: dp_misc.cxx:527
Reference< XDispatch > xDispatch
IgnoredUpdate(const OUString &rExtensionID, const OUString &rVersion)
css::uno::Reference< css::deployment::XPackage > extension
Definition: dp_update.hxx:96
RET_OK
Reference< XExecutableDialog > m_xDialog
void * p
Reference< XComponentContext > getProcessComponentContext()
virtual void execute() override
bool update(UpdateDialog::DisabledUpdate const &du, dp_gui::UpdateData const &data) const
#define PROPERTY_VERSION
OUString DpResId(const char *pId)
Definition: dp_shared.hxx:38
::o3tl::optional< OUString > getLocalizedUpdateWebsiteURL() const
returns the download website URL from the update information.
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString getErrorText(css::uno::Reference< css::xml::dom::XElement > const &dependency)
Obtain the (human-readable) error message of a failed dependency.
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString getIdentifier(css::uno::Reference< css::deployment::XPackage > const &package)
Gets the identifier of a package.
Index(Kind theKind, sal_uInt16 nIndex, const OUString &rName)
uno::Sequence< OUString > unsatisfiedDependencies
sal_uInt16 nPos
Access to the content of an XML description element.