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