1*46dbaceeSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*46dbaceeSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*46dbaceeSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*46dbaceeSAndrew Rist * distributed with this work for additional information 6*46dbaceeSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*46dbaceeSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*46dbaceeSAndrew Rist * "License"); you may not use this file except in compliance 9*46dbaceeSAndrew Rist * with the License. You may obtain a copy of the License at 10*46dbaceeSAndrew Rist * 11*46dbaceeSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*46dbaceeSAndrew Rist * 13*46dbaceeSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*46dbaceeSAndrew Rist * software distributed under the License is distributed on an 15*46dbaceeSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*46dbaceeSAndrew Rist * KIND, either express or implied. See the License for the 17*46dbaceeSAndrew Rist * specific language governing permissions and limitations 18*46dbaceeSAndrew Rist * under the License. 19*46dbaceeSAndrew Rist * 20*46dbaceeSAndrew Rist *************************************************************/ 21*46dbaceeSAndrew Rist 22*46dbaceeSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef INCLUDED_UPDATE_HDL_HXX 25cdf0e10cSrcweir #define INCLUDED_UPDATE_HDL_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "boost/utility.hpp" 28cdf0e10cSrcweir #include <osl/mutex.hxx> 29cdf0e10cSrcweir #include "com/sun/star/uno/Any.h" 30cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_ 31cdf0e10cSrcweir #include "com/sun/star/uno/Reference.h" 32cdf0e10cSrcweir #endif 33cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp" 34cdf0e10cSrcweir #include "com/sun/star/awt/Rectangle.hpp" 35cdf0e10cSrcweir #include "com/sun/star/awt/XActionListener.hpp" 36cdf0e10cSrcweir #include "com/sun/star/awt/XControlModel.hpp" 37cdf0e10cSrcweir #include "com/sun/star/awt/XDialog.hpp" 38cdf0e10cSrcweir #include "com/sun/star/awt/XTopWindowListener.hpp" 39cdf0e10cSrcweir #include "com/sun/star/beans/NamedValue.hpp" 40cdf0e10cSrcweir #include "com/sun/star/frame/XTerminateListener.hpp" 41cdf0e10cSrcweir #include <com/sun/star/resource/XResourceBundle.hpp> 42cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 43cdf0e10cSrcweir #include "cppuhelper/implbase4.hxx" 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include "actionlistener.hxx" 46cdf0e10cSrcweir 47cdf0e10cSrcweir enum DialogControls 48cdf0e10cSrcweir { 49cdf0e10cSrcweir CANCEL_BUTTON = 0, 50cdf0e10cSrcweir PAUSE_BUTTON, 51cdf0e10cSrcweir RESUME_BUTTON, 52cdf0e10cSrcweir INSTALL_BUTTON, 53cdf0e10cSrcweir DOWNLOAD_BUTTON, 54cdf0e10cSrcweir CLOSE_BUTTON, 55cdf0e10cSrcweir HELP_BUTTON, 56cdf0e10cSrcweir BUTTON_COUNT, 57cdf0e10cSrcweir THROBBER_CTRL, 58cdf0e10cSrcweir PROGRESS_CTRL 59cdf0e10cSrcweir }; 60cdf0e10cSrcweir 61cdf0e10cSrcweir enum UpdateState { 62cdf0e10cSrcweir UPDATESTATE_CHECKING = 0, 63cdf0e10cSrcweir UPDATESTATE_ERROR_CHECKING, 64cdf0e10cSrcweir UPDATESTATE_NO_UPDATE_AVAIL, 65cdf0e10cSrcweir UPDATESTATE_UPDATE_AVAIL, 66cdf0e10cSrcweir UPDATESTATE_UPDATE_NO_DOWNLOAD, 67cdf0e10cSrcweir UPDATESTATE_AUTO_START, 68cdf0e10cSrcweir UPDATESTATE_DOWNLOADING, 69cdf0e10cSrcweir UPDATESTATE_DOWNLOAD_PAUSED, 70cdf0e10cSrcweir UPDATESTATE_ERROR_DOWNLOADING, 71cdf0e10cSrcweir UPDATESTATE_DOWNLOAD_AVAIL, 72cdf0e10cSrcweir UPDATESTATE_EXT_UPD_AVAIL, 73cdf0e10cSrcweir UPDATESTATES_COUNT 74cdf0e10cSrcweir }; 75cdf0e10cSrcweir 76cdf0e10cSrcweir class UpdateHandler : ::boost::noncopyable, 77cdf0e10cSrcweir public cppu::WeakImplHelper4< com::sun::star::awt::XActionListener, 78cdf0e10cSrcweir com::sun::star::awt::XTopWindowListener, 79cdf0e10cSrcweir com::sun::star::task::XInteractionHandler, 80cdf0e10cSrcweir com::sun::star::frame::XTerminateListener > 81cdf0e10cSrcweir { 82cdf0e10cSrcweir private: 83cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > mxContext; 84cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::awt::XDialog > mxUpdDlg; 85cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > mxInteractionHdl; 86cdf0e10cSrcweir rtl::Reference< IActionListener > mxActionListener; 87cdf0e10cSrcweir 88cdf0e10cSrcweir UpdateState meCurState; 89cdf0e10cSrcweir UpdateState meLastState; 90cdf0e10cSrcweir sal_Int32 mnPercent; 91cdf0e10cSrcweir short mnLastCtrlState; 92cdf0e10cSrcweir bool mbDownloadBtnHasDots; 93cdf0e10cSrcweir bool mbVisible; 94cdf0e10cSrcweir bool mbStringsLoaded; 95cdf0e10cSrcweir bool mbMinimized; 96cdf0e10cSrcweir bool mbListenerAdded; 97cdf0e10cSrcweir mutable bool mbShowsMessageBox; 98cdf0e10cSrcweir 99cdf0e10cSrcweir osl::Mutex maMutex; 100cdf0e10cSrcweir 101cdf0e10cSrcweir rtl::OUString msNextVersion; 102cdf0e10cSrcweir rtl::OUString msDownloadPath; 103cdf0e10cSrcweir rtl::OUString msDownloadFile; 104cdf0e10cSrcweir rtl::OUString msDescriptionMsg; 105cdf0e10cSrcweir rtl::OUString msChecking; // RID_UPDATE_STR_CHECKING 106cdf0e10cSrcweir rtl::OUString msCheckingError; // RID_UPDATE_STR_CHECKING_ERR 107cdf0e10cSrcweir rtl::OUString msNoUpdFound; // RID_UPDATE_STR_NO_UPD_FOUND 108cdf0e10cSrcweir rtl::OUString msUpdFound; // RID_UPDATE_STR_UPD_FOUND 109cdf0e10cSrcweir rtl::OUString msDlgTitle; // RID_UPDATE_STR_DLG_TITLE 110cdf0e10cSrcweir rtl::OUString msDownloadPause; // RID_UPDATE_STR_DOWNLOAD_PAUSE 111cdf0e10cSrcweir rtl::OUString msDownloadError; // RID_UPDATE_STR_DOWNLOAD_ERR 112cdf0e10cSrcweir rtl::OUString msDownloadWarning; // RID_UPDATE_STR_DOWNLOAD_WARN 113cdf0e10cSrcweir rtl::OUString msDownloadDescr; // RID_UPDATE_STR_DOWNLOAD_WARN 114cdf0e10cSrcweir rtl::OUString msDownloadNotAvail; // RID_UPDATE_STR_DOWNLOAD_UNAVAIL 115cdf0e10cSrcweir rtl::OUString msDownloading; // RID_UPDATE_STR_DOWNLOADING 116cdf0e10cSrcweir rtl::OUString msReady2Install; // RID_UPDATE_STR_READY_INSTALL 117cdf0e10cSrcweir rtl::OUString msCancelTitle; // RID_UPDATE_STR_CANCEL_TITLE 118cdf0e10cSrcweir rtl::OUString msCancelMessage; // RID_UPDATE_STR_CANCEL_DOWNLOAD 119cdf0e10cSrcweir rtl::OUString msInstallMessage; // RID_UPDATE_STR_BEGIN_INSTALL 120cdf0e10cSrcweir rtl::OUString msInstallNow; // RID_UPDATE_STR_INSTALL_NOW 121cdf0e10cSrcweir rtl::OUString msInstallLater; // RID_UPDATE_STR_INSTALL_LATER 122cdf0e10cSrcweir rtl::OUString msInstallError; // RID_UPDATE_STR_INSTALL_ERROR 123cdf0e10cSrcweir rtl::OUString msOverwriteWarning; // RID_UPDATE_STR_OVERWRITE_WARNING 124cdf0e10cSrcweir rtl::OUString msPercent; // RID_UPDATE_STR_PERCENT 125cdf0e10cSrcweir rtl::OUString msReloadWarning; // RID_UPDATE_STR_OVERWRITE_WARNING 126cdf0e10cSrcweir rtl::OUString msReloadReload; // RID_UPDATE_STR_OVERWRITE_WARNING 127cdf0e10cSrcweir rtl::OUString msReloadContinue; // RID_UPDATE_STR_OVERWRITE_WARNING 128cdf0e10cSrcweir rtl::OUString msStatusFL; // RID_UPDATE_FT_STATUS 129cdf0e10cSrcweir rtl::OUString msDescription; // RID_UPDATE_FT_DESCRIPTION 130cdf0e10cSrcweir rtl::OUString msClose; // RID_UPDATE_BTN_CLOSE 131cdf0e10cSrcweir rtl::OUString msDownload; // RID_UPDATE_BTN_DOWNLOAD 132cdf0e10cSrcweir rtl::OUString msInstall; // RID_UPDATE_BTN_INSTALL 133cdf0e10cSrcweir rtl::OUString msPauseBtn; // RID_UPDATE_BTN_PAUSE 134cdf0e10cSrcweir rtl::OUString msResumeBtn; // RID_UPDATE_BTN_RESUME 135cdf0e10cSrcweir rtl::OUString msCancelBtn; // RID_UPDATE_BTN_CANCEL 136cdf0e10cSrcweir rtl::OUString msButtonIDs[ BUTTON_COUNT ]; 137cdf0e10cSrcweir rtl::OUString msBubbleTexts[ UPDATESTATES_COUNT ]; 138cdf0e10cSrcweir rtl::OUString msBubbleTitles[ UPDATESTATES_COUNT ]; 139cdf0e10cSrcweir 140cdf0e10cSrcweir void createDialog(); 141cdf0e10cSrcweir void updateState( UpdateState eNewState ); 142cdf0e10cSrcweir void startThrobber( bool bStart = true ); 143cdf0e10cSrcweir void setControlProperty( const rtl::OUString &rCtrlName, 144cdf0e10cSrcweir const rtl::OUString &rPropName, 145cdf0e10cSrcweir const com::sun::star::uno::Any &rPropValue ); 146cdf0e10cSrcweir void showControl( const rtl::OUString &rCtrlName, bool bShow = true ); 147cdf0e10cSrcweir void showControls( short nControls ); 148cdf0e10cSrcweir void focusControl( DialogControls eID ); 149cdf0e10cSrcweir void enableControls( short nCtrlState ); 150cdf0e10cSrcweir void setDownloadBtnLabel( bool bAppendDots ); 151cdf0e10cSrcweir void loadStrings(); 152cdf0e10cSrcweir rtl::OUString loadString( const com::sun::star::uno::Reference< com::sun::star::resource::XResourceBundle > xBundle, 153cdf0e10cSrcweir sal_Int32 nResourceId ) const; 154cdf0e10cSrcweir rtl::OUString substVariables( const rtl::OUString &rSource ) const; setProperty(com::sun::star::uno::Sequence<com::sun::star::beans::NamedValue> & rProps,const int nIndex,const rtl::OUString & rPropName,const com::sun::star::uno::Any & rPropValue)155cdf0e10cSrcweir static void setProperty( com::sun::star::uno::Sequence< com::sun::star::beans::NamedValue > &rProps, 156cdf0e10cSrcweir const int nIndex, const rtl::OUString &rPropName, const com::sun::star::uno::Any &rPropValue ) 157cdf0e10cSrcweir { rProps[ nIndex ].Name = rPropName; rProps[ nIndex ].Value = rPropValue; } 158cdf0e10cSrcweir static void insertControlModel( com::sun::star::uno::Reference< com::sun::star::awt::XControlModel > & rxDialogModel, 159cdf0e10cSrcweir rtl::OUString const & rServiceName, 160cdf0e10cSrcweir rtl::OUString const & rControlName, 161cdf0e10cSrcweir com::sun::star::awt::Rectangle const & rPosSize, 162cdf0e10cSrcweir com::sun::star::uno::Sequence< com::sun::star::beans::NamedValue > const & rProps ); 163cdf0e10cSrcweir 164cdf0e10cSrcweir void setFullVersion( rtl::OUString& rString ); 165cdf0e10cSrcweir void searchAndReplaceAll( rtl::OUString &rText, const rtl::OUString &rWhat, const rtl::OUString &rWith ) const; 166cdf0e10cSrcweir 167cdf0e10cSrcweir public: 168cdf0e10cSrcweir UpdateHandler( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > & rxContext, 169cdf0e10cSrcweir const rtl::Reference< IActionListener > & rxActionListener ); 170cdf0e10cSrcweir virtual ~UpdateHandler(); 171cdf0e10cSrcweir 172cdf0e10cSrcweir bool isVisible() const; isMinimized() const173cdf0e10cSrcweir bool isMinimized() const { return mbMinimized; } 174cdf0e10cSrcweir void setVisible( bool bVisible = true ); 175cdf0e10cSrcweir void setProgress( sal_Int32 nPercent ); setNextVersion(const rtl::OUString & rNextVersion)176cdf0e10cSrcweir void setNextVersion( const rtl::OUString &rNextVersion ) { msNextVersion = rNextVersion; } setDownloadPath(const rtl::OUString & rPath)177cdf0e10cSrcweir void setDownloadPath( const rtl::OUString &rPath ) { msDownloadPath = rPath; } 178cdf0e10cSrcweir void setDownloadFile( const rtl::OUString &rPath ); 179cdf0e10cSrcweir void setErrorMessage( const rtl::OUString &rErrorMsg ); setDescription(const rtl::OUString & rDescription)180cdf0e10cSrcweir void setDescription( const rtl::OUString &rDescription ){ msDescriptionMsg = rDescription; } 181cdf0e10cSrcweir 182cdf0e10cSrcweir void setState( UpdateState eState ); 183cdf0e10cSrcweir rtl::OUString getBubbleText( UpdateState eState ); 184cdf0e10cSrcweir rtl::OUString getBubbleTitle( UpdateState eState ); 185cdf0e10cSrcweir rtl::OUString getDefaultInstErrMsg(); 186cdf0e10cSrcweir bool showWarning( const rtl::OUString &rWarning ) const; 187cdf0e10cSrcweir bool showWarning( const rtl::OUString &rWarning, const rtl::OUString& rBtnText_1, const rtl::OUString& rBtnText_2 ) const; 188cdf0e10cSrcweir bool showOverwriteWarning( const rtl::OUString &rFileName ) const; 189cdf0e10cSrcweir bool showOverwriteWarning() const; 190cdf0e10cSrcweir 191cdf0e10cSrcweir // Allows runtime exceptions to be thrown by const methods operator com::sun::star::uno::Reference<com::sun::star::uno::XInterface>() const192cdf0e10cSrcweir inline SAL_CALL operator com::sun::star::uno::Reference< com::sun::star::uno::XInterface > () const 193cdf0e10cSrcweir { return const_cast< cppu::OWeakObject * > (static_cast< cppu::OWeakObject const * > (this)); }; 194cdf0e10cSrcweir 195cdf0e10cSrcweir // XActionListener 196cdf0e10cSrcweir virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject &rObj ) throw( com::sun::star::uno::RuntimeException ); 197cdf0e10cSrcweir virtual void SAL_CALL actionPerformed( com::sun::star::awt::ActionEvent const & rEvent) throw( com::sun::star::uno::RuntimeException ); 198cdf0e10cSrcweir 199cdf0e10cSrcweir // XTopWindowListener 200cdf0e10cSrcweir virtual void SAL_CALL windowOpened( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); 201cdf0e10cSrcweir virtual void SAL_CALL windowClosing( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); 202cdf0e10cSrcweir virtual void SAL_CALL windowClosed( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); 203cdf0e10cSrcweir virtual void SAL_CALL windowMinimized( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); 204cdf0e10cSrcweir virtual void SAL_CALL windowNormalized( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); 205cdf0e10cSrcweir virtual void SAL_CALL windowActivated( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); 206cdf0e10cSrcweir virtual void SAL_CALL windowDeactivated( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); 207cdf0e10cSrcweir 208cdf0e10cSrcweir // XInteractionHandler 209cdf0e10cSrcweir virtual void SAL_CALL handle( const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& Request ) 210cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ); 211cdf0e10cSrcweir 212cdf0e10cSrcweir // XTerminateListener 213cdf0e10cSrcweir virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException); 214cdf0e10cSrcweir virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException); 215cdf0e10cSrcweir }; 216cdf0e10cSrcweir 217cdf0e10cSrcweir #endif /* INCLUDED_UPDATE_HDL_HXX */ 218