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 #include <com/sun/star/beans/NamedValue.hpp> 29*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 30*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <osl/conditn.hxx> 34*cdf0e10cSrcweir #include <osl/thread.hxx> 35*cdf0e10cSrcweir #include <rtl/instance.hxx> 36*cdf0e10cSrcweir #include <salhelper/refobj.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include "updateinfo.hxx" 39*cdf0e10cSrcweir #include "updatecheckconfiglistener.hxx" 40*cdf0e10cSrcweir #include "actionlistener.hxx" 41*cdf0e10cSrcweir #include "updatehdl.hxx" 42*cdf0e10cSrcweir #include "download.hxx" 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir class UpdateCheck; 46*cdf0e10cSrcweir class UpdateCheckConfig; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir class UpdateCheckInitData { 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir public: 51*cdf0e10cSrcweir inline rtl::Reference< UpdateCheck > SAL_CALL operator() () const; 52*cdf0e10cSrcweir }; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir class WorkerThread : public osl::Thread 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir public: 57*cdf0e10cSrcweir virtual void SAL_CALL cancel() = 0; 58*cdf0e10cSrcweir }; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir class UpdateCheck : 61*cdf0e10cSrcweir public UpdateCheckConfigListener, 62*cdf0e10cSrcweir public IActionListener, 63*cdf0e10cSrcweir public DownloadInteractionHandler, 64*cdf0e10cSrcweir public salhelper::ReferenceObject, 65*cdf0e10cSrcweir public rtl::StaticWithInit< rtl::Reference< UpdateCheck >, UpdateCheckInitData > 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir UpdateCheck() : m_eState(NOT_INITIALIZED), m_eUpdateState(UPDATESTATES_COUNT), m_pThread(NULL) {}; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir public: 70*cdf0e10cSrcweir inline SAL_CALL operator rtl::Reference< UpdateCheckConfigListener > () 71*cdf0e10cSrcweir { return static_cast< UpdateCheckConfigListener * > (this); } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir void initialize(const com::sun::star::uno::Sequence<com::sun::star::beans::NamedValue>& rValues, 74*cdf0e10cSrcweir const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& xContext); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir /* Returns an instance of the specified service obtained from the specified 77*cdf0e10cSrcweir * component context 78*cdf0e10cSrcweir */ 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir static com::sun::star::uno::Reference< com::sun::star::uno::XInterface > createService( 81*cdf0e10cSrcweir const rtl::OUString& aServiceName, 82*cdf0e10cSrcweir const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& xContext); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir // Update internal update info member 85*cdf0e10cSrcweir void setUpdateInfo(const UpdateInfo& aInfo); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir /* This method turns on the menubar icon, triggers the bubble window or 88*cdf0e10cSrcweir * updates the dialog text when appropriate 89*cdf0e10cSrcweir */ 90*cdf0e10cSrcweir void setUIState(UpdateState eState, bool suppressBubble = false); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir // Returns the UI state that matches rInfo best 93*cdf0e10cSrcweir static UpdateState getUIState(const UpdateInfo& rInfo); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // Check for updates failed 96*cdf0e10cSrcweir void setCheckFailedState(); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir // Executes the update check dialog for manual checks and downloads interaction 99*cdf0e10cSrcweir void showDialog(bool forceCheck = false); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir // Returns true if the update dialog is currently showing 102*cdf0e10cSrcweir bool isDialogShowing() const; 103*cdf0e10cSrcweir bool shouldShowExtUpdDlg() const { return ( m_bShowExtUpdDlg && m_bHasExtensionUpdate ); } 104*cdf0e10cSrcweir void showExtensionDialog(); 105*cdf0e10cSrcweir void setHasExtensionUpdates( bool bHasUpdates ) { m_bHasExtensionUpdate = bHasUpdates; } 106*cdf0e10cSrcweir bool hasOfficeUpdate() const { return (m_aUpdateInfo.BuildId.getLength() > 0); } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir // DownloadInteractionHandler 109*cdf0e10cSrcweir virtual bool downloadTargetExists(const rtl::OUString& rFileName); 110*cdf0e10cSrcweir virtual void downloadStalled(const rtl::OUString& rErrorMessage); 111*cdf0e10cSrcweir virtual void downloadProgressAt(sal_Int8 nProcent); 112*cdf0e10cSrcweir virtual void downloadStarted(const rtl::OUString& rLocalFileName, sal_Int64 nFileSize); 113*cdf0e10cSrcweir virtual void downloadFinished(const rtl::OUString& rLocalFileName); 114*cdf0e10cSrcweir // checks if the download target already exists and asks user what to do next 115*cdf0e10cSrcweir virtual bool checkDownloadDestination( const rtl::OUString& rFile ); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir // Cancels the download action (and resumes checking if enabled) 118*cdf0e10cSrcweir void cancelDownload(); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // Returns the XInteractionHandler of the UpdateHandler instance if present (and visible) 121*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > getInteractionHandler() const; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir // UpdateCheckConfigListener 124*cdf0e10cSrcweir virtual void autoCheckStatusChanged(bool enabled); 125*cdf0e10cSrcweir virtual void autoCheckIntervalChanged(); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // IActionListener 128*cdf0e10cSrcweir void cancel(); 129*cdf0e10cSrcweir void download(); 130*cdf0e10cSrcweir void install(); 131*cdf0e10cSrcweir void pause(); 132*cdf0e10cSrcweir void resume(); 133*cdf0e10cSrcweir void closeAfterFailure(); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // rtl::IReference 136*cdf0e10cSrcweir virtual oslInterlockedCount SAL_CALL acquire() SAL_THROW(()); 137*cdf0e10cSrcweir virtual oslInterlockedCount SAL_CALL release() SAL_THROW(()); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir private: 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // Schedules or cancels next automatic check for updates 142*cdf0e10cSrcweir void enableAutoCheck(bool enable); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // Starts/resumes or stops a download 145*cdf0e10cSrcweir void enableDownload(bool enable, bool paused=false); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // Shuts down the currently running thread 148*cdf0e10cSrcweir void shutdownThread(bool join); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir // Returns the update handler instance 151*cdf0e10cSrcweir rtl::Reference<UpdateHandler> getUpdateHandler(); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // Open the given URL in a browser 154*cdf0e10cSrcweir void showReleaseNote(const rtl::OUString& rURL) const; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // stores the release note url on disk to be used by setup app 157*cdf0e10cSrcweir static bool storeReleaseNote(sal_Int8 nNum, const rtl::OUString &rURL); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir /* This method turns on the menubar icon and triggers the bubble window 160*cdf0e10cSrcweir */ 161*cdf0e10cSrcweir void handleMenuBarUI( rtl::Reference< UpdateHandler > rUpdateHandler, 162*cdf0e10cSrcweir UpdateState& eState, bool suppressBubble ); 163*cdf0e10cSrcweir enum State { 164*cdf0e10cSrcweir NOT_INITIALIZED, 165*cdf0e10cSrcweir DISABLED, 166*cdf0e10cSrcweir CHECK_SCHEDULED, 167*cdf0e10cSrcweir DOWNLOADING, 168*cdf0e10cSrcweir DOWNLOAD_PAUSED 169*cdf0e10cSrcweir }; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir State m_eState; 172*cdf0e10cSrcweir UpdateState m_eUpdateState; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir mutable osl::Mutex m_aMutex; 175*cdf0e10cSrcweir WorkerThread *m_pThread; 176*cdf0e10cSrcweir osl::Condition m_aCondition; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir UpdateInfo m_aUpdateInfo; 179*cdf0e10cSrcweir rtl::OUString m_aImageName; 180*cdf0e10cSrcweir bool m_bHasExtensionUpdate; 181*cdf0e10cSrcweir bool m_bShowExtUpdDlg; 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir rtl::Reference<UpdateHandler> m_aUpdateHandler; 184*cdf0e10cSrcweir com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> m_xMenuBarUI; 185*cdf0e10cSrcweir com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> m_xContext; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir friend class UpdateCheckInitData; 188*cdf0e10cSrcweir }; 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir inline rtl::Reference< UpdateCheck > SAL_CALL 191*cdf0e10cSrcweir UpdateCheckInitData::operator() () const 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir return rtl::Reference< UpdateCheck > (new UpdateCheck()); 194*cdf0e10cSrcweir } 195