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