bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / source / update / check / updatehdl.cxx
blob9630a9395218aac48d37667835835cb0a893aeaa
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 <helpids.h>
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>
58 #include <com/sun/star/frame/TerminationVetoException.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 <strings.hrc>
64 #include <unotools/resmgr.hxx>
65 #include <tools/urlobj.hxx>
66 #include <vcl/settings.hxx>
67 #include <vcl/svapp.hxx>
69 #define COMMAND_CLOSE "close"
71 #define CTRL_THROBBER "throbber"
72 #define CTRL_PROGRESS "progress"
74 #define TEXT_STATUS "text_status"
75 #define TEXT_PERCENT "text_percent"
76 #define TEXT_DESCRIPTION "text_description"
78 #define FIXED_LINE_MODEL "com.sun.star.awt.UnoControlFixedLineModel"
79 #define FIXED_TEXT_MODEL "com.sun.star.awt.UnoControlFixedTextModel"
80 #define EDIT_FIELD_MODEL "com.sun.star.awt.UnoControlEditModel"
81 #define BUTTON_MODEL "com.sun.star.awt.UnoControlButtonModel"
82 #define GROUP_BOX_MODEL "com.sun.star.awt.UnoControlGroupBoxModel"
84 using namespace com::sun::star;
87 UpdateHandler::UpdateHandler( const uno::Reference< uno::XComponentContext > & rxContext,
88 const rtl::Reference< IActionListener > & rxActionListener ) :
89 mxContext( rxContext ),
90 mxActionListener( rxActionListener ),
91 meCurState( UPDATESTATES_COUNT ),
92 meLastState( UPDATESTATES_COUNT ),
93 mnPercent( 0 ),
94 mnLastCtrlState( -1 ),
95 mbDownloadBtnHasDots( false ),
96 mbVisible( false ),
97 mbStringsLoaded( false ),
98 mbMinimized( false ),
99 mbListenerAdded(false),
100 mbShowsMessageBox(false)
105 UpdateHandler::~UpdateHandler()
107 mxContext = nullptr;
108 mxUpdDlg = nullptr;
109 mxInteractionHdl = nullptr;
110 mxActionListener = nullptr;
114 void UpdateHandler::enableControls( short nCtrlState )
116 osl::MutexGuard aGuard( maMutex );
118 if ( nCtrlState == mnLastCtrlState )
119 return;
121 // the help button should always be the last button in the
122 // enum list and must never be disabled
123 for ( int i=0; i<HELP_BUTTON; i++ )
125 short nCurStateVal = static_cast<short>(nCtrlState >> i);
126 short nOldStateVal = static_cast<short>(mnLastCtrlState >> i);
127 if ( ( nCurStateVal & 0x01 ) != ( nOldStateVal & 0x01 ) )
129 bool bEnableControl = ( ( nCurStateVal & 0x01 ) == 0x01 );
130 setControlProperty( msButtonIDs[i], "Enabled", uno::Any( bEnableControl ) );
134 mnLastCtrlState = nCtrlState;
138 void UpdateHandler::setDownloadBtnLabel( bool bAppendDots )
140 osl::MutexGuard aGuard( maMutex );
142 if ( mbDownloadBtnHasDots != bAppendDots )
144 OUString aLabel( msDownload );
146 if ( bAppendDots )
147 aLabel += "...";
149 setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], "Label", uno::Any( aLabel ) );
150 setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DOWNLOAD2 ) );
152 mbDownloadBtnHasDots = bAppendDots;
157 void UpdateHandler::setState( UpdateState eState )
159 osl::MutexGuard aGuard( maMutex );
161 meCurState = eState;
163 if ( mxUpdDlg.is() && mbVisible )
164 updateState( meCurState );
168 bool UpdateHandler::isVisible() const
170 if ( !mxUpdDlg.is() ) return false;
172 uno::Reference< awt::XWindow2 > xWindow( mxUpdDlg, uno::UNO_QUERY );
174 if ( xWindow.is() )
175 return xWindow->isVisible();
176 else
177 return false;
181 void UpdateHandler::setVisible( bool bVisible )
183 osl::MutexGuard aGuard( maMutex );
185 mbVisible = bVisible;
187 if ( bVisible )
189 if ( !mxUpdDlg.is() )
190 createDialog();
192 // this should never happen, but if it happens we better return here
193 if ( !mxUpdDlg.is() )
194 return;
196 updateState( meCurState );
198 uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
200 if ( xWindow.is() )
201 xWindow->setVisible( bVisible );
203 uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
204 if ( xTopWindow.is() )
206 xTopWindow->toFront();
207 if ( !mbListenerAdded )
209 xTopWindow->addTopWindowListener( this );
210 mbListenerAdded = true;
214 else if ( mxUpdDlg.is() )
216 uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
218 if ( xWindow.is() )
219 xWindow->setVisible( bVisible );
224 void UpdateHandler::setProgress( sal_Int32 nPercent )
226 if ( nPercent > 100 )
227 nPercent = 100;
228 else if ( nPercent < 0 )
229 nPercent = 0;
231 if ( nPercent != mnPercent )
233 osl::MutexGuard aGuard( maMutex );
235 mnPercent = nPercent;
236 setControlProperty( CTRL_PROGRESS, "ProgressValue", uno::Any( nPercent ) );
237 setControlProperty( TEXT_PERCENT, "Text", uno::Any( substVariables(msPercent) ) );
242 void UpdateHandler::setErrorMessage( const OUString& rErrorMsg )
244 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( rErrorMsg ) );
248 void UpdateHandler::setDownloadFile( const OUString& rFilePath )
250 sal_Int32 nLast = rFilePath.lastIndexOf( '/' );
251 if ( nLast != -1 )
253 msDownloadFile = rFilePath.copy( nLast+1 );
254 const OUString aDownloadURL = rFilePath.copy( 0, nLast );
255 osl::FileBase::getSystemPathFromFileURL( aDownloadURL, msDownloadPath );
260 OUString UpdateHandler::getBubbleText( UpdateState eState )
262 osl::MutexGuard aGuard( maMutex );
264 OUString sText;
265 sal_Int32 nIndex = static_cast<sal_Int32>(eState);
267 loadStrings();
269 if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
270 sText = substVariables( msBubbleTexts[ nIndex - UPDATESTATE_UPDATE_AVAIL ] );
272 return sText;
276 OUString UpdateHandler::getBubbleTitle( UpdateState eState )
278 osl::MutexGuard aGuard( maMutex );
280 OUString sText;
281 sal_Int32 nIndex = static_cast<sal_Int32>(eState);
283 loadStrings();
285 if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
286 sText = substVariables( msBubbleTitles[ nIndex - UPDATESTATE_UPDATE_AVAIL] );
288 return sText;
292 OUString UpdateHandler::getDefaultInstErrMsg()
294 osl::MutexGuard aGuard( maMutex );
296 loadStrings();
298 return substVariables( msInstallError );
301 // XActionListener
303 void SAL_CALL UpdateHandler::disposing( const lang::EventObject& rEvt )
305 if ( rEvt.Source == mxUpdDlg )
306 mxUpdDlg.clear();
310 void SAL_CALL UpdateHandler::actionPerformed( awt::ActionEvent const & rEvent )
312 DialogControls eButton = BUTTON_COUNT;
313 for ( int i = 0; i < BUTTON_COUNT; i++ )
315 if ( rEvent.ActionCommand == msButtonIDs[i] )
317 eButton = static_cast<DialogControls>(i);
318 break;
322 if ( rEvent.ActionCommand == COMMAND_CLOSE )
324 if ( ( mnLastCtrlState & ( 1 << CLOSE_BUTTON ) ) == ( 1 << CLOSE_BUTTON ) )
325 eButton = CLOSE_BUTTON;
326 else
327 eButton = CANCEL_BUTTON;
330 switch ( eButton ) {
331 case CANCEL_BUTTON:
333 bool bCancel = true;
335 if ( ( meCurState == UPDATESTATE_DOWNLOADING ) ||
336 ( meCurState == UPDATESTATE_DOWNLOAD_PAUSED ) ||
337 ( meCurState == UPDATESTATE_ERROR_DOWNLOADING ) )
338 bCancel = showWarning( msCancelMessage );
340 if ( bCancel )
342 mxActionListener->cancel();
343 setVisible( false );
345 break;
347 case CLOSE_BUTTON:
348 setVisible( false );
349 if ( meCurState == UPDATESTATE_ERROR_CHECKING )
350 mxActionListener->closeAfterFailure();
351 break;
352 case DOWNLOAD_BUTTON:
353 mxActionListener->download();
354 break;
355 case INSTALL_BUTTON:
356 if ( showWarning( msInstallMessage ) )
357 mxActionListener->install();
358 break;
359 case PAUSE_BUTTON:
360 mxActionListener->pause();
361 break;
362 case RESUME_BUTTON:
363 mxActionListener->resume();
364 break;
365 case HELP_BUTTON:
366 break;
367 default:
368 OSL_FAIL( "UpdateHandler::actionPerformed: unknown command!" );
372 // XTopWindowListener
374 void SAL_CALL UpdateHandler::windowOpened( const lang::EventObject& )
379 void SAL_CALL UpdateHandler::windowClosing( const lang::EventObject& e )
381 awt::ActionEvent aActionEvt;
382 aActionEvt.ActionCommand = COMMAND_CLOSE;
383 aActionEvt.Source = e.Source;
385 actionPerformed( aActionEvt );
389 void SAL_CALL UpdateHandler::windowClosed( const lang::EventObject& )
394 void SAL_CALL UpdateHandler::windowMinimized( const lang::EventObject& )
396 mbMinimized = true;
400 void SAL_CALL UpdateHandler::windowNormalized( const lang::EventObject& )
402 mbMinimized = false;
406 void SAL_CALL UpdateHandler::windowActivated( const lang::EventObject& )
411 void SAL_CALL UpdateHandler::windowDeactivated( const lang::EventObject& )
415 // XInteractionHandler
417 void SAL_CALL UpdateHandler::handle( uno::Reference< task::XInteractionRequest > const & rRequest)
419 if ( !mxInteractionHdl.is() )
421 if( !mxContext.is() )
422 throw uno::RuntimeException( "UpdateHandler:: empty component context", *this );
424 uno::Reference< lang::XMultiComponentFactory > xServiceManager(mxContext->getServiceManager());
426 if( !xServiceManager.is() )
427 throw uno::RuntimeException( "UpdateHandler: unable to obtain service manager from component context", *this );
429 mxInteractionHdl.set(
430 task::InteractionHandler::createWithParent(mxContext, nullptr),
431 uno::UNO_QUERY_THROW);
433 uno::Reference< task::XInteractionRequestStringResolver > xStrResolver =
434 task::InteractionRequestStringResolver::create( mxContext );
435 beans::Optional< OUString > aErrorText = xStrResolver->getStringFromInformationalRequest( rRequest );
436 if ( aErrorText.IsPresent )
438 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( aErrorText.Value ) );
440 uno::Sequence< uno::Reference< task::XInteractionContinuation > > xContinuations = rRequest->getContinuations();
441 if ( xContinuations.getLength() == 1 )
443 if ( meCurState == UPDATESTATE_CHECKING )
444 setState( UPDATESTATE_ERROR_CHECKING );
445 else if ( meCurState == UPDATESTATE_DOWNLOADING )
446 setState( UPDATESTATE_ERROR_DOWNLOADING );
448 xContinuations[0]->select();
450 else
451 mxInteractionHdl->handle( rRequest );
453 else
454 mxInteractionHdl->handle( rRequest );
458 // XTerminateListener
460 void SAL_CALL UpdateHandler::queryTermination( const lang::EventObject& )
462 if ( mbShowsMessageBox )
464 uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
465 if ( xTopWindow.is() )
466 xTopWindow->toFront();
468 throw frame::TerminationVetoException(
469 "The office cannot be closed while displaying a warning!",
470 static_cast<frame::XTerminateListener*>(this));
472 else
473 setVisible( false );
477 void SAL_CALL UpdateHandler::notifyTermination( const lang::EventObject& )
479 osl::MutexGuard aGuard( maMutex );
481 if ( mxUpdDlg.is() )
483 uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
484 if ( xTopWindow.is() )
485 xTopWindow->removeTopWindowListener( this );
487 uno::Reference< lang::XComponent > xComponent( mxUpdDlg, uno::UNO_QUERY );
488 if ( xComponent.is() )
489 xComponent->dispose();
491 mxUpdDlg.clear();
496 void UpdateHandler::updateState( UpdateState eState )
498 if ( meLastState == eState )
499 return;
501 OUString sText;
503 switch ( eState )
505 case UPDATESTATE_CHECKING:
506 showControls( (1<<CANCEL_BUTTON) + (1<<THROBBER_CTRL) );
507 enableControls( 1<<CANCEL_BUTTON );
508 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msChecking) ) );
509 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( OUString() ) );
510 focusControl( CANCEL_BUTTON );
511 break;
512 case UPDATESTATE_ERROR_CHECKING:
513 showControls( 0 );
514 enableControls( 1 << CLOSE_BUTTON );
515 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msCheckingError) ) );
516 focusControl( CLOSE_BUTTON );
517 break;
518 case UPDATESTATE_UPDATE_AVAIL:
519 showControls( 0 );
520 enableControls( ( 1 << CLOSE_BUTTON ) + ( 1 << DOWNLOAD_BUTTON ) );
521 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msUpdFound) ) );
523 sText = substVariables(msDownloadWarning);
524 if ( !msDescriptionMsg.isEmpty() )
525 sText += "\n\n" + msDescriptionMsg;
526 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( sText ) );
528 setDownloadBtnLabel( false );
529 focusControl( DOWNLOAD_BUTTON );
530 break;
531 case UPDATESTATE_UPDATE_NO_DOWNLOAD:
532 showControls( 0 );
533 enableControls( ( 1 << CLOSE_BUTTON ) + ( 1 << DOWNLOAD_BUTTON ) );
534 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msUpdFound) ) );
536 sText = substVariables(msDownloadNotAvail);
537 if ( !msDescriptionMsg.isEmpty() )
538 sText += "\n\n" + msDescriptionMsg;
539 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( sText ) );
541 setDownloadBtnLabel( true );
542 focusControl( DOWNLOAD_BUTTON );
543 break;
544 case UPDATESTATE_NO_UPDATE_AVAIL:
545 case UPDATESTATE_EXT_UPD_AVAIL: // will only be set, when there are no office updates avail
546 showControls( 0 );
547 enableControls( 1 << CLOSE_BUTTON );
548 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msNoUpdFound) ) );
549 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( OUString() ) );
550 focusControl( CLOSE_BUTTON );
551 break;
552 case UPDATESTATE_DOWNLOADING:
553 showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
554 enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) );
555 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msDownloading) ) );
556 setControlProperty( TEXT_PERCENT, "Text", uno::Any( substVariables(msPercent) ) );
557 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( substVariables(msDownloadWarning) ) );
558 setControlProperty( CTRL_PROGRESS, "ProgressValue", uno::Any( mnPercent ) );
559 focusControl( CLOSE_BUTTON );
560 break;
561 case UPDATESTATE_DOWNLOAD_PAUSED:
562 showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
563 enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<RESUME_BUTTON) );
564 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msDownloadPause) ) );
565 setControlProperty( TEXT_PERCENT, "Text", uno::Any( substVariables(msPercent) ) );
566 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( substVariables(msDownloadWarning) ) );
567 setControlProperty( CTRL_PROGRESS, "ProgressValue", uno::Any( mnPercent ) );
568 focusControl( CLOSE_BUTTON );
569 break;
570 case UPDATESTATE_ERROR_DOWNLOADING:
571 showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
572 enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) );
573 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msDownloadError) ) );
574 focusControl( CLOSE_BUTTON );
575 break;
576 case UPDATESTATE_DOWNLOAD_AVAIL:
577 showControls( 0 );
578 enableControls( (1<<CLOSE_BUTTON) + (1<<INSTALL_BUTTON) );
579 setControlProperty( TEXT_STATUS, "Text", uno::Any( substVariables(msReady2Install) ) );
580 setControlProperty( TEXT_DESCRIPTION, "Text", uno::Any( substVariables(msDownloadDescr) ) );
581 focusControl( INSTALL_BUTTON );
582 break;
583 case UPDATESTATE_AUTO_START:
584 case UPDATESTATES_COUNT:
585 //do nothing, only count!
586 break;
589 meLastState = eState;
592 OUString UpdateHandler::loadString(const std::locale& rLocale,
593 const char* pResourceId)
595 return Translate::get(pResourceId, rLocale);
598 OUString UpdateHandler::substVariables( const OUString &rSource ) const
600 return rSource
601 .replaceAll( "%NEXTVERSION", msNextVersion )
602 .replaceAll( "%DOWNLOAD_PATH", msDownloadPath )
603 .replaceAll( "%FILE_NAME", msDownloadFile )
604 .replaceAll( "%PERCENT", OUString::number( mnPercent ) );
607 void UpdateHandler::loadStrings()
609 if ( mbStringsLoaded )
610 return;
611 else
612 mbStringsLoaded = true;
614 std::locale loc = Translate::Create("pcr");
616 msChecking = loadString( loc, RID_UPDATE_STR_CHECKING );
617 msCheckingError = loadString( loc, RID_UPDATE_STR_CHECKING_ERR );
618 msNoUpdFound = loadString( loc, RID_UPDATE_STR_NO_UPD_FOUND );
620 msUpdFound = loadString( loc, RID_UPDATE_STR_UPD_FOUND );
621 setFullVersion( msUpdFound );
623 msDlgTitle = loadString( loc, RID_UPDATE_STR_DLG_TITLE );
624 msDownloadPause = loadString( loc, RID_UPDATE_STR_DOWNLOAD_PAUSE );
625 msDownloadError = loadString( loc, RID_UPDATE_STR_DOWNLOAD_ERR );
626 msDownloadWarning = loadString( loc, RID_UPDATE_STR_DOWNLOAD_WARN );
627 msDownloadDescr = loadString( loc, RID_UPDATE_STR_DOWNLOAD_DESCR );
628 msDownloadNotAvail = loadString( loc, RID_UPDATE_STR_DOWNLOAD_UNAVAIL );
629 msDownloading = loadString( loc, RID_UPDATE_STR_DOWNLOADING );
630 msReady2Install = loadString( loc, RID_UPDATE_STR_READY_INSTALL );
631 msCancelMessage = loadString( loc, RID_UPDATE_STR_CANCEL_DOWNLOAD );
632 msInstallMessage = loadString( loc, RID_UPDATE_STR_BEGIN_INSTALL );
633 msInstallError = loadString( loc, RID_UPDATE_STR_INSTALL_ERROR );
634 msOverwriteWarning = loadString( loc, RID_UPDATE_STR_OVERWRITE_WARNING );
635 msPercent = loadString( loc, RID_UPDATE_STR_PERCENT );
636 msReloadWarning = loadString( loc, RID_UPDATE_STR_RELOAD_WARNING );
637 msReloadReload = loadString( loc, RID_UPDATE_STR_RELOAD_RELOAD );
638 msReloadContinue = loadString( loc, RID_UPDATE_STR_RELOAD_CONTINUE );
640 msStatusFL = loadString( loc, RID_UPDATE_FT_STATUS );
641 msDescription = loadString( loc, RID_UPDATE_FT_DESCRIPTION );
643 msClose = loadString( loc, RID_UPDATE_BTN_CLOSE );
644 msDownload = loadString( loc, RID_UPDATE_BTN_DOWNLOAD );
645 msInstall = loadString( loc, RID_UPDATE_BTN_INSTALL );
646 msPauseBtn = loadString( loc, RID_UPDATE_BTN_PAUSE );
647 msResumeBtn = loadString( loc, RID_UPDATE_BTN_RESUME );
648 msCancelBtn = loadString( loc, RID_UPDATE_BTN_CANCEL );
650 std::pair<const char*, const char*> RID_UPDATE_BUBBLE[] =
652 { RID_UPDATE_BUBBLE_UPDATE_AVAIL, RID_UPDATE_BUBBLE_T_UPDATE_AVAIL },
653 { RID_UPDATE_BUBBLE_UPDATE_NO_DOWN, RID_UPDATE_BUBBLE_T_UPDATE_NO_DOWN },
654 { RID_UPDATE_BUBBLE_AUTO_START, RID_UPDATE_BUBBLE_T_AUTO_START },
655 { RID_UPDATE_BUBBLE_DOWNLOADING, RID_UPDATE_BUBBLE_T_DOWNLOADING },
656 { RID_UPDATE_BUBBLE_DOWNLOAD_PAUSED, RID_UPDATE_BUBBLE_T_DOWNLOAD_PAUSED },
657 { RID_UPDATE_BUBBLE_ERROR_DOWNLOADING, RID_UPDATE_BUBBLE_T_ERROR_DOWNLOADING },
658 { RID_UPDATE_BUBBLE_DOWNLOAD_AVAIL, RID_UPDATE_BUBBLE_T_DOWNLOAD_AVAIL },
659 { RID_UPDATE_BUBBLE_EXT_UPD_AVAIL, RID_UPDATE_BUBBLE_T_EXT_UPD_AVAIL }
662 static_assert(SAL_N_ELEMENTS(RID_UPDATE_BUBBLE) == UPDATESTATES_COUNT - UPDATESTATE_UPDATE_AVAIL, "mismatch");
664 // all update states before UPDATESTATE_UPDATE_AVAIL don't have a bubble
665 // so we can ignore them
666 for (size_t i = 0; i < SAL_N_ELEMENTS(RID_UPDATE_BUBBLE); ++i)
668 msBubbleTexts[i] = loadString(loc, RID_UPDATE_BUBBLE[i].first);
669 msBubbleTitles[i] = loadString(loc, RID_UPDATE_BUBBLE[i].second);
672 for ( int i=0; i < BUTTON_COUNT; i++ )
674 msButtonIDs[ i ] = "BUTTON_" + OUString::number( i );
679 void UpdateHandler::startThrobber( bool bStart )
681 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
682 uno::Reference< awt::XAnimation > xThrobber( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
684 if ( xThrobber.is() )
686 if ( bStart )
687 xThrobber->startAnimation();
688 else
689 xThrobber->stopAnimation();
692 uno::Reference< awt::XWindow > xWindow( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
693 if (xWindow.is() )
694 xWindow->setVisible( bStart );
698 void UpdateHandler::setControlProperty( const OUString &rCtrlName,
699 const OUString &rPropName,
700 const uno::Any &rPropValue )
702 if ( !mxUpdDlg.is() ) return;
704 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
705 uno::Reference< awt::XControl > xControl( xContainer->getControl( rCtrlName ), uno::UNO_SET_THROW );
706 uno::Reference< awt::XControlModel > xControlModel( xControl->getModel(), uno::UNO_SET_THROW );
707 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
709 try {
710 xPropSet->setPropertyValue( rPropName, rPropValue );
712 catch( const beans::UnknownPropertyException& )
714 OSL_FAIL( "UpdateHandler::setControlProperty: caught an exception!" );
719 void UpdateHandler::showControl( const OUString &rCtrlName, bool bShow )
721 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
723 if ( !xContainer.is() )
725 OSL_FAIL( "UpdateHandler::showControl: could not get control container!" );
726 return;
729 uno::Reference< awt::XWindow > xWindow( xContainer->getControl( rCtrlName ), uno::UNO_QUERY );
730 if ( xWindow.is() )
731 xWindow->setVisible( bShow );
735 void UpdateHandler::focusControl( DialogControls eID )
737 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
739 if ( !xContainer.is() )
741 OSL_FAIL( "UpdateHandler::focusControl: could not get control container!" );
742 return;
745 OSL_ENSURE( (eID < BUTTON_COUNT), "UpdateHandler::focusControl: id too big!" );
747 uno::Reference< awt::XWindow > xWindow( xContainer->getControl( msButtonIDs[static_cast<short>(eID)] ), uno::UNO_QUERY );
748 if ( xWindow.is() )
749 xWindow->setFocus();
753 void UpdateHandler::insertControlModel( uno::Reference< awt::XControlModel > const & rxDialogModel,
754 OUString const & rServiceName,
755 OUString const & rControlName,
756 awt::Rectangle const & rPosSize,
757 uno::Sequence< beans::NamedValue > const & rProps )
759 uno::Reference< lang::XMultiServiceFactory > xFactory (rxDialogModel, uno::UNO_QUERY_THROW);
760 uno::Reference< awt::XControlModel > xModel (xFactory->createInstance (rServiceName), uno::UNO_QUERY_THROW);
761 uno::Reference< beans::XPropertySet > xPropSet (xModel, uno::UNO_QUERY_THROW);
763 for (sal_Int32 i = 0, n = rProps.getLength(); i < n; i++)
765 xPropSet->setPropertyValue (rProps[i].Name, rProps[i].Value);
768 // @see awt/UnoControlDialogElement.idl
769 xPropSet->setPropertyValue( "Name", uno::Any (rControlName) );
770 xPropSet->setPropertyValue( "PositionX", uno::Any (rPosSize.X) );
771 xPropSet->setPropertyValue( "PositionY", uno::Any (rPosSize.Y) );
772 xPropSet->setPropertyValue( "Height", uno::Any (rPosSize.Height) );
773 xPropSet->setPropertyValue( "Width", uno::Any (rPosSize.Width) );
775 // insert by Name into DialogModel container
776 uno::Reference< container::XNameContainer > xContainer (rxDialogModel, uno::UNO_QUERY_THROW);
777 xContainer->insertByName( rControlName, uno::Any (uno::Reference< uno::XInterface >(xModel, uno::UNO_QUERY)));
781 void UpdateHandler::setFullVersion( OUString& rString )
783 uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider(
784 css::configuration::theDefaultProvider::get( mxContext ) );
786 beans::PropertyValue aProperty;
787 aProperty.Name = "nodepath";
788 aProperty.Value <<= OUString("org.openoffice.Setup/Product");
790 uno::Sequence< uno::Any > aArgumentList( 1 );
791 aArgumentList[0] <<= aProperty;
793 uno::Reference< uno::XInterface > xConfigAccess = xConfigurationProvider->createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess",
794 aArgumentList );
796 uno::Reference< container::XNameAccess > xNameAccess( xConfigAccess, uno::UNO_QUERY_THROW );
798 OUString aProductVersion;
799 xNameAccess->getByName("ooSetupVersion") >>= aProductVersion;
800 OUString aProductFullVersion;
801 xNameAccess->getByName("ooSetupVersionAboutBox") >>= aProductFullVersion;
802 rString = rString.replaceFirst( aProductVersion, aProductFullVersion );
806 bool UpdateHandler::showWarning( const OUString &rWarningText ) const
808 bool bRet = false;
810 uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
811 if ( !xControl.is() ) return bRet;
813 uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
814 if ( !xPeer.is() ) return bRet;
816 uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
817 if ( !xToolkit.is() ) return bRet;
819 awt::WindowDescriptor aDescriptor;
821 sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
822 nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
823 nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
825 aDescriptor.Type = awt::WindowClass_MODALTOP;
826 aDescriptor.WindowServiceName = "warningbox";
827 aDescriptor.ParentIndex = -1;
828 aDescriptor.Parent = xPeer;
829 aDescriptor.Bounds = awt::Rectangle( 10, 10, 250, 150 );
830 aDescriptor.WindowAttributes = nWindowAttributes;
832 uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
833 if ( xMsgBox.is() )
835 mbShowsMessageBox = true;
836 sal_Int16 nRet;
837 // xMsgBox->setCaptionText( msCancelTitle );
838 xMsgBox->setMessageText( rWarningText );
839 nRet = xMsgBox->execute();
840 if ( nRet == 2 ) // RET_YES == 2
841 bRet = true;
842 mbShowsMessageBox = false;
845 uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
846 if ( xComponent.is() )
847 xComponent->dispose();
849 return bRet;
853 bool UpdateHandler::showWarning( const OUString &rWarningText,
854 const OUString &rBtnText_1,
855 const OUString &rBtnText_2 ) const
857 bool bRet = false;
859 uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
860 if ( !xControl.is() ) return bRet;
862 uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
863 if ( !xPeer.is() ) return bRet;
865 uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
866 if ( !xToolkit.is() ) return bRet;
868 awt::WindowDescriptor aDescriptor;
870 sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
871 nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
872 nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
874 aDescriptor.Type = awt::WindowClass_MODALTOP;
875 aDescriptor.WindowServiceName = "warningbox";
876 aDescriptor.ParentIndex = -1;
877 aDescriptor.Parent = xPeer;
878 aDescriptor.Bounds = awt::Rectangle( 10, 10, 250, 150 );
879 aDescriptor.WindowAttributes = nWindowAttributes;
881 uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
882 if ( xMsgBox.is() )
884 uno::Reference< awt::XVclContainer > xMsgBoxCtrls( xMsgBox, uno::UNO_QUERY );
885 if ( xMsgBoxCtrls.is() )
887 uno::Sequence< uno::Reference< awt::XWindow > > xChildren = xMsgBoxCtrls->getWindows();
889 for ( long i=0; i < xChildren.getLength(); i++ )
891 uno::Reference< awt::XVclWindowPeer > xMsgBoxCtrl( xChildren[i], uno::UNO_QUERY );
892 if ( xMsgBoxCtrl.is() )
894 bool bIsDefault = true;
895 uno::Any aValue = xMsgBoxCtrl->getProperty( "DefaultButton" );
896 aValue >>= bIsDefault;
897 if ( bIsDefault )
898 xMsgBoxCtrl->setProperty( "Text", uno::Any( rBtnText_1 ) );
899 else
900 xMsgBoxCtrl->setProperty( "Text", uno::Any( rBtnText_2 ) );
905 sal_Int16 nRet;
906 // xMsgBox->setCaptionText( msCancelTitle );
907 mbShowsMessageBox = true;
908 xMsgBox->setMessageText( rWarningText );
909 nRet = xMsgBox->execute();
910 if ( nRet == 2 ) // RET_YES == 2
911 bRet = true;
913 mbShowsMessageBox = false;
916 uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
917 if ( xComponent.is() )
918 xComponent->dispose();
920 return bRet;
924 bool UpdateHandler::showOverwriteWarning( const OUString& rFileName ) const
926 return showWarning(
927 (msReloadWarning
928 .replaceAll( "%FILENAME", rFileName )
929 .replaceAll( "%DOWNLOAD_PATH", msDownloadPath )),
930 msReloadContinue, msReloadReload );
934 bool UpdateHandler::showOverwriteWarning() const
936 return showWarning( msOverwriteWarning );
940 #define BUTTON_HEIGHT 14
941 #define BUTTON_WIDTH 50
942 #define BUTTON_X_OFFSET 7
943 #define BUTTON_Y_OFFSET 3
944 #define LABEL_HEIGHT 10
946 #define DIALOG_WIDTH 300
947 #define DIALOG_BORDER 5
948 #define INNER_BORDER 3
949 #define TEXT_OFFSET 1
950 #define BOX_HEIGHT1 ( LABEL_HEIGHT + 3*BUTTON_HEIGHT + 2*BUTTON_Y_OFFSET + 2*INNER_BORDER )
951 #define BOX_HEIGHT2 50
952 #define EDIT_WIDTH ( DIALOG_WIDTH - 2 * DIALOG_BORDER )
953 #define BOX1_BTN_X ( DIALOG_BORDER + EDIT_WIDTH - BUTTON_WIDTH - INNER_BORDER )
954 #define BOX1_BTN_Y ( DIALOG_BORDER + LABEL_HEIGHT + INNER_BORDER)
955 #define THROBBER_WIDTH 16
956 #define THROBBER_HEIGHT 16
957 #define THROBBER_X_POS ( DIALOG_BORDER + 8 )
958 #define THROBBER_Y_POS ( DIALOG_BORDER + 23 )
959 #define BUTTON_BAR_HEIGHT 24
960 #define LABEL_OFFSET ( LABEL_HEIGHT + 4 )
961 #define DIALOG_HEIGHT ( BOX_HEIGHT1 + BOX_HEIGHT2 + LABEL_OFFSET + BUTTON_BAR_HEIGHT + 3 * DIALOG_BORDER )
962 #define LABEL_Y_POS ( 2 * DIALOG_BORDER + BOX_HEIGHT1 )
963 #define EDIT2_Y_POS ( LABEL_Y_POS + LABEL_HEIGHT )
964 #define BUTTON_BAR_Y_POS ( EDIT2_Y_POS + DIALOG_BORDER + BOX_HEIGHT2 )
965 #define BUTTON_Y_POS ( BUTTON_BAR_Y_POS + 8 )
966 #define CLOSE_BTN_X ( DIALOG_WIDTH - DIALOG_BORDER - BUTTON_WIDTH )
967 #define INSTALL_BTN_X ( CLOSE_BTN_X - 2 * BUTTON_X_OFFSET - BUTTON_WIDTH )
968 #define DOWNLOAD_BTN_X ( INSTALL_BTN_X - BUTTON_X_OFFSET - BUTTON_WIDTH )
969 #define PROGRESS_WIDTH 80
970 #define PROGRESS_HEIGHT 10
971 #define PROGRESS_X_POS ( DIALOG_BORDER + 8 )
972 #define PROGRESS_Y_POS ( DIALOG_BORDER + 2*LABEL_OFFSET )
975 void UpdateHandler::showControls( short nControls )
977 // The buttons from CANCEL_BUTTON to RESUME_BUTTON will be shown or
978 // hidden on demand
979 short nShiftMe;
980 for ( int i = 0; i <= int(RESUME_BUTTON); i++ )
982 nShiftMe = static_cast<short>(nControls >> i);
983 showControl( msButtonIDs[i], static_cast<bool>(nShiftMe & 0x01) );
986 nShiftMe = static_cast<short>(nControls >> THROBBER_CTRL);
987 startThrobber( static_cast<bool>(nShiftMe & 0x01) );
989 nShiftMe = static_cast<short>(nControls >> PROGRESS_CTRL);
990 showControl( CTRL_PROGRESS, static_cast<bool>(nShiftMe & 0x01) );
991 showControl( TEXT_PERCENT, static_cast<bool>(nShiftMe & 0x01) );
993 // Status text needs to be smaller, when there are buttons at the right side of the dialog
994 if ( ( nControls & ( (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) ) ) != 0 )
995 setControlProperty( TEXT_STATUS, "Width", uno::Any( sal_Int32(EDIT_WIDTH - BUTTON_WIDTH - 2*INNER_BORDER - TEXT_OFFSET ) ) );
996 else
997 setControlProperty( TEXT_STATUS, "Width", uno::Any( sal_Int32(EDIT_WIDTH - 2*TEXT_OFFSET ) ) );
999 // Status text needs to be taller, when we show the progress bar
1000 if ( ( nControls & ( 1<<PROGRESS_CTRL ) ) != 0 )
1001 setControlProperty( TEXT_STATUS, "Height", uno::Any( sal_Int32(LABEL_HEIGHT) ) );
1002 else
1003 setControlProperty( TEXT_STATUS, "Height", uno::Any( sal_Int32(BOX_HEIGHT1 - 4*TEXT_OFFSET - LABEL_HEIGHT ) ) );
1007 void UpdateHandler::createDialog()
1009 if ( !mxContext.is() )
1011 OSL_ASSERT( false );
1012 return;
1015 if( mxContext.is() )
1017 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( mxContext );
1018 xDesktop->addTerminateListener( this );
1021 loadStrings();
1023 uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_SET_THROW );
1024 uno::Reference< awt::XControlModel > xControlModel( xFactory->createInstanceWithContext(
1025 "com.sun.star.awt.UnoControlDialogModel",
1026 mxContext), uno::UNO_QUERY_THROW );
1028 // @see awt/UnoControlDialogModel.idl
1029 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
1031 xPropSet->setPropertyValue( "Title", uno::Any( msDlgTitle ) );
1032 xPropSet->setPropertyValue( "Closeable", uno::Any( true ) );
1033 xPropSet->setPropertyValue( "Enabled", uno::Any( true ) );
1034 xPropSet->setPropertyValue( "Moveable", uno::Any( true ) );
1035 xPropSet->setPropertyValue( "Sizeable", uno::Any( true ) );
1036 xPropSet->setPropertyValue( "DesktopAsParent", uno::Any( true ) );
1037 xPropSet->setPropertyValue( "PositionX", uno::Any(sal_Int32( 100 )) );
1038 xPropSet->setPropertyValue( "PositionY", uno::Any(sal_Int32( 100 )) );
1039 xPropSet->setPropertyValue( "Width", uno::Any(sal_Int32( DIALOG_WIDTH )) );
1040 xPropSet->setPropertyValue( "Height", uno::Any(sal_Int32( DIALOG_HEIGHT )) );
1041 xPropSet->setPropertyValue( "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DLG ) );
1043 { // Label (fixed text) <status>
1044 uno::Sequence< beans::NamedValue > aProps { { "Label", uno::Any( msStatusFL ) } };
1046 insertControlModel( xControlModel, FIXED_TEXT_MODEL, "fixedLineStatus",
1047 awt::Rectangle( DIALOG_BORDER+1, DIALOG_BORDER, EDIT_WIDTH-2, LABEL_HEIGHT ),
1048 aProps );
1050 { // box around <status> text
1051 uno::Sequence< beans::NamedValue > aProps;
1053 insertControlModel( xControlModel, GROUP_BOX_MODEL, "StatusBox",
1054 awt::Rectangle( DIALOG_BORDER, DIALOG_BORDER + LABEL_HEIGHT, EDIT_WIDTH, BOX_HEIGHT1 - LABEL_HEIGHT ),
1055 aProps );
1057 { // Text (multiline edit) <status>
1058 uno::Sequence< beans::NamedValue > aProps
1060 { "Text", uno::Any( substVariables(msChecking) ) },
1061 { "Border", uno::Any( sal_Int16( 0 ) ) },
1062 { "PaintTransparent", uno::Any( true ) },
1063 { "MultiLine", uno::Any( true ) },
1064 { "ReadOnly", uno::Any( true ) },
1065 { "AutoVScroll", uno::Any( true ) },
1066 { "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_STATUS ) }
1069 insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_STATUS,
1070 awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
1071 DIALOG_BORDER + LABEL_HEIGHT + TEXT_OFFSET,
1072 EDIT_WIDTH - 2*TEXT_OFFSET,
1073 BOX_HEIGHT1 - 4*TEXT_OFFSET - LABEL_HEIGHT ),
1074 aProps );
1076 { // Text (edit) <percent>
1077 uno::Sequence< beans::NamedValue > aProps
1079 { "Text", uno::Any( msPercent ) },
1080 { "Border", uno::Any( sal_Int16( 0 ) ) },
1081 { "PaintTransparent", uno::Any( true ) },
1082 { "ReadOnly", uno::Any( true ) },
1085 insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_PERCENT,
1086 awt::Rectangle( PROGRESS_X_POS + PROGRESS_WIDTH + DIALOG_BORDER,
1087 PROGRESS_Y_POS,
1088 EDIT_WIDTH - PROGRESS_WIDTH - BUTTON_WIDTH - 2*DIALOG_BORDER,
1089 LABEL_HEIGHT ),
1090 aProps );
1092 { // pause button
1093 uno::Sequence< beans::NamedValue > aProps
1095 { "DefaultButton", uno::Any( false ) },
1096 { "Enabled", uno::Any( true ) },
1097 { "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
1098 { "Label", uno::Any( msPauseBtn ) },
1099 { "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_PAUSE ) }
1102 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[PAUSE_BUTTON],
1103 awt::Rectangle( BOX1_BTN_X, BOX1_BTN_Y, BUTTON_WIDTH, BUTTON_HEIGHT ),
1104 aProps );
1106 { // resume button
1107 uno::Sequence< beans::NamedValue > aProps
1109 { "DefaultButton", uno::Any( false ) },
1110 { "Enabled", uno::Any( true ) },
1111 { "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
1112 { "Label", uno::Any( msResumeBtn ) },
1113 { "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_RESUME ) }
1116 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[RESUME_BUTTON],
1117 awt::Rectangle( BOX1_BTN_X,
1118 BOX1_BTN_Y + BUTTON_Y_OFFSET + BUTTON_HEIGHT,
1119 BUTTON_WIDTH,
1120 BUTTON_HEIGHT ),
1121 aProps );
1123 { // abort button
1124 uno::Sequence< beans::NamedValue > aProps
1126 { "DefaultButton", uno::Any( false ) },
1127 { "Enabled", uno::Any( true ) },
1128 { "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
1129 { "Label", uno::Any( msCancelBtn ) },
1130 { "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_CANCEL ) }
1133 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[CANCEL_BUTTON],
1134 awt::Rectangle( BOX1_BTN_X,
1135 BOX1_BTN_Y + (2*(BUTTON_HEIGHT+BUTTON_Y_OFFSET)),
1136 BUTTON_WIDTH,
1137 BUTTON_HEIGHT ),
1138 aProps );
1140 { // Label (FixedText) <description>
1141 uno::Sequence< beans::NamedValue > aProps { { "Label", uno::Any( msDescription ) } };
1143 insertControlModel( xControlModel, FIXED_TEXT_MODEL, "fixedTextDescription",
1144 awt::Rectangle( DIALOG_BORDER+1, LABEL_Y_POS, EDIT_WIDTH-2, LABEL_HEIGHT ),
1145 aProps );
1147 { // box around <description> text
1148 uno::Sequence< beans::NamedValue > aProps;
1150 insertControlModel( xControlModel, GROUP_BOX_MODEL, "DescriptionBox",
1151 awt::Rectangle( DIALOG_BORDER, EDIT2_Y_POS, EDIT_WIDTH, BOX_HEIGHT2 ),
1152 aProps );
1154 { // Text (MultiLineEdit) <description>
1155 uno::Sequence< beans::NamedValue > aProps
1157 { "Text", uno::Any( OUString() ) },
1158 { "Border", uno::Any( sal_Int16( 0 ) ) },
1159 { "PaintTransparent", uno::Any( true ) },
1160 { "MultiLine", uno::Any( true ) },
1161 { "ReadOnly", uno::Any( true ) },
1162 { "AutoVScroll", uno::Any( true ) },
1163 { "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DESCRIPTION ) }
1166 insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_DESCRIPTION,
1167 awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
1168 EDIT2_Y_POS + 2*TEXT_OFFSET,
1169 EDIT_WIDTH - 3*TEXT_OFFSET,
1170 BOX_HEIGHT2 - 3*TEXT_OFFSET ),
1171 aProps );
1173 { // @see awt/UnoControlFixedLineModel.idl
1174 uno::Sequence< beans::NamedValue > aProps { { "Orientation", uno::Any( sal_Int32( 0 ) ) } };
1176 insertControlModel( xControlModel, FIXED_LINE_MODEL, "fixedLine",
1177 awt::Rectangle( 0, BUTTON_BAR_Y_POS, DIALOG_WIDTH, 5 ),
1178 aProps );
1180 { // close button // @see awt/UnoControlButtonModel.idl
1181 uno::Sequence< beans::NamedValue > aProps
1183 { "DefaultButton", uno::Any( false ) },
1184 { "Enabled", uno::Any( true ) },
1185 // [property] short PushButtonType
1186 // with own "ButtonActionListener"
1187 { "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
1188 // with default ActionListener => endDialog().
1189 // setProperty( aProps, 2, "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_CANCEL) ) );
1190 // [property] string Label // only if PushButtonType_STANDARD
1191 { "Label", uno::Any( msClose ) },
1192 { "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_CLOSE ) }
1195 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[ CLOSE_BUTTON ],
1196 awt::Rectangle( CLOSE_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1197 aProps );
1199 { // install button
1200 uno::Sequence< beans::NamedValue > aProps
1202 { "DefaultButton", uno::Any( false ) },
1203 { "Enabled", uno::Any( true ) },
1204 { "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
1205 { "Label", uno::Any( msInstall ) },
1206 { "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_INSTALL ) }
1209 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[INSTALL_BUTTON],
1210 awt::Rectangle( INSTALL_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1211 aProps );
1213 { // download button
1214 uno::Sequence< beans::NamedValue > aProps
1216 { "DefaultButton", uno::Any( false ) },
1217 { "Enabled", uno::Any( true ) },
1218 { "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) },
1219 { "Label", uno::Any( msDownload ) },
1220 { "HelpURL", uno::makeAny<OUString>( INET_HID_SCHEME HID_CHECK_FOR_UPD_DOWNLOAD ) }
1223 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[DOWNLOAD_BUTTON],
1224 awt::Rectangle( DOWNLOAD_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1225 aProps );
1227 { // help button
1228 uno::Sequence< beans::NamedValue > aProps
1230 { "DefaultButton", uno::Any( false ) },
1231 { "Enabled", uno::Any( true ) },
1232 { "PushButtonType", uno::Any( sal_Int16(awt::PushButtonType_HELP) ) }
1235 insertControlModel( xControlModel, BUTTON_MODEL, msButtonIDs[HELP_BUTTON],
1236 awt::Rectangle( DIALOG_BORDER, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1237 aProps );
1239 { // @see awt/UnoControlThrobberModel.idl
1240 uno::Sequence< beans::NamedValue > aProps;
1242 insertControlModel( xControlModel, "com.sun.star.awt.SpinningProgressControlModel", CTRL_THROBBER,
1243 awt::Rectangle( THROBBER_X_POS, THROBBER_Y_POS, THROBBER_WIDTH, THROBBER_HEIGHT),
1244 aProps );
1246 { // @see awt/UnoControlProgressBarModel.idl
1247 uno::Sequence< beans::NamedValue > aProps
1249 { "Enabled", uno::Any( true ) },
1250 { "ProgressValue", uno::Any( sal_Int32( 0 ) ) },
1251 { "ProgressValueMax", uno::Any( sal_Int32( 100 ) ) },
1252 { "ProgressValueMin", uno::Any( sal_Int32( 0 ) ) },
1254 insertControlModel( xControlModel, "com.sun.star.awt.UnoControlProgressBarModel", CTRL_PROGRESS,
1255 awt::Rectangle( PROGRESS_X_POS, PROGRESS_Y_POS, PROGRESS_WIDTH, PROGRESS_HEIGHT ),
1256 aProps);
1259 uno::Reference< awt::XUnoControlDialog > xControl = awt::UnoControlDialog::create( mxContext );
1260 xControl->setModel( xControlModel );
1262 if ( !mbVisible )
1264 xControl->setVisible( false );
1267 xControl->createPeer( nullptr, nullptr );
1269 for ( int i = 0; i < HELP_BUTTON; i++ )
1271 uno::Reference< awt::XButton > xButton ( xControl->getControl( msButtonIDs[i] ), uno::UNO_QUERY);
1272 if (xButton.is())
1274 xButton->setActionCommand( msButtonIDs[i] );
1275 xButton->addActionListener( this );
1280 mxUpdDlg.set( xControl, uno::UNO_QUERY_THROW );
1281 mnLastCtrlState = -1;
1284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */