LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/desktop/source/deployment/gui - dp_gui_updatedialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 646 0.0 %
Date: 2013-07-09 Functions: 0 64 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <memory>
      27             : #include <utility>
      28             : #include <vector>
      29             : 
      30             : 
      31             : #include "boost/optional.hpp"
      32             : #include "com/sun/star/awt/Rectangle.hpp"
      33             : #include "com/sun/star/awt/WindowAttribute.hpp"
      34             : #include "com/sun/star/awt/WindowClass.hpp"
      35             : #include "com/sun/star/awt/WindowDescriptor.hpp"
      36             : #include "com/sun/star/awt/Toolkit.hpp"
      37             : #include "com/sun/star/awt/XWindow.hpp"
      38             : #include "com/sun/star/awt/XWindowPeer.hpp"
      39             : #include "com/sun/star/beans/NamedValue.hpp"
      40             : #include "com/sun/star/beans/Optional.hpp"
      41             : #include "com/sun/star/beans/PropertyValue.hpp"
      42             : #include "com/sun/star/beans/XPropertySet.hpp"
      43             : #include "com/sun/star/configuration/theDefaultProvider.hpp"
      44             : #include "com/sun/star/container/XNameAccess.hpp"
      45             : #include "com/sun/star/container/XNameContainer.hpp"
      46             : #include "com/sun/star/deployment/DeploymentException.hpp"
      47             : #include "com/sun/star/deployment/UpdateInformationProvider.hpp"
      48             : #include "com/sun/star/deployment/XPackage.hpp"
      49             : #include "com/sun/star/deployment/XExtensionManager.hpp"
      50             : #include "com/sun/star/deployment/ExtensionManager.hpp"
      51             : #include "com/sun/star/deployment/XUpdateInformationProvider.hpp"
      52             : #include "com/sun/star/frame/Desktop.hpp"
      53             : #include "com/sun/star/frame/XDispatch.hpp"
      54             : #include "com/sun/star/frame/XDispatchProvider.hpp"
      55             : #include "com/sun/star/lang/IllegalArgumentException.hpp"
      56             : #include "com/sun/star/lang/XMultiComponentFactory.hpp"
      57             : #include "com/sun/star/lang/XSingleServiceFactory.hpp"
      58             : #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
      59             : #include "com/sun/star/system/SystemShellExecute.hpp"
      60             : #include "com/sun/star/task/InteractionHandler.hpp"
      61             : #include "com/sun/star/task/XAbortChannel.hpp"
      62             : #include "com/sun/star/task/XJob.hpp"
      63             : #include "com/sun/star/ucb/CommandAbortedException.hpp"
      64             : #include "com/sun/star/ucb/CommandFailedException.hpp"
      65             : #include "com/sun/star/ucb/XCommandEnvironment.hpp"
      66             : #include "com/sun/star/uno/Any.hxx"
      67             : #include "com/sun/star/uno/Exception.hpp"
      68             : #include "com/sun/star/uno/Reference.hxx"
      69             : #include "com/sun/star/uno/RuntimeException.hpp"
      70             : #include "com/sun/star/uno/Sequence.hxx"
      71             : #include "com/sun/star/uno/XInterface.hpp"
      72             : #include "com/sun/star/util/URL.hpp"
      73             : #include "com/sun/star/util/XChangesBatch.hpp"
      74             : #include "com/sun/star/util/URLTransformer.hpp"
      75             : #include "com/sun/star/util/XURLTransformer.hpp"
      76             : #include "com/sun/star/xml/dom/XElement.hpp"
      77             : #include "com/sun/star/xml/dom/XNode.hpp"
      78             : #include "osl/diagnose.h"
      79             : #include "rtl/ref.hxx"
      80             : #include "rtl/string.h"
      81             : #include "rtl/ustrbuf.hxx"
      82             : #include "rtl/ustring.h"
      83             : #include "rtl/ustring.hxx"
      84             : #include "sal/types.h"
      85             : #include "salhelper/thread.hxx"
      86             : #include "svtools/svlbitm.hxx"
      87             : #include "svtools/treelistbox.hxx"
      88             : #include <svtools/controldims.hrc>
      89             : #include "svx/checklbx.hxx"
      90             : #include "tools/gen.hxx"
      91             : #include "tools/link.hxx"
      92             : #include "tools/resid.hxx"
      93             : #include "tools/solar.h"
      94             : #include "unotools/configmgr.hxx"
      95             : #include "vcl/button.hxx"
      96             : #include "vcl/dialog.hxx"
      97             : #include "vcl/fixed.hxx"
      98             : #include "vcl/image.hxx"
      99             : #include "vcl/msgbox.hxx"
     100             : #include "vcl/svapp.hxx"
     101             : #include "osl/mutex.hxx"
     102             : 
     103             : #include "comphelper/processfactory.hxx"
     104             : 
     105             : #include "dp_dependencies.hxx"
     106             : #include "dp_descriptioninfoset.hxx"
     107             : #include "dp_identifier.hxx"
     108             : #include "dp_version.hxx"
     109             : #include "dp_misc.h"
     110             : #include "dp_update.hxx"
     111             : 
     112             : #include "dp_gui.h"
     113             : #include "dp_gui.hrc"
     114             : #include "dp_gui_updatedata.hxx"
     115             : #include "dp_gui_updatedialog.hxx"
     116             : #include "dp_gui_shared.hxx"
     117             : 
     118             : class KeyEvent;
     119             : class MouseEvent;
     120             : class Window;
     121             : namespace com { namespace sun { namespace star { namespace uno {
     122             :     class XComponentContext;
     123             : } } } }
     124             : 
     125             : using namespace ::com::sun::star;
     126             : using dp_gui::UpdateDialog;
     127             : 
     128             : namespace {
     129             : 
     130             : static sal_Unicode const LF = 0x000A;
     131             : static sal_Unicode const CR = 0x000D;
     132             : static const sal_uInt16 CMD_ENABLE_UPDATE = 1;
     133             : static const sal_uInt16 CMD_IGNORE_UPDATE = 2;
     134             : static const sal_uInt16 CMD_IGNORE_ALL_UPDATES = 3;
     135             : 
     136             : #define IGNORED_UPDATES     OUString("/org.openoffice.Office.ExtensionManager/ExtensionUpdateData/IgnoredUpdates")
     137             : #define PROPERTY_VERSION    "Version"
     138             : 
     139             : enum Kind { ENABLED_UPDATE, DISABLED_UPDATE, SPECIFIC_ERROR };
     140             : 
     141           0 : OUString confineToParagraph(OUString const & text) {
     142             :     // Confine arbitrary text to a single paragraph in a dp_gui::AutoScrollEdit.
     143             :     // This assumes that U+000A and U+000D are the only paragraph separators in
     144             :     // a dp_gui::AutoScrollEdit, and that replacing them with a single space
     145             :     // each is acceptable:
     146           0 :     return text.replace(LF, ' ').replace(CR, ' ');
     147             : }
     148             : }
     149             : 
     150           0 : struct UpdateDialog::DisabledUpdate {
     151             :     OUString name;
     152             :     uno::Sequence< OUString > unsatisfiedDependencies;
     153             :     // We also want to show release notes and publisher for disabled updates
     154             :     ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode > aUpdateInfo;
     155             :     sal_uInt16 m_nID;
     156             : };
     157             : 
     158           0 : struct UpdateDialog::SpecificError {
     159             :     OUString name;
     160             :     OUString message;
     161             :     sal_uInt16 m_nID;
     162             : };
     163             : 
     164             : //------------------------------------------------------------------------------
     165           0 : struct UpdateDialog::IgnoredUpdate {
     166             :     OUString sExtensionID;
     167             :     OUString sVersion;
     168             :     bool          bRemoved;
     169             : 
     170             :     IgnoredUpdate( const OUString &rExtensionID, const OUString &rVersion );
     171             : };
     172             : 
     173             : //------------------------------------------------------------------------------
     174           0 : UpdateDialog::IgnoredUpdate::IgnoredUpdate( const OUString &rExtensionID, const OUString &rVersion ):
     175             :     sExtensionID( rExtensionID ),
     176             :     sVersion( rVersion ),
     177           0 :     bRemoved( false )
     178           0 : {}
     179             : 
     180             : //------------------------------------------------------------------------------
     181           0 : struct UpdateDialog::Index
     182             : {
     183             :     Kind          m_eKind;
     184             :     bool          m_bIgnored;
     185             :     sal_uInt16        m_nID;
     186             :     sal_uInt16        m_nIndex;
     187             :     OUString m_aName;
     188             : 
     189             :     Index( Kind theKind, sal_uInt16 nID, sal_uInt16 nIndex, const OUString &rName );
     190             : };
     191             : 
     192             : //------------------------------------------------------------------------------
     193           0 : UpdateDialog::Index::Index( Kind theKind, sal_uInt16 nID, sal_uInt16 nIndex, const OUString &rName ):
     194             :     m_eKind( theKind ),
     195             :     m_bIgnored( false ),
     196             :     m_nID( nID ),
     197             :     m_nIndex( nIndex ),
     198           0 :     m_aName( rName )
     199           0 : {}
     200             : 
     201             : //------------------------------------------------------------------------------
     202             : //------------------------------------------------------------------------------
     203             : //------------------------------------------------------------------------------
     204             : class UpdateDialog::Thread: public salhelper::Thread {
     205             : public:
     206             :     Thread(
     207             :         uno::Reference< uno::XComponentContext > const & context,
     208             :         UpdateDialog & dialog,
     209             :         const std::vector< uno::Reference< deployment::XPackage >  > & vExtensionList);
     210             : 
     211             :     void stop();
     212             : 
     213             : private:
     214             :     virtual ~Thread();
     215             : 
     216             :     virtual void execute();
     217             : 
     218             :     void handleSpecificError(
     219             :         uno::Reference< deployment::XPackage > const & package,
     220             :         uno::Any const & exception) const;
     221             : 
     222             :     uno::Sequence< uno::Reference< xml::dom::XElement > >
     223             :     getUpdateInformation(
     224             :         uno::Reference< deployment::XPackage > const & package,
     225             :         uno::Sequence< OUString > const & urls,
     226             :         OUString const & identifier) const;
     227             : 
     228             :     OUString getUpdateDisplayString(
     229             :         dp_gui::UpdateData const & data, OUString const & version = OUString()) const;
     230             : 
     231             :     void prepareUpdateData(
     232             :         ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode > const & updateInfo,
     233             :         UpdateDialog::DisabledUpdate & out_du,
     234             :         dp_gui::UpdateData & out_data) const;
     235             : 
     236             :     bool update(
     237             :         UpdateDialog::DisabledUpdate & du,
     238             :         dp_gui::UpdateData & data) const;
     239             : 
     240             :     uno::Reference< uno::XComponentContext > m_context;
     241             :     UpdateDialog & m_dialog;
     242             :     std::vector< uno::Reference< deployment::XPackage > > m_vExtensionList;
     243             :     uno::Reference< deployment::XUpdateInformationProvider > m_updateInformation;
     244             :     uno::Reference< task::XInteractionHandler > m_xInteractionHdl;
     245             : 
     246             :     // guarded by Application::GetSolarMutex():
     247             :     uno::Reference< task::XAbortChannel > m_abort;
     248             :     bool m_stop;
     249             : };
     250             : 
     251           0 : UpdateDialog::Thread::Thread(
     252             :     uno::Reference< uno::XComponentContext > const & context,
     253             :     UpdateDialog & dialog,
     254             :     const std::vector< uno::Reference< deployment::XPackage > > &vExtensionList):
     255             :     salhelper::Thread("dp_gui_updatedialog"),
     256             :     m_context(context),
     257             :     m_dialog(dialog),
     258             :     m_vExtensionList(vExtensionList),
     259             :     m_updateInformation(
     260             :         deployment::UpdateInformationProvider::create(context)),
     261           0 :     m_stop(false)
     262             : {
     263           0 :     if( m_context.is() )
     264             :     {
     265             :         m_xInteractionHdl.set(
     266             :             task::InteractionHandler::createWithParent(m_context, 0),
     267           0 :             uno::UNO_QUERY );
     268           0 :         m_updateInformation->setInteractionHandler( m_xInteractionHdl );
     269             :     }
     270           0 : }
     271             : 
     272           0 : void UpdateDialog::Thread::stop() {
     273           0 :     uno::Reference< task::XAbortChannel > abort;
     274             :     {
     275           0 :         SolarMutexGuard g;
     276           0 :         abort = m_abort;
     277           0 :         m_stop = true;
     278             :     }
     279           0 :     if (abort.is()) {
     280           0 :         abort->sendAbort();
     281             :     }
     282           0 :     m_updateInformation->cancel();
     283           0 : }
     284             : 
     285           0 : UpdateDialog::Thread::~Thread()
     286             : {
     287           0 :     if ( m_xInteractionHdl.is() )
     288           0 :         m_updateInformation->setInteractionHandler( uno::Reference< task::XInteractionHandler > () );
     289           0 : }
     290             : 
     291           0 : void UpdateDialog::Thread::execute()
     292             : {
     293             :     {
     294           0 :         SolarMutexGuard g;
     295           0 :         if ( m_stop ) {
     296           0 :             return;
     297           0 :         }
     298             :     }
     299             :     uno::Reference<deployment::XExtensionManager> extMgr =
     300           0 :         deployment::ExtensionManager::get(m_context);
     301             : 
     302           0 :     std::vector<std::pair<uno::Reference<deployment::XPackage>, uno::Any > > errors;
     303             : 
     304             :     dp_misc::UpdateInfoMap updateInfoMap = dp_misc::getOnlineUpdateInfos(
     305           0 :         m_context, extMgr, m_updateInformation, &m_vExtensionList, errors);
     306             : 
     307             :     typedef std::vector<std::pair<uno::Reference<deployment::XPackage>,
     308             :         uno::Any> >::const_iterator ITERROR;
     309           0 :     for (ITERROR ite = errors.begin(); ite != errors.end(); ++ite )
     310           0 :         handleSpecificError(ite->first, ite->second);
     311             : 
     312           0 :     for (dp_misc::UpdateInfoMap::iterator i(updateInfoMap.begin()); i != updateInfoMap.end(); ++i)
     313             :     {
     314           0 :         dp_misc::UpdateInfo const & info = i->second;
     315           0 :         UpdateData updateData(info.extension);
     316           0 :         DisabledUpdate disableUpdate;
     317             :         //determine if online updates meet the requirements
     318           0 :         prepareUpdateData(info.info, disableUpdate, updateData);
     319             : 
     320             :         //determine if the update is installed in the user or shared repository
     321           0 :         OUString sOnlineVersion;
     322           0 :         if (info.info.is())
     323           0 :             sOnlineVersion = info.version;
     324           0 :         OUString sVersionUser;
     325           0 :         OUString sVersionShared;
     326           0 :         OUString sVersionBundled;
     327           0 :         uno::Sequence< uno::Reference< deployment::XPackage> > extensions;
     328             :         try {
     329           0 :             extensions = extMgr->getExtensionsWithSameIdentifier(
     330           0 :                 dp_misc::getIdentifier(info.extension), info.extension->getName(),
     331           0 :                 uno::Reference<ucb::XCommandEnvironment>());
     332           0 :         } catch ( const lang::IllegalArgumentException& ) {
     333             :             OSL_ASSERT(0);
     334           0 :             continue;
     335           0 :         } catch ( const css::ucb::CommandFailedException& ) {
     336             :             OSL_ASSERT(0);
     337           0 :             continue;
     338             :         }
     339             :         OSL_ASSERT(extensions.getLength() == 3);
     340           0 :         if (extensions[0].is() )
     341           0 :             sVersionUser = extensions[0]->getVersion();
     342           0 :         if (extensions[1].is() )
     343           0 :             sVersionShared = extensions[1]->getVersion();
     344           0 :         if (extensions[2].is() )
     345           0 :             sVersionBundled = extensions[2]->getVersion();
     346             : 
     347           0 :         bool bSharedReadOnly = extMgr->isReadOnlyRepository("shared");
     348             : 
     349             :         dp_misc::UPDATE_SOURCE sourceUser = dp_misc::isUpdateUserExtension(
     350           0 :             bSharedReadOnly, sVersionUser, sVersionShared, sVersionBundled, sOnlineVersion);
     351             :         dp_misc::UPDATE_SOURCE sourceShared = dp_misc::isUpdateSharedExtension(
     352           0 :             bSharedReadOnly, sVersionShared, sVersionBundled, sOnlineVersion);
     353             : 
     354           0 :         uno::Reference<deployment::XPackage> updateSource;
     355           0 :         if (sourceUser != dp_misc::UPDATE_SOURCE_NONE)
     356             :         {
     357           0 :             if (sourceUser == dp_misc::UPDATE_SOURCE_SHARED)
     358             :             {
     359           0 :                 updateData.aUpdateSource = extensions[1];
     360           0 :                 updateData.updateVersion = extensions[1]->getVersion();
     361             :             }
     362           0 :             else if (sourceUser == dp_misc::UPDATE_SOURCE_BUNDLED)
     363             :             {
     364           0 :                 updateData.aUpdateSource = extensions[2];
     365           0 :                 updateData.updateVersion = extensions[2]->getVersion();
     366             :             }
     367           0 :             if (!update(disableUpdate, updateData))
     368           0 :                 return;
     369             :         }
     370             : 
     371           0 :         if (sourceShared != dp_misc::UPDATE_SOURCE_NONE)
     372             :         {
     373           0 :             if (sourceShared == dp_misc::UPDATE_SOURCE_BUNDLED)
     374             :             {
     375           0 :                 updateData.aUpdateSource = extensions[2];
     376           0 :                 updateData.updateVersion = extensions[2]->getVersion();
     377             :             }
     378           0 :             updateData.bIsShared = true;
     379           0 :             if (!update(disableUpdate, updateData))
     380           0 :                 return;
     381             :         }
     382           0 :     }
     383             : 
     384             : 
     385           0 :     SolarMutexGuard g;
     386           0 :     if (!m_stop) {
     387           0 :         m_dialog.checkingDone();
     388           0 :     }
     389             : }
     390             : 
     391             : //Parameter package can be null
     392           0 : void UpdateDialog::Thread::handleSpecificError(
     393             :     uno::Reference< deployment::XPackage > const & package,
     394             :     uno::Any const & exception) const
     395             : {
     396           0 :     UpdateDialog::SpecificError data;
     397           0 :     if (package.is())
     398           0 :         data.name = package->getDisplayName();
     399           0 :     uno::Exception e;
     400           0 :     if (exception >>= e) {
     401           0 :         data.message = e.Message;
     402             :     }
     403           0 :     SolarMutexGuard g;
     404           0 :     if (!m_stop) {
     405           0 :         m_dialog.addSpecificError(data);
     406           0 :     }
     407           0 : }
     408             : 
     409           0 : OUString UpdateDialog::Thread::getUpdateDisplayString(
     410             :     dp_gui::UpdateData const & data, OUString const & version) const
     411             : {
     412             :     OSL_ASSERT(data.aInstalledPackage.is());
     413           0 :     OUStringBuffer b(data.aInstalledPackage->getDisplayName());
     414           0 :     b.append(static_cast< sal_Unicode >(' '));
     415             :     {
     416           0 :         SolarMutexGuard g;
     417           0 :         if(!m_stop)
     418           0 :             b.append(m_dialog.m_version);
     419             :     }
     420           0 :     b.append(static_cast< sal_Unicode >(' '));
     421           0 :     if (!version.isEmpty())
     422           0 :         b.append(version);
     423             :     else
     424           0 :         b.append(data.updateVersion);
     425             : 
     426           0 :     if (!data.sWebsiteURL.isEmpty())
     427             :     {
     428           0 :         b.append(static_cast< sal_Unicode >(' '));
     429             :         {
     430           0 :             SolarMutexGuard g;
     431           0 :             if(!m_stop)
     432           0 :                 b.append(m_dialog.m_browserbased);
     433             :         }
     434             :     }
     435           0 :     return  b.makeStringAndClear();
     436             : }
     437             : 
     438             : /** out_data will only be filled if all dependencies are ok.
     439             :  */
     440           0 : void UpdateDialog::Thread::prepareUpdateData(
     441             :     uno::Reference< xml::dom::XNode > const & updateInfo,
     442             :     UpdateDialog::DisabledUpdate & out_du,
     443             :     dp_gui::UpdateData & out_data) const
     444             : {
     445           0 :     if (!updateInfo.is())
     446           0 :         return;
     447           0 :     dp_misc::DescriptionInfoset infoset(m_context, updateInfo);
     448             :     OSL_ASSERT(!infoset.getVersion().isEmpty());
     449             :     uno::Sequence< uno::Reference< xml::dom::XElement > > ds(
     450           0 :         dp_misc::Dependencies::check(infoset));
     451             : 
     452           0 :     out_du.aUpdateInfo = updateInfo;
     453           0 :     out_du.unsatisfiedDependencies.realloc(ds.getLength());
     454           0 :     for (sal_Int32 i = 0; i < ds.getLength(); ++i) {
     455           0 :         out_du.unsatisfiedDependencies[i] = dp_misc::Dependencies::getErrorText(ds[i]);
     456             :     }
     457             : 
     458           0 :     const ::boost::optional< OUString> updateWebsiteURL(infoset.getLocalizedUpdateWebsiteURL());
     459             : 
     460           0 :     out_du.name = getUpdateDisplayString(out_data, infoset.getVersion());
     461             : 
     462           0 :     if (out_du.unsatisfiedDependencies.getLength() == 0)
     463             :     {
     464           0 :         out_data.aUpdateInfo = updateInfo;
     465           0 :         out_data.updateVersion = infoset.getVersion();
     466           0 :         if (updateWebsiteURL)
     467           0 :             out_data.sWebsiteURL = *updateWebsiteURL;
     468           0 :     }
     469             : }
     470             : 
     471           0 : bool UpdateDialog::Thread::update(
     472             :     UpdateDialog::DisabledUpdate & du,
     473             :     dp_gui::UpdateData & data) const
     474             : {
     475           0 :     bool ret = false;
     476           0 :     if (du.unsatisfiedDependencies.getLength() == 0)
     477             :     {
     478           0 :         SolarMutexGuard g;
     479           0 :         if (!m_stop) {
     480           0 :             m_dialog.addEnabledUpdate(getUpdateDisplayString(data), data);
     481             :         }
     482           0 :         ret = !m_stop;
     483             :     } else {
     484           0 :         SolarMutexGuard g;
     485           0 :         if (!m_stop) {
     486           0 :                 m_dialog.addDisabledUpdate(du);
     487             :         }
     488           0 :         ret = !m_stop;
     489             :     }
     490           0 :     return ret;
     491             : }
     492             : 
     493             : // UpdateDialog ----------------------------------------------------------
     494           0 : UpdateDialog::UpdateDialog(
     495             :     uno::Reference< uno::XComponentContext > const & context,
     496             :     Window * parent,
     497             :     const std::vector<uno::Reference< deployment::XPackage > > &vExtensionList,
     498             :     std::vector< dp_gui::UpdateData > * updateData):
     499             :     ModalDialog(parent,DpGuiResId(RID_DLG_UPDATE)),
     500             :     m_context(context),
     501             :     m_checking(this, DpGuiResId(RID_DLG_UPDATE_CHECKING)),
     502             :     m_throbber(this, DpGuiResId(RID_DLG_UPDATE_THROBBER)),
     503             :     m_update(this, DpGuiResId(RID_DLG_UPDATE_UPDATE)),
     504             :     m_updates(
     505             :         *this, DpGuiResId(RID_DLG_UPDATE_UPDATES),
     506             :         Image(DpGuiResId(RID_DLG_UPDATE_NORMALALERT))),
     507             :     m_all(this, DpGuiResId(RID_DLG_UPDATE_ALL)),
     508             :     m_description(this, DpGuiResId(RID_DLG_UPDATE_DESCRIPTION)),
     509             :     m_PublisherLabel(this, DpGuiResId(RID_DLG_UPDATE_PUBLISHER_LABEL)),
     510             :     m_PublisherLink(this, DpGuiResId(RID_DLG_UPDATE_PUBLISHER_LINK)),
     511             :     m_ReleaseNotesLabel(this, DpGuiResId(RID_DLG_UPDATE_RELEASENOTES_LABEL)),
     512             :     m_ReleaseNotesLink(this, DpGuiResId(RID_DLG_UPDATE_RELEASENOTES_LINK)),
     513             :     m_descriptions(this, DpGuiResId(RID_DLG_UPDATE_DESCRIPTIONS)),
     514             :     m_line(this, DpGuiResId(RID_DLG_UPDATE_LINE)),
     515             :     m_help(this, DpGuiResId(RID_DLG_UPDATE_HELP)),
     516             :     m_ok(this, DpGuiResId(RID_DLG_UPDATE_OK)),
     517             :     m_close(this, DpGuiResId(RID_DLG_UPDATE_CLOSE)),
     518             :     m_error(DPGUI_RESSTR(RID_DLG_UPDATE_ERROR)),
     519             :     m_none(DPGUI_RESSTR(RID_DLG_UPDATE_NONE)),
     520             :     m_noInstallable(DPGUI_RESSTR(RID_DLG_UPDATE_NOINSTALLABLE)),
     521             :     m_failure(DPGUI_RESSTR(RID_DLG_UPDATE_FAILURE)),
     522             :     m_unknownError(DPGUI_RESSTR(RID_DLG_UPDATE_UNKNOWNERROR)),
     523             :     m_noDescription(DPGUI_RESSTR(RID_DLG_UPDATE_NODESCRIPTION)),
     524             :     m_noInstall(DPGUI_RESSTR(RID_DLG_UPDATE_NOINSTALL)),
     525             :     m_noDependency(DPGUI_RESSTR(RID_DLG_UPDATE_NODEPENDENCY)),
     526             :     m_noDependencyCurVer(DPGUI_RESSTR(RID_DLG_UPDATE_NODEPENDENCY_CUR_VER)),
     527             :     m_browserbased(DPGUI_RESSTR(RID_DLG_UPDATE_BROWSERBASED)),
     528             :     m_version(DPGUI_RESSTR(RID_DLG_UPDATE_VERSION)),
     529             :     m_ignoredUpdate(DPGUI_RESSTR(RID_DLG_UPDATE_IGNORED_UPDATE)),
     530             :     m_updateData(*updateData),
     531             :     m_thread(
     532             :         new UpdateDialog::Thread(
     533           0 :             context, *this, vExtensionList)),
     534             :     m_nFirstLineDelta(0),
     535             :     m_nOneLineMissing(0),
     536             :     m_nLastID(1),
     537           0 :     m_bModified( false )
     538             :     // TODO: check!
     539             : //    ,
     540             : //    m_extensionManagerDialog(extensionManagerDialog)
     541             : {
     542             :     OSL_ASSERT(updateData != NULL);
     543             : 
     544           0 :     m_xExtensionManager = deployment::ExtensionManager::get( context );
     545             : 
     546           0 :     uno::Reference< awt::XToolkit2 > toolkit;
     547             :     try {
     548           0 :         toolkit = awt::Toolkit::create(m_context);
     549           0 :     } catch (const uno::RuntimeException &) {
     550           0 :         throw;
     551           0 :     } catch (const uno::Exception & e) {
     552           0 :         throw uno::RuntimeException(e.Message, e.Context);
     553             :     }
     554           0 :     m_updates.SetSelectHdl(LINK(this, UpdateDialog, selectionHandler));
     555           0 :     m_all.SetToggleHdl(LINK(this, UpdateDialog, allHandler));
     556           0 :     m_ok.SetClickHdl(LINK(this, UpdateDialog, okHandler));
     557           0 :     m_close.SetClickHdl(LINK(this, UpdateDialog, closeHandler));
     558           0 :     if ( ! dp_misc::office_is_running())
     559           0 :         m_help.Disable();
     560           0 :     FreeResource();
     561             : 
     562           0 :     initDescription();
     563           0 :     getIgnoredUpdates();
     564           0 : }
     565             : 
     566             : //------------------------------------------------------------------------------
     567           0 : UpdateDialog::~UpdateDialog()
     568             : {
     569           0 :     storeIgnoredUpdates();
     570             : 
     571           0 :     for ( std::vector< UpdateDialog::Index* >::iterator i( m_ListboxEntries.begin() ); i != m_ListboxEntries.end(); ++i )
     572             :     {
     573           0 :         delete (*i);
     574             :     }
     575           0 :     for ( std::vector< UpdateDialog::IgnoredUpdate* >::iterator i( m_ignoredUpdates.begin() ); i != m_ignoredUpdates.end(); ++i )
     576             :     {
     577           0 :         delete (*i);
     578             :     }
     579           0 : }
     580             : 
     581             : //------------------------------------------------------------------------------
     582           0 : sal_Bool UpdateDialog::Close() {
     583           0 :     m_thread->stop();
     584           0 :     return ModalDialog::Close();
     585             : }
     586             : 
     587           0 : short UpdateDialog::Execute() {
     588           0 :     m_throbber.start();
     589           0 :     m_thread->launch();
     590           0 :     return ModalDialog::Execute();
     591             : }
     592             : 
     593             : //------------------------------------------------------------------------------
     594             : //------------------------------------------------------------------------------
     595             : //------------------------------------------------------------------------------
     596           0 : UpdateDialog::CheckListBox::CheckListBox( UpdateDialog & dialog, ResId const & resource,
     597             :                                           Image const & normalStaticImage ):
     598             :     SvxCheckListBox( &dialog, resource, normalStaticImage ),
     599             :     m_ignoreUpdate( DPGUI_RESSTR( RID_DLG_UPDATE_IGNORE ) ),
     600             :     m_ignoreAllUpdates( DPGUI_RESSTR( RID_DLG_UPDATE_IGNORE_ALL ) ),
     601             :     m_enableUpdate( DPGUI_RESSTR( RID_DLG_UPDATE_ENABLE ) ),
     602           0 :     m_dialog(dialog)
     603           0 : {}
     604             : 
     605             : //------------------------------------------------------------------------------
     606           0 : UpdateDialog::CheckListBox::~CheckListBox() {}
     607             : 
     608             : //------------------------------------------------------------------------------
     609           0 : sal_uInt16 UpdateDialog::CheckListBox::getItemCount() const {
     610           0 :     sal_uLong i = GetEntryCount();
     611             :     OSL_ASSERT(i <= std::numeric_limits< sal_uInt16 >::max());
     612           0 :     return sal::static_int_cast< sal_uInt16 >(i);
     613             : }
     614             : 
     615             : //------------------------------------------------------------------------------
     616           0 : void UpdateDialog::CheckListBox::MouseButtonDown( MouseEvent const & event )
     617             : {
     618             :     // When clicking on a selected entry in an SvxCheckListBox, the entry's
     619             :     // checkbox is toggled on mouse button down:
     620           0 :     SvxCheckListBox::MouseButtonDown( event );
     621             : 
     622           0 :     if ( event.IsRight() )
     623             :     {
     624           0 :         handlePopupMenu( event.GetPosPixel() );
     625             :     }
     626             : 
     627           0 :     m_dialog.enableOk();
     628           0 : }
     629             : 
     630             : //------------------------------------------------------------------------------
     631           0 : void UpdateDialog::CheckListBox::MouseButtonUp(MouseEvent const & event) {
     632             :     // When clicking on an entry's checkbox in an SvxCheckListBox, the entry's
     633             :     // checkbox is toggled on mouse button up:
     634           0 :     SvxCheckListBox::MouseButtonUp(event);
     635           0 :     m_dialog.enableOk();
     636           0 : }
     637             : 
     638           0 : void UpdateDialog::CheckListBox::KeyInput(KeyEvent const & event) {
     639           0 :     SvxCheckListBox::KeyInput(event);
     640           0 :     m_dialog.enableOk();
     641           0 : }
     642             : 
     643             : //------------------------------------------------------------------------------
     644           0 : void UpdateDialog::CheckListBox::handlePopupMenu( const Point &rPos )
     645             : {
     646           0 :     SvTreeListEntry *pData = GetEntry( rPos );
     647             : 
     648           0 :     if ( pData )
     649             :     {
     650           0 :         sal_uInt16 nEntryPos = GetSelectEntryPos();
     651           0 :         UpdateDialog::Index * p = static_cast< UpdateDialog::Index * >( GetEntryData( nEntryPos ) );
     652             : 
     653           0 :         if ( ( p->m_eKind == ENABLED_UPDATE ) || ( p->m_eKind == DISABLED_UPDATE ) )
     654             :         {
     655           0 :             PopupMenu aPopup;
     656             : 
     657           0 :             if ( p->m_bIgnored )
     658           0 :                 aPopup.InsertItem( CMD_ENABLE_UPDATE, m_enableUpdate );
     659             :             else
     660             :             {
     661           0 :                 aPopup.InsertItem( CMD_IGNORE_UPDATE, m_ignoreUpdate );
     662           0 :                 aPopup.InsertItem( CMD_IGNORE_ALL_UPDATES, m_ignoreAllUpdates );
     663             :             }
     664             : 
     665           0 :             sal_uInt16 aCmd = aPopup.Execute( this, rPos );
     666           0 :             if ( ( aCmd == CMD_IGNORE_UPDATE ) || ( aCmd == CMD_IGNORE_ALL_UPDATES ) )
     667             :             {
     668           0 :                 p->m_bIgnored = true;
     669           0 :                 if ( p->m_eKind == ENABLED_UPDATE )
     670             :                 {
     671           0 :                     RemoveEntry( nEntryPos );
     672           0 :                     m_dialog.addAdditional( p, SvLBoxButtonKind_disabledCheckbox );
     673             :                 }
     674           0 :                 if ( aCmd == CMD_IGNORE_UPDATE )
     675           0 :                     m_dialog.setIgnoredUpdate( p, true, false );
     676             :                 else
     677           0 :                     m_dialog.setIgnoredUpdate( p, true, true );
     678             :                 // TODO: reselect entry to display new description!
     679             :             }
     680           0 :             else if ( aCmd == CMD_ENABLE_UPDATE )
     681             :             {
     682           0 :                 p->m_bIgnored = false;
     683           0 :                 if ( p->m_eKind == ENABLED_UPDATE )
     684             :                 {
     685           0 :                     RemoveEntry( nEntryPos );
     686           0 :                     m_dialog.insertItem( p, SvLBoxButtonKind_enabledCheckbox );
     687             :                 }
     688           0 :                 m_dialog.setIgnoredUpdate( p, false, false );
     689           0 :             }
     690             :         }
     691             :     }
     692           0 : }
     693             : 
     694             : //------------------------------------------------------------------------------
     695             : //------------------------------------------------------------------------------
     696             : //------------------------------------------------------------------------------
     697           0 : sal_uInt16 UpdateDialog::insertItem( UpdateDialog::Index *pEntry, SvLBoxButtonKind kind )
     698             : {
     699           0 :     m_updates.InsertEntry( pEntry->m_aName, LISTBOX_APPEND, static_cast< void * >( pEntry ), kind );
     700             : 
     701           0 :     for ( sal_uInt16 i = m_updates.getItemCount(); i != 0 ; )
     702             :     {
     703           0 :         i -= 1;
     704           0 :         UpdateDialog::Index const * p = static_cast< UpdateDialog::Index const * >( m_updates.GetEntryData( i ) );
     705           0 :         if ( p == pEntry )
     706           0 :             return i;
     707             :     }
     708             :     OSL_ASSERT(0);
     709           0 :     return 0;
     710             : }
     711             : 
     712             : //------------------------------------------------------------------------------
     713           0 : void UpdateDialog::addAdditional( UpdateDialog::Index * index, SvLBoxButtonKind kind )
     714             : {
     715           0 :     m_all.Enable();
     716           0 :     if (m_all.IsChecked())
     717             :     {
     718           0 :         insertItem( index, kind );
     719           0 :         m_update.Enable();
     720           0 :         m_updates.Enable();
     721           0 :         m_description.Enable();
     722           0 :         m_descriptions.Enable();
     723             :     }
     724           0 : }
     725             : 
     726             : //------------------------------------------------------------------------------
     727           0 : void UpdateDialog::addEnabledUpdate( OUString const & name,
     728             :                                      dp_gui::UpdateData & data )
     729             : {
     730           0 :     sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_enabledUpdates.size() );
     731           0 :     UpdateDialog::Index *pEntry = new UpdateDialog::Index( ENABLED_UPDATE, m_nLastID, nIndex, name );
     732             : 
     733           0 :     data.m_nID = m_nLastID;
     734           0 :     m_nLastID += 1;
     735             : 
     736           0 :     m_enabledUpdates.push_back( data );
     737           0 :     m_ListboxEntries.push_back( pEntry );
     738             : 
     739           0 :     if ( ! isIgnoredUpdate( pEntry ) )
     740             :     {
     741           0 :         sal_uInt16 nPos = insertItem( pEntry, SvLBoxButtonKind_enabledCheckbox );
     742           0 :         m_updates.CheckEntryPos( nPos );
     743             :     }
     744             :     else
     745           0 :         addAdditional( pEntry, SvLBoxButtonKind_disabledCheckbox );
     746             : 
     747           0 :     m_update.Enable();
     748           0 :     m_updates.Enable();
     749           0 :     m_description.Enable();
     750           0 :     m_descriptions.Enable();
     751           0 : }
     752             : 
     753             : //------------------------------------------------------------------------------
     754           0 : void UpdateDialog::addDisabledUpdate( UpdateDialog::DisabledUpdate & data )
     755             : {
     756           0 :     sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_disabledUpdates.size() );
     757           0 :     UpdateDialog::Index *pEntry = new UpdateDialog::Index( DISABLED_UPDATE, m_nLastID, nIndex, data.name );
     758             : 
     759           0 :     data.m_nID = m_nLastID;
     760           0 :     m_nLastID += 1;
     761             : 
     762           0 :     m_disabledUpdates.push_back( data );
     763           0 :     m_ListboxEntries.push_back( pEntry );
     764             : 
     765           0 :     isIgnoredUpdate( pEntry );
     766           0 :     addAdditional( pEntry, SvLBoxButtonKind_disabledCheckbox );
     767           0 : }
     768             : 
     769             : //------------------------------------------------------------------------------
     770           0 : void UpdateDialog::addSpecificError( UpdateDialog::SpecificError & data )
     771             : {
     772           0 :     sal_uInt16 nIndex = sal::static_int_cast< sal_uInt16 >( m_specificErrors.size() );
     773           0 :     UpdateDialog::Index *pEntry = new UpdateDialog::Index( SPECIFIC_ERROR, m_nLastID, nIndex, data.name );
     774             : 
     775           0 :     data.m_nID = m_nLastID;
     776           0 :     m_nLastID += 1;
     777             : 
     778           0 :     m_specificErrors.push_back( data );
     779           0 :     m_ListboxEntries.push_back( pEntry );
     780             : 
     781           0 :     addAdditional( pEntry, SvLBoxButtonKind_staticImage);
     782           0 : }
     783             : 
     784           0 : void UpdateDialog::checkingDone() {
     785           0 :     m_checking.Hide();
     786           0 :     m_throbber.stop();
     787           0 :     m_throbber.Hide();
     788           0 :     if (m_updates.getItemCount() == 0)
     789             :     {
     790           0 :         clearDescription();
     791           0 :         m_description.Enable();
     792           0 :         m_descriptions.Enable();
     793             : 
     794           0 :         if ( m_disabledUpdates.empty() && m_specificErrors.empty() && m_ignoredUpdates.empty() )
     795           0 :             showDescription( m_none, false );
     796             :         else
     797           0 :             showDescription( m_noInstallable, false );
     798             :     }
     799             : 
     800           0 :     enableOk();
     801           0 : }
     802             : 
     803           0 : void UpdateDialog::enableOk() {
     804           0 :     if (!m_checking.IsVisible()) {
     805           0 :         m_ok.Enable(m_updates.GetCheckedEntryCount() != 0);
     806             :     }
     807           0 : }
     808             : 
     809             : // *********************************************************************************
     810           0 : void UpdateDialog::createNotifyJob( bool bPrepareOnly,
     811             :     uno::Sequence< uno::Sequence< OUString > > &rItemList )
     812             : {
     813           0 :     if ( !dp_misc::office_is_running() )
     814           0 :         return;
     815             : 
     816             :     // notify update check job
     817             :     try
     818             :     {
     819             :         uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
     820             :             configuration::theDefaultProvider::get(
     821           0 :                 comphelper::getProcessComponentContext()));
     822             : 
     823           0 :         beans::PropertyValue aProperty;
     824           0 :         aProperty.Name  = "nodepath";
     825           0 :         aProperty.Value = uno::makeAny( OUString("org.openoffice.Office.Addons/AddonUI/OfficeHelp/UpdateCheckJob") );
     826             : 
     827           0 :         uno::Sequence< uno::Any > aArgumentList( 1 );
     828           0 :         aArgumentList[0] = uno::makeAny( aProperty );
     829             : 
     830             :         uno::Reference< container::XNameAccess > xNameAccess(
     831           0 :             xConfigProvider->createInstanceWithArguments(
     832           0 :                 "com.sun.star.configuration.ConfigurationAccess", aArgumentList ),
     833           0 :             uno::UNO_QUERY_THROW );
     834             : 
     835           0 :         util::URL aURL;
     836           0 :         xNameAccess->getByName("URL") >>= aURL.Complete;
     837             : 
     838           0 :         uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
     839           0 :         uno::Reference < util::XURLTransformer > xTransformer = util::URLTransformer::create(xContext);
     840             : 
     841           0 :         xTransformer->parseStrict(aURL);
     842             : 
     843           0 :         uno::Reference < frame::XDesktop2 > xDesktop = frame::Desktop::create( xContext );
     844           0 :         uno::Reference< frame::XDispatchProvider > xDispatchProvider( xDesktop->getCurrentFrame(),
     845           0 :             uno::UNO_QUERY_THROW );
     846           0 :         uno::Reference< frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch(aURL, OUString(), 0);
     847             : 
     848           0 :         if( xDispatch.is() )
     849             :         {
     850           0 :             uno::Sequence< beans::PropertyValue > aPropList(2);
     851           0 :             aProperty.Name  = "updateList";
     852           0 :             aProperty.Value = uno::makeAny( rItemList );
     853           0 :             aPropList[0] = aProperty;
     854           0 :             aProperty.Name  = "prepareOnly";
     855           0 :             aProperty.Value = uno::makeAny( bPrepareOnly );
     856           0 :             aPropList[1] = aProperty;
     857             : 
     858           0 :             xDispatch->dispatch(aURL, aPropList );
     859           0 :         }
     860             :     }
     861           0 :     catch( const uno::Exception& e )
     862             :     {
     863             :         dp_misc::TRACE( "Caught exception: "
     864           0 :             + e.Message + "\n thread terminated.\n\n");
     865             :     }
     866             : }
     867             : 
     868             : // *********************************************************************************
     869           0 : void UpdateDialog::notifyMenubar( bool bPrepareOnly, bool bRecheckOnly )
     870             : {
     871           0 :     if ( !dp_misc::office_is_running() )
     872           0 :         return;
     873             : 
     874           0 :     uno::Sequence< uno::Sequence< OUString > > aItemList;
     875             : 
     876           0 :     if ( ! bRecheckOnly )
     877             :     {
     878           0 :         sal_Int32 nCount = 0;
     879           0 :         for ( sal_Int16 i = 0; i < m_updates.getItemCount(); ++i )
     880             :         {
     881           0 :             uno::Sequence< OUString > aItem(2);
     882             : 
     883           0 :             UpdateDialog::Index const * p = static_cast< UpdateDialog::Index const * >(m_updates.GetEntryData(i));
     884             : 
     885           0 :             if ( p->m_eKind == ENABLED_UPDATE )
     886             :             {
     887           0 :                 dp_gui::UpdateData aUpdData = m_enabledUpdates[ p->m_nIndex ];
     888           0 :                 aItem[0] = dp_misc::getIdentifier( aUpdData.aInstalledPackage );
     889             : 
     890           0 :                 dp_misc::DescriptionInfoset aInfoset( m_context, aUpdData.aUpdateInfo );
     891           0 :                 aItem[1] = aInfoset.getVersion();
     892             :             }
     893             :             else
     894           0 :                 continue;
     895             : 
     896           0 :             aItemList.realloc( nCount + 1 );
     897           0 :             aItemList[ nCount ] = aItem;
     898           0 :             nCount += 1;
     899           0 :         }
     900             :     }
     901             : 
     902           0 :     storeIgnoredUpdates();
     903           0 :     createNotifyJob( bPrepareOnly, aItemList );
     904             : }
     905             : 
     906             : // *********************************************************************************
     907             : 
     908           0 : void UpdateDialog::initDescription()
     909             : {
     910           0 :     m_PublisherLabel.Hide();
     911           0 :     m_PublisherLink.Hide();
     912           0 :     m_ReleaseNotesLabel.Hide();
     913           0 :     m_ReleaseNotesLink.Hide();
     914           0 :     m_descriptions.Hide();
     915             : 
     916           0 :     Link aLink = LINK( this, UpdateDialog, hyperlink_clicked );
     917           0 :     m_PublisherLink.SetClickHdl( aLink );
     918           0 :     m_ReleaseNotesLink.SetClickHdl( aLink );
     919             : 
     920           0 :     long nTextWidth = m_PublisherLabel.GetCtrlTextWidth( m_PublisherLabel.GetText() );
     921           0 :     long nTemp = m_ReleaseNotesLabel.GetTextWidth( m_ReleaseNotesLabel.GetText() );
     922           0 :     if ( nTemp > nTextWidth )
     923           0 :         nTextWidth = nTemp;
     924           0 :     nTextWidth = nTextWidth * 110 / 100;
     925             : 
     926           0 :     Size aNewSize = m_PublisherLabel.GetSizePixel();
     927           0 :     if ( nTextWidth > aNewSize.Width() )
     928             :     {
     929           0 :         long nDelta = nTextWidth - aNewSize.Width();
     930           0 :         aNewSize.Width() = nTextWidth;
     931           0 :         m_PublisherLabel.SetSizePixel( aNewSize );
     932           0 :         m_ReleaseNotesLabel.SetSizePixel( aNewSize );
     933             : 
     934           0 :         aNewSize = m_PublisherLink.GetSizePixel();
     935           0 :         aNewSize.Width() = aNewSize.Width() - nDelta;
     936           0 :         Point aNewPos = m_PublisherLink.GetPosPixel();
     937           0 :         aNewPos.X() = aNewPos.X() + nDelta;
     938           0 :         m_PublisherLink.SetPosSizePixel( aNewPos, aNewSize );
     939           0 :         aNewPos.Y() = m_ReleaseNotesLink.GetPosPixel().Y();
     940           0 :         m_ReleaseNotesLink.SetPosSizePixel( aNewPos, aNewSize );
     941             :     }
     942             : 
     943           0 :     m_aFirstLinePos = m_descriptions.GetPosPixel();
     944           0 :     m_aFirstLineSize = m_descriptions.GetSizePixel();
     945           0 :     Size aMarginSize = LogicToPixel( Size( RSC_SP_CTRL_GROUP_X, RSC_SP_CTRL_GROUP_Y ), MAP_APPFONT );
     946           0 :     Point aThirdLinePos = m_ReleaseNotesLabel.GetPosPixel();
     947           0 :     aThirdLinePos.Y() = aThirdLinePos.Y() + m_ReleaseNotesLabel.GetSizePixel().Height() + aMarginSize.Height();
     948           0 :     m_nFirstLineDelta = aThirdLinePos.Y() - m_aFirstLinePos.Y();
     949           0 :     m_nOneLineMissing = m_ReleaseNotesLabel.GetPosPixel().Y() - m_PublisherLabel.GetPosPixel().Y();
     950           0 : }
     951             : 
     952           0 : void UpdateDialog::clearDescription()
     953             : {
     954           0 :     String sEmpty;
     955           0 :     m_PublisherLabel.Hide();
     956           0 :     m_PublisherLink.Hide();
     957           0 :     m_PublisherLink.SetText( sEmpty );
     958           0 :     m_PublisherLink.SetURL( sEmpty );
     959           0 :     m_ReleaseNotesLabel.Hide();
     960           0 :     m_ReleaseNotesLink.Hide();
     961           0 :     m_ReleaseNotesLink.SetURL( sEmpty );
     962           0 :     if ( m_PublisherLabel.GetPosPixel().Y() == m_ReleaseNotesLabel.GetPosPixel().Y() )
     963             :     {
     964           0 :         Point aNewPos = m_ReleaseNotesLabel.GetPosPixel();
     965           0 :         aNewPos.Y() += m_nOneLineMissing;
     966           0 :         m_ReleaseNotesLabel.SetPosPixel( aNewPos );
     967           0 :         aNewPos = m_ReleaseNotesLink.GetPosPixel();
     968           0 :         aNewPos.Y() += m_nOneLineMissing;
     969           0 :         m_ReleaseNotesLink.SetPosPixel( aNewPos );
     970             :     }
     971           0 :     m_descriptions.Hide();
     972           0 :     m_descriptions.Clear();
     973           0 :     m_descriptions.SetPosSizePixel( m_aFirstLinePos, m_aFirstLineSize );
     974           0 : }
     975             : 
     976           0 : bool UpdateDialog::showDescription(uno::Reference< xml::dom::XNode > const & aUpdateInfo)
     977             : {
     978           0 :     dp_misc::DescriptionInfoset infoset(m_context, aUpdateInfo);
     979             :     return showDescription(infoset.getLocalizedPublisherNameAndURL(),
     980           0 :                            infoset.getLocalizedReleaseNotesURL());
     981             : }
     982             : 
     983           0 : bool UpdateDialog::showDescription(uno::Reference< deployment::XPackage > const & aExtension)
     984             : {
     985             :     OSL_ASSERT(aExtension.is());
     986           0 :     beans::StringPair pubInfo = aExtension->getPublisherInfo();
     987             :     return showDescription(std::make_pair(pubInfo.First, pubInfo.Second),
     988           0 :                            "");
     989             : }
     990             : 
     991           0 : bool UpdateDialog::showDescription(std::pair< OUString, OUString > const & pairPublisher,
     992             :                                    OUString const & sReleaseNotes)
     993             : {
     994           0 :     OUString sPub = pairPublisher.first;
     995           0 :     OUString sURL = pairPublisher.second;
     996             : 
     997           0 :     if ( sPub.isEmpty() && sURL.isEmpty() && sReleaseNotes.isEmpty() )
     998             :         // nothing to show
     999           0 :         return false;
    1000             : 
    1001           0 :     bool bPublisher = false;
    1002           0 :     if ( !sPub.isEmpty() )
    1003             :     {
    1004           0 :         m_PublisherLabel.Show();
    1005           0 :         m_PublisherLink.Show();
    1006           0 :         m_PublisherLink.SetText( sPub );
    1007           0 :         m_PublisherLink.SetURL( sURL );
    1008           0 :         bPublisher = true;
    1009             :     }
    1010             : 
    1011           0 :     if ( !sReleaseNotes.isEmpty() )
    1012             :     {
    1013           0 :         if ( !bPublisher )
    1014             :         {
    1015           0 :             m_ReleaseNotesLabel.SetPosPixel( m_PublisherLabel.GetPosPixel() );
    1016           0 :             m_ReleaseNotesLink.SetPosPixel( m_PublisherLink.GetPosPixel() );
    1017             :         }
    1018           0 :         m_ReleaseNotesLabel.Show();
    1019           0 :         m_ReleaseNotesLink.Show();
    1020           0 :         m_ReleaseNotesLink.SetURL( sReleaseNotes );
    1021             :     }
    1022           0 :     return true;
    1023             : }
    1024             : 
    1025           0 : bool UpdateDialog::showDescription( const String& rDescription, bool bWithPublisher )
    1026             : {
    1027           0 :     if ( rDescription.Len() == 0 )
    1028             :         // nothing to show
    1029           0 :         return false;
    1030             : 
    1031           0 :     if ( bWithPublisher )
    1032             :     {
    1033           0 :         bool bOneLineMissing = !m_ReleaseNotesLabel.IsVisible() || !m_PublisherLabel.IsVisible();
    1034           0 :         Point aNewPos = m_aFirstLinePos;
    1035           0 :         aNewPos.Y() += m_nFirstLineDelta;
    1036           0 :         if ( bOneLineMissing )
    1037           0 :             aNewPos.Y() -= m_nOneLineMissing;
    1038           0 :         Size aNewSize = m_aFirstLineSize;
    1039           0 :         aNewSize.Height() -= m_nFirstLineDelta;
    1040           0 :         if ( bOneLineMissing )
    1041           0 :             aNewSize.Height() += m_nOneLineMissing;
    1042           0 :         m_descriptions.SetPosSizePixel( aNewPos, aNewSize );
    1043             :     }
    1044           0 :     m_descriptions.Show();
    1045           0 :     m_descriptions.SetText( rDescription );
    1046           0 :     return true;
    1047             : }
    1048             : 
    1049             : //------------------------------------------------------------------------------
    1050           0 : void UpdateDialog::getIgnoredUpdates()
    1051             : {
    1052             :     uno::Reference< lang::XMultiServiceFactory > xConfig(
    1053           0 :         configuration::theDefaultProvider::get(m_context));
    1054           0 :     beans::NamedValue aValue( "nodepath", uno::Any( IGNORED_UPDATES ) );
    1055           0 :     uno::Sequence< uno::Any > args(1);
    1056           0 :     args[0] <<= aValue;
    1057             : 
    1058           0 :     uno::Reference< container::XNameAccess > xNameAccess( xConfig->createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", args), uno::UNO_QUERY_THROW );
    1059           0 :     uno::Sequence< OUString > aElementNames = xNameAccess->getElementNames();
    1060             : 
    1061           0 :     for ( sal_Int32 i = 0; i < aElementNames.getLength(); i++ )
    1062             :     {
    1063           0 :         OUString aIdentifier = aElementNames[i];
    1064           0 :         OUString aVersion;
    1065             : 
    1066           0 :         uno::Any aPropValue( uno::Reference< beans::XPropertySet >( xNameAccess->getByName( aIdentifier ), uno::UNO_QUERY_THROW )->getPropertyValue( PROPERTY_VERSION ) );
    1067           0 :         aPropValue >>= aVersion;
    1068           0 :         IgnoredUpdate *pData = new IgnoredUpdate( aIdentifier, aVersion );
    1069           0 :         m_ignoredUpdates.push_back( pData );
    1070           0 :     }
    1071           0 : }
    1072             : 
    1073             : //------------------------------------------------------------------------------
    1074           0 : void UpdateDialog::storeIgnoredUpdates()
    1075             : {
    1076           0 :     if ( m_bModified && ( !m_ignoredUpdates.empty() ) )
    1077             :     {
    1078             :         uno::Reference< lang::XMultiServiceFactory > xConfig(
    1079           0 :             configuration::theDefaultProvider::get(m_context));
    1080           0 :         beans::NamedValue aValue( "nodepath", uno::Any( IGNORED_UPDATES ) );
    1081           0 :         uno::Sequence< uno::Any > args(1);
    1082           0 :         args[0] <<= aValue;
    1083             : 
    1084           0 :         uno::Reference< container::XNameContainer > xNameContainer( xConfig->createInstanceWithArguments(
    1085           0 :             "com.sun.star.configuration.ConfigurationUpdateAccess", args ), uno::UNO_QUERY_THROW );
    1086             : 
    1087           0 :         for ( std::vector< UpdateDialog::IgnoredUpdate* >::iterator i( m_ignoredUpdates.begin() ); i != m_ignoredUpdates.end(); ++i )
    1088             :         {
    1089           0 :             if ( xNameContainer->hasByName( (*i)->sExtensionID ) )
    1090             :             {
    1091           0 :                 if ( (*i)->bRemoved )
    1092           0 :                     xNameContainer->removeByName( (*i)->sExtensionID );
    1093             :                 else
    1094           0 :                     uno::Reference< beans::XPropertySet >( xNameContainer->getByName( (*i)->sExtensionID ), uno::UNO_QUERY_THROW )->setPropertyValue( PROPERTY_VERSION, uno::Any( (*i)->sVersion ) );
    1095             :             }
    1096           0 :             else if ( ! (*i)->bRemoved )
    1097             :             {
    1098           0 :                 uno::Reference< beans::XPropertySet > elem( uno::Reference< lang::XSingleServiceFactory >( xNameContainer, uno::UNO_QUERY_THROW )->createInstance(), uno::UNO_QUERY_THROW );
    1099           0 :                 elem->setPropertyValue( PROPERTY_VERSION, uno::Any( (*i)->sVersion ) );
    1100           0 :                 xNameContainer->insertByName( (*i)->sExtensionID, uno::Any( elem ) );
    1101             :             }
    1102             :         }
    1103             : 
    1104           0 :         uno::Reference< util::XChangesBatch > xChangesBatch( xNameContainer, uno::UNO_QUERY );
    1105           0 :         if ( xChangesBatch.is() && xChangesBatch->hasPendingChanges() )
    1106           0 :             xChangesBatch->commitChanges();
    1107             :     }
    1108             : 
    1109           0 :     m_bModified = false;
    1110           0 : }
    1111             : 
    1112             : //------------------------------------------------------------------------------
    1113           0 : bool UpdateDialog::isIgnoredUpdate( UpdateDialog::Index * index )
    1114             : {
    1115           0 :     bool bIsIgnored = false;
    1116             : 
    1117           0 :     if (! m_ignoredUpdates.empty() )
    1118             :     {
    1119           0 :         OUString aExtensionID;
    1120           0 :         OUString aVersion;
    1121             : 
    1122           0 :         if ( index->m_eKind == ENABLED_UPDATE )
    1123             :         {
    1124           0 :             dp_gui::UpdateData aUpdData = m_enabledUpdates[ index->m_nIndex ];
    1125           0 :             aExtensionID = dp_misc::getIdentifier( aUpdData.aInstalledPackage );
    1126           0 :             aVersion = aUpdData.updateVersion;
    1127             :         }
    1128           0 :         else if ( index->m_eKind == DISABLED_UPDATE )
    1129             :         {
    1130           0 :             DisabledUpdate &rData = m_disabledUpdates[ index->m_nIndex ];
    1131           0 :             dp_misc::DescriptionInfoset aInfoset( m_context, rData.aUpdateInfo );
    1132           0 :             ::boost::optional< OUString > aID( aInfoset.getIdentifier() );
    1133           0 :             if ( aID )
    1134           0 :                 aExtensionID = *aID;
    1135           0 :             aVersion = aInfoset.getVersion();
    1136             :         }
    1137             : 
    1138           0 :         for ( std::vector< UpdateDialog::IgnoredUpdate* >::iterator i( m_ignoredUpdates.begin() ); i != m_ignoredUpdates.end(); ++i )
    1139             :         {
    1140           0 :             if ( (*i)->sExtensionID == aExtensionID )
    1141             :             {
    1142           0 :                 if ( ( !(*i)->sVersion.isEmpty() ) || ( (*i)->sVersion == aVersion ) )
    1143             :                 {
    1144           0 :                     bIsIgnored = true;
    1145           0 :                     index->m_bIgnored = true;
    1146             :                 }
    1147             :                 else // when we find another update of an ignored version, we will remove the old one to keep the ignored list small
    1148           0 :                     (*i)->bRemoved = true;
    1149           0 :                 break;
    1150             :             }
    1151           0 :         }
    1152             :     }
    1153             : 
    1154           0 :     return bIsIgnored;
    1155             : }
    1156             : 
    1157             : //------------------------------------------------------------------------------
    1158           0 : void UpdateDialog::setIgnoredUpdate( UpdateDialog::Index *pIndex, bool bIgnore, bool bIgnoreAll )
    1159             : {
    1160           0 :     OUString aExtensionID;
    1161           0 :     OUString aVersion;
    1162             : 
    1163           0 :     m_bModified = true;
    1164             : 
    1165           0 :     if ( pIndex->m_eKind == ENABLED_UPDATE )
    1166             :     {
    1167           0 :         dp_gui::UpdateData aUpdData = m_enabledUpdates[ pIndex->m_nIndex ];
    1168           0 :         aExtensionID = dp_misc::getIdentifier( aUpdData.aInstalledPackage );
    1169           0 :         if ( !bIgnoreAll )
    1170           0 :             aVersion = aUpdData.updateVersion;
    1171             :     }
    1172           0 :     else if ( pIndex->m_eKind == DISABLED_UPDATE )
    1173             :     {
    1174           0 :         DisabledUpdate &rData = m_disabledUpdates[ pIndex->m_nIndex ];
    1175           0 :         dp_misc::DescriptionInfoset aInfoset( m_context, rData.aUpdateInfo );
    1176           0 :         ::boost::optional< OUString > aID( aInfoset.getIdentifier() );
    1177           0 :         if ( aID )
    1178           0 :             aExtensionID = *aID;
    1179           0 :         if ( !bIgnoreAll )
    1180           0 :             aVersion = aInfoset.getVersion();
    1181             :     }
    1182             : 
    1183           0 :     if ( !aExtensionID.isEmpty() )
    1184             :     {
    1185           0 :         bool bFound = false;
    1186           0 :         for ( std::vector< UpdateDialog::IgnoredUpdate* >::iterator i( m_ignoredUpdates.begin() ); i != m_ignoredUpdates.end(); ++i )
    1187             :         {
    1188           0 :             if ( (*i)->sExtensionID == aExtensionID )
    1189             :             {
    1190           0 :                 (*i)->sVersion = aVersion;
    1191           0 :                 (*i)->bRemoved = !bIgnore;
    1192           0 :                 bFound = true;
    1193           0 :                 break;
    1194             :             }
    1195             :         }
    1196           0 :         if ( bIgnore && !bFound )
    1197             :         {
    1198           0 :             IgnoredUpdate *pData = new IgnoredUpdate( aExtensionID, aVersion );
    1199           0 :             m_ignoredUpdates.push_back( pData );
    1200             :         }
    1201           0 :     }
    1202           0 : }
    1203             : 
    1204             : //------------------------------------------------------------------------------
    1205             : 
    1206           0 : IMPL_LINK_NOARG(UpdateDialog, selectionHandler)
    1207             : {
    1208           0 :     OUStringBuffer b;
    1209           0 :     bool bInserted = false;
    1210             :     UpdateDialog::Index const * p = static_cast< UpdateDialog::Index const * >(
    1211           0 :         m_updates.GetEntryData(m_updates.GetSelectEntryPos()));
    1212           0 :     clearDescription();
    1213             : 
    1214           0 :     if ( p != NULL )
    1215             :     {
    1216           0 :         sal_uInt16 pos = p->m_nIndex;
    1217             : 
    1218           0 :         switch (p->m_eKind)
    1219             :         {
    1220             :             case ENABLED_UPDATE:
    1221             :             {
    1222           0 :                 if ( m_enabledUpdates[ pos ].aUpdateSource.is() )
    1223           0 :                     bInserted = showDescription( m_enabledUpdates[ pos ].aUpdateSource );
    1224             :                 else
    1225           0 :                     bInserted = showDescription( m_enabledUpdates[ pos ].aUpdateInfo );
    1226             : 
    1227           0 :                 if ( p->m_bIgnored )
    1228           0 :                     b.append( m_ignoredUpdate );
    1229             : 
    1230           0 :                 break;
    1231             :             }
    1232             :             case DISABLED_UPDATE:
    1233             :             {
    1234           0 :                 if ( !m_disabledUpdates.empty() )
    1235           0 :                     bInserted = showDescription( m_disabledUpdates[pos].aUpdateInfo );
    1236             : 
    1237           0 :                 if ( p->m_bIgnored )
    1238           0 :                     b.append( m_ignoredUpdate );
    1239             : 
    1240           0 :                 if ( m_disabledUpdates.empty() )
    1241           0 :                     break;
    1242             : 
    1243           0 :                 UpdateDialog::DisabledUpdate & data = m_disabledUpdates[ pos ];
    1244           0 :                 if (data.unsatisfiedDependencies.getLength() != 0)
    1245             :                 {
    1246             :                     // create error string for version mismatch
    1247           0 :                     OUString sVersion( "%VERSION" );
    1248           0 :                     OUString sProductName( "%PRODUCTNAME" );
    1249           0 :                     sal_Int32 nPos = m_noDependencyCurVer.indexOf( sVersion );
    1250           0 :                     if ( nPos >= 0 )
    1251             :                     {
    1252           0 :                         m_noDependencyCurVer = m_noDependencyCurVer.replaceAt( nPos, sVersion.getLength(), utl::ConfigManager::getAboutBoxProductVersion() );
    1253             :                     }
    1254           0 :                     nPos = m_noDependencyCurVer.indexOf( sProductName );
    1255           0 :                     if ( nPos >= 0 )
    1256             :                     {
    1257           0 :                         m_noDependencyCurVer = m_noDependencyCurVer.replaceAt( nPos, sProductName.getLength(), utl::ConfigManager::getProductName() );
    1258             :                     }
    1259           0 :                     nPos = m_noDependency.indexOf( sProductName );
    1260           0 :                     if ( nPos >= 0 )
    1261             :                     {
    1262           0 :                         m_noDependency = m_noDependency.replaceAt( nPos, sProductName.getLength(), utl::ConfigManager::getProductName() );
    1263             :                     }
    1264             : 
    1265           0 :                     b.append(m_noInstall);
    1266           0 :                     b.append(LF);
    1267           0 :                     b.append(m_noDependency);
    1268           0 :                     for (sal_Int32 i = 0;
    1269           0 :                          i < data.unsatisfiedDependencies.getLength(); ++i)
    1270             :                     {
    1271           0 :                         b.append(LF);
    1272           0 :                         b.appendAscii("  ");
    1273             :                             // U+2003 EM SPACE would be better than two spaces,
    1274             :                             // but some fonts do not contain it
    1275             :                         b.append(
    1276             :                             confineToParagraph(
    1277           0 :                                 data.unsatisfiedDependencies[i]));
    1278             :                     }
    1279           0 :                     b.append(LF);
    1280           0 :                     b.appendAscii("  ");
    1281           0 :                     b.append(m_noDependencyCurVer);
    1282             :                 }
    1283           0 :                 break;
    1284             :             }
    1285             :             case SPECIFIC_ERROR:
    1286             :             {
    1287           0 :                 UpdateDialog::SpecificError & data = m_specificErrors[ pos ];
    1288           0 :                 b.append(m_failure);
    1289           0 :                 b.append(LF);
    1290           0 :                 b.append( data.message.isEmpty() ? m_unknownError : data.message );
    1291           0 :                 break;
    1292             :             }
    1293             :             default:
    1294             :                 OSL_ASSERT(false);
    1295           0 :                 break;
    1296             :         }
    1297             :     }
    1298             : 
    1299           0 :     if ( b.isEmpty() )
    1300           0 :         b.append( m_noDescription );
    1301             : 
    1302           0 :     showDescription( b.makeStringAndClear(), bInserted );
    1303           0 :     return 0;
    1304             : }
    1305             : 
    1306           0 : IMPL_LINK_NOARG(UpdateDialog, allHandler)
    1307             : {
    1308           0 :     if (m_all.IsChecked())
    1309             :     {
    1310           0 :         m_update.Enable();
    1311           0 :         m_updates.Enable();
    1312           0 :         m_description.Enable();
    1313           0 :         m_descriptions.Enable();
    1314             : 
    1315           0 :         for (std::vector< UpdateDialog::Index* >::iterator i( m_ListboxEntries.begin() );
    1316           0 :              i != m_ListboxEntries.end(); ++i )
    1317             :         {
    1318           0 :             if ( (*i)->m_bIgnored || ( (*i)->m_eKind != ENABLED_UPDATE ) )
    1319           0 :                 insertItem( (*i), SvLBoxButtonKind_disabledCheckbox );
    1320             :         }
    1321             :     }
    1322             :     else
    1323             :     {
    1324           0 :         for ( sal_uInt16 i = 0; i < m_updates.getItemCount(); )
    1325             :         {
    1326           0 :             UpdateDialog::Index const * p = static_cast< UpdateDialog::Index const * >( m_updates.GetEntryData(i) );
    1327           0 :             if ( p->m_bIgnored || ( p->m_eKind != ENABLED_UPDATE ) )
    1328             :             {
    1329           0 :                 m_updates.RemoveEntry(i);
    1330             :             } else {
    1331           0 :                 ++i;
    1332             :             }
    1333             :         }
    1334             : 
    1335           0 :         if (m_updates.getItemCount() == 0)
    1336             :         {
    1337           0 :             clearDescription();
    1338           0 :             m_update.Disable();
    1339           0 :             m_updates.Disable();
    1340           0 :             if (m_checking.IsVisible())
    1341           0 :                 m_description.Disable();
    1342             :             else
    1343           0 :                 showDescription(m_noInstallable,false);
    1344             :         }
    1345             :     }
    1346           0 :     return 0;
    1347             : }
    1348             : 
    1349           0 : IMPL_LINK_NOARG(UpdateDialog, okHandler)
    1350             : {
    1351             :     //If users are going to update a shared extension then we need
    1352             :     //to warn them
    1353             :     typedef ::std::vector<UpdateData>::const_iterator CIT;
    1354           0 :     for (CIT i = m_enabledUpdates.begin(); i < m_enabledUpdates.end(); ++i)
    1355             :     {
    1356             :         OSL_ASSERT(i->aInstalledPackage.is());
    1357             :         //If the user has no write access to the shared folder then the update
    1358             :         //for a shared extension is disable, that is it cannot be in m_enabledUpdates
    1359             :     }
    1360             : 
    1361             : 
    1362           0 :     for (sal_uInt16 i = 0; i < m_updates.getItemCount(); ++i) {
    1363             :         UpdateDialog::Index const * p =
    1364             :             static_cast< UpdateDialog::Index const * >(
    1365           0 :                 m_updates.GetEntryData(i));
    1366           0 :         if (p->m_eKind == ENABLED_UPDATE && m_updates.IsChecked(i)) {
    1367           0 :             m_updateData.push_back( m_enabledUpdates[ p->m_nIndex ] );
    1368             :         }
    1369             :     }
    1370             : 
    1371           0 :     EndDialog(RET_OK);
    1372           0 :     return 0;
    1373             : }
    1374             : 
    1375           0 : IMPL_LINK_NOARG(UpdateDialog, closeHandler) {
    1376           0 :     m_thread->stop();
    1377           0 :     EndDialog(RET_CANCEL);
    1378           0 :     return 0;
    1379             : }
    1380             : 
    1381           0 : IMPL_LINK( UpdateDialog, hyperlink_clicked, FixedHyperlink*, pHyperlink )
    1382             : {
    1383           0 :     OUString sURL;
    1384           0 :     if ( pHyperlink )
    1385           0 :         sURL = OUString( pHyperlink->GetURL() );
    1386           0 :     if ( sURL.isEmpty() )
    1387           0 :         return 0;
    1388             : 
    1389             :     try
    1390             :     {
    1391             :         uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
    1392           0 :             com::sun::star::system::SystemShellExecute::create(m_context) );
    1393             :         //throws lang::IllegalArgumentException, system::SystemShellExecuteException
    1394           0 :         xSystemShellExecute->execute( sURL, OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY);
    1395             :     }
    1396           0 :     catch ( const uno::Exception& )
    1397             :     {
    1398             :     }
    1399             : 
    1400           0 :     return 1;
    1401           0 : }
    1402             : 
    1403             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10