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