xref: /AOO41X/main/extensions/source/update/check/updatehdl.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 #ifndef INCLUDED_UPDATE_HDL_HXX
29*cdf0e10cSrcweir #define INCLUDED_UPDATE_HDL_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "boost/utility.hpp"
32*cdf0e10cSrcweir #include <osl/mutex.hxx>
33*cdf0e10cSrcweir #include "com/sun/star/uno/Any.h"
34*cdf0e10cSrcweir #ifndef  _COM_SUN_STAR_UNO_REFERENCE_HPP_
35*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.h"
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
38*cdf0e10cSrcweir #include "com/sun/star/awt/Rectangle.hpp"
39*cdf0e10cSrcweir #include "com/sun/star/awt/XActionListener.hpp"
40*cdf0e10cSrcweir #include "com/sun/star/awt/XControlModel.hpp"
41*cdf0e10cSrcweir #include "com/sun/star/awt/XDialog.hpp"
42*cdf0e10cSrcweir #include "com/sun/star/awt/XTopWindowListener.hpp"
43*cdf0e10cSrcweir #include "com/sun/star/beans/NamedValue.hpp"
44*cdf0e10cSrcweir #include "com/sun/star/frame/XTerminateListener.hpp"
45*cdf0e10cSrcweir #include <com/sun/star/resource/XResourceBundle.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
47*cdf0e10cSrcweir #include "cppuhelper/implbase4.hxx"
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include "actionlistener.hxx"
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir enum DialogControls
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir     CANCEL_BUTTON = 0,
54*cdf0e10cSrcweir     PAUSE_BUTTON,
55*cdf0e10cSrcweir     RESUME_BUTTON,
56*cdf0e10cSrcweir     INSTALL_BUTTON,
57*cdf0e10cSrcweir     DOWNLOAD_BUTTON,
58*cdf0e10cSrcweir     CLOSE_BUTTON,
59*cdf0e10cSrcweir     HELP_BUTTON,
60*cdf0e10cSrcweir     BUTTON_COUNT,
61*cdf0e10cSrcweir     THROBBER_CTRL,
62*cdf0e10cSrcweir     PROGRESS_CTRL
63*cdf0e10cSrcweir };
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir enum UpdateState {
66*cdf0e10cSrcweir     UPDATESTATE_CHECKING = 0,
67*cdf0e10cSrcweir     UPDATESTATE_ERROR_CHECKING,
68*cdf0e10cSrcweir     UPDATESTATE_NO_UPDATE_AVAIL,
69*cdf0e10cSrcweir     UPDATESTATE_UPDATE_AVAIL,
70*cdf0e10cSrcweir     UPDATESTATE_UPDATE_NO_DOWNLOAD,
71*cdf0e10cSrcweir     UPDATESTATE_AUTO_START,
72*cdf0e10cSrcweir     UPDATESTATE_DOWNLOADING,
73*cdf0e10cSrcweir     UPDATESTATE_DOWNLOAD_PAUSED,
74*cdf0e10cSrcweir     UPDATESTATE_ERROR_DOWNLOADING,
75*cdf0e10cSrcweir     UPDATESTATE_DOWNLOAD_AVAIL,
76*cdf0e10cSrcweir     UPDATESTATE_EXT_UPD_AVAIL,
77*cdf0e10cSrcweir     UPDATESTATES_COUNT
78*cdf0e10cSrcweir };
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir class UpdateHandler : ::boost::noncopyable,
81*cdf0e10cSrcweir                       public cppu::WeakImplHelper4< com::sun::star::awt::XActionListener,
82*cdf0e10cSrcweir                                                     com::sun::star::awt::XTopWindowListener,
83*cdf0e10cSrcweir                                                     com::sun::star::task::XInteractionHandler,
84*cdf0e10cSrcweir                                                     com::sun::star::frame::XTerminateListener >
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir private:
87*cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > mxContext;
88*cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::awt::XDialog > mxUpdDlg;
89*cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > mxInteractionHdl;
90*cdf0e10cSrcweir     rtl::Reference< IActionListener > mxActionListener;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     UpdateState             meCurState;
93*cdf0e10cSrcweir     UpdateState             meLastState;
94*cdf0e10cSrcweir     sal_Int32               mnPercent;
95*cdf0e10cSrcweir     short                   mnLastCtrlState;
96*cdf0e10cSrcweir     bool                    mbDownloadBtnHasDots;
97*cdf0e10cSrcweir     bool                    mbVisible;
98*cdf0e10cSrcweir     bool                    mbStringsLoaded;
99*cdf0e10cSrcweir     bool                    mbMinimized;
100*cdf0e10cSrcweir     bool                    mbListenerAdded;
101*cdf0e10cSrcweir     mutable bool            mbShowsMessageBox;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     osl::Mutex              maMutex;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     rtl::OUString           msNextVersion;
106*cdf0e10cSrcweir     rtl::OUString           msDownloadPath;
107*cdf0e10cSrcweir     rtl::OUString           msDownloadFile;
108*cdf0e10cSrcweir     rtl::OUString           msDescriptionMsg;
109*cdf0e10cSrcweir     rtl::OUString           msChecking;         // RID_UPDATE_STR_CHECKING
110*cdf0e10cSrcweir     rtl::OUString           msCheckingError;    // RID_UPDATE_STR_CHECKING_ERR
111*cdf0e10cSrcweir     rtl::OUString           msNoUpdFound;       // RID_UPDATE_STR_NO_UPD_FOUND
112*cdf0e10cSrcweir     rtl::OUString           msUpdFound;         // RID_UPDATE_STR_UPD_FOUND
113*cdf0e10cSrcweir     rtl::OUString           msDlgTitle;         // RID_UPDATE_STR_DLG_TITLE
114*cdf0e10cSrcweir     rtl::OUString           msDownloadPause;    // RID_UPDATE_STR_DOWNLOAD_PAUSE
115*cdf0e10cSrcweir     rtl::OUString           msDownloadError;    // RID_UPDATE_STR_DOWNLOAD_ERR
116*cdf0e10cSrcweir     rtl::OUString           msDownloadWarning;  // RID_UPDATE_STR_DOWNLOAD_WARN
117*cdf0e10cSrcweir     rtl::OUString           msDownloadDescr;    // RID_UPDATE_STR_DOWNLOAD_WARN
118*cdf0e10cSrcweir     rtl::OUString           msDownloadNotAvail; // RID_UPDATE_STR_DOWNLOAD_UNAVAIL
119*cdf0e10cSrcweir     rtl::OUString           msDownloading;      // RID_UPDATE_STR_DOWNLOADING
120*cdf0e10cSrcweir     rtl::OUString           msReady2Install;    // RID_UPDATE_STR_READY_INSTALL
121*cdf0e10cSrcweir     rtl::OUString           msCancelTitle;      // RID_UPDATE_STR_CANCEL_TITLE
122*cdf0e10cSrcweir     rtl::OUString           msCancelMessage;    // RID_UPDATE_STR_CANCEL_DOWNLOAD
123*cdf0e10cSrcweir     rtl::OUString           msInstallMessage;   // RID_UPDATE_STR_BEGIN_INSTALL
124*cdf0e10cSrcweir     rtl::OUString           msInstallNow;       // RID_UPDATE_STR_INSTALL_NOW
125*cdf0e10cSrcweir     rtl::OUString           msInstallLater;     // RID_UPDATE_STR_INSTALL_LATER
126*cdf0e10cSrcweir     rtl::OUString           msInstallError;     // RID_UPDATE_STR_INSTALL_ERROR
127*cdf0e10cSrcweir     rtl::OUString           msOverwriteWarning; // RID_UPDATE_STR_OVERWRITE_WARNING
128*cdf0e10cSrcweir     rtl::OUString           msPercent;          // RID_UPDATE_STR_PERCENT
129*cdf0e10cSrcweir     rtl::OUString           msReloadWarning;    // RID_UPDATE_STR_OVERWRITE_WARNING
130*cdf0e10cSrcweir     rtl::OUString           msReloadReload;     // RID_UPDATE_STR_OVERWRITE_WARNING
131*cdf0e10cSrcweir     rtl::OUString           msReloadContinue;   // RID_UPDATE_STR_OVERWRITE_WARNING
132*cdf0e10cSrcweir     rtl::OUString           msStatusFL;         // RID_UPDATE_FT_STATUS
133*cdf0e10cSrcweir     rtl::OUString           msDescription;      // RID_UPDATE_FT_DESCRIPTION
134*cdf0e10cSrcweir     rtl::OUString           msClose;            // RID_UPDATE_BTN_CLOSE
135*cdf0e10cSrcweir     rtl::OUString           msDownload;         // RID_UPDATE_BTN_DOWNLOAD
136*cdf0e10cSrcweir     rtl::OUString           msInstall;          // RID_UPDATE_BTN_INSTALL
137*cdf0e10cSrcweir     rtl::OUString           msPauseBtn;         // RID_UPDATE_BTN_PAUSE
138*cdf0e10cSrcweir     rtl::OUString           msResumeBtn;        // RID_UPDATE_BTN_RESUME
139*cdf0e10cSrcweir     rtl::OUString           msCancelBtn;        // RID_UPDATE_BTN_CANCEL
140*cdf0e10cSrcweir     rtl::OUString           msButtonIDs[ BUTTON_COUNT ];
141*cdf0e10cSrcweir     rtl::OUString           msBubbleTexts[ UPDATESTATES_COUNT ];
142*cdf0e10cSrcweir     rtl::OUString           msBubbleTitles[ UPDATESTATES_COUNT ];
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir     void                    createDialog();
145*cdf0e10cSrcweir     void                    updateState( UpdateState eNewState );
146*cdf0e10cSrcweir     void                    startThrobber( bool bStart = true );
147*cdf0e10cSrcweir     void                    setControlProperty( const rtl::OUString &rCtrlName,
148*cdf0e10cSrcweir                                                 const rtl::OUString &rPropName,
149*cdf0e10cSrcweir                                                 const com::sun::star::uno::Any &rPropValue );
150*cdf0e10cSrcweir     void                    showControl( const rtl::OUString &rCtrlName, bool bShow = true );
151*cdf0e10cSrcweir     void                    showControls( short nControls );
152*cdf0e10cSrcweir     void                    focusControl( DialogControls eID );
153*cdf0e10cSrcweir     void                    enableControls( short nCtrlState );
154*cdf0e10cSrcweir     void                    setDownloadBtnLabel( bool bAppendDots );
155*cdf0e10cSrcweir     void                    loadStrings();
156*cdf0e10cSrcweir     rtl::OUString           loadString( const com::sun::star::uno::Reference< com::sun::star::resource::XResourceBundle > xBundle,
157*cdf0e10cSrcweir                                         sal_Int32 nResourceId ) const;
158*cdf0e10cSrcweir     rtl::OUString           substVariables( const rtl::OUString &rSource ) const;
159*cdf0e10cSrcweir     static void             setProperty( com::sun::star::uno::Sequence< com::sun::star::beans::NamedValue > &rProps,
160*cdf0e10cSrcweir                                          const int nIndex, const rtl::OUString &rPropName, const com::sun::star::uno::Any &rPropValue )
161*cdf0e10cSrcweir                                          { rProps[ nIndex ].Name = rPropName; rProps[ nIndex ].Value = rPropValue; }
162*cdf0e10cSrcweir     static void             insertControlModel( com::sun::star::uno::Reference< com::sun::star::awt::XControlModel > & rxDialogModel,
163*cdf0e10cSrcweir                                                 rtl::OUString const & rServiceName,
164*cdf0e10cSrcweir                                                 rtl::OUString const & rControlName,
165*cdf0e10cSrcweir                                                 com::sun::star::awt::Rectangle const & rPosSize,
166*cdf0e10cSrcweir                                                 com::sun::star::uno::Sequence< com::sun::star::beans::NamedValue > const & rProps );
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir     void                    setFullVersion( rtl::OUString& rString );
169*cdf0e10cSrcweir     void                    searchAndReplaceAll( rtl::OUString &rText, const rtl::OUString &rWhat, const rtl::OUString &rWith ) const;
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir public:
172*cdf0e10cSrcweir                             UpdateHandler( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > & rxContext,
173*cdf0e10cSrcweir                                            const rtl::Reference< IActionListener > & rxActionListener );
174*cdf0e10cSrcweir     virtual                ~UpdateHandler();
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     bool                    isVisible() const;
177*cdf0e10cSrcweir     bool                    isMinimized() const { return mbMinimized; }
178*cdf0e10cSrcweir     void                    setVisible( bool bVisible = true );
179*cdf0e10cSrcweir     void                    setProgress( sal_Int32 nPercent );
180*cdf0e10cSrcweir     void                    setNextVersion( const rtl::OUString &rNextVersion ) { msNextVersion = rNextVersion; }
181*cdf0e10cSrcweir     void                    setDownloadPath( const rtl::OUString &rPath ) { msDownloadPath = rPath; }
182*cdf0e10cSrcweir     void                    setDownloadFile( const rtl::OUString &rPath );
183*cdf0e10cSrcweir     void                    setErrorMessage( const rtl::OUString &rErrorMsg );
184*cdf0e10cSrcweir     void                    setDescription( const rtl::OUString &rDescription ){ msDescriptionMsg = rDescription; }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     void                    setState( UpdateState eState );
187*cdf0e10cSrcweir     rtl::OUString           getBubbleText( UpdateState eState );
188*cdf0e10cSrcweir     rtl::OUString           getBubbleTitle( UpdateState eState );
189*cdf0e10cSrcweir     rtl::OUString           getDefaultInstErrMsg();
190*cdf0e10cSrcweir     bool                    showWarning( const rtl::OUString &rWarning ) const;
191*cdf0e10cSrcweir     bool                    showWarning( const rtl::OUString &rWarning, const rtl::OUString& rBtnText_1, const rtl::OUString& rBtnText_2 ) const;
192*cdf0e10cSrcweir     bool                    showOverwriteWarning( const rtl::OUString &rFileName ) const;
193*cdf0e10cSrcweir     bool                    showOverwriteWarning() const;
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir     // Allows runtime exceptions to be thrown by const methods
196*cdf0e10cSrcweir     inline SAL_CALL operator com::sun::star::uno::Reference< com::sun::star::uno::XInterface > () const
197*cdf0e10cSrcweir         { return const_cast< cppu::OWeakObject * > (static_cast< cppu::OWeakObject const * > (this)); };
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir     // XActionListener
200*cdf0e10cSrcweir     virtual void SAL_CALL   disposing( const com::sun::star::lang::EventObject &rObj ) throw( com::sun::star::uno::RuntimeException );
201*cdf0e10cSrcweir     virtual void SAL_CALL   actionPerformed( com::sun::star::awt::ActionEvent const & rEvent) throw( com::sun::star::uno::RuntimeException );
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	// XTopWindowListener
204*cdf0e10cSrcweir     virtual void SAL_CALL   windowOpened( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
205*cdf0e10cSrcweir     virtual void SAL_CALL   windowClosing( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
206*cdf0e10cSrcweir     virtual void SAL_CALL   windowClosed( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
207*cdf0e10cSrcweir     virtual void SAL_CALL   windowMinimized( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
208*cdf0e10cSrcweir     virtual void SAL_CALL   windowNormalized( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
209*cdf0e10cSrcweir     virtual void SAL_CALL   windowActivated( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
210*cdf0e10cSrcweir     virtual void SAL_CALL   windowDeactivated( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     // XInteractionHandler
213*cdf0e10cSrcweir 	virtual void SAL_CALL   handle( const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& Request )
214*cdf0e10cSrcweir 		                        throw( com::sun::star::uno::RuntimeException );
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir     // XTerminateListener
217*cdf0e10cSrcweir     virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException);
218*cdf0e10cSrcweir     virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& e ) throw (::com::sun::star::uno::RuntimeException);
219*cdf0e10cSrcweir };
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir #endif /* INCLUDED_UPDATE_HDL_HXX */
222