bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / update / check / updatehdl.cxx
blob2f9d68d94f6fd16b9f80c32cf319c0fbb0bf3925
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "updatehdl.hxx"
22 #include "update.hrc"
24 #include "osl/diagnose.h"
25 #include "osl/thread.hxx"
26 #include "osl/file.hxx"
27 #include "rtl/ustring.hxx"
28 #include "rtl/bootstrap.hxx"
30 #include "com/sun/star/uno/Sequence.h"
32 #include <com/sun/star/style/VerticalAlignment.hpp>
34 #include "com/sun/star/awt/ActionEvent.hpp"
35 #include "com/sun/star/awt/PushButtonType.hpp"
36 #include "com/sun/star/awt/UnoControlDialog.hpp"
37 #include "com/sun/star/awt/VclWindowPeerAttribute.hpp"
38 #include "com/sun/star/awt/WindowAttribute.hpp"
39 #include "com/sun/star/awt/XButton.hpp"
40 #include "com/sun/star/awt/XControl.hpp"
41 #include "com/sun/star/awt/XControlContainer.hpp"
42 #include "com/sun/star/awt/XMessageBox.hpp"
43 #include "com/sun/star/awt/XAnimation.hpp"
44 #include "com/sun/star/awt/XTopWindow.hpp"
45 #include "com/sun/star/awt/XVclWindowPeer.hpp"
46 #include "com/sun/star/awt/XVclContainer.hpp"
47 #include "com/sun/star/awt/XWindow.hpp"
48 #include "com/sun/star/awt/XWindow2.hpp"
50 #include <com/sun/star/beans/PropertyValue.hpp>
51 #include "com/sun/star/beans/XPropertySet.hpp"
53 #include <com/sun/star/configuration/theDefaultProvider.hpp>
55 #include "com/sun/star/container/XNameContainer.hpp"
57 #include "com/sun/star/frame/Desktop.hpp"
59 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
60 #include "com/sun/star/task/InteractionHandler.hpp"
61 #include "com/sun/star/task/InteractionRequestStringResolver.hpp"
63 #include <com/sun/star/resource/XResourceBundleLoader.hpp>
65 #include "updatehdl.hrc"
66 #include <tools/urlobj.hxx>
68 #define COMMAND_CLOSE "close"
70 #define CTRL_THROBBER "throbber"
71 #define CTRL_PROGRESS "progress"
73 #define TEXT_STATUS "text_status"
74 #define TEXT_PERCENT "text_percent"
75 #define TEXT_DESCRIPTION "text_description"
77 #define FIXED_LINE_MODEL "com.sun.star.awt.UnoControlFixedLineModel"
78 #define FIXED_TEXT_MODEL "com.sun.star.awt.UnoControlFixedTextModel"
79 #define EDIT_FIELD_MODEL "com.sun.star.awt.UnoControlEditModel"
80 #define BUTTON_MODEL "com.sun.star.awt.UnoControlButtonModel"
81 #define GROUP_BOX_MODEL "com.sun.star.awt.UnoControlGroupBoxModel"
83 using namespace com::sun::star;
86 UpdateHandler::UpdateHandler( const uno::Reference< uno::XComponentContext > & rxContext,
87 const rtl::Reference< IActionListener > & rxActionListener ) :
88 mxContext( rxContext ),
89 mxActionListener( rxActionListener ),
90 meCurState( UPDATESTATES_COUNT ),
91 meLastState( UPDATESTATES_COUNT ),
92 mnPercent( 0 ),
93 mnLastCtrlState( -1 ),
94 mbDownloadBtnHasDots( false ),
95 mbVisible( false ),
96 mbStringsLoaded( false ),
97 mbMinimized( false ),
98 mbListenerAdded(false),
99 mbShowsMessageBox(false)
104 UpdateHandler::~UpdateHandler()
106 mxContext = NULL;
107 mxUpdDlg = NULL;
108 mxInteractionHdl = NULL;
109 mxActionListener = NULL;
113 void UpdateHandler::enableControls( short nCtrlState )
115 osl::MutexGuard aGuard( maMutex );
117 if ( nCtrlState == mnLastCtrlState )
118 return;
120 // the help button should always be the last button in the
121 // enum list und must never be disabled
122 for ( int i=0; i<HELP_BUTTON; i++ )
124 short nCurStateVal = (short)(nCtrlState >> i);
125 short nOldStateVal = (short)(mnLastCtrlState >> i);
126 if ( ( nCurStateVal & 0x01 ) != ( nOldStateVal & 0x01 ) )
128 bool bEnableControl = ( ( nCurStateVal & 0x01 ) == 0x01 );
129 setControlProperty( msButtonIDs[i], "Enabled", uno::Any( bEnableControl ) );
133 mnLastCtrlState = nCtrlState;
137 void UpdateHandler::setDownloadBtnLabel( bool bAppendDots )
139 osl::MutexGuard aGuard( maMutex );
141 if ( mbDownloadBtnHasDots != bAppendDots )
143 OUString aLabel( msDownload );
145 if ( bAppendDots )
146 aLabel += "...";
148 setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], "Label", uno::Any( aLabel ) );
149 setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DOWNLOAD2 ) );
151 mbDownloadBtnHasDots = bAppendDots;
156 void UpdateHandler::setState( UpdateState eState )
158 osl::MutexGuard aGuard( maMutex );
160 meCurState = eState;
162 if ( mxUpdDlg.is() && mbVisible )
163 updateState( meCurState );
167 bool UpdateHandler::isVisible() const
169 if ( !mxUpdDlg.is() ) return false;
171 uno::Reference< awt::XWindow2 > xWindow( mxUpdDlg, uno::UNO_QUERY );
173 if ( xWindow.is() )
174 return xWindow->isVisible();
175 else
176 return false;
180 void UpdateHandler::setVisible( bool bVisible )
182 osl::MutexGuard aGuard( maMutex );
184 mbVisible = bVisible;
186 if ( bVisible )
188 if ( !mxUpdDlg.is() )
189 createDialog();
191 // this should never happen, but if it happens we better return here
192 if ( !mxUpdDlg.is() )
193 return;
195 updateState( meCurState );
197 uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
199 if ( xWindow.is() )
200 xWindow->setVisible( bVisible );
202 uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
203 if ( xTopWindow.is() )
205 xTopWindow->toFront();
206 if ( !mbListenerAdded )
208 xTopWindow->addTopWindowListener( this );
209 mbListenerAdded = true;
213 else if ( mxUpdDlg.is() )
215 uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
217 if ( xWindow.is() )
218 xWindow->setVisible( bVisible );
223 void UpdateHandler::setProgress( sal_Int32 nPercent )
225 if ( nPercent > 100 )
226 nPercent = 100;
227 else if ( nPercent < 0 )
228 nPercent = 0;
230 if ( nPercent != mnPercent )
232 osl::MutexGuard aGuard( maMutex );
234 mnPercent = nPercent;
235 setControlProperty( CTRL_PROGRESS, "ProgressValue", uno::Any( nPercent ) );
236 setControlProperty( TEXT_PERCENT, "Text", uno::Any( substVariables(msPercent) ) );
241 void UpdateHandler::setErrorMessage( const OUString& rErrorMsg )
243 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( rErrorMsg ) );
247 void UpdateHandler::setDownloadFile( const OUString& rFilePath )
249 sal_Int32 nLast = rFilePath.lastIndexOf( '/' );
250 if ( nLast != -1 )
252 msDownloadFile = rFilePath.copy( nLast+1 );
253 const OUString aDownloadURL = rFilePath.copy( 0, nLast );
254 osl::FileBase::getSystemPathFromFileURL( aDownloadURL, msDownloadPath );
259 OUString UpdateHandler::getBubbleText( UpdateState eState )
261 osl::MutexGuard aGuard( maMutex );
263 OUString sText;
264 sal_Int32 nIndex = (sal_Int32) eState;
266 loadStrings();
268 if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
269 sText = substVariables( msBubbleTexts[ nIndex - UPDATESTATE_UPDATE_AVAIL ] );
271 return sText;
275 OUString UpdateHandler::getBubbleTitle( UpdateState eState )
277 osl::MutexGuard aGuard( maMutex );
279 OUString sText;
280 sal_Int32 nIndex = (sal_Int32) eState;
282 loadStrings();
284 if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
285 sText = substVariables( msBubbleTitles[ nIndex - UPDATESTATE_UPDATE_AVAIL] );
287 return sText;
291 OUString UpdateHandler::getDefaultInstErrMsg()
293 osl::MutexGuard aGuard( maMutex );
295 loadStrings();
297 return substVariables( msInstallError );
300 // XActionListener
302 void SAL_CALL UpdateHandler::disposing( const lang::EventObject& rEvt )
303 throw( uno::RuntimeException, std::exception )
305 if ( rEvt.Source == mxUpdDlg )
306 mxUpdDlg.clear();
310 void SAL_CALL UpdateHandler::actionPerformed( awt::ActionEvent const & rEvent )
311 throw( uno::RuntimeException, std::exception )
313 DialogControls eButton = BUTTON_COUNT;
314 for ( int i = 0; i < BUTTON_COUNT; i++ )
316 if ( rEvent.ActionCommand.equals( msButtonIDs[i] ) )
318 eButton = (DialogControls) i;
319 break;
323 if ( rEvent.ActionCommand == COMMAND_CLOSE )
325 if ( ( mnLastCtrlState & ( 1 << CLOSE_BUTTON ) ) == ( 1 << CLOSE_BUTTON ) )
326 eButton = CLOSE_BUTTON;
327 else
328 eButton = CANCEL_BUTTON;
331 switch ( eButton ) {
332 case CANCEL_BUTTON:
334 bool bCancel = true;
336 if ( ( meCurState == UPDATESTATE_DOWNLOADING ) ||
337 ( meCurState == UPDATESTATE_DOWNLOAD_PAUSED ) ||
338 ( meCurState == UPDATESTATE_ERROR_DOWNLOADING ) )
339 bCancel = showWarning( msCancelMessage );
341 if ( bCancel )
343 mxActionListener->cancel();
344 setVisible( false );
346 break;
348 case CLOSE_BUTTON:
349 setVisible( false );
350 if ( meCurState == UPDATESTATE_ERROR_CHECKING )
351 mxActionListener->closeAfterFailure();
352 break;
353 case DOWNLOAD_BUTTON:
354 mxActionListener->download();
355 break;
356 case INSTALL_BUTTON:
357 if ( showWarning( msInstallMessage ) )
358 mxActionListener->install();
359 break;
360 case PAUSE_BUTTON:
361 mxActionListener->pause();
362 break;
363 case RESUME_BUTTON:
364 mxActionListener->resume();
365 break;
366 case HELP_BUTTON:
367 break;
368 default:
369 OSL_FAIL( "UpdateHandler::actionPerformed: unknown command!" );
373 // XTopWindowListener
375 void SAL_CALL UpdateHandler::windowOpened( const lang::EventObject& )
376 throw( uno::RuntimeException, std::exception )
381 void SAL_CALL UpdateHandler::windowClosing( const lang::EventObject& e )
382 throw( uno::RuntimeException, std::exception )
384 awt::ActionEvent aActionEvt;
385 aActionEvt.ActionCommand = COMMAND_CLOSE;
386 aActionEvt.Source = e.Source;
388 actionPerformed( aActionEvt );
392 void SAL_CALL UpdateHandler::windowClosed( const lang::EventObject& )
393 throw( uno::RuntimeException, std::exception )
398 void SAL_CALL UpdateHandler::windowMinimized( const lang::EventObject& )
399 throw( uno::RuntimeException, std::exception )
401 mbMinimized = true;
405 void SAL_CALL UpdateHandler::windowNormalized( const lang::EventObject& )
406 throw( uno::RuntimeException, std::exception )
408 mbMinimized = false;
412 void SAL_CALL UpdateHandler::windowActivated( const lang::EventObject& )
413 throw( uno::RuntimeException, std::exception )
418 void SAL_CALL UpdateHandler::windowDeactivated( const lang::EventObject& )
419 throw( uno::RuntimeException, std::exception )
423 // XInteractionHandler
425 void SAL_CALL UpdateHandler::handle( uno::Reference< task::XInteractionRequest > const & rRequest)
426 throw (uno::RuntimeException, std::exception)
428 if ( !mxInteractionHdl.is() )
430 if( !mxContext.is() )
431 throw uno::RuntimeException( "UpdateHandler:: empty component context", *this );
433 uno::Reference< lang::XMultiComponentFactory > xServiceManager(mxContext->getServiceManager());
435 if( !xServiceManager.is() )
436 throw uno::RuntimeException( "UpdateHandler: unable to obtain service manager from component context", *this );
438 mxInteractionHdl.set(
439 task::InteractionHandler::createWithParent(mxContext, 0),
440 uno::UNO_QUERY_THROW);
442 uno::Reference< task::XInteractionRequestStringResolver > xStrResolver =
443 task::InteractionRequestStringResolver::create( mxContext );
444 beans::Optional< OUString > aErrorText = xStrResolver->getStringFromInformationalRequest( rRequest );
445 if ( aErrorText.IsPresent )
447 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( aErrorText.Value ) );
449 uno::Sequence< uno::Reference< task::XInteractionContinuation > > xContinuations = rRequest->getContinuations();
450 if ( xContinuations.getLength() == 1 )
452 if ( meCurState == UPDATESTATE_CHECKING )
453 setState( UPDATESTATE_ERROR_CHECKING );
454 else if ( meCurState == UPDATESTATE_DOWNLOADING )
455 setState( UPDATESTATE_ERROR_DOWNLOADING );
457 xContinuations[0]->select();
459 else
460 mxInteractionHdl->handle( rRequest );
462 else
463 mxInteractionHdl->handle( rRequest );
467 // XTerminateListener
469 void SAL_CALL UpdateHandler::queryTermination( const lang::EventObject& )
470 throw ( frame::TerminationVetoException, uno::RuntimeException, std::exception )
472 if ( mbShowsMessageBox )
474 uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
475 if ( xTopWindow.is() )
476 xTopWindow->toFront();
478 throw frame::TerminationVetoException(
479 "The office cannot be closed while displaying a warning!",
480 static_cast<frame::XTerminateListener*>(this));
482 else
483 setVisible( false );
487 void SAL_CALL UpdateHandler::notifyTermination( const lang::EventObject& )
488 throw ( uno::RuntimeException, std::exception )
490 osl::MutexGuard aGuard( maMutex );
492 if ( mxUpdDlg.is() )
494 uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
495 if ( xTopWindow.is() )
496 xTopWindow->removeTopWindowListener( this );
498 uno::Reference< lang::XComponent > xComponent( mxUpdDlg, uno::UNO_QUERY );
499 if ( xComponent.is() )
500 xComponent->dispose();
502 mxUpdDlg.clear();
509 void UpdateHandler::updateState( UpdateState eState )
511 if ( meLastState == eState )
512 return;
514 if ( isVisible() )
515 {} // ToTop();
517 OUString sText;
519 switch ( eState )
521 case UPDATESTATE_CHECKING:
522 showControls( (1<<CANCEL_BUTTON) + (1<<THROBBER_CTRL) );
523 enableControls( 1<<CANCEL_BUTTON );
524 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msChecking) ) );
525 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( OUString() ) );
526 focusControl( CANCEL_BUTTON );
527 break;
528 case UPDATESTATE_ERROR_CHECKING:
529 showControls( 0 );
530 enableControls( 1 << CLOSE_BUTTON );
531 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msCheckingError) ) );
532 focusControl( CLOSE_BUTTON );
533 break;
534 case UPDATESTATE_UPDATE_AVAIL:
535 showControls( 0 );
536 enableControls( ( 1 << CLOSE_BUTTON ) + ( 1 << DOWNLOAD_BUTTON ) );
537 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msUpdFound) ) );
539 sText = substVariables(msDownloadWarning);
540 if ( !msDescriptionMsg.isEmpty() )
541 sText += "\n\n" + msDescriptionMsg;
542 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( sText ) );
544 setDownloadBtnLabel( false );
545 focusControl( DOWNLOAD_BUTTON );
546 break;
547 case UPDATESTATE_UPDATE_NO_DOWNLOAD:
548 showControls( 0 );
549 enableControls( ( 1 << CLOSE_BUTTON ) + ( 1 << DOWNLOAD_BUTTON ) );
550 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msUpdFound) ) );
552 sText = substVariables(msDownloadNotAvail);
553 if ( !msDescriptionMsg.isEmpty() )
554 sText += "\n\n" + msDescriptionMsg;
555 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( sText ) );
557 setDownloadBtnLabel( true );
558 focusControl( DOWNLOAD_BUTTON );
559 break;
560 case UPDATESTATE_NO_UPDATE_AVAIL:
561 case UPDATESTATE_EXT_UPD_AVAIL: // will only be set, when there are no office updates avail
562 showControls( 0 );
563 enableControls( 1 << CLOSE_BUTTON );
564 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msNoUpdFound) ) );
565 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( OUString() ) );
566 focusControl( CLOSE_BUTTON );
567 break;
568 case UPDATESTATE_DOWNLOADING:
569 showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
570 enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) );
571 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msDownloading) ) );
572 setControlProperty( TEXT_PERCENT, "Text", uno::Any( substVariables(msPercent) ) );
573 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( substVariables(msDownloadWarning) ) );
574 setControlProperty( CTRL_PROGRESS, "ProgressValue", uno::Any( mnPercent ) );
575 focusControl( CLOSE_BUTTON );
576 break;
577 case UPDATESTATE_DOWNLOAD_PAUSED:
578 showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
579 enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<RESUME_BUTTON) );
580 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msDownloadPause) ) );
581 setControlProperty( TEXT_PERCENT, "Text", uno::Any( substVariables(msPercent) ) );
582 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( substVariables(msDownloadWarning) ) );
583 setControlProperty( CTRL_PROGRESS, "ProgressValue", uno::Any( mnPercent ) );
584 focusControl( CLOSE_BUTTON );
585 break;
586 case UPDATESTATE_ERROR_DOWNLOADING:
587 showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
588 enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) );
589 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msDownloadError) ) );
590 focusControl( CLOSE_BUTTON );
591 break;
592 case UPDATESTATE_DOWNLOAD_AVAIL:
593 showControls( 0 );
594 enableControls( (1<<CLOSE_BUTTON) + (1<<INSTALL_BUTTON) );
595 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msReady2Install) ) );
596 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( substVariables(msDownloadDescr) ) );
597 focusControl( INSTALL_BUTTON );
598 break;
599 case UPDATESTATE_AUTO_START:
600 case UPDATESTATES_COUNT:
601 //do nothing, only count!
602 break;
605 meLastState = eState;
609 OUString UpdateHandler::loadString( const uno::Reference< resource::XResourceBundle >& rBundle,
610 sal_Int32 nResourceId )
612 OUString sString;
613 OUString sKey = "string:" + OUString::number( nResourceId );
617 OSL_VERIFY( rBundle->getByName( sKey ) >>= sString );
619 catch( const uno::Exception& )
621 OSL_FAIL( "UpdateHandler::loadString: caught an exception!" );
622 sString = "Missing " + sKey;
625 return sString;
628 OUString UpdateHandler::substVariables( const OUString &rSource ) const
630 return rSource
631 .replaceAll( "%NEXTVERSION", msNextVersion )
632 .replaceAll( "%DOWNLOAD_PATH", msDownloadPath )
633 .replaceAll( "%FILE_NAME", msDownloadFile )
634 .replaceAll( "%PERCENT", OUString::number( mnPercent ) );
638 void UpdateHandler::loadStrings()
640 if ( mbStringsLoaded )
641 return;
642 else
643 mbStringsLoaded = true;
645 uno::Reference< resource::XResourceBundleLoader > xLoader;
648 uno::Any aValue( mxContext->getValueByName(
649 "/singletons/com.sun.star.resource.OfficeResourceLoader" ) );
650 OSL_VERIFY( aValue >>= xLoader );
652 catch( const uno::Exception& )
654 OSL_FAIL( "UpdateHandler::loadStrings: could not create the resource loader!" );
657 if ( !xLoader.is() ) return;
659 uno::Reference< resource::XResourceBundle > xBundle;
663 xBundle = xLoader->loadBundle_Default( "upd" );
665 catch( const resource::MissingResourceException& )
667 OSL_FAIL( "UpdateHandler::loadStrings: missing the resource bundle!" );
670 if ( !xBundle.is() ) return;
672 msChecking = loadString( xBundle, RID_UPDATE_STR_CHECKING );
673 msCheckingError = loadString( xBundle, RID_UPDATE_STR_CHECKING_ERR );
674 msNoUpdFound = loadString( xBundle, RID_UPDATE_STR_NO_UPD_FOUND );
676 msUpdFound = loadString( xBundle, RID_UPDATE_STR_UPD_FOUND );
677 setFullVersion( msUpdFound );
679 msDlgTitle = loadString( xBundle, RID_UPDATE_STR_DLG_TITLE );
680 msDownloadPause = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_PAUSE );
681 msDownloadError = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_ERR );
682 msDownloadWarning = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_WARN );
683 msDownloadDescr = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_DESCR );
684 msDownloadNotAvail = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_UNAVAIL );
685 msDownloading = loadString( xBundle, RID_UPDATE_STR_DOWNLOADING );
686 msReady2Install = loadString( xBundle, RID_UPDATE_STR_READY_INSTALL );
687 msCancelTitle = loadString( xBundle, RID_UPDATE_STR_CANCEL_TITLE );
688 msCancelMessage = loadString( xBundle, RID_UPDATE_STR_CANCEL_DOWNLOAD );
689 msInstallMessage = loadString( xBundle, RID_UPDATE_STR_BEGIN_INSTALL );
690 msInstallNow = loadString( xBundle, RID_UPDATE_STR_INSTALL_NOW );
691 msInstallLater = loadString( xBundle, RID_UPDATE_STR_INSTALL_LATER );
692 msInstallError = loadString( xBundle, RID_UPDATE_STR_INSTALL_ERROR );
693 msOverwriteWarning = loadString( xBundle, RID_UPDATE_STR_OVERWRITE_WARNING );
694 msPercent = loadString( xBundle, RID_UPDATE_STR_PERCENT );
695 msReloadWarning = loadString( xBundle, RID_UPDATE_STR_RELOAD_WARNING );
696 msReloadReload = loadString( xBundle, RID_UPDATE_STR_RELOAD_RELOAD );
697 msReloadContinue = loadString( xBundle, RID_UPDATE_STR_RELOAD_CONTINUE );
699 msStatusFL = loadString( xBundle, RID_UPDATE_FT_STATUS );
700 msDescription = loadString( xBundle, RID_UPDATE_FT_DESCRIPTION );
702 msClose = loadString( xBundle, RID_UPDATE_BTN_CLOSE );
703 msDownload = loadString( xBundle, RID_UPDATE_BTN_DOWNLOAD );
704 msInstall = loadString( xBundle, RID_UPDATE_BTN_INSTALL );
705 msPauseBtn = loadString( xBundle, RID_UPDATE_BTN_PAUSE );
706 msResumeBtn = loadString( xBundle, RID_UPDATE_BTN_RESUME );
707 msCancelBtn = loadString( xBundle, RID_UPDATE_BTN_CANCEL );
709 // all update states before UPDATESTATE_UPDATE_AVAIL don't have a bubble
710 // so we can ignore them
711 for ( int i=0; i < (int)(UPDATESTATES_COUNT - UPDATESTATE_UPDATE_AVAIL); i++ )
713 msBubbleTexts[ i ] = loadString( xBundle, RID_UPDATE_BUBBLE_TEXT_START + i );
714 msBubbleTitles[ i ] = loadString( xBundle, RID_UPDATE_BUBBLE_T_TEXT_START + i );
717 for ( int i=0; i < BUTTON_COUNT; i++ )
719 msButtonIDs[ i ] = "BUTTON_" + OUString::number( i );
725 void UpdateHandler::startThrobber( bool bStart )
727 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
728 uno::Reference< awt::XAnimation > xThrobber( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
730 if ( xThrobber.is() )
732 if ( bStart )
733 xThrobber->startAnimation();
734 else
735 xThrobber->stopAnimation();
738 uno::Reference< awt::XWindow > xWindow( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
739 if (xWindow.is() )
740 xWindow->setVisible( bStart );
744 void UpdateHandler::setControlProperty( const OUString &rCtrlName,
745 const OUString &rPropName,
746 const uno::Any &rPropValue )
748 if ( !mxUpdDlg.is() ) return;
750 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
751 uno::Reference< awt::XControl > xControl( xContainer->getControl( rCtrlName ), uno::UNO_QUERY_THROW );
752 uno::Reference< awt::XControlModel > xControlModel( xControl->getModel(), uno::UNO_QUERY_THROW );
753 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
755 try {
756 xPropSet->setPropertyValue( rPropName, rPropValue );
758 catch( const beans::UnknownPropertyException& )
760 OSL_FAIL( "UpdateHandler::setControlProperty: caught an exception!" );
765 void UpdateHandler::showControl( const OUString &rCtrlName, bool bShow )
767 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
769 if ( !xContainer.is() )
771 OSL_FAIL( "UpdateHandler::showControl: could not get control container!" );
772 return;
775 uno::Reference< awt::XWindow > xWindow( xContainer->getControl( rCtrlName ), uno::UNO_QUERY );
776 if ( xWindow.is() )
777 xWindow->setVisible( bShow );
781 void UpdateHandler::focusControl( DialogControls eID )
783 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
785 if ( !xContainer.is() )
787 OSL_FAIL( "UpdateHandler::focusControl: could not get control container!" );
788 return;
791 OSL_ENSURE( (eID < BUTTON_COUNT), "UpdateHandler::focusControl: id to big!" );
793 uno::Reference< awt::XWindow > xWindow( xContainer->getControl( msButtonIDs[(short)eID] ), uno::UNO_QUERY );
794 if ( xWindow.is() )
795 xWindow->setFocus();
799 void UpdateHandler::insertControlModel( uno::Reference< awt::XControlModel > const & rxDialogModel,
800 OUString const & rServiceName,
801 OUString const & rControlName,
802 awt::Rectangle const & rPosSize,
803 uno::Sequence< beans::NamedValue > const & rProps )
805 uno::Reference< lang::XMultiServiceFactory > xFactory (rxDialogModel, uno::UNO_QUERY_THROW);
806 uno::Reference< awt::XControlModel > xModel (xFactory->createInstance (rServiceName), uno::UNO_QUERY_THROW);
807 uno::Reference< beans::XPropertySet > xPropSet (xModel, uno::UNO_QUERY_THROW);
809 for (sal_Int32 i = 0, n = rProps.getLength(); i < n; i++)
811 xPropSet->setPropertyValue (rProps[i].Name, rProps[i].Value);
814 // @see awt/UnoControlDialogElement.idl
815 xPropSet->setPropertyValue( "Name", uno::Any (rControlName) );
816 xPropSet->setPropertyValue( "PositionX", uno::Any (rPosSize.X) );
817 xPropSet->setPropertyValue( "PositionY", uno::Any (rPosSize.Y) );
818 xPropSet->setPropertyValue( "Height", uno::Any (rPosSize.Height) );
819 xPropSet->setPropertyValue( "Width", uno::Any (rPosSize.Width) );
821 // insert by Name into DialogModel container
822 uno::Reference< container::XNameContainer > xContainer (rxDialogModel, uno::UNO_QUERY_THROW);
823 xContainer->insertByName( rControlName, uno::Any (uno::Reference< uno::XInterface >(xModel, uno::UNO_QUERY)));
827 void UpdateHandler::setFullVersion( OUString& rString )
829 uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider(
830 com::sun::star::configuration::theDefaultProvider::get( mxContext ) );
832 beans::PropertyValue aProperty;
833 aProperty.Name = "nodepath";
834 aProperty.Value = uno::makeAny( OUString("org.openoffice.Setup/Product") );
836 uno::Sequence< uno::Any > aArgumentList( 1 );
837 aArgumentList[0] = uno::makeAny( aProperty );
839 uno::Reference< uno::XInterface > xConfigAccess;
840 xConfigAccess = xConfigurationProvider->createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess",
841 aArgumentList );
843 uno::Reference< container::XNameAccess > xNameAccess( xConfigAccess, uno::UNO_QUERY_THROW );
845 OUString aProductVersion;
846 xNameAccess->getByName("ooSetupVersion") >>= aProductVersion;
847 OUString aProductFullVersion;
848 xNameAccess->getByName("ooSetupVersionAboutBox") >>= aProductFullVersion;
849 rString = rString.replaceFirst( aProductVersion, aProductFullVersion );
853 bool UpdateHandler::showWarning( const OUString &rWarningText ) const
855 bool bRet = false;
857 uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
858 if ( !xControl.is() ) return bRet;
860 uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
861 if ( !xPeer.is() ) return bRet;
863 uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
864 if ( !xToolkit.is() ) return bRet;
866 awt::WindowDescriptor aDescriptor;
868 sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
869 nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
870 nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
872 aDescriptor.Type = awt::WindowClass_MODALTOP;
873 aDescriptor.WindowServiceName = "warningbox";
874 aDescriptor.ParentIndex = -1;
875 aDescriptor.Parent = xPeer;
876 aDescriptor.Bounds = awt::Rectangle( 10, 10, 250, 150 );
877 aDescriptor.WindowAttributes = nWindowAttributes;
879 uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
880 if ( xMsgBox.is() )
882 mbShowsMessageBox = true;
883 sal_Int16 nRet;
884 // xMsgBox->setCaptionText( msCancelTitle );
885 xMsgBox->setMessageText( rWarningText );
886 nRet = xMsgBox->execute();
887 if ( nRet == 2 ) // RET_YES == 2
888 bRet = true;
889 mbShowsMessageBox = false;
892 uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
893 if ( xComponent.is() )
894 xComponent->dispose();
896 return bRet;
900 bool UpdateHandler::showWarning( const OUString &rWarningText,
901 const OUString &rBtnText_1,
902 const OUString &rBtnText_2 ) const
904 bool bRet = false;
906 uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
907 if ( !xControl.is() ) return bRet;
909 uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
910 if ( !xPeer.is() ) return bRet;
912 uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
913 if ( !xToolkit.is() ) return bRet;
915 awt::WindowDescriptor aDescriptor;
917 sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
918 nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
919 nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
921 aDescriptor.Type = awt::WindowClass_MODALTOP;
922 aDescriptor.WindowServiceName = "warningbox";
923 aDescriptor.ParentIndex = -1;
924 aDescriptor.Parent = xPeer;
925 aDescriptor.Bounds = awt::Rectangle( 10, 10, 250, 150 );
926 aDescriptor.WindowAttributes = nWindowAttributes;
928 uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
929 if ( xMsgBox.is() )
931 uno::Reference< awt::XVclContainer > xMsgBoxCtrls( xMsgBox, uno::UNO_QUERY );
932 if ( xMsgBoxCtrls.is() )
934 uno::Sequence< uno::Reference< awt::XWindow > > xChildren = xMsgBoxCtrls->getWindows();
936 for ( long i=0; i < xChildren.getLength(); i++ )
938 uno::Reference< awt::XVclWindowPeer > xMsgBoxCtrl( xChildren[i], uno::UNO_QUERY );
939 if ( xMsgBoxCtrl.is() )
941 bool bIsDefault = true;
942 uno::Any aValue = xMsgBoxCtrl->getProperty( "DefaultButton" );
943 aValue >>= bIsDefault;
944 if ( bIsDefault )
945 xMsgBoxCtrl->setProperty( "Text", uno::Any( rBtnText_1 ) );
946 else
947 xMsgBoxCtrl->setProperty( "Text", uno::Any( rBtnText_2 ) );
952 sal_Int16 nRet;
953 // xMsgBox->setCaptionText( msCancelTitle );
954 mbShowsMessageBox = true;
955 xMsgBox->setMessageText( rWarningText );
956 nRet = xMsgBox->execute();
957 if ( nRet == 2 ) // RET_YES == 2
958 bRet = true;
960 mbShowsMessageBox = false;
963 uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
964 if ( xComponent.is() )
965 xComponent->dispose();
967 return bRet;
971 bool UpdateHandler::showOverwriteWarning( const OUString& rFileName ) const
973 return showWarning(
974 (msReloadWarning
975 .replaceAll( "%FILENAME", rFileName )
976 .replaceAll( "%DOWNLOAD_PATH", msDownloadPath )),
977 msReloadContinue, msReloadReload );
981 bool UpdateHandler::showOverwriteWarning() const
983 return showWarning( msOverwriteWarning );
987 #define BUTTON_HEIGHT 14
988 #define BUTTON_WIDTH 50
989 #define BUTTON_X_OFFSET 7
990 #define BUTTON_Y_OFFSET 3
991 #define LABEL_HEIGHT 10
993 #define DIALOG_WIDTH 300
994 #define DIALOG_BORDER 5
995 #define INNER_BORDER 3
996 #define TEXT_OFFSET 1
997 #define BOX_HEIGHT1 ( LABEL_HEIGHT + 3*BUTTON_HEIGHT + 2*BUTTON_Y_OFFSET + 2*INNER_BORDER )
998 #define BOX_HEIGHT2 50
999 #define EDIT_WIDTH ( DIALOG_WIDTH - 2 * DIALOG_BORDER )
1000 #define BOX1_BTN_X ( DIALOG_BORDER + EDIT_WIDTH - BUTTON_WIDTH - INNER_BORDER )
1001 #define BOX1_BTN_Y ( DIALOG_BORDER + LABEL_HEIGHT + INNER_BORDER)
1002 #define THROBBER_WIDTH 16
1003 #define THROBBER_HEIGHT 16
1004 #define THROBBER_X_POS ( DIALOG_BORDER + 8 )
1005 #define THROBBER_Y_POS ( DIALOG_BORDER + 23 )
1006 #define BUTTON_BAR_HEIGHT 24
1007 #define LABEL_OFFSET ( LABEL_HEIGHT + 4 )
1008 #define DIALOG_HEIGHT ( BOX_HEIGHT1 + BOX_HEIGHT2 + LABEL_OFFSET + BUTTON_BAR_HEIGHT + 3 * DIALOG_BORDER )
1009 #define LABEL_Y_POS ( 2 * DIALOG_BORDER + BOX_HEIGHT1 )
1010 #define EDIT2_Y_POS ( LABEL_Y_POS + LABEL_HEIGHT )
1011 #define BUTTON_BAR_Y_POS ( EDIT2_Y_POS + DIALOG_BORDER + BOX_HEIGHT2 )
1012 #define BUTTON_Y_POS ( BUTTON_BAR_Y_POS + 8 )
1013 #define CLOSE_BTN_X ( DIALOG_WIDTH - DIALOG_BORDER - BUTTON_WIDTH )
1014 #define INSTALL_BTN_X ( CLOSE_BTN_X - 2 * BUTTON_X_OFFSET - BUTTON_WIDTH )
1015 #define DOWNLOAD_BTN_X ( INSTALL_BTN_X - BUTTON_X_OFFSET - BUTTON_WIDTH )
1016 #define PROGRESS_WIDTH 80
1017 #define PROGRESS_HEIGHT 10
1018 #define PROGRESS_X_POS ( DIALOG_BORDER + 8 )
1019 #define PROGRESS_Y_POS ( DIALOG_BORDER + 2*LABEL_OFFSET )
1022 void UpdateHandler::showControls( short nControls )
1024 // The buttons from CANCEL_BUTTON to RESUME_BUTTON will be shown or
1025 // hidden on demand
1026 short nShiftMe;
1027 for ( int i = 0; i <= (int)RESUME_BUTTON; i++ )
1029 nShiftMe = (short)(nControls >> i);
1030 showControl( msButtonIDs[i], (bool)(nShiftMe & 0x01) );
1033 nShiftMe = (short)(nControls >> THROBBER_CTRL);
1034 startThrobber( (bool)(nShiftMe & 0x01) );
1036 nShiftMe = (short)(nControls >> PROGRESS_CTRL);
1037 showControl( CTRL_PROGRESS, (bool)(nShiftMe & 0x01) );
1038 showControl( TEXT_PERCENT, (bool)(nShiftMe & 0x01) );
1040 // Status text needs to be smaller, when there are buttons at the right side of the dialog
1041 if ( ( nControls & ( (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) ) ) != 0 )
1042 setControlProperty( TEXT_STATUS, "Width", uno::Any( sal_Int32(EDIT_WIDTH - BUTTON_WIDTH - 2*INNER_BORDER - TEXT_OFFSET ) ) );
1043 else
1044 setControlProperty( TEXT_STATUS, "Width", uno::Any( sal_Int32(EDIT_WIDTH - 2*TEXT_OFFSET ) ) );
1046 // Status text needs to be taller, when we show the progress bar
1047 if ( ( nControls & ( 1<<PROGRESS_CTRL ) ) != 0 )
1048 setControlProperty( TEXT_STATUS, "Height", uno::Any( sal_Int32(LABEL_HEIGHT) ) );
1049 else
1050 setControlProperty( TEXT_STATUS, "Height", uno::Any( sal_Int32(BOX_HEIGHT1 - 4*TEXT_OFFSET - LABEL_HEIGHT ) ) );
1054 void UpdateHandler::createDialog()
1056 if ( !mxContext.is() )
1058 OSL_ASSERT( false );
1059 return;
1062 if( mxContext.is() )
1064 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( mxContext );
1065 xDesktop->addTerminateListener( this );
1068 loadStrings();
1070 uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
1071 uno::Reference< awt::XControlModel > xControlModel( xFactory->createInstanceWithContext(
1072 "com.sun.star.awt.UnoControlDialogModel",
1073 mxContext), uno::UNO_QUERY_THROW );
1075 // @see awt/UnoControlDialogModel.idl
1076 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
1078 xPropSet->setPropertyValue( "Title", uno::Any( msDlgTitle ) );
1079 xPropSet->setPropertyValue( "Closeable", uno::Any( true ) );
1080 xPropSet->setPropertyValue( "Enabled", uno::Any( true ) );
1081 xPropSet->setPropertyValue( "Moveable", uno::Any( true ) );
1082 xPropSet->setPropertyValue( "Sizeable", uno::Any( true ) );
1083 xPropSet->setPropertyValue( "DesktopAsParent", uno::Any( true ) );
1084 xPropSet->setPropertyValue( "PositionX", uno::Any(sal_Int32( 100 )) );
1085 xPropSet->setPropertyValue( "PositionY", uno::Any(sal_Int32( 100 )) );
1086 xPropSet->setPropertyValue( "Width", uno::Any(sal_Int32( DIALOG_WIDTH )) );
1087 xPropSet->setPropertyValue( "Height", uno::Any(sal_Int32( DIALOG_HEIGHT )) );
1088 xPropSet->setPropertyValue( "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DLG ) );
1090 { // Label (fixed text) <status>
1091 uno::Sequence< beans::NamedValue > aProps(1);
1093 setProperty( aProps, 0, "Label", uno::Any( msStatusFL ) );
1095 insertControlModel( xControlModel, FIXED_TEXT_MODEL, "fixedLineStatus",
1096 awt::Rectangle( DIALOG_BORDER+1, DIALOG_BORDER, EDIT_WIDTH-2, LABEL_HEIGHT ),
1097 aProps );
1099 { // box around <status> text
1100 uno::Sequence< beans::NamedValue > aProps;
1102 insertControlModel( xControlModel, GROUP_BOX_MODEL, "StatusBox",
1103 awt::Rectangle( DIALOG_BORDER, DIALOG_BORDER + LABEL_HEIGHT, EDIT_WIDTH, BOX_HEIGHT1 - LABEL_HEIGHT ),
1104 aProps );
1106 { // Text (multiline edit) <status>
1107 uno::Sequence< beans::NamedValue > aProps(7);
1109 setProperty( aProps, 0, "Text", uno::Any( substVariables(msChecking) ) );
1110 setProperty( aProps, 1, "Border", uno::Any( sal_Int16( 0 ) ) );
1111 setProperty( aProps, 2, "PaintTransparent", uno::Any( true ) );
1112 setProperty( aProps, 3, "MultiLine", uno::Any( true ) );
1113 setProperty( aProps, 4, "ReadOnly", uno::Any( true ) );
1114 setProperty( aProps, 5, "AutoVScroll", uno::Any( true ) );
1115 setProperty( aProps, 6, "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_STATUS ) );
1117 insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_STATUS,
1118 awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
1119 DIALOG_BORDER + LABEL_HEIGHT + TEXT_OFFSET,
1120 EDIT_WIDTH - 2*TEXT_OFFSET,
1121 BOX_HEIGHT1 - 4*TEXT_OFFSET - LABEL_HEIGHT ),
1122 aProps );
1124 { // Text (edit) <percent>
1125 uno::Sequence< beans::NamedValue > aProps(4);
1127 setProperty( aProps, 0, "Text", uno::Any( msPercent ) );
1128 setProperty( aProps, 1, "Border", uno::Any( sal_Int16( 0 ) ) );
1129 setProperty( aProps, 2, "PaintTransparent", uno::Any( true ) );
1130 setProperty( aProps, 3, "ReadOnly", uno::Any( true ) );
1132 insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_PERCENT,
1133 awt::Rectangle( PROGRESS_X_POS + PROGRESS_WIDTH + DIALOG_BORDER,
1134 PROGRESS_Y_POS,
1135 EDIT_WIDTH - PROGRESS_WIDTH - BUTTON_WIDTH - 2*DIALOG_BORDER,
1136 LABEL_HEIGHT ),
1137 aProps );
1139 { // pause button
1140 uno::Sequence< beans::NamedValue > aProps(5);
1142 setProperty( aProps, 0, "DefaultButton", uno::Any( false ) );
1143 setProperty( aProps, 1, "Enabled", uno::Any( true ) );
1144 setProperty( aProps, 2, "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1145 setProperty( aProps, 3, "Label", uno::Any( msPauseBtn ) );
1146 setProperty( aProps, 4, "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_PAUSE ) );
1148 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[PAUSE_BUTTON],
1149 awt::Rectangle( BOX1_BTN_X, BOX1_BTN_Y, BUTTON_WIDTH, BUTTON_HEIGHT ),
1150 aProps );
1152 { // resume button
1153 uno::Sequence< beans::NamedValue > aProps(5);
1155 setProperty( aProps, 0, "DefaultButton", uno::Any( false ) );
1156 setProperty( aProps, 1, "Enabled", uno::Any( true ) );
1157 setProperty( aProps, 2, "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1158 setProperty( aProps, 3, "Label", uno::Any( msResumeBtn ) );
1159 setProperty( aProps, 4, "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_RESUME ) );
1161 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[RESUME_BUTTON],
1162 awt::Rectangle( BOX1_BTN_X,
1163 BOX1_BTN_Y + BUTTON_Y_OFFSET + BUTTON_HEIGHT,
1164 BUTTON_WIDTH,
1165 BUTTON_HEIGHT ),
1166 aProps );
1168 { // abort button
1169 uno::Sequence< beans::NamedValue > aProps(5);
1171 setProperty( aProps, 0, "DefaultButton", uno::Any( false ) );
1172 setProperty( aProps, 1, "Enabled", uno::Any( true ) );
1173 setProperty( aProps, 2, "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1174 setProperty( aProps, 3, "Label", uno::Any( msCancelBtn ) );
1175 setProperty( aProps, 4, "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_CANCEL ) );
1177 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[CANCEL_BUTTON],
1178 awt::Rectangle( BOX1_BTN_X,
1179 BOX1_BTN_Y + (2*(BUTTON_HEIGHT+BUTTON_Y_OFFSET)),
1180 BUTTON_WIDTH,
1181 BUTTON_HEIGHT ),
1182 aProps );
1184 { // Label (FixedText) <description>
1185 uno::Sequence< beans::NamedValue > aProps(1);
1187 setProperty( aProps, 0, "Label", uno::Any( msDescription ) );
1189 insertControlModel( xControlModel, FIXED_TEXT_MODEL, "fixedTextDescription",
1190 awt::Rectangle( DIALOG_BORDER+1, LABEL_Y_POS, EDIT_WIDTH-2, LABEL_HEIGHT ),
1191 aProps );
1193 { // box around <description> text
1194 uno::Sequence< beans::NamedValue > aProps;
1196 insertControlModel( xControlModel, GROUP_BOX_MODEL, "DescriptionBox",
1197 awt::Rectangle( DIALOG_BORDER, EDIT2_Y_POS, EDIT_WIDTH, BOX_HEIGHT2 ),
1198 aProps );
1200 { // Text (MultiLineEdit) <description>
1201 uno::Sequence< beans::NamedValue > aProps(7);
1203 setProperty( aProps, 0, "Text", uno::Any( OUString() ) );
1204 setProperty( aProps, 1, "Border", uno::Any( sal_Int16( 0 ) ) );
1205 setProperty( aProps, 2, "PaintTransparent", uno::Any( true ) );
1206 setProperty( aProps, 3, "MultiLine", uno::Any( true ) );
1207 setProperty( aProps, 4, "ReadOnly", uno::Any( true ) );
1208 setProperty( aProps, 5, "AutoVScroll", uno::Any( true ) );
1209 setProperty( aProps, 6, "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DESCRIPTION ) );
1211 insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_DESCRIPTION,
1212 awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
1213 EDIT2_Y_POS + 2*TEXT_OFFSET,
1214 EDIT_WIDTH - 3*TEXT_OFFSET,
1215 BOX_HEIGHT2 - 3*TEXT_OFFSET ),
1216 aProps );
1218 { // @see awt/UnoControlFixedLineModel.idl
1219 uno::Sequence< beans::NamedValue > aProps(1);
1221 setProperty( aProps, 0, "Orientation", uno::Any( sal_Int32( 0 ) ) );
1223 insertControlModel( xControlModel, FIXED_LINE_MODEL, "fixedLine",
1224 awt::Rectangle( 0, BUTTON_BAR_Y_POS, DIALOG_WIDTH, 5 ),
1225 aProps );
1227 { // close button // @see awt/UnoControlButtonModel.idl
1228 uno::Sequence< beans::NamedValue > aProps(5);
1230 setProperty( aProps, 0, "DefaultButton", uno::Any( false ) );
1231 setProperty( aProps, 1, "Enabled", uno::Any( true ) );
1232 // [property] short PushButtonType
1233 // with own "ButtonActionListener"
1234 setProperty( aProps, 2, "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1235 // with default ActionListener => endDialog().
1236 // setProperty( aProps, 2, "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_CANCEL) ) );
1237 // [property] string Label // only if PushButtonType_STANDARD
1238 setProperty( aProps, 3, "Label", uno::Any( msClose ) );
1239 setProperty( aProps, 4, "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_CLOSE ) );
1241 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[ CLOSE_BUTTON ],
1242 awt::Rectangle( CLOSE_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1243 aProps );
1245 { // install button
1246 uno::Sequence< beans::NamedValue > aProps(5);
1248 setProperty( aProps, 0, "DefaultButton", uno::Any( false ) );
1249 setProperty( aProps, 1, "Enabled", uno::Any( true ) );
1250 setProperty( aProps, 2, "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1251 setProperty( aProps, 3, "Label", uno::Any( msInstall ) );
1252 setProperty( aProps, 4, "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_INSTALL ) );
1254 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[INSTALL_BUTTON],
1255 awt::Rectangle( INSTALL_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1256 aProps );
1258 { // download button
1259 uno::Sequence< beans::NamedValue > aProps(5);
1261 setProperty( aProps, 0, "DefaultButton", uno::Any( false ) );
1262 setProperty( aProps, 1, "Enabled", uno::Any( true ) );
1263 setProperty( aProps, 2, "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1264 setProperty( aProps, 3, "Label", uno::Any( msDownload ) );
1265 setProperty( aProps, 4, "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DOWNLOAD ) );
1267 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[DOWNLOAD_BUTTON],
1268 awt::Rectangle( DOWNLOAD_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1269 aProps );
1271 { // help button
1272 uno::Sequence< beans::NamedValue > aProps(3);
1274 setProperty( aProps, 0, "DefaultButton", uno::Any( false ) );
1275 setProperty( aProps, 1, "Enabled", uno::Any( true ) );
1276 setProperty( aProps, 2, "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_HELP) ) );
1278 insertControlModel( xControlModel, BUTTON_MODEL, msButtonIDs[HELP_BUTTON],
1279 awt::Rectangle( DIALOG_BORDER, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1280 aProps );
1282 { // @see awt/UnoControlThrobberModel.idl
1283 uno::Sequence< beans::NamedValue > aProps;
1285 insertControlModel( xControlModel, "com.sun.star.awt.SpinningProgressControlModel", CTRL_THROBBER,
1286 awt::Rectangle( THROBBER_X_POS, THROBBER_Y_POS, THROBBER_WIDTH, THROBBER_HEIGHT),
1287 aProps );
1289 { // @see awt/UnoControlProgressBarModel.idl
1290 uno::Sequence< beans::NamedValue > aProps(4);
1291 setProperty( aProps, 0, "Enabled", uno::Any( true ) );
1292 setProperty( aProps, 1, "ProgressValue", uno::Any( sal_Int32( 0 ) ) );
1293 setProperty( aProps, 2, "ProgressValueMax", uno::Any( sal_Int32( 100 ) ) );
1294 setProperty( aProps, 3, "ProgressValueMin", uno::Any( sal_Int32( 0 ) ) );
1296 insertControlModel( xControlModel, "com.sun.star.awt.UnoControlProgressBarModel", CTRL_PROGRESS,
1297 awt::Rectangle( PROGRESS_X_POS, PROGRESS_Y_POS, PROGRESS_WIDTH, PROGRESS_HEIGHT ),
1298 aProps);
1301 uno::Reference< awt::XUnoControlDialog > xControl = awt::UnoControlDialog::create( mxContext );
1302 xControl->setModel( xControlModel );
1304 if ( !mbVisible )
1306 xControl->setVisible( false );
1309 xControl->createPeer( NULL, NULL );
1311 for ( int i = 0; i < HELP_BUTTON; i++ )
1313 uno::Reference< awt::XButton > xButton ( xControl->getControl( msButtonIDs[i] ), uno::UNO_QUERY);
1314 if (xButton.is())
1316 xButton->setActionCommand( msButtonIDs[i] );
1317 xButton->addActionListener( this );
1322 mxUpdDlg.set( xControl, uno::UNO_QUERY_THROW );
1323 mnLastCtrlState = -1;
1326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */