xref: /AOO41X/main/extensions/source/update/check/updatehdl.cxx (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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_extensions.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "updatehdl.hxx"
32*cdf0e10cSrcweir #include "update.hrc"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include "osl/diagnose.h"
35*cdf0e10cSrcweir #include "osl/thread.hxx"
36*cdf0e10cSrcweir #include "osl/file.hxx"
37*cdf0e10cSrcweir #include "rtl/ustring.hxx"
38*cdf0e10cSrcweir #include "rtl/bootstrap.hxx"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.h"
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include <com/sun/star/style/VerticalAlignment.hpp>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include "com/sun/star/awt/ActionEvent.hpp"
45*cdf0e10cSrcweir #include "com/sun/star/awt/PushButtonType.hpp"
46*cdf0e10cSrcweir #include "com/sun/star/awt/VclWindowPeerAttribute.hpp"
47*cdf0e10cSrcweir #include "com/sun/star/awt/WindowAttribute.hpp"
48*cdf0e10cSrcweir #include "com/sun/star/awt/XButton.hpp"
49*cdf0e10cSrcweir #include "com/sun/star/awt/XControl.hpp"
50*cdf0e10cSrcweir #include "com/sun/star/awt/XControlContainer.hpp"
51*cdf0e10cSrcweir #include "com/sun/star/awt/XMessageBox.hpp"
52*cdf0e10cSrcweir #include "com/sun/star/awt/XAnimation.hpp"
53*cdf0e10cSrcweir #include "com/sun/star/awt/XTopWindow.hpp"
54*cdf0e10cSrcweir #include "com/sun/star/awt/XVclWindowPeer.hpp"
55*cdf0e10cSrcweir #include "com/sun/star/awt/XVclContainer.hpp"
56*cdf0e10cSrcweir #include "com/sun/star/awt/XWindow.hpp"
57*cdf0e10cSrcweir #include "com/sun/star/awt/XWindow2.hpp"
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
60*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir #include "com/sun/star/container/XNameContainer.hpp"
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir #include "com/sun/star/frame/XDesktop.hpp"
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp"
67*cdf0e10cSrcweir #include "com/sun/star/task/InteractionRequestStringResolver.hpp"
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir #include <com/sun/star/resource/XResourceBundleLoader.hpp>
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir #include "updatehdl.hrc"
72*cdf0e10cSrcweir #include <tools/urlobj.hxx>
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir #define COMMAND_CLOSE       UNISTRING("close")
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir #define CTRL_THROBBER       UNISTRING("throbber")
79*cdf0e10cSrcweir #define CTRL_PROGRESS       UNISTRING("progress")
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir #define TEXT_STATUS         UNISTRING("text_status")
82*cdf0e10cSrcweir #define TEXT_PERCENT        UNISTRING("text_percent")
83*cdf0e10cSrcweir #define TEXT_DESCRIPTION    UNISTRING("text_description")
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir #define FIXED_LINE_MODEL    UNISTRING("com.sun.star.awt.UnoControlFixedLineModel")
86*cdf0e10cSrcweir #define FIXED_TEXT_MODEL    UNISTRING("com.sun.star.awt.UnoControlFixedTextModel")
87*cdf0e10cSrcweir #define EDIT_FIELD_MODEL    UNISTRING("com.sun.star.awt.UnoControlEditModel")
88*cdf0e10cSrcweir #define BUTTON_MODEL        UNISTRING("com.sun.star.awt.UnoControlButtonModel")
89*cdf0e10cSrcweir #define GROUP_BOX_MODEL     UNISTRING("com.sun.star.awt.UnoControlGroupBoxModel")
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir using namespace com::sun::star;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir //--------------------------------------------------------------------
94*cdf0e10cSrcweir UpdateHandler::UpdateHandler( const uno::Reference< uno::XComponentContext > & rxContext,
95*cdf0e10cSrcweir                               const rtl::Reference< IActionListener > & rxActionListener ) :
96*cdf0e10cSrcweir     mxContext( rxContext ),
97*cdf0e10cSrcweir     mxActionListener( rxActionListener ),
98*cdf0e10cSrcweir     meCurState( UPDATESTATES_COUNT ),
99*cdf0e10cSrcweir     meLastState( UPDATESTATES_COUNT ),
100*cdf0e10cSrcweir     mnPercent( 0 ),
101*cdf0e10cSrcweir     mnLastCtrlState( -1 ),
102*cdf0e10cSrcweir     mbDownloadBtnHasDots( false ),
103*cdf0e10cSrcweir     mbVisible( false ),
104*cdf0e10cSrcweir     mbStringsLoaded( false ),
105*cdf0e10cSrcweir     mbMinimized( false ),
106*cdf0e10cSrcweir     mbListenerAdded(false),
107*cdf0e10cSrcweir     mbShowsMessageBox(false)
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir //--------------------------------------------------------------------
112*cdf0e10cSrcweir UpdateHandler::~UpdateHandler()
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir     mxContext = NULL;
115*cdf0e10cSrcweir     mxUpdDlg = NULL;
116*cdf0e10cSrcweir     mxInteractionHdl = NULL;
117*cdf0e10cSrcweir     mxActionListener = NULL;
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir //--------------------------------------------------------------------
121*cdf0e10cSrcweir void UpdateHandler::enableControls( short nCtrlState )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     if ( nCtrlState == mnLastCtrlState )
126*cdf0e10cSrcweir         return;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     bool bEnableControl;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     short nCurStateVal = nCtrlState;
131*cdf0e10cSrcweir     short nOldStateVal = mnLastCtrlState;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     // the help button should always be the last button in the
134*cdf0e10cSrcweir     // enum list und must never be disabled
135*cdf0e10cSrcweir     for ( int i=0; i<HELP_BUTTON; i++ )
136*cdf0e10cSrcweir     {
137*cdf0e10cSrcweir         nCurStateVal = (short)(nCtrlState >> i);
138*cdf0e10cSrcweir         nOldStateVal = (short)(mnLastCtrlState >> i);
139*cdf0e10cSrcweir         if ( ( nCurStateVal & 0x01 ) != ( nOldStateVal & 0x01 ) )
140*cdf0e10cSrcweir         {
141*cdf0e10cSrcweir             bEnableControl = ( ( nCurStateVal & 0x01 ) == 0x01 );
142*cdf0e10cSrcweir             setControlProperty( msButtonIDs[i], UNISTRING("Enabled"), uno::Any( bEnableControl ) );
143*cdf0e10cSrcweir         }
144*cdf0e10cSrcweir     }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     mnLastCtrlState = nCtrlState;
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir //--------------------------------------------------------------------
150*cdf0e10cSrcweir void UpdateHandler::setDownloadBtnLabel( bool bAppendDots )
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     if ( mbDownloadBtnHasDots != bAppendDots )
155*cdf0e10cSrcweir     {
156*cdf0e10cSrcweir         rtl::OUString aLabel( msDownload );
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir         if ( bAppendDots )
159*cdf0e10cSrcweir             aLabel += UNISTRING( "..." );
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir         setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], UNISTRING("Label"), uno::Any( aLabel ) );
162*cdf0e10cSrcweir         setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_DOWNLOAD2 ) ) );
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir         mbDownloadBtnHasDots = bAppendDots;
165*cdf0e10cSrcweir     }
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir //--------------------------------------------------------------------
169*cdf0e10cSrcweir void UpdateHandler::setState( UpdateState eState )
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir     meCurState = eState;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir     if ( mxUpdDlg.is() && mbVisible )
176*cdf0e10cSrcweir         updateState( meCurState );
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir //--------------------------------------------------------------------
180*cdf0e10cSrcweir bool UpdateHandler::isVisible() const
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir     if ( !mxUpdDlg.is() ) return false;
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     uno::Reference< awt::XWindow2 > xWindow( mxUpdDlg, uno::UNO_QUERY );
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     if ( xWindow.is() )
187*cdf0e10cSrcweir         return xWindow->isVisible();
188*cdf0e10cSrcweir     else
189*cdf0e10cSrcweir         return false;
190*cdf0e10cSrcweir }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir //--------------------------------------------------------------------
193*cdf0e10cSrcweir void UpdateHandler::setVisible( bool bVisible )
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir     mbVisible = bVisible;
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir     if ( bVisible )
200*cdf0e10cSrcweir     {
201*cdf0e10cSrcweir         if ( !mxUpdDlg.is() )
202*cdf0e10cSrcweir             createDialog();
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir         // this should never happen, but if it happens we better return here
205*cdf0e10cSrcweir         if ( !mxUpdDlg.is() )
206*cdf0e10cSrcweir             return;
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir         updateState( meCurState );
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir         if ( xWindow.is() )
213*cdf0e10cSrcweir             xWindow->setVisible( bVisible );
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir         uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
216*cdf0e10cSrcweir         if ( xTopWindow.is() )
217*cdf0e10cSrcweir         {
218*cdf0e10cSrcweir             xTopWindow->toFront();
219*cdf0e10cSrcweir             if ( !mbListenerAdded )
220*cdf0e10cSrcweir             {
221*cdf0e10cSrcweir                 xTopWindow->addTopWindowListener( this );
222*cdf0e10cSrcweir                 mbListenerAdded = true;
223*cdf0e10cSrcweir             }
224*cdf0e10cSrcweir         }
225*cdf0e10cSrcweir     }
226*cdf0e10cSrcweir     else if ( mxUpdDlg.is() )
227*cdf0e10cSrcweir     {
228*cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir         if ( xWindow.is() )
231*cdf0e10cSrcweir             xWindow->setVisible( bVisible );
232*cdf0e10cSrcweir     }
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir //--------------------------------------------------------------------
236*cdf0e10cSrcweir void UpdateHandler::setProgress( sal_Int32 nPercent )
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     if ( nPercent > 100 )
239*cdf0e10cSrcweir         nPercent = 100;
240*cdf0e10cSrcweir     else if ( nPercent < 0 )
241*cdf0e10cSrcweir         nPercent = 0;
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     if ( nPercent != mnPercent )
244*cdf0e10cSrcweir     {
245*cdf0e10cSrcweir         osl::MutexGuard aGuard( maMutex );
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir         mnPercent = nPercent;
248*cdf0e10cSrcweir         setControlProperty( CTRL_PROGRESS, UNISTRING("ProgressValue"), uno::Any( nPercent ) );
249*cdf0e10cSrcweir         setControlProperty( TEXT_PERCENT, UNISTRING("Text"), uno::Any( substVariables(msPercent) ) );
250*cdf0e10cSrcweir     }
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir //--------------------------------------------------------------------
254*cdf0e10cSrcweir void UpdateHandler::setErrorMessage( const rtl::OUString& rErrorMsg )
255*cdf0e10cSrcweir {
256*cdf0e10cSrcweir     setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( rErrorMsg ) );
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir //--------------------------------------------------------------------
260*cdf0e10cSrcweir void UpdateHandler::setDownloadFile( const rtl::OUString& rFilePath )
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir     sal_Int32 nLast = rFilePath.lastIndexOf( '/' );
263*cdf0e10cSrcweir     if ( nLast != -1 )
264*cdf0e10cSrcweir     {
265*cdf0e10cSrcweir         msDownloadFile = rFilePath.copy( nLast+1 );
266*cdf0e10cSrcweir         const rtl::OUString aDownloadURL = rFilePath.copy( 0, nLast );
267*cdf0e10cSrcweir         osl::FileBase::getSystemPathFromFileURL( aDownloadURL, msDownloadPath );
268*cdf0e10cSrcweir     }
269*cdf0e10cSrcweir }
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir //--------------------------------------------------------------------
272*cdf0e10cSrcweir rtl::OUString UpdateHandler::getBubbleText( UpdateState eState )
273*cdf0e10cSrcweir {
274*cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir     rtl::OUString sText;
277*cdf0e10cSrcweir     sal_Int32 nIndex = (sal_Int32) eState;
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     loadStrings();
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
282*cdf0e10cSrcweir         sText = substVariables( msBubbleTexts[ nIndex - UPDATESTATE_UPDATE_AVAIL ] );
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir     return sText;
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir //--------------------------------------------------------------------
288*cdf0e10cSrcweir rtl::OUString UpdateHandler::getBubbleTitle( UpdateState eState )
289*cdf0e10cSrcweir {
290*cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     rtl::OUString sText;
293*cdf0e10cSrcweir     sal_Int32 nIndex = (sal_Int32) eState;
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir     loadStrings();
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir     if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
298*cdf0e10cSrcweir         sText = substVariables( msBubbleTitles[ nIndex - UPDATESTATE_UPDATE_AVAIL] );
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     return sText;
301*cdf0e10cSrcweir }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir //--------------------------------------------------------------------
304*cdf0e10cSrcweir rtl::OUString UpdateHandler::getDefaultInstErrMsg()
305*cdf0e10cSrcweir {
306*cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir     loadStrings();
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     return substVariables( msInstallError );
311*cdf0e10cSrcweir }
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir // XActionListener
314*cdf0e10cSrcweir //--------------------------------------------------------------------
315*cdf0e10cSrcweir void SAL_CALL UpdateHandler::disposing( const lang::EventObject& rEvt )
316*cdf0e10cSrcweir     throw( uno::RuntimeException )
317*cdf0e10cSrcweir {
318*cdf0e10cSrcweir     if ( rEvt.Source == mxUpdDlg )
319*cdf0e10cSrcweir         mxUpdDlg.clear();
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir //--------------------------------------------------------------------
323*cdf0e10cSrcweir void SAL_CALL UpdateHandler::actionPerformed( awt::ActionEvent const & rEvent )
324*cdf0e10cSrcweir     throw( uno::RuntimeException )
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir     DialogControls eButton = BUTTON_COUNT;
327*cdf0e10cSrcweir     for ( int i = 0; i < BUTTON_COUNT; i++ )
328*cdf0e10cSrcweir     {
329*cdf0e10cSrcweir         if ( rEvent.ActionCommand.equals( msButtonIDs[i] ) )
330*cdf0e10cSrcweir         {
331*cdf0e10cSrcweir             eButton = (DialogControls) i;
332*cdf0e10cSrcweir             break;
333*cdf0e10cSrcweir         }
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     if ( rEvent.ActionCommand.equals( COMMAND_CLOSE ) )
337*cdf0e10cSrcweir     {
338*cdf0e10cSrcweir         if ( ( mnLastCtrlState & ( 1 << CLOSE_BUTTON ) ) == ( 1 << CLOSE_BUTTON ) )
339*cdf0e10cSrcweir             eButton = CLOSE_BUTTON;
340*cdf0e10cSrcweir         else
341*cdf0e10cSrcweir             eButton = CANCEL_BUTTON;
342*cdf0e10cSrcweir     }
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir     switch ( eButton ) {
345*cdf0e10cSrcweir         case CANCEL_BUTTON:
346*cdf0e10cSrcweir         {
347*cdf0e10cSrcweir             bool bCancel = true;
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir             if ( ( meCurState == UPDATESTATE_DOWNLOADING ) ||
350*cdf0e10cSrcweir                  ( meCurState == UPDATESTATE_DOWNLOAD_PAUSED ) ||
351*cdf0e10cSrcweir                  ( meCurState == UPDATESTATE_ERROR_DOWNLOADING ) )
352*cdf0e10cSrcweir                 bCancel = showWarning( msCancelMessage );
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir             if ( bCancel )
355*cdf0e10cSrcweir             {
356*cdf0e10cSrcweir                 mxActionListener->cancel();
357*cdf0e10cSrcweir                 setVisible( false );
358*cdf0e10cSrcweir             }
359*cdf0e10cSrcweir             break;
360*cdf0e10cSrcweir         }
361*cdf0e10cSrcweir         case CLOSE_BUTTON:
362*cdf0e10cSrcweir             setVisible( false );
363*cdf0e10cSrcweir             if ( meCurState == UPDATESTATE_ERROR_CHECKING )
364*cdf0e10cSrcweir                 mxActionListener->closeAfterFailure();
365*cdf0e10cSrcweir             break;
366*cdf0e10cSrcweir         case DOWNLOAD_BUTTON:
367*cdf0e10cSrcweir             mxActionListener->download();
368*cdf0e10cSrcweir             break;
369*cdf0e10cSrcweir         case INSTALL_BUTTON:
370*cdf0e10cSrcweir             if ( showWarning( msInstallMessage ) )
371*cdf0e10cSrcweir                 mxActionListener->install();
372*cdf0e10cSrcweir             break;
373*cdf0e10cSrcweir         case PAUSE_BUTTON:
374*cdf0e10cSrcweir             mxActionListener->pause();
375*cdf0e10cSrcweir             break;
376*cdf0e10cSrcweir         case RESUME_BUTTON:
377*cdf0e10cSrcweir             mxActionListener->resume();
378*cdf0e10cSrcweir             break;
379*cdf0e10cSrcweir         case HELP_BUTTON:
380*cdf0e10cSrcweir             break;
381*cdf0e10cSrcweir         default:
382*cdf0e10cSrcweir             OSL_ENSURE( false, "UpdateHandler::actionPerformed: unknown command!" );
383*cdf0e10cSrcweir     }
384*cdf0e10cSrcweir }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir // XTopWindowListener
387*cdf0e10cSrcweir //--------------------------------------------------------------------
388*cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowOpened( const lang::EventObject& )
389*cdf0e10cSrcweir     throw( uno::RuntimeException )
390*cdf0e10cSrcweir {
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir //--------------------------------------------------------------------
394*cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowClosing( const lang::EventObject& e )
395*cdf0e10cSrcweir     throw( uno::RuntimeException )
396*cdf0e10cSrcweir {
397*cdf0e10cSrcweir     awt::ActionEvent aActionEvt;
398*cdf0e10cSrcweir     aActionEvt.ActionCommand = COMMAND_CLOSE;
399*cdf0e10cSrcweir     aActionEvt.Source = e.Source;
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir     actionPerformed( aActionEvt );
402*cdf0e10cSrcweir }
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir //--------------------------------------------------------------------
405*cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowClosed( const lang::EventObject& )
406*cdf0e10cSrcweir     throw( uno::RuntimeException )
407*cdf0e10cSrcweir {
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir //--------------------------------------------------------------------
411*cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowMinimized( const lang::EventObject& )
412*cdf0e10cSrcweir     throw( uno::RuntimeException )
413*cdf0e10cSrcweir {
414*cdf0e10cSrcweir     mbMinimized = true;
415*cdf0e10cSrcweir }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir //--------------------------------------------------------------------
418*cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowNormalized( const lang::EventObject& )
419*cdf0e10cSrcweir     throw( uno::RuntimeException )
420*cdf0e10cSrcweir {
421*cdf0e10cSrcweir     mbMinimized = false;
422*cdf0e10cSrcweir }
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir //--------------------------------------------------------------------
425*cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowActivated( const lang::EventObject& )
426*cdf0e10cSrcweir     throw( uno::RuntimeException )
427*cdf0e10cSrcweir {
428*cdf0e10cSrcweir }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir //--------------------------------------------------------------------
431*cdf0e10cSrcweir void SAL_CALL UpdateHandler::windowDeactivated( const lang::EventObject& )
432*cdf0e10cSrcweir     throw( uno::RuntimeException )
433*cdf0e10cSrcweir {
434*cdf0e10cSrcweir }
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir // XInteractionHandler
437*cdf0e10cSrcweir //------------------------------------------------------------------------------
438*cdf0e10cSrcweir void SAL_CALL UpdateHandler::handle( uno::Reference< task::XInteractionRequest > const & rRequest)
439*cdf0e10cSrcweir     throw (uno::RuntimeException)
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir     if ( !mxInteractionHdl.is() )
442*cdf0e10cSrcweir     {
443*cdf0e10cSrcweir         if( !mxContext.is() )
444*cdf0e10cSrcweir             throw uno::RuntimeException( UNISTRING( "UpdateHandler:: empty component context" ), *this );
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir         uno::Reference< lang::XMultiComponentFactory > xServiceManager(mxContext->getServiceManager());
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir         if( !xServiceManager.is() )
449*cdf0e10cSrcweir             throw uno::RuntimeException( UNISTRING( "UpdateHandler: unable to obtain service manager from component context" ), *this );
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir         mxInteractionHdl = uno::Reference<task::XInteractionHandler> (
452*cdf0e10cSrcweir                                 xServiceManager->createInstanceWithContext(
453*cdf0e10cSrcweir                                     UNISTRING( "com.sun.star.task.InteractionHandler" ),
454*cdf0e10cSrcweir                                     mxContext),
455*cdf0e10cSrcweir                                 uno::UNO_QUERY_THROW);
456*cdf0e10cSrcweir         if( !mxInteractionHdl.is() )
457*cdf0e10cSrcweir             throw uno::RuntimeException( UNISTRING( "UpdateHandler:: could not get default interaction handler" ), *this );
458*cdf0e10cSrcweir     }
459*cdf0e10cSrcweir     uno::Reference< task::XInteractionRequestStringResolver > xStrResolver =
460*cdf0e10cSrcweir             task::InteractionRequestStringResolver::create( mxContext );
461*cdf0e10cSrcweir     beans::Optional< ::rtl::OUString > aErrorText = xStrResolver->getStringFromInformationalRequest( rRequest );
462*cdf0e10cSrcweir     if ( aErrorText.IsPresent )
463*cdf0e10cSrcweir     {
464*cdf0e10cSrcweir         setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( aErrorText.Value ) );
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir         uno::Sequence< uno::Reference< task::XInteractionContinuation > > xContinuations = rRequest->getContinuations();
467*cdf0e10cSrcweir         if ( xContinuations.getLength() == 1 )
468*cdf0e10cSrcweir         {
469*cdf0e10cSrcweir             if ( meCurState == UPDATESTATE_CHECKING )
470*cdf0e10cSrcweir                 setState( UPDATESTATE_ERROR_CHECKING );
471*cdf0e10cSrcweir             else if ( meCurState == UPDATESTATE_DOWNLOADING )
472*cdf0e10cSrcweir                 setState( UPDATESTATE_ERROR_DOWNLOADING );
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir             xContinuations[0]->select();
475*cdf0e10cSrcweir         }
476*cdf0e10cSrcweir         else
477*cdf0e10cSrcweir             mxInteractionHdl->handle( rRequest );
478*cdf0e10cSrcweir     }
479*cdf0e10cSrcweir     else
480*cdf0e10cSrcweir         mxInteractionHdl->handle( rRequest );
481*cdf0e10cSrcweir }
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir //------------------------------------------------------------------------------
484*cdf0e10cSrcweir // XTerminateListener
485*cdf0e10cSrcweir //------------------------------------------------------------------------------
486*cdf0e10cSrcweir void SAL_CALL UpdateHandler::queryTermination( const lang::EventObject& )
487*cdf0e10cSrcweir     throw ( frame::TerminationVetoException, uno::RuntimeException )
488*cdf0e10cSrcweir {
489*cdf0e10cSrcweir     if ( mbShowsMessageBox )
490*cdf0e10cSrcweir     {
491*cdf0e10cSrcweir         uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
492*cdf0e10cSrcweir         if ( xTopWindow.is() )
493*cdf0e10cSrcweir             xTopWindow->toFront();
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir         throw frame::TerminationVetoException(
496*cdf0e10cSrcweir             UNISTRING("The office cannot be closed while displaying a warning!"),
497*cdf0e10cSrcweir             uno::Reference<XInterface>(static_cast<frame::XTerminateListener*>(this), uno::UNO_QUERY));
498*cdf0e10cSrcweir     }
499*cdf0e10cSrcweir     else
500*cdf0e10cSrcweir         setVisible( false );
501*cdf0e10cSrcweir }
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir //------------------------------------------------------------------------------
504*cdf0e10cSrcweir void SAL_CALL UpdateHandler::notifyTermination( const lang::EventObject& )
505*cdf0e10cSrcweir     throw ( uno::RuntimeException )
506*cdf0e10cSrcweir {
507*cdf0e10cSrcweir     osl::MutexGuard aGuard( maMutex );
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir     if ( mxUpdDlg.is() )
510*cdf0e10cSrcweir     {
511*cdf0e10cSrcweir         uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
512*cdf0e10cSrcweir         if ( xTopWindow.is() )
513*cdf0e10cSrcweir             xTopWindow->removeTopWindowListener( this );
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir         uno::Reference< lang::XComponent > xComponent( mxUpdDlg, uno::UNO_QUERY );
516*cdf0e10cSrcweir         if ( xComponent.is() )
517*cdf0e10cSrcweir             xComponent->dispose();
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir         mxUpdDlg.clear();
520*cdf0e10cSrcweir     }
521*cdf0e10cSrcweir }
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir //--------------------------------------------------------------------
524*cdf0e10cSrcweir //--------------------------------------------------------------------
525*cdf0e10cSrcweir //--------------------------------------------------------------------
526*cdf0e10cSrcweir void UpdateHandler::updateState( UpdateState eState )
527*cdf0e10cSrcweir {
528*cdf0e10cSrcweir     if ( meLastState == eState )
529*cdf0e10cSrcweir         return;
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir     if ( isVisible() )
532*cdf0e10cSrcweir         {} // ToTop();
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir     rtl::OUString sText;
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir     switch ( eState )
537*cdf0e10cSrcweir     {
538*cdf0e10cSrcweir         case UPDATESTATE_CHECKING:
539*cdf0e10cSrcweir             showControls( (1<<CANCEL_BUTTON) + (1<<THROBBER_CTRL) );
540*cdf0e10cSrcweir             enableControls( 1<<CANCEL_BUTTON );
541*cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msChecking) ) );
542*cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( rtl::OUString() ) );
543*cdf0e10cSrcweir             focusControl( CANCEL_BUTTON );
544*cdf0e10cSrcweir             break;
545*cdf0e10cSrcweir         case UPDATESTATE_ERROR_CHECKING:
546*cdf0e10cSrcweir             showControls( 0 );
547*cdf0e10cSrcweir             enableControls( 1 << CLOSE_BUTTON );
548*cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msCheckingError) ) );
549*cdf0e10cSrcweir             focusControl( CLOSE_BUTTON );
550*cdf0e10cSrcweir             break;
551*cdf0e10cSrcweir         case UPDATESTATE_UPDATE_AVAIL:
552*cdf0e10cSrcweir             showControls( 0 );
553*cdf0e10cSrcweir             enableControls( ( 1 << CLOSE_BUTTON )  + ( 1 << DOWNLOAD_BUTTON ) );
554*cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msUpdFound) ) );
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir             sText = substVariables(msDownloadWarning);
557*cdf0e10cSrcweir             if ( msDescriptionMsg.getLength() )
558*cdf0e10cSrcweir                 sText += UNISTRING("\n\n") + msDescriptionMsg;
559*cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( sText ) );
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir             setDownloadBtnLabel( false );
562*cdf0e10cSrcweir             focusControl( DOWNLOAD_BUTTON );
563*cdf0e10cSrcweir             break;
564*cdf0e10cSrcweir         case UPDATESTATE_UPDATE_NO_DOWNLOAD:
565*cdf0e10cSrcweir             showControls( 0 );
566*cdf0e10cSrcweir             enableControls( ( 1 << CLOSE_BUTTON )  + ( 1 << DOWNLOAD_BUTTON ) );
567*cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msUpdFound) ) );
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir             sText = substVariables(msDownloadNotAvail);
570*cdf0e10cSrcweir             if ( msDescriptionMsg.getLength() )
571*cdf0e10cSrcweir                 sText += UNISTRING("\n\n") + msDescriptionMsg;
572*cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( sText ) );
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir             setDownloadBtnLabel( true );
575*cdf0e10cSrcweir             focusControl( DOWNLOAD_BUTTON );
576*cdf0e10cSrcweir             break;
577*cdf0e10cSrcweir         case UPDATESTATE_NO_UPDATE_AVAIL:
578*cdf0e10cSrcweir         case UPDATESTATE_EXT_UPD_AVAIL:     // will only be set, when there are no office updates avail
579*cdf0e10cSrcweir             showControls( 0 );
580*cdf0e10cSrcweir             enableControls( 1 << CLOSE_BUTTON );
581*cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msNoUpdFound) ) );
582*cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( rtl::OUString() ) );
583*cdf0e10cSrcweir             focusControl( CLOSE_BUTTON );
584*cdf0e10cSrcweir             break;
585*cdf0e10cSrcweir         case UPDATESTATE_DOWNLOADING:
586*cdf0e10cSrcweir             showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
587*cdf0e10cSrcweir             enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) );
588*cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msDownloading) ) );
589*cdf0e10cSrcweir             setControlProperty( TEXT_PERCENT, UNISTRING("Text"), uno::Any( substVariables(msPercent) ) );
590*cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( substVariables(msDownloadWarning) ) );
591*cdf0e10cSrcweir             setControlProperty( CTRL_PROGRESS, UNISTRING("ProgressValue"), uno::Any( mnPercent ) );
592*cdf0e10cSrcweir             focusControl( CLOSE_BUTTON );
593*cdf0e10cSrcweir             break;
594*cdf0e10cSrcweir         case UPDATESTATE_DOWNLOAD_PAUSED:
595*cdf0e10cSrcweir             showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
596*cdf0e10cSrcweir             enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<RESUME_BUTTON) );
597*cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msDownloadPause) ) );
598*cdf0e10cSrcweir             setControlProperty( TEXT_PERCENT, UNISTRING("Text"), uno::Any( substVariables(msPercent) ) );
599*cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( substVariables(msDownloadWarning) ) );
600*cdf0e10cSrcweir             setControlProperty( CTRL_PROGRESS, UNISTRING("ProgressValue"), uno::Any( mnPercent ) );
601*cdf0e10cSrcweir             focusControl( CLOSE_BUTTON );
602*cdf0e10cSrcweir             break;
603*cdf0e10cSrcweir         case UPDATESTATE_ERROR_DOWNLOADING:
604*cdf0e10cSrcweir             showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
605*cdf0e10cSrcweir             enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) );
606*cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msDownloadError) ) );
607*cdf0e10cSrcweir             focusControl( CLOSE_BUTTON );
608*cdf0e10cSrcweir             break;
609*cdf0e10cSrcweir         case UPDATESTATE_DOWNLOAD_AVAIL:
610*cdf0e10cSrcweir             showControls( 0 );
611*cdf0e10cSrcweir             enableControls( (1<<CLOSE_BUTTON) + (1<<INSTALL_BUTTON) );
612*cdf0e10cSrcweir             setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msReady2Install) ) );
613*cdf0e10cSrcweir             setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( substVariables(msDownloadDescr) ) );
614*cdf0e10cSrcweir             focusControl( INSTALL_BUTTON );
615*cdf0e10cSrcweir             break;
616*cdf0e10cSrcweir         case UPDATESTATE_AUTO_START:
617*cdf0e10cSrcweir         case UPDATESTATES_COUNT:
618*cdf0e10cSrcweir             //do nothing, only count!
619*cdf0e10cSrcweir             break;
620*cdf0e10cSrcweir     }
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir     meLastState = eState;
623*cdf0e10cSrcweir }
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir //--------------------------------------------------------------------
626*cdf0e10cSrcweir void UpdateHandler::searchAndReplaceAll( rtl::OUString &rText,
627*cdf0e10cSrcweir                                          const rtl::OUString &rWhat,
628*cdf0e10cSrcweir                                          const rtl::OUString &rWith ) const
629*cdf0e10cSrcweir {
630*cdf0e10cSrcweir     sal_Int32 nIndex = rText.indexOf( rWhat );
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir     while ( nIndex != -1 )
633*cdf0e10cSrcweir     {
634*cdf0e10cSrcweir         rText = rText.replaceAt( nIndex, rWhat.getLength(), rWith );
635*cdf0e10cSrcweir         nIndex = rText.indexOf( rWhat, nIndex );
636*cdf0e10cSrcweir     }
637*cdf0e10cSrcweir }
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir //--------------------------------------------------------------------
640*cdf0e10cSrcweir rtl::OUString UpdateHandler::loadString( const uno::Reference< resource::XResourceBundle > xBundle,
641*cdf0e10cSrcweir                                          sal_Int32 nResourceId ) const
642*cdf0e10cSrcweir {
643*cdf0e10cSrcweir     rtl::OUString sString;
644*cdf0e10cSrcweir     rtl::OUString sKey = UNISTRING( "string:" ) + rtl::OUString::valueOf( nResourceId );
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir     try
647*cdf0e10cSrcweir     {
648*cdf0e10cSrcweir         OSL_VERIFY( xBundle->getByName( sKey ) >>= sString );
649*cdf0e10cSrcweir     }
650*cdf0e10cSrcweir     catch( const uno::Exception& )
651*cdf0e10cSrcweir     {
652*cdf0e10cSrcweir         OSL_ENSURE( false, "UpdateHandler::loadString: caught an exception!" );
653*cdf0e10cSrcweir         sString = UNISTRING("Missing ") + sKey;
654*cdf0e10cSrcweir     }
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir     return sString;
657*cdf0e10cSrcweir }
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir rtl::OUString UpdateHandler::substVariables( const rtl::OUString &rSource ) const
660*cdf0e10cSrcweir {
661*cdf0e10cSrcweir     rtl::OUString sString( rSource );
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir     searchAndReplaceAll( sString, UNISTRING( "%NEXTVERSION" ), msNextVersion );
664*cdf0e10cSrcweir     searchAndReplaceAll( sString, UNISTRING( "%DOWNLOAD_PATH" ), msDownloadPath );
665*cdf0e10cSrcweir     searchAndReplaceAll( sString, UNISTRING( "%FILE_NAME" ), msDownloadFile );
666*cdf0e10cSrcweir     searchAndReplaceAll( sString, UNISTRING( "%PERCENT" ), rtl::OUString::valueOf( mnPercent ) );
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir     return sString;
669*cdf0e10cSrcweir }
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir //--------------------------------------------------------------------
672*cdf0e10cSrcweir void UpdateHandler::loadStrings()
673*cdf0e10cSrcweir {
674*cdf0e10cSrcweir     if ( mbStringsLoaded )
675*cdf0e10cSrcweir         return;
676*cdf0e10cSrcweir     else
677*cdf0e10cSrcweir         mbStringsLoaded = true;
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir     uno::Reference< resource::XResourceBundleLoader > xLoader;
680*cdf0e10cSrcweir     try
681*cdf0e10cSrcweir     {
682*cdf0e10cSrcweir         uno::Any aValue( mxContext->getValueByName(
683*cdf0e10cSrcweir                 UNISTRING( "/singletons/com.sun.star.resource.OfficeResourceLoader" ) ) );
684*cdf0e10cSrcweir         OSL_VERIFY( aValue >>= xLoader );
685*cdf0e10cSrcweir     }
686*cdf0e10cSrcweir     catch( const uno::Exception& )
687*cdf0e10cSrcweir     {
688*cdf0e10cSrcweir         OSL_ENSURE( false, "UpdateHandler::loadStrings: could not create the resource loader!" );
689*cdf0e10cSrcweir     }
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir     if ( !xLoader.is() ) return;
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir     uno::Reference< resource::XResourceBundle > xBundle;
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir     try
696*cdf0e10cSrcweir     {
697*cdf0e10cSrcweir         xBundle = xLoader->loadBundle_Default( UNISTRING( "upd" ) );
698*cdf0e10cSrcweir     }
699*cdf0e10cSrcweir     catch( const resource::MissingResourceException& )
700*cdf0e10cSrcweir     {
701*cdf0e10cSrcweir         OSL_ENSURE( false, "UpdateHandler::loadStrings: missing the resource bundle!" );
702*cdf0e10cSrcweir     }
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir     if ( !xBundle.is() ) return;
705*cdf0e10cSrcweir 
706*cdf0e10cSrcweir     msChecking      = loadString( xBundle, RID_UPDATE_STR_CHECKING );
707*cdf0e10cSrcweir     msCheckingError = loadString( xBundle, RID_UPDATE_STR_CHECKING_ERR );
708*cdf0e10cSrcweir     msNoUpdFound    = loadString( xBundle, RID_UPDATE_STR_NO_UPD_FOUND );
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir     msUpdFound      = loadString( xBundle, RID_UPDATE_STR_UPD_FOUND );
711*cdf0e10cSrcweir     setFullVersion( msUpdFound );
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir     msDlgTitle      = loadString( xBundle, RID_UPDATE_STR_DLG_TITLE );
714*cdf0e10cSrcweir     msDownloadPause = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_PAUSE );
715*cdf0e10cSrcweir     msDownloadError = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_ERR );
716*cdf0e10cSrcweir     msDownloadWarning = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_WARN );
717*cdf0e10cSrcweir     msDownloadDescr =  loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_DESCR );
718*cdf0e10cSrcweir     msDownloadNotAvail = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_UNAVAIL );
719*cdf0e10cSrcweir     msDownloading   = loadString( xBundle, RID_UPDATE_STR_DOWNLOADING );
720*cdf0e10cSrcweir     msReady2Install = loadString( xBundle, RID_UPDATE_STR_READY_INSTALL );
721*cdf0e10cSrcweir     msCancelTitle   = loadString( xBundle, RID_UPDATE_STR_CANCEL_TITLE );
722*cdf0e10cSrcweir     msCancelMessage = loadString( xBundle, RID_UPDATE_STR_CANCEL_DOWNLOAD );
723*cdf0e10cSrcweir     msInstallMessage = loadString( xBundle, RID_UPDATE_STR_BEGIN_INSTALL );
724*cdf0e10cSrcweir     msInstallNow    = loadString( xBundle, RID_UPDATE_STR_INSTALL_NOW );
725*cdf0e10cSrcweir     msInstallLater  = loadString( xBundle, RID_UPDATE_STR_INSTALL_LATER );
726*cdf0e10cSrcweir     msInstallError  = loadString( xBundle, RID_UPDATE_STR_INSTALL_ERROR );
727*cdf0e10cSrcweir     msOverwriteWarning = loadString( xBundle, RID_UPDATE_STR_OVERWRITE_WARNING );
728*cdf0e10cSrcweir     msPercent       = loadString( xBundle, RID_UPDATE_STR_PERCENT );
729*cdf0e10cSrcweir     msReloadWarning = loadString( xBundle, RID_UPDATE_STR_RELOAD_WARNING );
730*cdf0e10cSrcweir     msReloadReload  = loadString( xBundle, RID_UPDATE_STR_RELOAD_RELOAD );
731*cdf0e10cSrcweir     msReloadContinue = loadString( xBundle, RID_UPDATE_STR_RELOAD_CONTINUE );
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir     msStatusFL      = loadString( xBundle, RID_UPDATE_FT_STATUS );
734*cdf0e10cSrcweir     msDescription   = loadString( xBundle, RID_UPDATE_FT_DESCRIPTION );
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir     msClose         = loadString( xBundle, RID_UPDATE_BTN_CLOSE );
737*cdf0e10cSrcweir     msDownload      = loadString( xBundle, RID_UPDATE_BTN_DOWNLOAD );
738*cdf0e10cSrcweir     msInstall       = loadString( xBundle, RID_UPDATE_BTN_INSTALL );
739*cdf0e10cSrcweir     msPauseBtn      = loadString( xBundle, RID_UPDATE_BTN_PAUSE );
740*cdf0e10cSrcweir     msResumeBtn     = loadString( xBundle, RID_UPDATE_BTN_RESUME );
741*cdf0e10cSrcweir     msCancelBtn     = loadString( xBundle, RID_UPDATE_BTN_CANCEL );
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir     // all update states before UPDATESTATE_UPDATE_AVAIL don't have a bubble
744*cdf0e10cSrcweir     // so we can ignore them
745*cdf0e10cSrcweir     for ( int i=0; i < (int)(UPDATESTATES_COUNT - UPDATESTATE_UPDATE_AVAIL); i++ )
746*cdf0e10cSrcweir     {
747*cdf0e10cSrcweir         msBubbleTexts[ i ] = loadString( xBundle, RID_UPDATE_BUBBLE_TEXT_START + i );
748*cdf0e10cSrcweir         msBubbleTitles[ i ] = loadString( xBundle, RID_UPDATE_BUBBLE_T_TEXT_START + i );
749*cdf0e10cSrcweir     }
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir     for ( int i=0; i < BUTTON_COUNT; i++ )
752*cdf0e10cSrcweir     {
753*cdf0e10cSrcweir         msButtonIDs[ i ] = UNISTRING("BUTTON_") + rtl::OUString::valueOf( (sal_Int32) i );
754*cdf0e10cSrcweir     }
755*cdf0e10cSrcweir }
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir 
758*cdf0e10cSrcweir //--------------------------------------------------------------------
759*cdf0e10cSrcweir void UpdateHandler::startThrobber( bool bStart )
760*cdf0e10cSrcweir {
761*cdf0e10cSrcweir     uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
762*cdf0e10cSrcweir     uno::Reference< awt::XAnimation > xThrobber( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir     if ( xThrobber.is() )
765*cdf0e10cSrcweir     {
766*cdf0e10cSrcweir         if ( bStart )
767*cdf0e10cSrcweir             xThrobber->startAnimation();
768*cdf0e10cSrcweir         else
769*cdf0e10cSrcweir             xThrobber->stopAnimation();
770*cdf0e10cSrcweir     }
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
773*cdf0e10cSrcweir     if (xWindow.is() )
774*cdf0e10cSrcweir         xWindow->setVisible( bStart );
775*cdf0e10cSrcweir }
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir //--------------------------------------------------------------------
778*cdf0e10cSrcweir void UpdateHandler::setControlProperty( const rtl::OUString &rCtrlName,
779*cdf0e10cSrcweir                                         const rtl::OUString &rPropName,
780*cdf0e10cSrcweir                                         const uno::Any &rPropValue )
781*cdf0e10cSrcweir {
782*cdf0e10cSrcweir     if ( !mxUpdDlg.is() ) return;
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir     uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
785*cdf0e10cSrcweir     uno::Reference< awt::XControl > xControl( xContainer->getControl( rCtrlName ), uno::UNO_QUERY_THROW );
786*cdf0e10cSrcweir     uno::Reference< awt::XControlModel > xControlModel( xControl->getModel(), uno::UNO_QUERY_THROW );
787*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir     try {
790*cdf0e10cSrcweir         xPropSet->setPropertyValue( rPropName, rPropValue );
791*cdf0e10cSrcweir     }
792*cdf0e10cSrcweir 	catch( const beans::UnknownPropertyException& )
793*cdf0e10cSrcweir 	{
794*cdf0e10cSrcweir 		OSL_ENSURE( false, "UpdateHandler::setControlProperty: caught an exception!" );
795*cdf0e10cSrcweir 	}
796*cdf0e10cSrcweir }
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir //--------------------------------------------------------------------
799*cdf0e10cSrcweir void UpdateHandler::showControl( const rtl::OUString &rCtrlName, bool bShow )
800*cdf0e10cSrcweir {
801*cdf0e10cSrcweir     uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir     if ( !xContainer.is() )
804*cdf0e10cSrcweir     {
805*cdf0e10cSrcweir         OSL_ENSURE( false, "UpdateHandler::showControl: could not get control container!" );
806*cdf0e10cSrcweir         return;
807*cdf0e10cSrcweir     }
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow( xContainer->getControl( rCtrlName ), uno::UNO_QUERY );
810*cdf0e10cSrcweir     if ( xWindow.is() )
811*cdf0e10cSrcweir         xWindow->setVisible( bShow );
812*cdf0e10cSrcweir }
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir //--------------------------------------------------------------------
815*cdf0e10cSrcweir void UpdateHandler::focusControl( DialogControls eID )
816*cdf0e10cSrcweir {
817*cdf0e10cSrcweir     uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
818*cdf0e10cSrcweir 
819*cdf0e10cSrcweir     if ( !xContainer.is() )
820*cdf0e10cSrcweir     {
821*cdf0e10cSrcweir         OSL_ENSURE( false, "UpdateHandler::focusControl: could not get control container!" );
822*cdf0e10cSrcweir         return;
823*cdf0e10cSrcweir     }
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir     OSL_ENSURE( (eID < BUTTON_COUNT), "UpdateHandler::focusControl: id to big!" );
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow( xContainer->getControl( msButtonIDs[(short)eID] ), uno::UNO_QUERY );
828*cdf0e10cSrcweir     if ( xWindow.is() )
829*cdf0e10cSrcweir         xWindow->setFocus();
830*cdf0e10cSrcweir }
831*cdf0e10cSrcweir 
832*cdf0e10cSrcweir //--------------------------------------------------------------------
833*cdf0e10cSrcweir void UpdateHandler::insertControlModel( uno::Reference< awt::XControlModel > & rxDialogModel,
834*cdf0e10cSrcweir                                         rtl::OUString const & rServiceName,
835*cdf0e10cSrcweir                                         rtl::OUString const & rControlName,
836*cdf0e10cSrcweir                                         awt::Rectangle const & rPosSize,
837*cdf0e10cSrcweir                                         uno::Sequence< beans::NamedValue > const & rProps )
838*cdf0e10cSrcweir {
839*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xFactory (rxDialogModel, uno::UNO_QUERY_THROW);
840*cdf0e10cSrcweir     uno::Reference< awt::XControlModel > xModel (xFactory->createInstance (rServiceName), uno::UNO_QUERY_THROW);
841*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xPropSet (xModel, uno::UNO_QUERY_THROW);
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir     for (sal_Int32 i = 0, n = rProps.getLength(); i < n; i++)
844*cdf0e10cSrcweir     {
845*cdf0e10cSrcweir         xPropSet->setPropertyValue (rProps[i].Name, rProps[i].Value);
846*cdf0e10cSrcweir     }
847*cdf0e10cSrcweir 
848*cdf0e10cSrcweir     // @see awt/UnoControlDialogElement.idl
849*cdf0e10cSrcweir     xPropSet->setPropertyValue( UNISTRING("Name"), uno::Any (rControlName) );
850*cdf0e10cSrcweir     xPropSet->setPropertyValue( UNISTRING("PositionX"), uno::Any (rPosSize.X) );
851*cdf0e10cSrcweir     xPropSet->setPropertyValue( UNISTRING("PositionY"), uno::Any (rPosSize.Y) );
852*cdf0e10cSrcweir     xPropSet->setPropertyValue( UNISTRING("Height"), uno::Any (rPosSize.Height) );
853*cdf0e10cSrcweir     xPropSet->setPropertyValue( UNISTRING("Width"), uno::Any (rPosSize.Width) );
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir     // insert by Name into DialogModel container
856*cdf0e10cSrcweir     uno::Reference< container::XNameContainer > xContainer (rxDialogModel, uno::UNO_QUERY_THROW);
857*cdf0e10cSrcweir     xContainer->insertByName( rControlName, uno::Any (uno::Reference< uno::XInterface >(xModel, uno::UNO_QUERY)));
858*cdf0e10cSrcweir }
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir //--------------------------------------------------------------------
861*cdf0e10cSrcweir void UpdateHandler::setFullVersion( rtl::OUString& rString )
862*cdf0e10cSrcweir {
863*cdf0e10cSrcweir     if( !mxContext.is() )
864*cdf0e10cSrcweir         throw uno::RuntimeException( UNISTRING( "getProductName: empty component context" ), *this );
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir     uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager() );
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir     if( !xServiceManager.is() )
869*cdf0e10cSrcweir         throw uno::RuntimeException( UNISTRING( "getProductName: unable to obtain service manager from component context" ), *this );
870*cdf0e10cSrcweir 
871*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider(
872*cdf0e10cSrcweir         xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.configuration.ConfigurationProvider" ), mxContext ),
873*cdf0e10cSrcweir         uno::UNO_QUERY_THROW);
874*cdf0e10cSrcweir 
875*cdf0e10cSrcweir     beans::PropertyValue aProperty;
876*cdf0e10cSrcweir     aProperty.Name  = UNISTRING( "nodepath" );
877*cdf0e10cSrcweir     aProperty.Value = uno::makeAny( UNISTRING("org.openoffice.Setup/Product") );
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir     uno::Sequence< uno::Any > aArgumentList( 1 );
880*cdf0e10cSrcweir     aArgumentList[0] = uno::makeAny( aProperty );
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir     uno::Reference< uno::XInterface > xConfigAccess;
883*cdf0e10cSrcweir     xConfigAccess = xConfigurationProvider->createInstanceWithArguments( UNISTRING("com.sun.star.configuration.ConfigurationAccess"),
884*cdf0e10cSrcweir                                                                          aArgumentList );
885*cdf0e10cSrcweir 
886*cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xNameAccess( xConfigAccess, uno::UNO_QUERY_THROW );
887*cdf0e10cSrcweir 
888*cdf0e10cSrcweir     rtl::OUString aProductVersion;
889*cdf0e10cSrcweir     rtl::OUString aProductFullVersion;
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir     xNameAccess->getByName(UNISTRING("ooSetupVersion")) >>= aProductVersion;
892*cdf0e10cSrcweir     aProductFullVersion = aProductVersion;
893*cdf0e10cSrcweir 
894*cdf0e10cSrcweir     sal_Int32 nVerIndex = rString.indexOf( aProductVersion );
895*cdf0e10cSrcweir     if ( nVerIndex != -1 )
896*cdf0e10cSrcweir     {
897*cdf0e10cSrcweir         rtl::OUString aPackageVersion = UNISTRING( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version") ":OOOPackageVersion}" );
898*cdf0e10cSrcweir         rtl::Bootstrap::expandMacros( aPackageVersion );
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir         if ( aPackageVersion.getLength() )
901*cdf0e10cSrcweir         {
902*cdf0e10cSrcweir             sal_Int32 nTokIndex = 0;
903*cdf0e10cSrcweir             rtl::OUString aVersionMinor = aPackageVersion.getToken( 1, '.', nTokIndex );
904*cdf0e10cSrcweir             rtl::OUString aVersionMicro;
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir             if ( nTokIndex > 0 )
907*cdf0e10cSrcweir                 aVersionMicro = aPackageVersion.getToken( 0, '.', nTokIndex );
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir             if ( aVersionMinor.getLength() == 0 )
910*cdf0e10cSrcweir                 aVersionMinor = UNISTRING( "0" );
911*cdf0e10cSrcweir             if ( aVersionMicro.getLength() == 0 )
912*cdf0e10cSrcweir                 aVersionMicro = UNISTRING( "0" );
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir             sal_Int32 nIndex = aProductFullVersion.indexOf( '.' );
915*cdf0e10cSrcweir             if ( nIndex == -1 )
916*cdf0e10cSrcweir             {
917*cdf0e10cSrcweir                 aProductFullVersion += UNISTRING( "." );
918*cdf0e10cSrcweir                 aProductFullVersion += aVersionMinor;
919*cdf0e10cSrcweir             }
920*cdf0e10cSrcweir             else
921*cdf0e10cSrcweir             {
922*cdf0e10cSrcweir                 nIndex = aProductFullVersion.indexOf( '.', nIndex+1 );
923*cdf0e10cSrcweir             }
924*cdf0e10cSrcweir             if ( nIndex == -1 )
925*cdf0e10cSrcweir             {
926*cdf0e10cSrcweir                 aProductFullVersion += UNISTRING( "." );
927*cdf0e10cSrcweir                 aProductFullVersion += aVersionMicro;
928*cdf0e10cSrcweir             }
929*cdf0e10cSrcweir             else
930*cdf0e10cSrcweir             {
931*cdf0e10cSrcweir                 aProductFullVersion = aProductFullVersion.replaceAt( nIndex+1, aProductFullVersion.getLength()-nIndex-1, aVersionMicro );
932*cdf0e10cSrcweir             }
933*cdf0e10cSrcweir         }
934*cdf0e10cSrcweir         rString = rString.replaceAt( nVerIndex, aProductVersion.getLength(), aProductFullVersion );
935*cdf0e10cSrcweir     }
936*cdf0e10cSrcweir }
937*cdf0e10cSrcweir 
938*cdf0e10cSrcweir //--------------------------------------------------------------------
939*cdf0e10cSrcweir bool UpdateHandler::showWarning( const rtl::OUString &rWarningText ) const
940*cdf0e10cSrcweir {
941*cdf0e10cSrcweir     bool bRet = false;
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir     uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
944*cdf0e10cSrcweir     if ( !xControl.is() ) return bRet;
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir     uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
947*cdf0e10cSrcweir     if ( !xPeer.is() ) return bRet;
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir     uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
950*cdf0e10cSrcweir     if ( !xToolkit.is() ) return bRet;
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir     awt::WindowDescriptor aDescriptor;
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir     sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
955*cdf0e10cSrcweir     nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
956*cdf0e10cSrcweir     nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
957*cdf0e10cSrcweir 
958*cdf0e10cSrcweir     aDescriptor.Type              = awt::WindowClass_MODALTOP;
959*cdf0e10cSrcweir     aDescriptor.WindowServiceName = UNISTRING( "warningbox" );
960*cdf0e10cSrcweir     aDescriptor.ParentIndex       = -1;
961*cdf0e10cSrcweir     aDescriptor.Parent            = xPeer;
962*cdf0e10cSrcweir     aDescriptor.Bounds            = awt::Rectangle( 10, 10, 250, 150 );
963*cdf0e10cSrcweir     aDescriptor.WindowAttributes  = nWindowAttributes;
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir     uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
966*cdf0e10cSrcweir     if ( xMsgBox.is() )
967*cdf0e10cSrcweir     {
968*cdf0e10cSrcweir         mbShowsMessageBox = true;
969*cdf0e10cSrcweir         sal_Int16 nRet;
970*cdf0e10cSrcweir         // xMsgBox->setCaptionText( msCancelTitle );
971*cdf0e10cSrcweir         xMsgBox->setMessageText( rWarningText );
972*cdf0e10cSrcweir         nRet = xMsgBox->execute();
973*cdf0e10cSrcweir         if ( nRet == 2 ) // RET_YES == 2
974*cdf0e10cSrcweir             bRet = true;
975*cdf0e10cSrcweir         mbShowsMessageBox = false;
976*cdf0e10cSrcweir     }
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir     uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
979*cdf0e10cSrcweir     if ( xComponent.is() )
980*cdf0e10cSrcweir         xComponent->dispose();
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir     return bRet;
983*cdf0e10cSrcweir }
984*cdf0e10cSrcweir 
985*cdf0e10cSrcweir //--------------------------------------------------------------------
986*cdf0e10cSrcweir bool UpdateHandler::showWarning( const rtl::OUString &rWarningText,
987*cdf0e10cSrcweir                                  const rtl::OUString &rBtnText_1,
988*cdf0e10cSrcweir                                  const rtl::OUString &rBtnText_2 ) const
989*cdf0e10cSrcweir {
990*cdf0e10cSrcweir     bool bRet = false;
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir     uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
993*cdf0e10cSrcweir     if ( !xControl.is() ) return bRet;
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir     uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
996*cdf0e10cSrcweir     if ( !xPeer.is() ) return bRet;
997*cdf0e10cSrcweir 
998*cdf0e10cSrcweir     uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
999*cdf0e10cSrcweir     if ( !xToolkit.is() ) return bRet;
1000*cdf0e10cSrcweir 
1001*cdf0e10cSrcweir     awt::WindowDescriptor aDescriptor;
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir     sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
1004*cdf0e10cSrcweir     nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
1005*cdf0e10cSrcweir     nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
1006*cdf0e10cSrcweir 
1007*cdf0e10cSrcweir     aDescriptor.Type              = awt::WindowClass_MODALTOP;
1008*cdf0e10cSrcweir     aDescriptor.WindowServiceName = UNISTRING( "warningbox" );
1009*cdf0e10cSrcweir     aDescriptor.ParentIndex       = -1;
1010*cdf0e10cSrcweir     aDescriptor.Parent            = xPeer;
1011*cdf0e10cSrcweir     aDescriptor.Bounds            = awt::Rectangle( 10, 10, 250, 150 );
1012*cdf0e10cSrcweir     aDescriptor.WindowAttributes  = nWindowAttributes;
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir     uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
1015*cdf0e10cSrcweir     if ( xMsgBox.is() )
1016*cdf0e10cSrcweir     {
1017*cdf0e10cSrcweir         uno::Reference< awt::XVclContainer > xMsgBoxCtrls( xMsgBox, uno::UNO_QUERY );
1018*cdf0e10cSrcweir         if ( xMsgBoxCtrls.is() )
1019*cdf0e10cSrcweir         {
1020*cdf0e10cSrcweir             uno::Sequence< uno::Reference< awt::XWindow > > xChildren = xMsgBoxCtrls->getWindows();
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir             for ( long i=0; i < xChildren.getLength(); i++ )
1023*cdf0e10cSrcweir             {
1024*cdf0e10cSrcweir                 uno::Reference< awt::XVclWindowPeer > xMsgBoxCtrl( xChildren[i], uno::UNO_QUERY );
1025*cdf0e10cSrcweir                 if ( xMsgBoxCtrl.is() )
1026*cdf0e10cSrcweir                 {
1027*cdf0e10cSrcweir                     bool bIsDefault = true;
1028*cdf0e10cSrcweir                     uno::Any aValue = xMsgBoxCtrl->getProperty( UNISTRING("DefaultButton") );
1029*cdf0e10cSrcweir                     aValue >>= bIsDefault;
1030*cdf0e10cSrcweir                     if ( bIsDefault )
1031*cdf0e10cSrcweir                         xMsgBoxCtrl->setProperty( UNISTRING("Text"), uno::Any( rBtnText_1 ) );
1032*cdf0e10cSrcweir                     else
1033*cdf0e10cSrcweir                         xMsgBoxCtrl->setProperty( UNISTRING("Text"), uno::Any( rBtnText_2 ) );
1034*cdf0e10cSrcweir                 }
1035*cdf0e10cSrcweir             }
1036*cdf0e10cSrcweir         }
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir         sal_Int16 nRet;
1039*cdf0e10cSrcweir         // xMsgBox->setCaptionText( msCancelTitle );
1040*cdf0e10cSrcweir         mbShowsMessageBox = true;
1041*cdf0e10cSrcweir         xMsgBox->setMessageText( rWarningText );
1042*cdf0e10cSrcweir         nRet = xMsgBox->execute();
1043*cdf0e10cSrcweir         if ( nRet == 2 ) // RET_YES == 2
1044*cdf0e10cSrcweir             bRet = true;
1045*cdf0e10cSrcweir 
1046*cdf0e10cSrcweir         mbShowsMessageBox = false;
1047*cdf0e10cSrcweir     }
1048*cdf0e10cSrcweir 
1049*cdf0e10cSrcweir     uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
1050*cdf0e10cSrcweir     if ( xComponent.is() )
1051*cdf0e10cSrcweir         xComponent->dispose();
1052*cdf0e10cSrcweir 
1053*cdf0e10cSrcweir     return bRet;
1054*cdf0e10cSrcweir }
1055*cdf0e10cSrcweir 
1056*cdf0e10cSrcweir //--------------------------------------------------------------------
1057*cdf0e10cSrcweir bool UpdateHandler::showOverwriteWarning( const rtl::OUString& rFileName ) const
1058*cdf0e10cSrcweir {
1059*cdf0e10cSrcweir     rtl::OUString aMsg( msReloadWarning );
1060*cdf0e10cSrcweir     searchAndReplaceAll( aMsg, UNISTRING( "%FILENAME" ), rFileName );
1061*cdf0e10cSrcweir     searchAndReplaceAll( aMsg, UNISTRING( "%DOWNLOAD_PATH" ), msDownloadPath );
1062*cdf0e10cSrcweir     return showWarning( aMsg, msReloadContinue, msReloadReload );
1063*cdf0e10cSrcweir }
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir //--------------------------------------------------------------------
1066*cdf0e10cSrcweir bool UpdateHandler::showOverwriteWarning() const
1067*cdf0e10cSrcweir {
1068*cdf0e10cSrcweir     return showWarning( msOverwriteWarning );
1069*cdf0e10cSrcweir }
1070*cdf0e10cSrcweir 
1071*cdf0e10cSrcweir //--------------------------------------------------------------------
1072*cdf0e10cSrcweir #define BUTTON_HEIGHT       14
1073*cdf0e10cSrcweir #define BUTTON_WIDTH        50
1074*cdf0e10cSrcweir #define BUTTON_X_OFFSET      7
1075*cdf0e10cSrcweir #define BUTTON_Y_OFFSET      3
1076*cdf0e10cSrcweir #define LABEL_HEIGHT        10
1077*cdf0e10cSrcweir 
1078*cdf0e10cSrcweir #define DIALOG_WIDTH       300
1079*cdf0e10cSrcweir #define DIALOG_BORDER        5
1080*cdf0e10cSrcweir #define INNER_BORDER         3
1081*cdf0e10cSrcweir #define TEXT_OFFSET          1
1082*cdf0e10cSrcweir #define BOX_HEIGHT1          ( LABEL_HEIGHT + 3*BUTTON_HEIGHT + 2*BUTTON_Y_OFFSET + 2*INNER_BORDER )
1083*cdf0e10cSrcweir #define BOX_HEIGHT2         50
1084*cdf0e10cSrcweir #define EDIT_WIDTH          ( DIALOG_WIDTH - 2 * DIALOG_BORDER )
1085*cdf0e10cSrcweir #define BOX1_BTN_X          ( DIALOG_BORDER + EDIT_WIDTH - BUTTON_WIDTH - INNER_BORDER )
1086*cdf0e10cSrcweir #define BOX1_BTN_Y          ( DIALOG_BORDER + LABEL_HEIGHT + INNER_BORDER)
1087*cdf0e10cSrcweir #define THROBBER_WIDTH      16
1088*cdf0e10cSrcweir #define THROBBER_HEIGHT     16
1089*cdf0e10cSrcweir #define THROBBER_X_POS      ( DIALOG_BORDER + 8 )
1090*cdf0e10cSrcweir #define THROBBER_Y_POS      ( DIALOG_BORDER + 23 )
1091*cdf0e10cSrcweir #define BUTTON_BAR_HEIGHT   24
1092*cdf0e10cSrcweir #define LABEL_OFFSET        ( LABEL_HEIGHT + 4 )
1093*cdf0e10cSrcweir #define DIALOG_HEIGHT       ( BOX_HEIGHT1 + BOX_HEIGHT2 + LABEL_OFFSET + BUTTON_BAR_HEIGHT + 3 * DIALOG_BORDER )
1094*cdf0e10cSrcweir #define LABEL_Y_POS         ( 2 * DIALOG_BORDER + BOX_HEIGHT1 )
1095*cdf0e10cSrcweir #define EDIT2_Y_POS         ( LABEL_Y_POS + LABEL_HEIGHT )
1096*cdf0e10cSrcweir #define BUTTON_BAR_Y_POS    ( EDIT2_Y_POS + DIALOG_BORDER + BOX_HEIGHT2 )
1097*cdf0e10cSrcweir #define BUTTON_Y_POS        ( BUTTON_BAR_Y_POS + 8 )
1098*cdf0e10cSrcweir #define CLOSE_BTN_X         ( DIALOG_WIDTH - DIALOG_BORDER - BUTTON_WIDTH )
1099*cdf0e10cSrcweir #define INSTALL_BTN_X       ( CLOSE_BTN_X - 2 * BUTTON_X_OFFSET - BUTTON_WIDTH )
1100*cdf0e10cSrcweir #define DOWNLOAD_BTN_X      ( INSTALL_BTN_X - BUTTON_X_OFFSET - BUTTON_WIDTH )
1101*cdf0e10cSrcweir #define PROGRESS_WIDTH      80
1102*cdf0e10cSrcweir #define PROGRESS_HEIGHT     10
1103*cdf0e10cSrcweir #define PROGRESS_X_POS      ( DIALOG_BORDER + 8 )
1104*cdf0e10cSrcweir #define PROGRESS_Y_POS      ( DIALOG_BORDER + 2*LABEL_OFFSET )
1105*cdf0e10cSrcweir 
1106*cdf0e10cSrcweir //--------------------------------------------------------------------
1107*cdf0e10cSrcweir void UpdateHandler::showControls( short nControls )
1108*cdf0e10cSrcweir {
1109*cdf0e10cSrcweir     // The buttons from CANCEL_BUTTON to RESUME_BUTTON will be shown or
1110*cdf0e10cSrcweir     // hidden on demand
1111*cdf0e10cSrcweir     short nShiftMe;
1112*cdf0e10cSrcweir     for ( int i = 0; i <= (int)RESUME_BUTTON; i++ )
1113*cdf0e10cSrcweir     {
1114*cdf0e10cSrcweir         nShiftMe = (short)(nControls >> i);
1115*cdf0e10cSrcweir         showControl( msButtonIDs[i], (bool)(nShiftMe & 0x01) );
1116*cdf0e10cSrcweir     }
1117*cdf0e10cSrcweir 
1118*cdf0e10cSrcweir     nShiftMe = (short)(nControls >> THROBBER_CTRL);
1119*cdf0e10cSrcweir     startThrobber( (bool)(nShiftMe & 0x01) );
1120*cdf0e10cSrcweir 
1121*cdf0e10cSrcweir     nShiftMe = (short)(nControls >> PROGRESS_CTRL);
1122*cdf0e10cSrcweir     showControl( CTRL_PROGRESS, (bool)(nShiftMe & 0x01) );
1123*cdf0e10cSrcweir     showControl( TEXT_PERCENT, (bool)(nShiftMe & 0x01) );
1124*cdf0e10cSrcweir 
1125*cdf0e10cSrcweir     // Status text needs to be smaller, when there are buttons at the right side of the dialog
1126*cdf0e10cSrcweir     if ( ( nControls & ( (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) ) )  != 0 )
1127*cdf0e10cSrcweir         setControlProperty( TEXT_STATUS, UNISTRING("Width"), uno::Any( sal_Int32(EDIT_WIDTH - BUTTON_WIDTH - 2*INNER_BORDER - TEXT_OFFSET ) ) );
1128*cdf0e10cSrcweir     else
1129*cdf0e10cSrcweir         setControlProperty( TEXT_STATUS, UNISTRING("Width"), uno::Any( sal_Int32(EDIT_WIDTH - 2*TEXT_OFFSET ) ) );
1130*cdf0e10cSrcweir 
1131*cdf0e10cSrcweir     // Status text needs to be taller, when we show the progress bar
1132*cdf0e10cSrcweir     if ( ( nControls & ( 1<<PROGRESS_CTRL ) ) != 0 )
1133*cdf0e10cSrcweir         setControlProperty( TEXT_STATUS, UNISTRING("Height"), uno::Any( sal_Int32(LABEL_HEIGHT) ) );
1134*cdf0e10cSrcweir     else
1135*cdf0e10cSrcweir         setControlProperty( TEXT_STATUS, UNISTRING("Height"), uno::Any( sal_Int32(BOX_HEIGHT1 - 4*TEXT_OFFSET - LABEL_HEIGHT ) ) );
1136*cdf0e10cSrcweir }
1137*cdf0e10cSrcweir 
1138*cdf0e10cSrcweir //--------------------------------------------------------------------
1139*cdf0e10cSrcweir void UpdateHandler::createDialog()
1140*cdf0e10cSrcweir {
1141*cdf0e10cSrcweir     if ( !mxContext.is() )
1142*cdf0e10cSrcweir     {
1143*cdf0e10cSrcweir         OSL_ASSERT( false );
1144*cdf0e10cSrcweir         return;
1145*cdf0e10cSrcweir     }
1146*cdf0e10cSrcweir 
1147*cdf0e10cSrcweir     uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager() );
1148*cdf0e10cSrcweir 
1149*cdf0e10cSrcweir     if( xServiceManager.is() )
1150*cdf0e10cSrcweir     {
1151*cdf0e10cSrcweir         uno::Reference< frame::XDesktop > xDesktop(
1152*cdf0e10cSrcweir                 xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.frame.Desktop"), mxContext ),
1153*cdf0e10cSrcweir                 uno::UNO_QUERY );
1154*cdf0e10cSrcweir         if ( xDesktop.is() )
1155*cdf0e10cSrcweir             xDesktop->addTerminateListener( this );
1156*cdf0e10cSrcweir     }
1157*cdf0e10cSrcweir 
1158*cdf0e10cSrcweir     loadStrings();
1159*cdf0e10cSrcweir 
1160*cdf0e10cSrcweir     uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
1161*cdf0e10cSrcweir     uno::Reference< awt::XControlModel > xControlModel( xFactory->createInstanceWithContext(
1162*cdf0e10cSrcweir                                                          UNISTRING("com.sun.star.awt.UnoControlDialogModel"),
1163*cdf0e10cSrcweir                                                          mxContext), uno::UNO_QUERY_THROW );
1164*cdf0e10cSrcweir     {
1165*cdf0e10cSrcweir         // @see awt/UnoControlDialogModel.idl
1166*cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
1167*cdf0e10cSrcweir 
1168*cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Title"), uno::Any( msDlgTitle ) );
1169*cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Closeable"), uno::Any( true ) );
1170*cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Enabled"), uno::Any( true ) );
1171*cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Moveable"), uno::Any( true ) );
1172*cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Sizeable"), uno::Any( true ) );
1173*cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("DesktopAsParent"), uno::Any( true ) );
1174*cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("PositionX"), uno::Any(sal_Int32( 100 )) );
1175*cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("PositionY"), uno::Any(sal_Int32( 100 )) );
1176*cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Width"), uno::Any(sal_Int32( DIALOG_WIDTH )) );
1177*cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("Height"), uno::Any(sal_Int32( DIALOG_HEIGHT )) );
1178*cdf0e10cSrcweir         xPropSet->setPropertyValue( UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_DLG ) ) );
1179*cdf0e10cSrcweir     }
1180*cdf0e10cSrcweir     {   // Label (fixed text) <status>
1181*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(1);
1182*cdf0e10cSrcweir 
1183*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Label"), uno::Any( msStatusFL ) );
1184*cdf0e10cSrcweir 
1185*cdf0e10cSrcweir         insertControlModel( xControlModel, FIXED_TEXT_MODEL, UNISTRING( "fixedLineStatus" ),
1186*cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER+1, DIALOG_BORDER, EDIT_WIDTH-2, LABEL_HEIGHT ),
1187*cdf0e10cSrcweir                             aProps );
1188*cdf0e10cSrcweir     }
1189*cdf0e10cSrcweir     {   // box around <status> text
1190*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps;
1191*cdf0e10cSrcweir 
1192*cdf0e10cSrcweir         insertControlModel( xControlModel, GROUP_BOX_MODEL, UNISTRING( "StatusBox" ),
1193*cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER, DIALOG_BORDER + LABEL_HEIGHT, EDIT_WIDTH, BOX_HEIGHT1 - LABEL_HEIGHT ),
1194*cdf0e10cSrcweir                             aProps );
1195*cdf0e10cSrcweir     }
1196*cdf0e10cSrcweir     {   // Text (multiline edit) <status>
1197*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(7);
1198*cdf0e10cSrcweir 
1199*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Text"), uno::Any( substVariables(msChecking) ) );
1200*cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Border"), uno::Any( sal_Int16( 0 ) ) );
1201*cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PaintTransparent"), uno::Any( true ) );
1202*cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("MultiLine"), uno::Any( true ) );
1203*cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("ReadOnly"), uno::Any( true ) );
1204*cdf0e10cSrcweir         setProperty( aProps, 5, UNISTRING("AutoVScroll"), uno::Any( true ) );
1205*cdf0e10cSrcweir         setProperty( aProps, 6, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_STATUS ) ) );
1206*cdf0e10cSrcweir 
1207*cdf0e10cSrcweir         insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_STATUS,
1208*cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
1209*cdf0e10cSrcweir                                             DIALOG_BORDER + LABEL_HEIGHT + TEXT_OFFSET,
1210*cdf0e10cSrcweir                                             EDIT_WIDTH - 2*TEXT_OFFSET,
1211*cdf0e10cSrcweir                                             BOX_HEIGHT1 - 4*TEXT_OFFSET - LABEL_HEIGHT ),
1212*cdf0e10cSrcweir                             aProps );
1213*cdf0e10cSrcweir     }
1214*cdf0e10cSrcweir     {   // Text (edit) <percent>
1215*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(4);
1216*cdf0e10cSrcweir 
1217*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Text"), uno::Any( msPercent ) );
1218*cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Border"), uno::Any( sal_Int16( 0 ) ) );
1219*cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PaintTransparent"), uno::Any( true ) );
1220*cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("ReadOnly"), uno::Any( true ) );
1221*cdf0e10cSrcweir 
1222*cdf0e10cSrcweir         insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_PERCENT,
1223*cdf0e10cSrcweir                             awt::Rectangle( PROGRESS_X_POS + PROGRESS_WIDTH + DIALOG_BORDER,
1224*cdf0e10cSrcweir                                             PROGRESS_Y_POS,
1225*cdf0e10cSrcweir                                             EDIT_WIDTH - PROGRESS_WIDTH - BUTTON_WIDTH - 2*DIALOG_BORDER,
1226*cdf0e10cSrcweir                                             LABEL_HEIGHT ),
1227*cdf0e10cSrcweir                             aProps );
1228*cdf0e10cSrcweir     }
1229*cdf0e10cSrcweir     {   // pause button
1230*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1231*cdf0e10cSrcweir 
1232*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1233*cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1234*cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1235*cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msPauseBtn ) );
1236*cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_PAUSE ) ) );
1237*cdf0e10cSrcweir 
1238*cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[PAUSE_BUTTON],
1239*cdf0e10cSrcweir                              awt::Rectangle( BOX1_BTN_X, BOX1_BTN_Y, BUTTON_WIDTH, BUTTON_HEIGHT ),
1240*cdf0e10cSrcweir                              aProps );
1241*cdf0e10cSrcweir     }
1242*cdf0e10cSrcweir     {   // resume button
1243*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1244*cdf0e10cSrcweir 
1245*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1246*cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1247*cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1248*cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msResumeBtn ) );
1249*cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_RESUME ) ) );
1250*cdf0e10cSrcweir 
1251*cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[RESUME_BUTTON],
1252*cdf0e10cSrcweir                              awt::Rectangle( BOX1_BTN_X,
1253*cdf0e10cSrcweir                                              BOX1_BTN_Y + BUTTON_Y_OFFSET + BUTTON_HEIGHT,
1254*cdf0e10cSrcweir                                              BUTTON_WIDTH,
1255*cdf0e10cSrcweir                                              BUTTON_HEIGHT ),
1256*cdf0e10cSrcweir                              aProps );
1257*cdf0e10cSrcweir     }
1258*cdf0e10cSrcweir     {   // abort button
1259*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1260*cdf0e10cSrcweir 
1261*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1262*cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1263*cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1264*cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msCancelBtn ) );
1265*cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_CANCEL ) ) );
1266*cdf0e10cSrcweir 
1267*cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[CANCEL_BUTTON],
1268*cdf0e10cSrcweir                              awt::Rectangle( BOX1_BTN_X,
1269*cdf0e10cSrcweir                                              BOX1_BTN_Y + (2*(BUTTON_HEIGHT+BUTTON_Y_OFFSET)),
1270*cdf0e10cSrcweir                                              BUTTON_WIDTH,
1271*cdf0e10cSrcweir                                              BUTTON_HEIGHT ),
1272*cdf0e10cSrcweir                              aProps );
1273*cdf0e10cSrcweir     }
1274*cdf0e10cSrcweir     {   // Label (FixedText) <description>
1275*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(1);
1276*cdf0e10cSrcweir 
1277*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Label"), uno::Any( msDescription ) );
1278*cdf0e10cSrcweir 
1279*cdf0e10cSrcweir         insertControlModel( xControlModel, FIXED_TEXT_MODEL, UNISTRING( "fixedTextDescription" ),
1280*cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER+1, LABEL_Y_POS, EDIT_WIDTH-2, LABEL_HEIGHT ),
1281*cdf0e10cSrcweir                             aProps );
1282*cdf0e10cSrcweir     }
1283*cdf0e10cSrcweir     {   // box around <description> text
1284*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps;
1285*cdf0e10cSrcweir 
1286*cdf0e10cSrcweir         insertControlModel( xControlModel, GROUP_BOX_MODEL, UNISTRING( "DescriptionBox" ),
1287*cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER, EDIT2_Y_POS, EDIT_WIDTH, BOX_HEIGHT2 ),
1288*cdf0e10cSrcweir                             aProps );
1289*cdf0e10cSrcweir     }
1290*cdf0e10cSrcweir     {   // Text (MultiLineEdit) <description>
1291*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(7);
1292*cdf0e10cSrcweir 
1293*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Text"), uno::Any( rtl::OUString() ) );
1294*cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Border"), uno::Any( sal_Int16( 0 ) ) );
1295*cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PaintTransparent"), uno::Any( true ) );
1296*cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("MultiLine"), uno::Any( true ) );
1297*cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("ReadOnly"), uno::Any( true ) );
1298*cdf0e10cSrcweir         setProperty( aProps, 5, UNISTRING("AutoVScroll"), uno::Any( true ) );
1299*cdf0e10cSrcweir         setProperty( aProps, 6, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_DESCRIPTION ) ) );
1300*cdf0e10cSrcweir 
1301*cdf0e10cSrcweir         insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_DESCRIPTION,
1302*cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
1303*cdf0e10cSrcweir                                             EDIT2_Y_POS + 2*TEXT_OFFSET,
1304*cdf0e10cSrcweir                                             EDIT_WIDTH - 3*TEXT_OFFSET,
1305*cdf0e10cSrcweir                                             BOX_HEIGHT2 - 3*TEXT_OFFSET ),
1306*cdf0e10cSrcweir                             aProps );
1307*cdf0e10cSrcweir     }
1308*cdf0e10cSrcweir     {   // @see awt/UnoControlFixedLineModel.idl
1309*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(1);
1310*cdf0e10cSrcweir 
1311*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Orientation"), uno::Any( sal_Int32( 0 ) ) );
1312*cdf0e10cSrcweir 
1313*cdf0e10cSrcweir         insertControlModel( xControlModel, FIXED_LINE_MODEL, UNISTRING("fixedLine"),
1314*cdf0e10cSrcweir                             awt::Rectangle( 0, BUTTON_BAR_Y_POS, DIALOG_WIDTH, 5 ),
1315*cdf0e10cSrcweir                             aProps );
1316*cdf0e10cSrcweir     }
1317*cdf0e10cSrcweir     {   // close button // @see awt/UnoControlButtonModel.idl
1318*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1319*cdf0e10cSrcweir 
1320*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1321*cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1322*cdf0e10cSrcweir         // [property] short PushButtonType
1323*cdf0e10cSrcweir         // with own "ButtonActionListener"
1324*cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1325*cdf0e10cSrcweir         // with default ActionListener => endDialog().
1326*cdf0e10cSrcweir         // setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_CANCEL) ) );
1327*cdf0e10cSrcweir         // [property] string Label // only if PushButtonType_STANDARD
1328*cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msClose ) );
1329*cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_CLOSE ) ) );
1330*cdf0e10cSrcweir 
1331*cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[ CLOSE_BUTTON ],
1332*cdf0e10cSrcweir                              awt::Rectangle( CLOSE_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1333*cdf0e10cSrcweir                              aProps );
1334*cdf0e10cSrcweir     }
1335*cdf0e10cSrcweir     {   // install button
1336*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1337*cdf0e10cSrcweir 
1338*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1339*cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1340*cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1341*cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msInstall ) );
1342*cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_INSTALL ) ) );
1343*cdf0e10cSrcweir 
1344*cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[INSTALL_BUTTON],
1345*cdf0e10cSrcweir                              awt::Rectangle( INSTALL_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1346*cdf0e10cSrcweir                              aProps );
1347*cdf0e10cSrcweir     }
1348*cdf0e10cSrcweir     {   // download button
1349*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(5);
1350*cdf0e10cSrcweir 
1351*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1352*cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1353*cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1354*cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msDownload ) );
1355*cdf0e10cSrcweir         setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( INET_HID_SCHEME ) + rtl::OUString::createFromAscii( HID_CHECK_FOR_UPD_DOWNLOAD ) ) );
1356*cdf0e10cSrcweir 
1357*cdf0e10cSrcweir         insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[DOWNLOAD_BUTTON],
1358*cdf0e10cSrcweir                              awt::Rectangle( DOWNLOAD_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1359*cdf0e10cSrcweir                              aProps );
1360*cdf0e10cSrcweir     }
1361*cdf0e10cSrcweir     {   // help button
1362*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(3);
1363*cdf0e10cSrcweir 
1364*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1365*cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1366*cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_HELP) ) );
1367*cdf0e10cSrcweir 
1368*cdf0e10cSrcweir         insertControlModel( xControlModel, BUTTON_MODEL, msButtonIDs[HELP_BUTTON],
1369*cdf0e10cSrcweir                             awt::Rectangle( DIALOG_BORDER, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1370*cdf0e10cSrcweir                             aProps );
1371*cdf0e10cSrcweir     }
1372*cdf0e10cSrcweir     {   // @see awt/UnoControlThrobberModel.idl
1373*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps;
1374*cdf0e10cSrcweir 
1375*cdf0e10cSrcweir         insertControlModel( xControlModel, UNISTRING("com.sun.star.awt.SpinningProgressControlModel"), CTRL_THROBBER,
1376*cdf0e10cSrcweir                             awt::Rectangle( THROBBER_X_POS, THROBBER_Y_POS, THROBBER_WIDTH, THROBBER_HEIGHT),
1377*cdf0e10cSrcweir                             aProps );
1378*cdf0e10cSrcweir     }
1379*cdf0e10cSrcweir     {    // @see awt/UnoControlProgressBarModel.idl
1380*cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aProps(4);
1381*cdf0e10cSrcweir         setProperty( aProps, 0, UNISTRING("Enabled"), uno::Any( true ) );
1382*cdf0e10cSrcweir         setProperty( aProps, 1, UNISTRING("ProgressValue"), uno::Any( sal_Int32( 0 ) ) );
1383*cdf0e10cSrcweir         setProperty( aProps, 2, UNISTRING("ProgressValueMax"), uno::Any( sal_Int32( 100 ) ) );
1384*cdf0e10cSrcweir         setProperty( aProps, 3, UNISTRING("ProgressValueMin"), uno::Any( sal_Int32( 0 ) ) );
1385*cdf0e10cSrcweir 
1386*cdf0e10cSrcweir         insertControlModel( xControlModel, UNISTRING("com.sun.star.awt.UnoControlProgressBarModel"), CTRL_PROGRESS,
1387*cdf0e10cSrcweir                             awt::Rectangle( PROGRESS_X_POS, PROGRESS_Y_POS, PROGRESS_WIDTH, PROGRESS_HEIGHT ),
1388*cdf0e10cSrcweir                             aProps);
1389*cdf0e10cSrcweir     }
1390*cdf0e10cSrcweir 
1391*cdf0e10cSrcweir     uno::Reference< awt::XControl > xControl(
1392*cdf0e10cSrcweir         xFactory->createInstanceWithContext( UNISTRING("com.sun.star.awt.UnoControlDialog"), mxContext),
1393*cdf0e10cSrcweir         uno::UNO_QUERY_THROW );
1394*cdf0e10cSrcweir     xControl->setModel( xControlModel );
1395*cdf0e10cSrcweir 
1396*cdf0e10cSrcweir     if ( mbVisible == false )
1397*cdf0e10cSrcweir     {
1398*cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow( xControl, uno::UNO_QUERY );
1399*cdf0e10cSrcweir 
1400*cdf0e10cSrcweir         if ( xWindow.is() )
1401*cdf0e10cSrcweir             xWindow->setVisible( false );
1402*cdf0e10cSrcweir     }
1403*cdf0e10cSrcweir 
1404*cdf0e10cSrcweir     xControl->createPeer( NULL, NULL );
1405*cdf0e10cSrcweir     {
1406*cdf0e10cSrcweir         uno::Reference< awt::XControlContainer > xContainer (xControl, uno::UNO_QUERY);
1407*cdf0e10cSrcweir         for ( int i = 0; i < HELP_BUTTON; i++ )
1408*cdf0e10cSrcweir         {
1409*cdf0e10cSrcweir             uno::Reference< awt::XButton > xButton ( xContainer->getControl( msButtonIDs[i] ), uno::UNO_QUERY);
1410*cdf0e10cSrcweir             if (xButton.is())
1411*cdf0e10cSrcweir             {
1412*cdf0e10cSrcweir                 xButton->setActionCommand( msButtonIDs[i] );
1413*cdf0e10cSrcweir                 xButton->addActionListener( this );
1414*cdf0e10cSrcweir             }
1415*cdf0e10cSrcweir         }
1416*cdf0e10cSrcweir     }
1417*cdf0e10cSrcweir 
1418*cdf0e10cSrcweir     mxUpdDlg.set( xControl, uno::UNO_QUERY_THROW );
1419*cdf0e10cSrcweir     mnLastCtrlState = -1;
1420*cdf0e10cSrcweir }
1421