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