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