LCOV - code coverage report
Current view: top level - desktop/source/deployment/gui - dp_gui_extensioncmdqueue.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 421 0.0 %
Date: 2012-08-25 Functions: 0 52 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #define _WIN32_WINNT 0x0500
      30                 :            : 
      31                 :            : 
      32                 :            : 
      33                 :            : 
      34                 :            : 
      35                 :            : #include "sal/config.h"
      36                 :            : 
      37                 :            : #include <cstddef>
      38                 :            : 
      39                 :            : #include "com/sun/star/beans/PropertyValue.hpp"
      40                 :            : #include "com/sun/star/beans/NamedValue.hpp"
      41                 :            : 
      42                 :            : #include "com/sun/star/deployment/DependencyException.hpp"
      43                 :            : #include "com/sun/star/deployment/LicenseException.hpp"
      44                 :            : #include "com/sun/star/deployment/VersionException.hpp"
      45                 :            : #include "com/sun/star/deployment/InstallException.hpp"
      46                 :            : #include "com/sun/star/deployment/PlatformException.hpp"
      47                 :            : 
      48                 :            : #include "com/sun/star/deployment/ui/LicenseDialog.hpp"
      49                 :            : #include "com/sun/star/deployment/DeploymentException.hpp"
      50                 :            : #include "com/sun/star/deployment/UpdateInformationProvider.hpp"
      51                 :            : #include "com/sun/star/deployment/XPackage.hpp"
      52                 :            : 
      53                 :            : #include "com/sun/star/task/XAbortChannel.hpp"
      54                 :            : #include "com/sun/star/task/XInteractionAbort.hpp"
      55                 :            : #include "com/sun/star/task/XInteractionApprove.hpp"
      56                 :            : 
      57                 :            : #include "com/sun/star/ucb/CommandAbortedException.hpp"
      58                 :            : #include "com/sun/star/ucb/CommandFailedException.hpp"
      59                 :            : #include "com/sun/star/ucb/XCommandEnvironment.hpp"
      60                 :            : 
      61                 :            : #include "com/sun/star/ui/dialogs/ExecutableDialogResults.hpp"
      62                 :            : 
      63                 :            : #include "com/sun/star/uno/Reference.hxx"
      64                 :            : #include "com/sun/star/uno/RuntimeException.hpp"
      65                 :            : #include "com/sun/star/uno/Sequence.hxx"
      66                 :            : #include "com/sun/star/uno/XInterface.hpp"
      67                 :            : #include "com/sun/star/uno/TypeClass.hpp"
      68                 :            : #include "osl/diagnose.h"
      69                 :            : #include "osl/mutex.hxx"
      70                 :            : #include "rtl/ref.hxx"
      71                 :            : #include "rtl/ustring.h"
      72                 :            : #include "rtl/ustring.hxx"
      73                 :            : #include "sal/types.h"
      74                 :            : #include "salhelper/thread.hxx"
      75                 :            : #include "ucbhelper/content.hxx"
      76                 :            : #include "cppuhelper/exc_hlp.hxx"
      77                 :            : #include "cppuhelper/implbase3.hxx"
      78                 :            : #include "comphelper/anytostring.hxx"
      79                 :            : #include "vcl/msgbox.hxx"
      80                 :            : #include "toolkit/helper/vclunohelper.hxx"
      81                 :            : 
      82                 :            : #include "dp_gui.h"
      83                 :            : #include "dp_gui_extensioncmdqueue.hxx"
      84                 :            : #include "dp_gui_dependencydialog.hxx"
      85                 :            : #include "dp_gui_dialog2.hxx"
      86                 :            : #include "dp_gui_shared.hxx"
      87                 :            : #include "dp_gui_theextmgr.hxx"
      88                 :            : #include "dp_gui_updatedialog.hxx"
      89                 :            : #include "dp_gui_updateinstalldialog.hxx"
      90                 :            : #include "dp_dependencies.hxx"
      91                 :            : #include "dp_identifier.hxx"
      92                 :            : #include "dp_version.hxx"
      93                 :            : 
      94                 :            : #include <queue>
      95                 :            : #include <boost/shared_ptr.hpp>
      96                 :            : #include <boost/scoped_ptr.hpp>
      97                 :            : 
      98                 :            : #if (defined(_MSC_VER) && (_MSC_VER < 1400))
      99                 :            : #define _WIN32_WINNT 0x0400
     100                 :            : #endif
     101                 :            : 
     102                 :            : #ifdef WNT
     103                 :            : #define GradientStyle_RECT BLA_GradientStyle_RECT
     104                 :            : #include <windows.h>
     105                 :            : #include <objbase.h>
     106                 :            : #undef GradientStyle_RECT
     107                 :            : #endif
     108                 :            : 
     109                 :            : 
     110                 :            : using namespace ::com::sun::star;
     111                 :            : using ::rtl::OUString;
     112                 :            : 
     113                 :            : namespace {
     114                 :            : 
     115                 :          0 : OUString getVersion( OUString const & sVersion )
     116                 :            : {
     117                 :          0 :     return ( sVersion.isEmpty() ) ? OUString( RTL_CONSTASCII_USTRINGPARAM( "0" ) ) : sVersion;
     118                 :            : }
     119                 :            : 
     120                 :          0 : OUString getVersion( const uno::Reference< deployment::XPackage > &rPackage )
     121                 :            : {
     122                 :          0 :     return getVersion( rPackage->getVersion());
     123                 :            : }
     124                 :            : }
     125                 :            : 
     126                 :            : 
     127                 :            : namespace dp_gui {
     128                 :            : 
     129                 :            : //==============================================================================
     130                 :            : 
     131                 :            : class ProgressCmdEnv
     132                 :            :     : public ::cppu::WeakImplHelper3< ucb::XCommandEnvironment,
     133                 :            :                                       task::XInteractionHandler,
     134                 :            :                                       ucb::XProgressHandler >
     135                 :            : {
     136                 :            :     uno::Reference< task::XInteractionHandler> m_xHandler;
     137                 :            :     uno::Reference< uno::XComponentContext > m_xContext;
     138                 :            :     uno::Reference< task::XAbortChannel> m_xAbortChannel;
     139                 :            : 
     140                 :            :     DialogHelper   *m_pDialogHelper;
     141                 :            :     OUString        m_sTitle;
     142                 :            :     bool            m_bAborted;
     143                 :            :     bool            m_bWarnUser;
     144                 :            :     sal_Int32       m_nCurrentProgress;
     145                 :            : 
     146                 :            :     void updateProgress();
     147                 :            : 
     148                 :            :     void update_( uno::Any const & Status ) throw ( uno::RuntimeException );
     149                 :            : 
     150                 :            : public:
     151                 :            :     virtual ~ProgressCmdEnv();
     152                 :            : 
     153                 :            :     /** When param bAskWhenInstalling = true, then the user is asked if he
     154                 :            :     agrees to install this extension. In case this extension is already installed
     155                 :            :     then the user is also notified and asked if he wants to replace that existing
     156                 :            :     extension. In first case an interaction request with an InstallException
     157                 :            :     will be handled and in the second case a VersionException will be handled.
     158                 :            :     */
     159                 :            : 
     160                 :          0 :     ProgressCmdEnv( const uno::Reference< uno::XComponentContext > rContext,
     161                 :            :                     DialogHelper *pDialogHelper,
     162                 :            :                     const OUString &rTitle )
     163                 :            :         :   m_xContext( rContext ),
     164                 :            :             m_pDialogHelper( pDialogHelper ),
     165                 :            :             m_sTitle( rTitle ),
     166                 :            :             m_bAborted( false ),
     167                 :          0 :             m_bWarnUser( false )
     168                 :          0 :     {}
     169                 :            : 
     170                 :          0 :     Dialog * activeDialog() { return m_pDialogHelper ? m_pDialogHelper->getWindow() : NULL; }
     171                 :            : 
     172                 :            :     void setTitle( const OUString& rNewTitle ) { m_sTitle = rNewTitle; }
     173                 :            :     void startProgress();
     174                 :            :     void stopProgress();
     175                 :            :     void progressSection( const OUString &rText,
     176                 :            :                           const uno::Reference< task::XAbortChannel > &xAbortChannel = 0 );
     177                 :          0 :     inline bool isAborted() const { return m_bAborted; }
     178                 :          0 :     inline void setWarnUser( bool bNewVal ) { m_bWarnUser = bNewVal; }
     179                 :            : 
     180                 :            :     // XCommandEnvironment
     181                 :            :     virtual uno::Reference< task::XInteractionHandler > SAL_CALL getInteractionHandler()
     182                 :            :         throw ( uno::RuntimeException );
     183                 :            :     virtual uno::Reference< ucb::XProgressHandler > SAL_CALL getProgressHandler()
     184                 :            :         throw ( uno::RuntimeException );
     185                 :            : 
     186                 :            :     // XInteractionHandler
     187                 :            :     virtual void SAL_CALL handle( uno::Reference< task::XInteractionRequest > const & xRequest )
     188                 :            :         throw ( uno::RuntimeException );
     189                 :            : 
     190                 :            :     // XProgressHandler
     191                 :            :     virtual void SAL_CALL push( uno::Any const & Status )
     192                 :            :         throw ( uno::RuntimeException );
     193                 :            :     virtual void SAL_CALL update( uno::Any const & Status )
     194                 :            :         throw ( uno::RuntimeException );
     195                 :            :     virtual void SAL_CALL pop() throw ( uno::RuntimeException );
     196                 :            : };
     197                 :            : 
     198                 :            : //------------------------------------------------------------------------------
     199                 :          0 : struct ExtensionCmd
     200                 :            : {
     201                 :            :     enum E_CMD_TYPE { ADD, ENABLE, DISABLE, REMOVE, CHECK_FOR_UPDATES, ACCEPT_LICENSE };
     202                 :            : 
     203                 :            :     E_CMD_TYPE  m_eCmdType;
     204                 :            :     bool        m_bWarnUser;
     205                 :            :     OUString    m_sExtensionURL;
     206                 :            :     OUString    m_sRepository;
     207                 :            :     uno::Reference< deployment::XPackage > m_xPackage;
     208                 :            :     std::vector< uno::Reference< deployment::XPackage > >        m_vExtensionList;
     209                 :            : 
     210                 :          0 :     ExtensionCmd( const E_CMD_TYPE eCommand,
     211                 :            :                   const OUString &rExtensionURL,
     212                 :            :                   const OUString &rRepository,
     213                 :            :                   const bool bWarnUser )
     214                 :            :         : m_eCmdType( eCommand ),
     215                 :            :           m_bWarnUser( bWarnUser ),
     216                 :            :           m_sExtensionURL( rExtensionURL ),
     217                 :          0 :           m_sRepository( rRepository ) {};
     218                 :          0 :     ExtensionCmd( const E_CMD_TYPE eCommand,
     219                 :            :                   const uno::Reference< deployment::XPackage > &rPackage )
     220                 :            :         : m_eCmdType( eCommand ),
     221                 :            :           m_bWarnUser( false ),
     222                 :          0 :           m_xPackage( rPackage ) {};
     223                 :          0 :     ExtensionCmd( const E_CMD_TYPE eCommand,
     224                 :            :                   const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList )
     225                 :            :         : m_eCmdType( eCommand ),
     226                 :            :           m_bWarnUser( false ),
     227                 :          0 :           m_vExtensionList( vExtensionList ) {};
     228                 :            : };
     229                 :            : 
     230                 :            : typedef ::boost::shared_ptr< ExtensionCmd > TExtensionCmd;
     231                 :            : 
     232                 :            : //------------------------------------------------------------------------------
     233                 :            : class ExtensionCmdQueue::Thread: public salhelper::Thread
     234                 :            : {
     235                 :            : public:
     236                 :            :     Thread( DialogHelper *pDialogHelper,
     237                 :            :             TheExtensionManager *pManager,
     238                 :            :             const uno::Reference< uno::XComponentContext > & rContext );
     239                 :            : 
     240                 :            :     void addExtension( const OUString &rExtensionURL,
     241                 :            :                        const OUString &rRepository,
     242                 :            :                        const bool bWarnUser );
     243                 :            :     void removeExtension( const uno::Reference< deployment::XPackage > &rPackage );
     244                 :            :     void enableExtension( const uno::Reference< deployment::XPackage > &rPackage,
     245                 :            :                           const bool bEnable );
     246                 :            :     void checkForUpdates( const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList );
     247                 :            :     void acceptLicense( const uno::Reference< deployment::XPackage > &rPackage );
     248                 :            :     void stop();
     249                 :            :     bool isBusy();
     250                 :            : 
     251                 :            : private:
     252                 :            :     virtual ~Thread();
     253                 :            : 
     254                 :            :     virtual void execute();
     255                 :            : 
     256                 :            :     void _insert(const TExtensionCmd& rExtCmd);
     257                 :            : 
     258                 :            :     void _addExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
     259                 :            :                         const OUString &rPackageURL,
     260                 :            :                         const OUString &rRepository,
     261                 :            :                         const bool bWarnUser );
     262                 :            :     void _removeExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
     263                 :            :                            const uno::Reference< deployment::XPackage > &xPackage );
     264                 :            :     void _enableExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
     265                 :            :                            const uno::Reference< deployment::XPackage > &xPackage );
     266                 :            :     void _disableExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
     267                 :            :                             const uno::Reference< deployment::XPackage > &xPackage );
     268                 :            :     void _checkForUpdates( const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList );
     269                 :            :     void _acceptLicense( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
     270                 :            :                            const uno::Reference< deployment::XPackage > &xPackage );
     271                 :            : 
     272                 :            :     enum Input { NONE, START, STOP };
     273                 :            : 
     274                 :            :     uno::Reference< uno::XComponentContext > m_xContext;
     275                 :            :     std::queue< TExtensionCmd >              m_queue;
     276                 :            : 
     277                 :            :     DialogHelper *m_pDialogHelper;
     278                 :            :     TheExtensionManager *m_pManager;
     279                 :            : 
     280                 :            :     const OUString   m_sEnablingPackages;
     281                 :            :     const OUString   m_sDisablingPackages;
     282                 :            :     const OUString   m_sAddingPackages;
     283                 :            :     const OUString   m_sRemovingPackages;
     284                 :            :     const OUString   m_sDefaultCmd;
     285                 :            :     const OUString   m_sAcceptLicense;
     286                 :            :     osl::Condition   m_wakeup;
     287                 :            :     osl::Mutex       m_mutex;
     288                 :            :     Input            m_eInput;
     289                 :            :     bool             m_bStopped;
     290                 :            :     bool             m_bWorking;
     291                 :            : };
     292                 :            : 
     293                 :            : //------------------------------------------------------------------------------
     294                 :          0 : void ProgressCmdEnv::startProgress()
     295                 :            : {
     296                 :          0 :     m_nCurrentProgress = 0;
     297                 :            : 
     298                 :          0 :     if ( m_pDialogHelper )
     299                 :          0 :         m_pDialogHelper->showProgress( true );
     300                 :          0 : }
     301                 :            : 
     302                 :            : //------------------------------------------------------------------------------
     303                 :          0 : void ProgressCmdEnv::stopProgress()
     304                 :            : {
     305                 :          0 :     if ( m_pDialogHelper )
     306                 :          0 :         m_pDialogHelper->showProgress( false );
     307                 :          0 : }
     308                 :            : 
     309                 :            : //------------------------------------------------------------------------------
     310                 :          0 : void ProgressCmdEnv::progressSection( const OUString &rText,
     311                 :            :                                       const uno::Reference< task::XAbortChannel > &xAbortChannel )
     312                 :            : {
     313                 :          0 :     m_xAbortChannel = xAbortChannel;
     314                 :          0 :     if (! m_bAborted)
     315                 :            :     {
     316                 :          0 :         m_nCurrentProgress = 0;
     317                 :          0 :         if ( m_pDialogHelper )
     318                 :            :         {
     319                 :          0 :             m_pDialogHelper->updateProgress( rText, xAbortChannel );
     320                 :          0 :             m_pDialogHelper->updateProgress( 5 );
     321                 :            :         }
     322                 :            :     }
     323                 :          0 : }
     324                 :            : 
     325                 :            : //------------------------------------------------------------------------------
     326                 :          0 : void ProgressCmdEnv::updateProgress()
     327                 :            : {
     328                 :          0 :     if ( ! m_bAborted )
     329                 :            :     {
     330                 :          0 :         long nProgress = ((m_nCurrentProgress*5) % 100) + 5;
     331                 :          0 :         if ( m_pDialogHelper )
     332                 :          0 :             m_pDialogHelper->updateProgress( nProgress );
     333                 :            :     }
     334                 :          0 : }
     335                 :            : 
     336                 :            : //------------------------------------------------------------------------------
     337                 :          0 : ProgressCmdEnv::~ProgressCmdEnv()
     338                 :            : {
     339                 :            :     // TODO: stop all threads and wait
     340                 :          0 : }
     341                 :            : 
     342                 :            : 
     343                 :            : //------------------------------------------------------------------------------
     344                 :            : // XCommandEnvironment
     345                 :            : //------------------------------------------------------------------------------
     346                 :          0 : uno::Reference< task::XInteractionHandler > ProgressCmdEnv::getInteractionHandler()
     347                 :            :     throw ( uno::RuntimeException )
     348                 :            : {
     349                 :          0 :     return this;
     350                 :            : }
     351                 :            : 
     352                 :            : //------------------------------------------------------------------------------
     353                 :          0 : uno::Reference< ucb::XProgressHandler > ProgressCmdEnv::getProgressHandler()
     354                 :            :     throw ( uno::RuntimeException )
     355                 :            : {
     356                 :          0 :     return this;
     357                 :            : }
     358                 :            : 
     359                 :            : //------------------------------------------------------------------------------
     360                 :            : // XInteractionHandler
     361                 :            : //------------------------------------------------------------------------------
     362                 :          0 : void ProgressCmdEnv::handle( uno::Reference< task::XInteractionRequest > const & xRequest )
     363                 :            :     throw ( uno::RuntimeException )
     364                 :            : {
     365                 :          0 :     uno::Any request( xRequest->getRequest() );
     366                 :            :     OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
     367                 :            :     dp_misc::TRACE( OUSTR("[dp_gui_cmdenv.cxx] incoming request:\n")
     368                 :          0 :         + ::comphelper::anyToString(request) + OUSTR("\n"));
     369                 :            : 
     370                 :          0 :     lang::WrappedTargetException wtExc;
     371                 :          0 :     deployment::DependencyException depExc;
     372                 :          0 :     deployment::LicenseException licExc;
     373                 :          0 :     deployment::VersionException verExc;
     374                 :          0 :     deployment::InstallException instExc;
     375                 :          0 :     deployment::PlatformException platExc;
     376                 :            : 
     377                 :            :     // selections:
     378                 :          0 :     bool approve = false;
     379                 :          0 :     bool abort = false;
     380                 :            : 
     381                 :          0 :     if (request >>= wtExc) {
     382                 :            :         // handable deployment error signalled, e.g.
     383                 :            :         // bundle item registration failed, notify cause only:
     384                 :          0 :         uno::Any cause;
     385                 :          0 :         deployment::DeploymentException dpExc;
     386                 :          0 :         if (wtExc.TargetException >>= dpExc)
     387                 :          0 :             cause = dpExc.Cause;
     388                 :            :         else {
     389                 :          0 :             ucb::CommandFailedException cfExc;
     390                 :          0 :             if (wtExc.TargetException >>= cfExc)
     391                 :          0 :                 cause = cfExc.Reason;
     392                 :            :             else
     393                 :          0 :                 cause = wtExc.TargetException;
     394                 :            :         }
     395                 :          0 :         update_( cause );
     396                 :            : 
     397                 :            :         // ignore intermediate errors of legacy packages, i.e.
     398                 :            :         // former pkgchk behaviour:
     399                 :          0 :         const uno::Reference< deployment::XPackage > xPackage( wtExc.Context, uno::UNO_QUERY );
     400                 :            :         OSL_ASSERT( xPackage.is() );
     401                 :          0 :         if ( xPackage.is() )
     402                 :            :         {
     403                 :          0 :             const uno::Reference< deployment::XPackageTypeInfo > xPackageType( xPackage->getPackageType() );
     404                 :            :             OSL_ASSERT( xPackageType.is() );
     405                 :          0 :             if (xPackageType.is())
     406                 :            :             {
     407                 :          0 :                 approve = ( xPackage->isBundle() &&
     408                 :          0 :                             xPackageType->getMediaType().matchAsciiL(
     409                 :            :                                 RTL_CONSTASCII_STRINGPARAM(
     410                 :            :                                     "application/"
     411                 :          0 :                                     "vnd.sun.star.legacy-package-bundle") ));
     412                 :          0 :             }
     413                 :            :         }
     414                 :          0 :         abort = !approve;
     415                 :            :     }
     416                 :          0 :     else if (request >>= depExc)
     417                 :            :     {
     418                 :          0 :         std::vector< rtl::OUString > deps;
     419                 :          0 :         for (sal_Int32 i = 0; i < depExc.UnsatisfiedDependencies.getLength();
     420                 :            :              ++i)
     421                 :            :         {
     422                 :            :             deps.push_back(
     423                 :          0 :                 dp_misc::Dependencies::getErrorText( depExc.UnsatisfiedDependencies[i]) );
     424                 :            :         }
     425                 :            :         {
     426                 :          0 :             SolarMutexGuard guard;
     427                 :          0 :             short n = DependencyDialog( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, deps ).Execute();
     428                 :            :             // Distinguish between closing the dialog and programatically
     429                 :            :             // canceling the dialog (headless VCL):
     430                 :            :             approve = n == RET_OK
     431                 :          0 :                 || (n == RET_CANCEL && !Application::IsDialogCancelEnabled());
     432                 :          0 :         }
     433                 :            :     }
     434                 :          0 :     else if (request >>= licExc)
     435                 :            :     {
     436                 :            :         uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
     437                 :            :             deployment::ui::LicenseDialog::create(
     438                 :          0 :             m_xContext, VCLUnoHelper::GetInterface( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL ),
     439                 :          0 :             licExc.ExtensionName, licExc.Text ) );
     440                 :          0 :         sal_Int16 res = xDialog->execute();
     441                 :          0 :         if ( res == ui::dialogs::ExecutableDialogResults::CANCEL )
     442                 :          0 :             abort = true;
     443                 :          0 :         else if ( res == ui::dialogs::ExecutableDialogResults::OK )
     444                 :          0 :             approve = true;
     445                 :            :         else
     446                 :            :         {
     447                 :            :             OSL_ASSERT(0);
     448                 :          0 :         }
     449                 :            :     }
     450                 :          0 :     else if (request >>= verExc)
     451                 :            :     {
     452                 :            :         sal_uInt32 id;
     453                 :          0 :         switch (dp_misc::compareVersions(
     454                 :          0 :                     verExc.NewVersion, verExc.Deployed->getVersion() ))
     455                 :            :         {
     456                 :            :         case dp_misc::LESS:
     457                 :          0 :             id = RID_WARNINGBOX_VERSION_LESS;
     458                 :          0 :             break;
     459                 :            :         case dp_misc::EQUAL:
     460                 :          0 :             id = RID_WARNINGBOX_VERSION_EQUAL;
     461                 :          0 :             break;
     462                 :            :         default: // dp_misc::GREATER
     463                 :          0 :             id = RID_WARNINGBOX_VERSION_GREATER;
     464                 :          0 :             break;
     465                 :            :         }
     466                 :            :         OSL_ASSERT( verExc.Deployed.is() );
     467                 :            :         bool bEqualNames = verExc.NewDisplayName.equals(
     468                 :          0 :             verExc.Deployed->getDisplayName());
     469                 :            :         {
     470                 :          0 :             SolarMutexGuard guard;
     471                 :          0 :             WarningBox box( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, ResId(id, *DeploymentGuiResMgr::get()));
     472                 :          0 :             String s;
     473                 :          0 :             if (bEqualNames)
     474                 :            :             {
     475                 :          0 :                 s = box.GetMessText();
     476                 :            :             }
     477                 :          0 :             else if (id == RID_WARNINGBOX_VERSION_EQUAL)
     478                 :            :             {
     479                 :            :                 //hypothetical: requires two instances of an extension with the same
     480                 :            :                 //version to have different display names. Probably the developer forgot
     481                 :            :                 //to change the version.
     482                 :          0 :                 s = String(ResId(RID_STR_WARNINGBOX_VERSION_EQUAL_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
     483                 :            :             }
     484                 :          0 :             else if (id == RID_WARNINGBOX_VERSION_LESS)
     485                 :            :             {
     486                 :          0 :                 s = String(ResId(RID_STR_WARNINGBOX_VERSION_LESS_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
     487                 :            :             }
     488                 :          0 :             else if (id == RID_WARNINGBOX_VERSION_GREATER)
     489                 :            :             {
     490                 :          0 :                s = String(ResId(RID_STR_WARNINGBOX_VERSION_GREATER_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
     491                 :            :             }
     492                 :          0 :             s.SearchAndReplaceAllAscii( "$NAME", verExc.NewDisplayName);
     493                 :          0 :             s.SearchAndReplaceAllAscii( "$OLDNAME", verExc.Deployed->getDisplayName());
     494                 :          0 :             s.SearchAndReplaceAllAscii( "$NEW", getVersion(verExc.NewVersion) );
     495                 :          0 :             s.SearchAndReplaceAllAscii( "$DEPLOYED", getVersion(verExc.Deployed) );
     496                 :          0 :             box.SetMessText(s);
     497                 :          0 :             approve = box.Execute() == RET_OK;
     498                 :          0 :             abort = !approve;
     499                 :            :         }
     500                 :            :     }
     501                 :          0 :     else if (request >>= instExc)
     502                 :            :     {
     503                 :          0 :         if ( ! m_bWarnUser )
     504                 :            :         {
     505                 :          0 :             approve = true;
     506                 :            :         }
     507                 :            :         else
     508                 :            :         {
     509                 :          0 :             if ( m_pDialogHelper )
     510                 :            :             {
     511                 :          0 :                 SolarMutexGuard guard;
     512                 :            : 
     513                 :          0 :                 approve = m_pDialogHelper->installExtensionWarn( instExc.displayName );
     514                 :            :             }
     515                 :            :             else
     516                 :          0 :                 approve = false;
     517                 :          0 :             abort = !approve;
     518                 :            :         }
     519                 :            :     }
     520                 :          0 :     else if (request >>= platExc)
     521                 :            :     {
     522                 :          0 :         SolarMutexGuard guard;
     523                 :          0 :         String sMsg( ResId( RID_STR_UNSUPPORTED_PLATFORM, *DeploymentGuiResMgr::get() ) );
     524                 :          0 :         sMsg.SearchAndReplaceAllAscii( "%Name", platExc.package->getDisplayName() );
     525                 :          0 :         ErrorBox box( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, WB_OK, sMsg );
     526                 :          0 :         box.Execute();
     527                 :          0 :         approve = true;
     528                 :            :     }
     529                 :            : 
     530                 :          0 :     if (approve == false && abort == false)
     531                 :            :     {
     532                 :            :         // forward to UUI handler:
     533                 :          0 :         if (! m_xHandler.is()) {
     534                 :            :             // late init:
     535                 :          0 :             uno::Sequence< uno::Any > handlerArgs( 1 );
     536                 :          0 :             handlerArgs[ 0 ] <<= beans::PropertyValue(
     537                 :            :                 OUSTR("Context"), -1, uno::Any( m_sTitle ),
     538                 :          0 :                 beans::PropertyState_DIRECT_VALUE );
     539                 :          0 :              m_xHandler.set( m_xContext->getServiceManager()
     540                 :          0 :                             ->createInstanceWithArgumentsAndContext(
     541                 :            :                                 OUSTR("com.sun.star.uui.InteractionHandler"),
     542                 :          0 :                                 handlerArgs, m_xContext ), uno::UNO_QUERY_THROW );
     543                 :            :         }
     544                 :          0 :         m_xHandler->handle( xRequest );
     545                 :            :     }
     546                 :            :     else
     547                 :            :     {
     548                 :            :         // select:
     549                 :            :         uno::Sequence< uno::Reference< task::XInteractionContinuation > > conts(
     550                 :          0 :             xRequest->getContinuations() );
     551                 :          0 :         uno::Reference< task::XInteractionContinuation > const * pConts = conts.getConstArray();
     552                 :          0 :         sal_Int32 len = conts.getLength();
     553                 :          0 :         for ( sal_Int32 pos = 0; pos < len; ++pos )
     554                 :            :         {
     555                 :          0 :             if (approve) {
     556                 :          0 :                 uno::Reference< task::XInteractionApprove > xInteractionApprove( pConts[ pos ], uno::UNO_QUERY );
     557                 :          0 :                 if (xInteractionApprove.is()) {
     558                 :          0 :                     xInteractionApprove->select();
     559                 :            :                     // don't query again for ongoing continuations:
     560                 :          0 :                     approve = false;
     561                 :          0 :                 }
     562                 :            :             }
     563                 :          0 :             else if (abort) {
     564                 :          0 :                 uno::Reference< task::XInteractionAbort > xInteractionAbort( pConts[ pos ], uno::UNO_QUERY );
     565                 :          0 :                 if (xInteractionAbort.is()) {
     566                 :          0 :                     xInteractionAbort->select();
     567                 :            :                     // don't query again for ongoing continuations:
     568                 :          0 :                     abort = false;
     569                 :          0 :                 }
     570                 :            :             }
     571                 :          0 :         }
     572                 :          0 :     }
     573                 :          0 : }
     574                 :            : 
     575                 :            : //------------------------------------------------------------------------------
     576                 :            : // XProgressHandler
     577                 :            : //------------------------------------------------------------------------------
     578                 :          0 : void ProgressCmdEnv::push( uno::Any const & rStatus )
     579                 :            :     throw( uno::RuntimeException )
     580                 :            : {
     581                 :          0 :     update_( rStatus );
     582                 :          0 : }
     583                 :            : 
     584                 :            : //------------------------------------------------------------------------------
     585                 :          0 : void ProgressCmdEnv::update_( uno::Any const & rStatus )
     586                 :            :     throw( uno::RuntimeException )
     587                 :            : {
     588                 :          0 :     OUString text;
     589                 :          0 :     if ( rStatus.hasValue() && !( rStatus >>= text) )
     590                 :            :     {
     591                 :          0 :         if ( rStatus.getValueTypeClass() == uno::TypeClass_EXCEPTION )
     592                 :          0 :             text = static_cast< uno::Exception const *>( rStatus.getValue() )->Message;
     593                 :          0 :         if ( text.isEmpty() )
     594                 :          0 :             text = ::comphelper::anyToString( rStatus ); // fallback
     595                 :            : 
     596                 :          0 :         const SolarMutexGuard aGuard;
     597                 :          0 :         const boost::scoped_ptr< ErrorBox > aBox( new ErrorBox( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, WB_OK, text ) );
     598                 :          0 :         aBox->Execute();
     599                 :            :     }
     600                 :          0 :     ++m_nCurrentProgress;
     601                 :          0 :     updateProgress();
     602                 :          0 : }
     603                 :            : 
     604                 :            : //------------------------------------------------------------------------------
     605                 :          0 : void ProgressCmdEnv::update( uno::Any const & rStatus )
     606                 :            :     throw( uno::RuntimeException )
     607                 :            : {
     608                 :          0 :     update_( rStatus );
     609                 :          0 : }
     610                 :            : 
     611                 :            : //------------------------------------------------------------------------------
     612                 :          0 : void ProgressCmdEnv::pop()
     613                 :            :     throw( uno::RuntimeException )
     614                 :            : {
     615                 :          0 :     update_( uno::Any() ); // no message
     616                 :          0 : }
     617                 :            : 
     618                 :            : //------------------------------------------------------------------------------
     619                 :          0 : ExtensionCmdQueue::Thread::Thread( DialogHelper *pDialogHelper,
     620                 :            :                                    TheExtensionManager *pManager,
     621                 :            :                                    const uno::Reference< uno::XComponentContext > & rContext ) :
     622                 :            :     salhelper::Thread( "dp_gui_extensioncmdqueue" ),
     623                 :            :     m_xContext( rContext ),
     624                 :            :     m_pDialogHelper( pDialogHelper ),
     625                 :            :     m_pManager( pManager ),
     626                 :            :     m_sEnablingPackages( DialogHelper::getResourceString( RID_STR_ENABLING_PACKAGES ) ),
     627                 :            :     m_sDisablingPackages( DialogHelper::getResourceString( RID_STR_DISABLING_PACKAGES ) ),
     628                 :            :     m_sAddingPackages( DialogHelper::getResourceString( RID_STR_ADDING_PACKAGES ) ),
     629                 :            :     m_sRemovingPackages( DialogHelper::getResourceString( RID_STR_REMOVING_PACKAGES ) ),
     630                 :            :     m_sDefaultCmd( DialogHelper::getResourceString( RID_STR_ADD_PACKAGES ) ),
     631                 :            :     m_sAcceptLicense( DialogHelper::getResourceString( RID_STR_ACCEPT_LICENSE ) ),
     632                 :            :     m_eInput( NONE ),
     633                 :            :     m_bStopped( false ),
     634                 :          0 :     m_bWorking( false )
     635                 :            : {
     636                 :            :     OSL_ASSERT( pDialogHelper );
     637                 :          0 : }
     638                 :            : 
     639                 :            : //------------------------------------------------------------------------------
     640                 :          0 : void ExtensionCmdQueue::Thread::addExtension( const ::rtl::OUString &rExtensionURL,
     641                 :            :                                               const ::rtl::OUString &rRepository,
     642                 :            :                                               const bool bWarnUser )
     643                 :            : {
     644                 :          0 :     if ( !rExtensionURL.isEmpty() )
     645                 :            :     {
     646                 :          0 :         TExtensionCmd pEntry( new ExtensionCmd( ExtensionCmd::ADD, rExtensionURL, rRepository, bWarnUser ) );
     647                 :          0 :         _insert( pEntry );
     648                 :            :     }
     649                 :          0 : }
     650                 :            : 
     651                 :            : //------------------------------------------------------------------------------
     652                 :          0 : void ExtensionCmdQueue::Thread::removeExtension( const uno::Reference< deployment::XPackage > &rPackage )
     653                 :            : {
     654                 :          0 :     if ( rPackage.is() )
     655                 :            :     {
     656                 :          0 :         TExtensionCmd pEntry( new ExtensionCmd( ExtensionCmd::REMOVE, rPackage ) );
     657                 :          0 :         _insert( pEntry );
     658                 :            :     }
     659                 :          0 : }
     660                 :            : 
     661                 :            : //------------------------------------------------------------------------------
     662                 :          0 : void ExtensionCmdQueue::Thread::acceptLicense( const uno::Reference< deployment::XPackage > &rPackage )
     663                 :            : {
     664                 :          0 :     if ( rPackage.is() )
     665                 :            :     {
     666                 :          0 :         TExtensionCmd pEntry( new ExtensionCmd( ExtensionCmd::ACCEPT_LICENSE, rPackage ) );
     667                 :          0 :         _insert( pEntry );
     668                 :            :     }
     669                 :          0 : }
     670                 :            : 
     671                 :            : //------------------------------------------------------------------------------
     672                 :          0 : void ExtensionCmdQueue::Thread::enableExtension( const uno::Reference< deployment::XPackage > &rPackage,
     673                 :            :                                                  const bool bEnable )
     674                 :            : {
     675                 :          0 :     if ( rPackage.is() )
     676                 :            :     {
     677                 :            :         TExtensionCmd pEntry( new ExtensionCmd( bEnable ? ExtensionCmd::ENABLE :
     678                 :            :                                                           ExtensionCmd::DISABLE,
     679                 :          0 :                                                 rPackage ) );
     680                 :          0 :         _insert( pEntry );
     681                 :            :     }
     682                 :          0 : }
     683                 :            : 
     684                 :            : //------------------------------------------------------------------------------
     685                 :          0 : void ExtensionCmdQueue::Thread::checkForUpdates(
     686                 :            :     const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList )
     687                 :            : {
     688                 :          0 :     TExtensionCmd pEntry( new ExtensionCmd( ExtensionCmd::CHECK_FOR_UPDATES, vExtensionList ) );
     689                 :          0 :     _insert( pEntry );
     690                 :          0 : }
     691                 :            : 
     692                 :            : //------------------------------------------------------------------------------
     693                 :            : //Stopping this thread will not abort the installation of extensions.
     694                 :          0 : void ExtensionCmdQueue::Thread::stop()
     695                 :            : {
     696                 :          0 :     osl::MutexGuard aGuard( m_mutex );
     697                 :          0 :     m_bStopped = true;
     698                 :          0 :     m_eInput = STOP;
     699                 :          0 :     m_wakeup.set();
     700                 :          0 : }
     701                 :            : 
     702                 :            : //------------------------------------------------------------------------------
     703                 :          0 : bool ExtensionCmdQueue::Thread::isBusy()
     704                 :            : {
     705                 :          0 :     osl::MutexGuard aGuard( m_mutex );
     706                 :          0 :     return m_bWorking;
     707                 :            : }
     708                 :            : 
     709                 :            : //------------------------------------------------------------------------------
     710                 :          0 : ExtensionCmdQueue::Thread::~Thread() {}
     711                 :            : 
     712                 :            : //------------------------------------------------------------------------------
     713                 :          0 : void ExtensionCmdQueue::Thread::execute()
     714                 :            : {
     715                 :            : #ifdef WNT
     716                 :            :     //Needed for use of the service "com.sun.star.system.SystemShellExecute" in
     717                 :            :     //DialogHelper::openWebBrowser
     718                 :            :     CoUninitialize();
     719                 :            :     (void) CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
     720                 :            : #endif
     721                 :          0 :     for (;;)
     722                 :            :     {
     723                 :          0 :         if ( m_wakeup.wait() != osl::Condition::result_ok )
     724                 :            :         {
     725                 :            :             dp_misc::TRACE( "dp_gui::ExtensionCmdQueue::Thread::run: ignored "
     726                 :          0 :                        "osl::Condition::wait failure\n" );
     727                 :            :         }
     728                 :          0 :         m_wakeup.reset();
     729                 :            : 
     730                 :            :         int nSize;
     731                 :            :         Input eInput;
     732                 :            :         {
     733                 :          0 :             osl::MutexGuard aGuard( m_mutex );
     734                 :          0 :             eInput = m_eInput;
     735                 :          0 :             m_eInput = NONE;
     736                 :          0 :             nSize = m_queue.size();
     737                 :          0 :             m_bWorking = false;
     738                 :            :         }
     739                 :            : 
     740                 :            :         // If this thread has been woken up by anything else except start, stop
     741                 :            :         // then input is NONE and we wait again.
     742                 :            :         // We only install the extension which are currently in the queue.
     743                 :            :         // The progressbar will be set to show the progress of the current number
     744                 :            :         // of extensions. If we allowed to add extensions now then the progressbar may
     745                 :            :         // have reached the end while we still install newly added extensions.
     746                 :          0 :         if ( ( eInput == NONE ) || ( nSize == 0 ) )
     747                 :          0 :             continue;
     748                 :          0 :         if ( eInput == STOP )
     749                 :            :             break;
     750                 :            : 
     751                 :          0 :         ::rtl::Reference< ProgressCmdEnv > currentCmdEnv( new ProgressCmdEnv( m_xContext, m_pDialogHelper, m_sDefaultCmd ) );
     752                 :            : 
     753                 :            :         // Do not lock the following part with addExtension. addExtension may be called in the main thread.
     754                 :            :         // If the message box "Do you want to install the extension (or similar)" is shown and then
     755                 :            :         // addExtension is called, which then blocks the main thread, then we deadlock.
     756                 :          0 :         bool bStartProgress = true;
     757                 :            : 
     758                 :          0 :         while ( !currentCmdEnv->isAborted() && --nSize >= 0 )
     759                 :            :         {
     760                 :            :             {
     761                 :          0 :                 osl::MutexGuard aGuard( m_mutex );
     762                 :          0 :                 m_bWorking = true;
     763                 :            :             }
     764                 :            : 
     765                 :            :             try
     766                 :            :             {
     767                 :          0 :                 TExtensionCmd pEntry;
     768                 :            :                 {
     769                 :          0 :                     ::osl::MutexGuard queueGuard( m_mutex );
     770                 :          0 :                     pEntry = m_queue.front();
     771                 :          0 :                     m_queue.pop();
     772                 :            :                 }
     773                 :            : 
     774                 :          0 :                 if ( bStartProgress && ( pEntry->m_eCmdType != ExtensionCmd::CHECK_FOR_UPDATES ) )
     775                 :            :                 {
     776                 :          0 :                     currentCmdEnv->startProgress();
     777                 :          0 :                     bStartProgress = false;
     778                 :            :                 }
     779                 :            : 
     780                 :          0 :                 switch ( pEntry->m_eCmdType ) {
     781                 :            :                 case ExtensionCmd::ADD :
     782                 :          0 :                     _addExtension( currentCmdEnv, pEntry->m_sExtensionURL, pEntry->m_sRepository, pEntry->m_bWarnUser );
     783                 :          0 :                     break;
     784                 :            :                 case ExtensionCmd::REMOVE :
     785                 :          0 :                     _removeExtension( currentCmdEnv, pEntry->m_xPackage );
     786                 :          0 :                     break;
     787                 :            :                 case ExtensionCmd::ENABLE :
     788                 :          0 :                     _enableExtension( currentCmdEnv, pEntry->m_xPackage );
     789                 :          0 :                     break;
     790                 :            :                 case ExtensionCmd::DISABLE :
     791                 :          0 :                     _disableExtension( currentCmdEnv, pEntry->m_xPackage );
     792                 :          0 :                     break;
     793                 :            :                 case ExtensionCmd::CHECK_FOR_UPDATES :
     794                 :          0 :                     _checkForUpdates( pEntry->m_vExtensionList );
     795                 :          0 :                     break;
     796                 :            :                 case ExtensionCmd::ACCEPT_LICENSE :
     797                 :          0 :                     _acceptLicense( currentCmdEnv, pEntry->m_xPackage );
     798                 :          0 :                     break;
     799                 :          0 :                 }
     800                 :            :             }
     801                 :          0 :             catch ( const ucb::CommandAbortedException & )
     802                 :            :             {
     803                 :            :                 //This exception is thrown when the user clicks cancel on the progressbar.
     804                 :            :                 //Then we cancel the installation of all extensions and remove them from
     805                 :            :                 //the queue.
     806                 :            :                 {
     807                 :          0 :                     ::osl::MutexGuard queueGuard2(m_mutex);
     808                 :          0 :                     while ( --nSize >= 0 )
     809                 :          0 :                         m_queue.pop();
     810                 :            :                 }
     811                 :            :                 break;
     812                 :            :             }
     813                 :          0 :             catch ( const ucb::CommandFailedException & )
     814                 :            :             {
     815                 :            :                 //This exception is thrown when a user clicked cancel in the messagebox which was
     816                 :            :                 //startet by the interaction handler. For example the user will be asked if he/she
     817                 :            :                 //really wants to install the extension.
     818                 :            :                 //These interaction are run for exectly one extension at a time. Therefore we continue
     819                 :            :                 //with installing the remaining extensions.
     820                 :          0 :                 continue;
     821                 :            :             }
     822                 :          0 :             catch ( const uno::Exception & )
     823                 :            :             {
     824                 :            :                 //Todo display the user an error
     825                 :            :                 //see also DialogImpl::SyncPushButton::Click()
     826                 :          0 :                 uno::Any exc( ::cppu::getCaughtException() );
     827                 :          0 :                 OUString msg;
     828                 :          0 :                 deployment::DeploymentException dpExc;
     829                 :          0 :                 if ((exc >>= dpExc) &&
     830                 :          0 :                     dpExc.Cause.getValueTypeClass() == uno::TypeClass_EXCEPTION)
     831                 :            :                 {
     832                 :            :                     // notify error cause only:
     833                 :          0 :                     msg = reinterpret_cast< uno::Exception const * >( dpExc.Cause.getValue() )->Message;
     834                 :            :                 }
     835                 :          0 :                 if (msg.isEmpty()) // fallback for debugging purposes
     836                 :          0 :                     msg = ::comphelper::anyToString(exc);
     837                 :            : 
     838                 :          0 :                 const SolarMutexGuard guard;
     839                 :            :                 boost::scoped_ptr<ErrorBox> box(
     840                 :          0 :                     new ErrorBox( currentCmdEnv->activeDialog(), WB_OK, msg ) );
     841                 :          0 :                 if ( m_pDialogHelper )
     842                 :          0 :                     box->SetText( m_pDialogHelper->getWindow()->GetText() );
     843                 :          0 :                 box->Execute();
     844                 :            :                     //Continue with installation of the remaining extensions
     845                 :            :             }
     846                 :            :             {
     847                 :          0 :                 osl::MutexGuard aGuard( m_mutex );
     848                 :          0 :                 m_bWorking = false;
     849                 :            :             }
     850                 :            :         }
     851                 :            : 
     852                 :            :         {
     853                 :            :             // when leaving the while loop with break, we should set working to false, too
     854                 :          0 :             osl::MutexGuard aGuard( m_mutex );
     855                 :          0 :             m_bWorking = false;
     856                 :            :         }
     857                 :            : 
     858                 :          0 :         if ( !bStartProgress )
     859                 :          0 :             currentCmdEnv->stopProgress();
     860                 :          0 :     }
     861                 :            :     //end for
     862                 :            : #ifdef WNT
     863                 :            :     CoUninitialize();
     864                 :            : #endif
     865                 :          0 : }
     866                 :            : 
     867                 :            : //------------------------------------------------------------------------------
     868                 :          0 : void ExtensionCmdQueue::Thread::_addExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
     869                 :            :                                                const OUString &rPackageURL,
     870                 :            :                                                const OUString &rRepository,
     871                 :            :                                                const bool bWarnUser )
     872                 :            : {
     873                 :            :     //check if we have a string in anyTitle. For example "unopkg gui \" caused anyTitle to be void
     874                 :            :     //and anyTitle.get<OUString> throws as RuntimeException.
     875                 :          0 :     uno::Any anyTitle;
     876                 :            :     try
     877                 :            :     {
     878                 :          0 :         anyTitle = ::ucbhelper::Content( rPackageURL, rCmdEnv.get() ).getPropertyValue( OUSTR("Title") );
     879                 :            :     }
     880                 :          0 :     catch ( const uno::Exception & )
     881                 :            :     {
     882                 :            :         return;
     883                 :            :     }
     884                 :            : 
     885                 :          0 :     OUString sName;
     886                 :          0 :     if ( ! (anyTitle >>= sName) )
     887                 :            :     {
     888                 :            :         OSL_FAIL("Could not get file name for extension.");
     889                 :            :         return;
     890                 :            :     }
     891                 :            : 
     892                 :          0 :     rCmdEnv->setWarnUser( bWarnUser );
     893                 :          0 :     uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager();
     894                 :          0 :     uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() );
     895                 :            :     OUString sTitle(
     896                 :          0 :         m_sAddingPackages.replaceAll("%EXTENSION_NAME", sName));
     897                 :          0 :     rCmdEnv->progressSection( sTitle, xAbortChannel );
     898                 :            : 
     899                 :            :     try
     900                 :            :     {
     901                 :          0 :         xExtMgr->addExtension(rPackageURL, uno::Sequence<beans::NamedValue>(),
     902                 :          0 :                               rRepository, xAbortChannel, rCmdEnv.get() );
     903                 :            :     }
     904                 :          0 :     catch ( const ucb::CommandFailedException & )
     905                 :            :     {
     906                 :            :         // When the extension is already installed we'll get a dialog asking if we want to overwrite. If we then press
     907                 :            :         // cancel this exception is thrown.
     908                 :            :     }
     909                 :          0 :     catch ( const ucb::CommandAbortedException & )
     910                 :            :     {
     911                 :            :         // User clicked the cancel button
     912                 :            :         // TODO: handle cancel
     913                 :            :     }
     914                 :          0 :     rCmdEnv->setWarnUser( false );
     915                 :            : }
     916                 :            : 
     917                 :            : //------------------------------------------------------------------------------
     918                 :          0 : void ExtensionCmdQueue::Thread::_removeExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
     919                 :            :                                                   const uno::Reference< deployment::XPackage > &xPackage )
     920                 :            : {
     921                 :          0 :     uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager();
     922                 :          0 :     uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() );
     923                 :            :     OUString sTitle(
     924                 :            :         m_sRemovingPackages.replaceAll("%EXTENSION_NAME",
     925                 :          0 :             xPackage->getDisplayName()));
     926                 :          0 :     rCmdEnv->progressSection( sTitle, xAbortChannel );
     927                 :            : 
     928                 :          0 :     OUString id( dp_misc::getIdentifier( xPackage ) );
     929                 :            :     try
     930                 :            :     {
     931                 :          0 :         xExtMgr->removeExtension( id, xPackage->getName(), xPackage->getRepositoryName(), xAbortChannel, rCmdEnv.get() );
     932                 :            :     }
     933                 :          0 :     catch ( const deployment::DeploymentException & )
     934                 :            :     {}
     935                 :          0 :     catch ( const ucb::CommandFailedException & )
     936                 :            :     {}
     937                 :          0 :     catch ( const ucb::CommandAbortedException & )
     938                 :            :     {}
     939                 :            : 
     940                 :            :     // Check, if there are still updates to be notified via menu bar icon
     941                 :          0 :     uno::Sequence< uno::Sequence< rtl::OUString > > aItemList;
     942                 :          0 :     UpdateDialog::createNotifyJob( false, aItemList );
     943                 :          0 : }
     944                 :            : 
     945                 :            : //------------------------------------------------------------------------------
     946                 :          0 : void ExtensionCmdQueue::Thread::_checkForUpdates(
     947                 :            :     const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList )
     948                 :            : {
     949                 :            :     UpdateDialog* pUpdateDialog;
     950                 :          0 :     std::vector< UpdateData > vData;
     951                 :            : 
     952                 :          0 :     const SolarMutexGuard guard;
     953                 :            : 
     954                 :          0 :     pUpdateDialog = new UpdateDialog( m_xContext, m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, vExtensionList, &vData );
     955                 :            : 
     956                 :          0 :     pUpdateDialog->notifyMenubar( true, false ); // prepare the checking, if there updates to be notified via menu bar icon
     957                 :            : 
     958                 :          0 :     if ( ( pUpdateDialog->Execute() == RET_OK ) && !vData.empty() )
     959                 :            :     {
     960                 :            :         // If there is at least one directly downloadable extension then we
     961                 :            :         // open the install dialog.
     962                 :          0 :         ::std::vector< UpdateData > dataDownload;
     963                 :          0 :         int countWebsiteDownload = 0;
     964                 :            :         typedef std::vector< dp_gui::UpdateData >::const_iterator cit;
     965                 :            : 
     966                 :          0 :         for ( cit i = vData.begin(); i < vData.end(); ++i )
     967                 :            :         {
     968                 :          0 :             if ( !i->sWebsiteURL.isEmpty() )
     969                 :          0 :                 countWebsiteDownload ++;
     970                 :            :             else
     971                 :          0 :                 dataDownload.push_back( *i );
     972                 :            :         }
     973                 :            : 
     974                 :          0 :         short nDialogResult = RET_OK;
     975                 :          0 :         if ( !dataDownload.empty() )
     976                 :            :         {
     977                 :          0 :             nDialogResult = UpdateInstallDialog( m_pDialogHelper? m_pDialogHelper->getWindow() : NULL, dataDownload, m_xContext ).Execute();
     978                 :          0 :             pUpdateDialog->notifyMenubar( false, true ); // Check, if there are still pending updates to be notified via menu bar icon
     979                 :            :         }
     980                 :            :         else
     981                 :          0 :             pUpdateDialog->notifyMenubar( false, false ); // Check, if there are pending updates to be notified via menu bar icon
     982                 :            : 
     983                 :            :         //Now start the webbrowser and navigate to the websites where we get the updates
     984                 :          0 :         if ( RET_OK == nDialogResult )
     985                 :            :         {
     986                 :          0 :             for ( cit i = vData.begin(); i < vData.end(); ++i )
     987                 :            :             {
     988                 :          0 :                 if ( m_pDialogHelper && ( !i->sWebsiteURL.isEmpty() ) )
     989                 :          0 :                     m_pDialogHelper->openWebBrowser( i->sWebsiteURL, m_pDialogHelper->getWindow()->GetText() );
     990                 :            :             }
     991                 :          0 :         }
     992                 :            :     }
     993                 :            :     else
     994                 :          0 :         pUpdateDialog->notifyMenubar( false, false ); // check if there updates to be notified via menu bar icon
     995                 :            : 
     996                 :          0 :     delete pUpdateDialog;
     997                 :          0 : }
     998                 :            : 
     999                 :            : //------------------------------------------------------------------------------
    1000                 :          0 : void ExtensionCmdQueue::Thread::_enableExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
    1001                 :            :                                                   const uno::Reference< deployment::XPackage > &xPackage )
    1002                 :            : {
    1003                 :          0 :     if ( !xPackage.is() )
    1004                 :          0 :         return;
    1005                 :            : 
    1006                 :          0 :     uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager();
    1007                 :          0 :     uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() );
    1008                 :            :     OUString sTitle(
    1009                 :            :         m_sEnablingPackages.replaceAll("%EXTENSION_NAME",
    1010                 :          0 :             xPackage->getDisplayName()));
    1011                 :          0 :     rCmdEnv->progressSection( sTitle, xAbortChannel );
    1012                 :            : 
    1013                 :            :     try
    1014                 :            :     {
    1015                 :          0 :         xExtMgr->enableExtension( xPackage, xAbortChannel, rCmdEnv.get() );
    1016                 :          0 :         if ( m_pDialogHelper )
    1017                 :          0 :             m_pDialogHelper->updatePackageInfo( xPackage );
    1018                 :            :     }
    1019                 :          0 :     catch ( const ::ucb::CommandAbortedException & )
    1020                 :          0 :     {}
    1021                 :            : }
    1022                 :            : 
    1023                 :            : //------------------------------------------------------------------------------
    1024                 :          0 : void ExtensionCmdQueue::Thread::_disableExtension( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
    1025                 :            :                                                    const uno::Reference< deployment::XPackage > &xPackage )
    1026                 :            : {
    1027                 :          0 :     if ( !xPackage.is() )
    1028                 :          0 :         return;
    1029                 :            : 
    1030                 :          0 :     uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager();
    1031                 :          0 :     uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() );
    1032                 :            :     OUString sTitle(
    1033                 :            :         m_sDisablingPackages.replaceAll("%EXTENSION_NAME",
    1034                 :          0 :             xPackage->getDisplayName()));
    1035                 :          0 :     rCmdEnv->progressSection( sTitle, xAbortChannel );
    1036                 :            : 
    1037                 :            :     try
    1038                 :            :     {
    1039                 :          0 :         xExtMgr->disableExtension( xPackage, xAbortChannel, rCmdEnv.get() );
    1040                 :          0 :         if ( m_pDialogHelper )
    1041                 :          0 :             m_pDialogHelper->updatePackageInfo( xPackage );
    1042                 :            :     }
    1043                 :          0 :     catch ( const ::ucb::CommandAbortedException & )
    1044                 :          0 :     {}
    1045                 :            : }
    1046                 :            : 
    1047                 :            : //------------------------------------------------------------------------------
    1048                 :          0 : void ExtensionCmdQueue::Thread::_acceptLicense( ::rtl::Reference< ProgressCmdEnv > &rCmdEnv,
    1049                 :            :                                                 const uno::Reference< deployment::XPackage > &xPackage )
    1050                 :            : {
    1051                 :          0 :     if ( !xPackage.is() )
    1052                 :          0 :         return;
    1053                 :            : 
    1054                 :          0 :     uno::Reference< deployment::XExtensionManager > xExtMgr = m_pManager->getExtensionManager();
    1055                 :          0 :     uno::Reference< task::XAbortChannel > xAbortChannel( xExtMgr->createAbortChannel() );
    1056                 :            :     OUString sTitle(
    1057                 :            :         m_sAcceptLicense.replaceAll("%EXTENSION_NAME",
    1058                 :          0 :             xPackage->getDisplayName()));
    1059                 :          0 :     rCmdEnv->progressSection( sTitle, xAbortChannel );
    1060                 :            : 
    1061                 :            :     try
    1062                 :            :     {
    1063                 :          0 :         xExtMgr->checkPrerequisitesAndEnable( xPackage, xAbortChannel, rCmdEnv.get() );
    1064                 :          0 :         if ( m_pDialogHelper )
    1065                 :          0 :             m_pDialogHelper->updatePackageInfo( xPackage );
    1066                 :            :     }
    1067                 :          0 :     catch ( const ::ucb::CommandAbortedException & )
    1068                 :          0 :     {}
    1069                 :            : }
    1070                 :            : 
    1071                 :          0 : void ExtensionCmdQueue::Thread::_insert(const TExtensionCmd& rExtCmd)
    1072                 :            : {
    1073                 :          0 :     ::osl::MutexGuard aGuard( m_mutex );
    1074                 :            : 
    1075                 :            :     // If someone called stop then we do not process the command -> game over!
    1076                 :          0 :     if ( m_bStopped )
    1077                 :          0 :         return;
    1078                 :            : 
    1079                 :          0 :     m_queue.push( rExtCmd );
    1080                 :          0 :     m_eInput = START;
    1081                 :          0 :     m_wakeup.set();
    1082                 :            : }
    1083                 :            : 
    1084                 :            : //------------------------------------------------------------------------------
    1085                 :          0 : ExtensionCmdQueue::ExtensionCmdQueue( DialogHelper * pDialogHelper,
    1086                 :            :                                       TheExtensionManager *pManager,
    1087                 :            :                                       const uno::Reference< uno::XComponentContext > &rContext )
    1088                 :          0 :   : m_thread( new Thread( pDialogHelper, pManager, rContext ) )
    1089                 :            : {
    1090                 :          0 :     m_thread->launch();
    1091                 :          0 : }
    1092                 :            : 
    1093                 :          0 : ExtensionCmdQueue::~ExtensionCmdQueue() {
    1094                 :          0 :     stop();
    1095                 :          0 : }
    1096                 :            : 
    1097                 :          0 : void ExtensionCmdQueue::addExtension( const ::rtl::OUString & extensionURL,
    1098                 :            :                                       const ::rtl::OUString & repository,
    1099                 :            :                                       const bool bWarnUser )
    1100                 :            : {
    1101                 :          0 :     m_thread->addExtension( extensionURL, repository, bWarnUser );
    1102                 :          0 : }
    1103                 :            : 
    1104                 :          0 : void ExtensionCmdQueue::removeExtension( const uno::Reference< deployment::XPackage > &rPackage )
    1105                 :            : {
    1106                 :          0 :     m_thread->removeExtension( rPackage );
    1107                 :          0 : }
    1108                 :            : 
    1109                 :          0 : void ExtensionCmdQueue::enableExtension( const uno::Reference< deployment::XPackage > &rPackage,
    1110                 :            :                                          const bool bEnable )
    1111                 :            : {
    1112                 :          0 :     m_thread->enableExtension( rPackage, bEnable );
    1113                 :          0 : }
    1114                 :            : 
    1115                 :          0 : void ExtensionCmdQueue::checkForUpdates( const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList )
    1116                 :            : {
    1117                 :          0 :     m_thread->checkForUpdates( vExtensionList );
    1118                 :          0 : }
    1119                 :            : 
    1120                 :          0 : void ExtensionCmdQueue::acceptLicense( const uno::Reference< deployment::XPackage > &rPackage )
    1121                 :            : {
    1122                 :          0 :     m_thread->acceptLicense( rPackage );
    1123                 :          0 : }
    1124                 :            : 
    1125                 :          0 : void ExtensionCmdQueue::syncRepositories( const uno::Reference< uno::XComponentContext > &xContext )
    1126                 :            : {
    1127                 :          0 :     dp_misc::syncRepositories( new ProgressCmdEnv( xContext, NULL, OUSTR("Extension Manager") ) );
    1128                 :          0 : }
    1129                 :            : 
    1130                 :          0 : void ExtensionCmdQueue::stop()
    1131                 :            : {
    1132                 :          0 :     m_thread->stop();
    1133                 :          0 : }
    1134                 :            : 
    1135                 :          0 : bool ExtensionCmdQueue::isBusy()
    1136                 :            : {
    1137                 :          0 :     return m_thread->isBusy();
    1138                 :            : }
    1139                 :            : 
    1140                 :          0 : void handleInteractionRequest( const uno::Reference< uno::XComponentContext > & xContext,
    1141                 :            :                                const uno::Reference< task::XInteractionRequest > & xRequest )
    1142                 :            : {
    1143                 :          0 :     ::rtl::Reference< ProgressCmdEnv > xCmdEnv( new ProgressCmdEnv( xContext, NULL, OUSTR("Extension Manager") ) );
    1144                 :          0 :     xCmdEnv->handle( xRequest );
    1145                 :          0 : }
    1146                 :            : 
    1147                 :            : } //namespace dp_gui
    1148                 :            : 
    1149                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10