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 <boost/optional.hpp>
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 ::boost::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 sal_uInt16 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  for (sal_uInt16 i = nEntry; i != 0 ;)
543  {
544  i -= 1;
545  UpdateDialog::Index const * p = reinterpret_cast< UpdateDialog::Index const * >(m_xUpdates->get_id(i).toInt64());
546  if ( p == pEntry )
547  return i;
548  }
549  OSL_ASSERT(false);
550  return 0;
551 }
552 
553 void UpdateDialog::addAdditional(UpdateDialog::Index * index, bool bEnabledCheckBox)
554 {
555  m_xAll->set_sensitive(true);
556  if (m_xAll->get_active())
557  {
558  insertItem(index, bEnabledCheckBox);
559  m_xUpdate->set_sensitive(true);
560  m_xUpdates->set_sensitive(true);
561  m_xDescription->set_sensitive(true);
562  m_xDescriptions->set_sensitive(true);
563  }
564 }
565 
566 void UpdateDialog::addEnabledUpdate( OUString const & name,
567  dp_gui::UpdateData const & data )
568 {
569  sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_enabledUpdates.size() );
570  UpdateDialog::Index *pEntry = new UpdateDialog::Index( ENABLED_UPDATE, nIndex, name );
571 
572  m_enabledUpdates.push_back( data );
573  m_ListboxEntries.emplace_back( pEntry );
574 
575  if (!isIgnoredUpdate(pEntry))
576  {
577  insertItem(pEntry, true);
578  }
579  else
580  addAdditional(pEntry, false);
581 
582  m_xUpdate->set_sensitive(true);
583  m_xUpdates->set_sensitive(true);
584  m_xDescription->set_sensitive(true);
585  m_xDescriptions->set_sensitive(true);
586 }
587 
588 void UpdateDialog::addDisabledUpdate( UpdateDialog::DisabledUpdate const & data )
589 {
590  sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_disabledUpdates.size() );
591  UpdateDialog::Index *pEntry = new UpdateDialog::Index( DISABLED_UPDATE, nIndex, data.name );
592 
593  m_disabledUpdates.push_back( data );
594  m_ListboxEntries.emplace_back( pEntry );
595 
596  isIgnoredUpdate( pEntry );
597  addAdditional(pEntry, false);
598 }
599 
600 void UpdateDialog::addSpecificError( UpdateDialog::SpecificError const & data )
601 {
602  sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_specificErrors.size() );
603  UpdateDialog::Index *pEntry = new UpdateDialog::Index( SPECIFIC_ERROR, nIndex, data.name );
604 
605  m_specificErrors.push_back( data );
606  m_ListboxEntries.emplace_back( pEntry );
607 
608  addAdditional(pEntry, false);
609 }
610 
611 void UpdateDialog::checkingDone() {
612  m_xChecking->hide();
613  m_xThrobber->stop();
614  m_xThrobber->hide();
615  if (m_xUpdates->n_children() == 0)
616  {
617  clearDescription();
618  m_xDescription->set_sensitive(true);
619  m_xDescriptions->set_sensitive(true);
620 
621  if ( m_disabledUpdates.empty() && m_specificErrors.empty() && m_ignoredUpdates.empty() )
622  showDescription( m_none );
623  else
624  showDescription( m_noInstallable );
625  }
626 
627  enableOk();
628 }
629 
630 void UpdateDialog::enableOk() {
631  if (!m_xChecking->get_visible()) {
632  int nChecked = 0;
633  for (int i = 0, nCount = m_xUpdates->n_children(); i < nCount; ++i) {
634  if (m_xUpdates->get_toggle(i, 0) == TRISTATE_TRUE)
635  ++nChecked;
636  }
637  m_xOk->set_sensitive(nChecked != 0);
638  }
639 }
640 
641 // *********************************************************************************
642 void UpdateDialog::createNotifyJob( bool bPrepareOnly,
643  uno::Sequence< uno::Sequence< OUString > > const &rItemList )
644 {
646  return;
647 
648  // notify update check job
649  try
650  {
651  uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
652  configuration::theDefaultProvider::get(
654 
655  beans::PropertyValue aProperty;
656  aProperty.Name = "nodepath";
657  aProperty.Value <<= OUString("org.openoffice.Office.Addons/AddonUI/OfficeHelp/UpdateCheckJob");
658 
659  uno::Sequence< uno::Any > aArgumentList( 1 );
660  aArgumentList[0] <<= aProperty;
661 
662  uno::Reference< container::XNameAccess > xNameAccess(
663  xConfigProvider->createInstanceWithArguments(
664  "com.sun.star.configuration.ConfigurationAccess", aArgumentList ),
665  uno::UNO_QUERY_THROW );
666 
667  util::URL aURL;
668  xNameAccess->getByName("URL") >>= aURL.Complete;
669 
670  uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
671  uno::Reference < util::XURLTransformer > xTransformer = util::URLTransformer::create(xContext);
672 
673  xTransformer->parseStrict(aURL);
674 
675  uno::Reference < frame::XDesktop2 > xDesktop = frame::Desktop::create( xContext );
676  uno::Reference< frame::XDispatchProvider > xDispatchProvider( xDesktop->getCurrentFrame(),
677  uno::UNO_QUERY_THROW );
678  uno::Reference< frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch(aURL, OUString(), 0);
679 
680  if( xDispatch.is() )
681  {
682  uno::Sequence< beans::PropertyValue > aPropList(2);
683  aProperty.Name = "updateList";
684  aProperty.Value <<= rItemList;
685  aPropList[0] = aProperty;
686  aProperty.Name = "prepareOnly";
687  aProperty.Value <<= bPrepareOnly;
688  aPropList[1] = aProperty;
689 
690  xDispatch->dispatch(aURL, aPropList );
691  }
692  }
693  catch( const uno::Exception& e )
694  {
695  dp_misc::TRACE( "Caught exception: "
696  + e.Message + "\n thread terminated.\n\n");
697  }
698 }
699 
700 // *********************************************************************************
701 void UpdateDialog::notifyMenubar( bool bPrepareOnly, bool bRecheckOnly )
702 {
704  return;
705 
706  uno::Sequence< uno::Sequence< OUString > > aItemList;
707 
708  if ( ! bRecheckOnly )
709  {
710  sal_Int32 nCount = 0;
711  for (sal_uInt16 i = 0, nItemCount = m_xUpdates->n_children(); i < nItemCount; ++i)
712  {
713  uno::Sequence< OUString > aItem(2);
714 
715  UpdateDialog::Index const * p = reinterpret_cast< UpdateDialog::Index const * >(m_xUpdates->get_id(i).toInt64());
716 
717  if ( p->m_eKind == ENABLED_UPDATE )
718  {
719  dp_gui::UpdateData aUpdData = m_enabledUpdates[ p->m_nIndex ];
720  aItem[0] = dp_misc::getIdentifier( aUpdData.aInstalledPackage );
721 
722  dp_misc::DescriptionInfoset aInfoset( m_context, aUpdData.aUpdateInfo );
723  aItem[1] = aInfoset.getVersion();
724  }
725  else
726  continue;
727 
728  aItemList.realloc( nCount + 1 );
729  aItemList[ nCount ] = aItem;
730  nCount += 1;
731  }
732  }
733 
734  createNotifyJob( bPrepareOnly, aItemList );
735 }
736 
737 // *********************************************************************************
738 
739 void UpdateDialog::initDescription()
740 {
741  m_xPublisherLabel->hide();
742  m_xPublisherLink->hide();
743  m_xReleaseNotesLabel->hide();
744  m_xReleaseNotesLink->hide();
745 }
746 
747 void UpdateDialog::clearDescription()
748 {
749  m_xPublisherLabel->hide();
750  m_xPublisherLink->hide();
751  m_xPublisherLink->set_label("");
752  m_xPublisherLink->set_uri("");
753  m_xReleaseNotesLabel->hide();
754  m_xReleaseNotesLink->hide();
755  m_xReleaseNotesLink->set_uri( "" );
756  m_xDescriptions->set_text("");
757 }
758 
759 bool UpdateDialog::showDescription(uno::Reference< xml::dom::XNode > const & aUpdateInfo)
760 {
761  dp_misc::DescriptionInfoset infoset(m_context, aUpdateInfo);
762  return showDescription(infoset.getLocalizedPublisherNameAndURL(),
763  infoset.getLocalizedReleaseNotesURL());
764 }
765 
766 bool UpdateDialog::showDescription(uno::Reference< deployment::XPackage > const & aExtension)
767 {
768  OSL_ASSERT(aExtension.is());
769  beans::StringPair pubInfo = aExtension->getPublisherInfo();
770  return showDescription(std::make_pair(pubInfo.First, pubInfo.Second),
771  "");
772 }
773 
774 bool UpdateDialog::showDescription(std::pair< OUString, OUString > const & pairPublisher,
775  OUString const & sReleaseNotes)
776 {
777  OUString sPub = pairPublisher.first;
778  OUString sURL = pairPublisher.second;
779 
780  if ( sPub.isEmpty() && sURL.isEmpty() && sReleaseNotes.isEmpty() )
781  // nothing to show
782  return false;
783 
784  if ( !sPub.isEmpty() )
785  {
786  m_xPublisherLabel->show();
787  m_xPublisherLink->show();
788  m_xPublisherLink->set_label(sPub);
789  m_xPublisherLink->set_uri(sURL);
790  }
791 
792  if ( !sReleaseNotes.isEmpty() )
793  {
794  m_xReleaseNotesLabel->show();
795  m_xReleaseNotesLink->show();
796  m_xReleaseNotesLink->set_uri( sReleaseNotes );
797  }
798  return true;
799 }
800 
801 bool UpdateDialog::showDescription( const OUString& rDescription)
802 {
803  if ( rDescription.isEmpty() )
804  // nothing to show
805  return false;
806 
807  m_xDescriptions->set_text(rDescription);
808  return true;
809 }
810 
811 void UpdateDialog::getIgnoredUpdates()
812 {
813  uno::Reference< lang::XMultiServiceFactory > xConfig(
814  configuration::theDefaultProvider::get(m_context));
815  beans::NamedValue aValue( "nodepath", uno::Any( IGNORED_UPDATES ) );
816  uno::Sequence< uno::Any > args(1);
817  args[0] <<= aValue;
818 
819  uno::Reference< container::XNameAccess > xNameAccess( xConfig->createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", args), uno::UNO_QUERY_THROW );
820  uno::Sequence< OUString > aElementNames = xNameAccess->getElementNames();
821 
822  for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
823  {
824  OUString aIdentifier = aElementNames[i];
825  OUString aVersion;
826 
827  uno::Any aPropValue( uno::Reference< beans::XPropertySet >( xNameAccess->getByName( aIdentifier ), uno::UNO_QUERY_THROW )->getPropertyValue( PROPERTY_VERSION ) );
828  aPropValue >>= aVersion;
829  IgnoredUpdate *pData = new IgnoredUpdate( aIdentifier, aVersion );
830  m_ignoredUpdates.emplace_back( pData );
831  }
832 }
833 
834 
835 bool UpdateDialog::isIgnoredUpdate( UpdateDialog::Index * index )
836 {
837  bool bIsIgnored = false;
838 
839  if (! m_ignoredUpdates.empty() )
840  {
841  OUString aExtensionID;
842  OUString aVersion;
843 
844  if ( index->m_eKind == ENABLED_UPDATE )
845  {
846  dp_gui::UpdateData aUpdData = m_enabledUpdates[ index->m_nIndex ];
847  aExtensionID = dp_misc::getIdentifier( aUpdData.aInstalledPackage );
848  aVersion = aUpdData.updateVersion;
849  }
850  else if ( index->m_eKind == DISABLED_UPDATE )
851  {
852  DisabledUpdate &rData = m_disabledUpdates[ index->m_nIndex ];
853  dp_misc::DescriptionInfoset aInfoset( m_context, rData.aUpdateInfo );
855  if ( aID )
856  aExtensionID = *aID;
857  aVersion = aInfoset.getVersion();
858  }
859 
860  for (auto const& ignoredUpdate : m_ignoredUpdates)
861  {
862  if ( ignoredUpdate->sExtensionID == aExtensionID )
863  {
864  if ( ( !ignoredUpdate->sVersion.isEmpty() ) || ( ignoredUpdate->sVersion == aVersion ) )
865  {
866  bIsIgnored = true;
867  index->m_bIgnored = true;
868  }
869  break;
870  }
871  }
872  }
873 
874  return bIsIgnored;
875 }
876 
877 
878 IMPL_LINK_NOARG(UpdateDialog, selectionHandler, weld::TreeView&, void)
879 {
880  OUStringBuffer b;
881  int nSelectedPos = m_xUpdates->get_selected_index();
882  clearDescription();
883 
884  const UpdateDialog::Index* p = nullptr;
885  if (nSelectedPos != -1)
886  p = reinterpret_cast<UpdateDialog::Index const *>(m_xUpdates->get_id(nSelectedPos).toInt64());
887  if (p != nullptr)
888  {
889  sal_uInt16 pos = p->m_nIndex;
890 
891  switch (p->m_eKind)
892  {
893  case ENABLED_UPDATE:
894  {
895  if ( m_enabledUpdates[ pos ].aUpdateSource.is() )
896  showDescription( m_enabledUpdates[ pos ].aUpdateSource );
897  else
898  showDescription( m_enabledUpdates[ pos ].aUpdateInfo );
899 
900  if ( p->m_bIgnored )
901  b.append( m_ignoredUpdate );
902 
903  break;
904  }
905  case DISABLED_UPDATE:
906  {
907  if ( !m_disabledUpdates.empty() )
908  showDescription( m_disabledUpdates[pos].aUpdateInfo );
909 
910  if ( p->m_bIgnored )
911  b.append( m_ignoredUpdate );
912 
913  if ( m_disabledUpdates.empty() )
914  break;
915 
916  UpdateDialog::DisabledUpdate & data = m_disabledUpdates[ pos ];
917  if (data.unsatisfiedDependencies.hasElements())
918  {
919  // create error string for version mismatch
920  OUString sVersion( "%VERSION" );
921  OUString sProductName( "%PRODUCTNAME" );
922  sal_Int32 nPos = m_noDependencyCurVer.indexOf( sVersion );
923  if ( nPos >= 0 )
924  {
925  m_noDependencyCurVer = m_noDependencyCurVer.replaceAt( nPos, sVersion.getLength(), utl::ConfigManager::getAboutBoxProductVersion() );
926  }
927  nPos = m_noDependencyCurVer.indexOf( sProductName );
928  if ( nPos >= 0 )
929  {
930  m_noDependencyCurVer = m_noDependencyCurVer.replaceAt( nPos, sProductName.getLength(), utl::ConfigManager::getProductName() );
931  }
932  nPos = m_noDependency.indexOf( sProductName );
933  if ( nPos >= 0 )
934  {
935  m_noDependency = m_noDependency.replaceAt( nPos, sProductName.getLength(), utl::ConfigManager::getProductName() );
936  }
937 
938  b.append(m_noInstall);
939  b.append(LF);
940  b.append(m_noDependency);
941  for (sal_Int32 i = 0;
942  i < data.unsatisfiedDependencies.getLength(); ++i)
943  {
944  b.append(LF);
945  b.append(" ");
946  // U+2003 EM SPACE would be better than two spaces,
947  // but some fonts do not contain it
948  b.append(
949  confineToParagraph(
950  data.unsatisfiedDependencies[i]));
951  }
952  b.append(LF);
953  b.append(" ");
954  b.append(m_noDependencyCurVer);
955  }
956  break;
957  }
958  case SPECIFIC_ERROR:
959  {
960  UpdateDialog::SpecificError & data = m_specificErrors[ pos ];
961  b.append(m_failure);
962  b.append(LF);
963  b.append( data.message.isEmpty() ? m_unknownError : data.message );
964  break;
965  }
966  default:
967  OSL_ASSERT(false);
968  break;
969  }
970  }
971 
972  if ( b.isEmpty() )
973  b.append( m_noDescription );
974 
975  showDescription( b.makeStringAndClear() );
976 }
977 
979 {
980  if (m_xAll->get_active())
981  {
982  m_xUpdate->set_sensitive(true);
983  m_xUpdates->set_sensitive(true);
984  m_xDescription->set_sensitive(true);
985  m_xDescriptions->set_sensitive(true);
986 
987  for (auto const& listboxEntry : m_ListboxEntries)
988  {
989  if ( listboxEntry->m_bIgnored || ( listboxEntry->m_eKind != ENABLED_UPDATE ) )
990  insertItem(listboxEntry.get(), false);
991  }
992  }
993  else
994  {
995  for (sal_uInt16 i = m_xUpdates->n_children(); i != 0 ;)
996  {
997  i -= 1;
998  UpdateDialog::Index const * p = reinterpret_cast< UpdateDialog::Index const * >( m_xUpdates->get_id(i).toInt64() );
999  if ( p->m_bIgnored || ( p->m_eKind != ENABLED_UPDATE ) )
1000  {
1001  m_xUpdates->remove(i);
1002  }
1003  }
1004 
1005  if (m_xUpdates->n_children() == 0)
1006  {
1007  clearDescription();
1008  m_xUpdate->set_sensitive(false);
1009  m_xUpdates->set_sensitive(false);
1010  if (m_xChecking->get_visible())
1011  m_xDescription->set_sensitive(false);
1012  else
1013  showDescription(m_noInstallable);
1014  }
1015  }
1016 }
1017 
1019 {
1020  //If users are going to update a shared extension then we need
1021  //to warn them
1022  for (auto const& enableUpdate : m_enabledUpdates)
1023  {
1024  OSL_ASSERT(enableUpdate.aInstalledPackage.is());
1025  //If the user has no write access to the shared folder then the update
1026  //for a shared extension is disable, that is it cannot be in m_enabledUpdates
1027  }
1028 
1029 
1030  for (sal_uInt16 i = 0, nCount = m_xUpdates->n_children(); i < nCount; ++i)
1031  {
1032  UpdateDialog::Index const * p =
1033  reinterpret_cast< UpdateDialog::Index const * >(
1034  m_xUpdates->get_id(i).toInt64());
1035  if (p->m_eKind == ENABLED_UPDATE && m_xUpdates->get_toggle(i, 0) == TRISTATE_TRUE) {
1036  m_updateData.push_back( m_enabledUpdates[ p->m_nIndex ] );
1037  }
1038  }
1039 
1040  m_xDialog->response(RET_OK);
1041 }
1042 
1044 {
1045  m_thread->stop();
1046  m_xDialog->response(RET_CANCEL);
1047 }
1048 
1049 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
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
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
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)
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
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
::boost::optional< OUString > getLocalizedUpdateWebsiteURL() const
returns the download website URL from the update information.
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:1798
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
IgnoredUpdate(const OUString &rExtensionID, const OUString &rVersion)
css::uno::Reference< css::deployment::XPackage > extension
Definition: dp_update.hxx:96
RET_OK
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
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.
sal_Int32 nPos
Index(Kind theKind, sal_uInt16 nIndex, const OUString &rName)
uno::Sequence< OUString > unsatisfiedDependencies
::boost::optional< OUString > getIdentifier() const
Return the identifier.
Access to the content of an XML description element.