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