merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / update / check / updatehdl.cxx
blobbb38c34a0b4e9864396ce06a276d32aac4081dce
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
31 #include "updatehdl.hxx"
32 #include "update.hrc"
34 #include "osl/diagnose.h"
35 #include "osl/thread.hxx"
36 #include "osl/file.hxx"
37 #include "rtl/ustring.hxx"
38 #include "rtl/bootstrap.hxx"
40 #include "com/sun/star/uno/Sequence.h"
42 #include <com/sun/star/style/VerticalAlignment.hpp>
44 #include "com/sun/star/awt/ActionEvent.hpp"
45 #include "com/sun/star/awt/PushButtonType.hpp"
46 #include "com/sun/star/awt/VclWindowPeerAttribute.hpp"
47 #include "com/sun/star/awt/WindowAttribute.hpp"
48 #include "com/sun/star/awt/XButton.hpp"
49 #include "com/sun/star/awt/XControl.hpp"
50 #include "com/sun/star/awt/XControlContainer.hpp"
51 #include "com/sun/star/awt/XMessageBox.hpp"
52 #include "com/sun/star/awt/XThrobber.hpp"
53 #include "com/sun/star/awt/XTopWindow.hpp"
54 #include "com/sun/star/awt/XVclWindowPeer.hpp"
55 #include "com/sun/star/awt/XVclContainer.hpp"
56 #include "com/sun/star/awt/XWindow.hpp"
57 #include "com/sun/star/awt/XWindow2.hpp"
59 #include <com/sun/star/beans/PropertyValue.hpp>
60 #include "com/sun/star/beans/XPropertySet.hpp"
62 #include "com/sun/star/container/XNameContainer.hpp"
64 #include "com/sun/star/frame/XDesktop.hpp"
66 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
67 #include "com/sun/star/task/InteractionRequestStringResolver.hpp"
69 #include <com/sun/star/resource/XResourceBundleLoader.hpp>
71 #include "updatehdl.hrc"
73 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
75 #define COMMAND_CLOSE UNISTRING("close")
77 #define CTRL_THROBBER UNISTRING("throbber")
78 #define CTRL_PROGRESS UNISTRING("progress")
80 #define TEXT_STATUS UNISTRING("text_status")
81 #define TEXT_PERCENT UNISTRING("text_percent")
82 #define TEXT_DESCRIPTION UNISTRING("text_description")
84 #define FIXED_LINE_MODEL UNISTRING("com.sun.star.awt.UnoControlFixedLineModel")
85 #define FIXED_TEXT_MODEL UNISTRING("com.sun.star.awt.UnoControlFixedTextModel")
86 #define EDIT_FIELD_MODEL UNISTRING("com.sun.star.awt.UnoControlEditModel")
87 #define BUTTON_MODEL UNISTRING("com.sun.star.awt.UnoControlButtonModel")
88 #define GROUP_BOX_MODEL UNISTRING("com.sun.star.awt.UnoControlGroupBoxModel")
90 using namespace com::sun::star;
92 //--------------------------------------------------------------------
93 UpdateHandler::UpdateHandler( const uno::Reference< uno::XComponentContext > & rxContext,
94 const rtl::Reference< IActionListener > & rxActionListener ) :
95 mxContext( rxContext ),
96 mxActionListener( rxActionListener ),
97 meCurState( UPDATESTATES_COUNT ),
98 meLastState( UPDATESTATES_COUNT ),
99 mnPercent( 0 ),
100 mnLastCtrlState( -1 ),
101 mbDownloadBtnHasDots( false ),
102 mbVisible( false ),
103 mbStringsLoaded( false ),
104 mbMinimized( false ),
105 mbListenerAdded(false),
106 mbShowsMessageBox(false)
110 //--------------------------------------------------------------------
111 UpdateHandler::~UpdateHandler()
113 mxContext = NULL;
114 mxUpdDlg = NULL;
115 mxInteractionHdl = NULL;
116 mxActionListener = NULL;
119 //--------------------------------------------------------------------
120 void UpdateHandler::enableControls( short nCtrlState )
122 osl::MutexGuard aGuard( maMutex );
124 if ( nCtrlState == mnLastCtrlState )
125 return;
127 bool bEnableControl;
129 short nCurStateVal = nCtrlState;
130 short nOldStateVal = mnLastCtrlState;
132 // the help button should always be the last button in the
133 // enum list und must never be disabled
134 for ( int i=0; i<HELP_BUTTON; i++ )
136 nCurStateVal = (short)(nCtrlState >> i);
137 nOldStateVal = (short)(mnLastCtrlState >> i);
138 if ( ( nCurStateVal & 0x01 ) != ( nOldStateVal & 0x01 ) )
140 bEnableControl = ( ( nCurStateVal & 0x01 ) == 0x01 );
141 setControlProperty( msButtonIDs[i], UNISTRING("Enabled"), uno::Any( bEnableControl ) );
145 mnLastCtrlState = nCtrlState;
148 //--------------------------------------------------------------------
149 void UpdateHandler::setDownloadBtnLabel( bool bAppendDots )
151 osl::MutexGuard aGuard( maMutex );
153 if ( mbDownloadBtnHasDots != bAppendDots )
155 rtl::OUString aLabel( msDownload );
157 if ( bAppendDots )
158 aLabel += UNISTRING( "..." );
160 setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], UNISTRING("Label"), uno::Any( aLabel ) );
161 setControlProperty( msButtonIDs[DOWNLOAD_BUTTON], UNISTRING("HelpURL"), uno::Any( UNISTRING( "HID:" ) + rtl::OUString::valueOf( (sal_Int32) HID_CHECK_FOR_UPD_DOWNLOAD2 ) ) );
163 mbDownloadBtnHasDots = bAppendDots;
167 //--------------------------------------------------------------------
168 void UpdateHandler::setState( UpdateState eState )
170 osl::MutexGuard aGuard( maMutex );
172 meCurState = eState;
174 if ( mxUpdDlg.is() && mbVisible )
175 updateState( meCurState );
178 //--------------------------------------------------------------------
179 bool UpdateHandler::isVisible() const
181 if ( !mxUpdDlg.is() ) return false;
183 uno::Reference< awt::XWindow2 > xWindow( mxUpdDlg, uno::UNO_QUERY );
185 if ( xWindow.is() )
186 return xWindow->isVisible();
187 else
188 return false;
191 //--------------------------------------------------------------------
192 void UpdateHandler::setVisible( bool bVisible )
194 osl::MutexGuard aGuard( maMutex );
196 mbVisible = bVisible;
198 if ( bVisible )
200 if ( !mxUpdDlg.is() )
201 createDialog();
203 // this should never happen, but if it happens we better return here
204 if ( !mxUpdDlg.is() )
205 return;
207 updateState( meCurState );
209 uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
211 if ( xWindow.is() )
212 xWindow->setVisible( bVisible );
214 uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
215 if ( xTopWindow.is() )
217 xTopWindow->toFront();
218 if ( !mbListenerAdded )
220 xTopWindow->addTopWindowListener( this );
221 mbListenerAdded = true;
225 else if ( mxUpdDlg.is() )
227 uno::Reference< awt::XWindow > xWindow( mxUpdDlg, uno::UNO_QUERY );
229 if ( xWindow.is() )
230 xWindow->setVisible( bVisible );
234 //--------------------------------------------------------------------
235 void UpdateHandler::setProgress( sal_Int32 nPercent )
237 if ( nPercent > 100 )
238 nPercent = 100;
239 else if ( nPercent < 0 )
240 nPercent = 0;
242 if ( nPercent != mnPercent )
244 osl::MutexGuard aGuard( maMutex );
246 mnPercent = nPercent;
247 setControlProperty( CTRL_PROGRESS, UNISTRING("ProgressValue"), uno::Any( nPercent ) );
248 setControlProperty( TEXT_PERCENT, UNISTRING("Text"), uno::Any( substVariables(msPercent) ) );
252 //--------------------------------------------------------------------
253 void UpdateHandler::setErrorMessage( const rtl::OUString& rErrorMsg )
255 setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( rErrorMsg ) );
258 //--------------------------------------------------------------------
259 void UpdateHandler::setDownloadFile( const rtl::OUString& rFilePath )
261 sal_Int32 nLast = rFilePath.lastIndexOf( '/' );
262 if ( nLast != -1 )
264 msDownloadFile = rFilePath.copy( nLast+1 );
265 const rtl::OUString aDownloadURL = rFilePath.copy( 0, nLast );
266 osl::FileBase::getSystemPathFromFileURL( aDownloadURL, msDownloadPath );
270 //--------------------------------------------------------------------
271 rtl::OUString UpdateHandler::getBubbleText( UpdateState eState )
273 osl::MutexGuard aGuard( maMutex );
275 rtl::OUString sText;
276 sal_Int32 nIndex = (sal_Int32) eState;
278 loadStrings();
280 if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
281 sText = substVariables( msBubbleTexts[ nIndex - UPDATESTATE_UPDATE_AVAIL ] );
283 return sText;
286 //--------------------------------------------------------------------
287 rtl::OUString UpdateHandler::getBubbleTitle( UpdateState eState )
289 osl::MutexGuard aGuard( maMutex );
291 rtl::OUString sText;
292 sal_Int32 nIndex = (sal_Int32) eState;
294 loadStrings();
296 if ( ( UPDATESTATE_UPDATE_AVAIL <= nIndex ) && ( nIndex < UPDATESTATES_COUNT ) )
297 sText = substVariables( msBubbleTitles[ nIndex - UPDATESTATE_UPDATE_AVAIL] );
299 return sText;
302 //--------------------------------------------------------------------
303 rtl::OUString UpdateHandler::getDefaultInstErrMsg()
305 osl::MutexGuard aGuard( maMutex );
307 loadStrings();
309 return substVariables( msInstallError );
312 // XActionListener
313 //--------------------------------------------------------------------
314 void SAL_CALL UpdateHandler::disposing( const lang::EventObject& rEvt )
315 throw( uno::RuntimeException )
317 if ( rEvt.Source == mxUpdDlg )
318 mxUpdDlg.clear();
321 //--------------------------------------------------------------------
322 void SAL_CALL UpdateHandler::actionPerformed( awt::ActionEvent const & rEvent )
323 throw( uno::RuntimeException )
325 DialogControls eButton = BUTTON_COUNT;
326 for ( int i = 0; i < BUTTON_COUNT; i++ )
328 if ( rEvent.ActionCommand.equals( msButtonIDs[i] ) )
330 eButton = (DialogControls) i;
331 break;
335 if ( rEvent.ActionCommand.equals( COMMAND_CLOSE ) )
337 if ( ( mnLastCtrlState & ( 1 << CLOSE_BUTTON ) ) == ( 1 << CLOSE_BUTTON ) )
338 eButton = CLOSE_BUTTON;
339 else
340 eButton = CANCEL_BUTTON;
343 switch ( eButton ) {
344 case CANCEL_BUTTON:
346 bool bCancel = true;
348 if ( ( meCurState == UPDATESTATE_DOWNLOADING ) ||
349 ( meCurState == UPDATESTATE_DOWNLOAD_PAUSED ) ||
350 ( meCurState == UPDATESTATE_ERROR_DOWNLOADING ) )
351 bCancel = showWarning( msCancelMessage );
353 if ( bCancel )
355 mxActionListener->cancel();
356 setVisible( false );
358 break;
360 case CLOSE_BUTTON:
361 setVisible( false );
362 if ( meCurState == UPDATESTATE_ERROR_CHECKING )
363 mxActionListener->closeAfterFailure();
364 break;
365 case DOWNLOAD_BUTTON:
366 mxActionListener->download();
367 break;
368 case INSTALL_BUTTON:
369 if ( showWarning( msInstallMessage ) )
370 mxActionListener->install();
371 break;
372 case PAUSE_BUTTON:
373 mxActionListener->pause();
374 break;
375 case RESUME_BUTTON:
376 mxActionListener->resume();
377 break;
378 case HELP_BUTTON:
379 break;
380 default:
381 OSL_ENSURE( false, "UpdateHandler::actionPerformed: unknown command!" );
385 // XTopWindowListener
386 //--------------------------------------------------------------------
387 void SAL_CALL UpdateHandler::windowOpened( const lang::EventObject& )
388 throw( uno::RuntimeException )
392 //--------------------------------------------------------------------
393 void SAL_CALL UpdateHandler::windowClosing( const lang::EventObject& e )
394 throw( uno::RuntimeException )
396 awt::ActionEvent aActionEvt;
397 aActionEvt.ActionCommand = COMMAND_CLOSE;
398 aActionEvt.Source = e.Source;
400 actionPerformed( aActionEvt );
403 //--------------------------------------------------------------------
404 void SAL_CALL UpdateHandler::windowClosed( const lang::EventObject& )
405 throw( uno::RuntimeException )
409 //--------------------------------------------------------------------
410 void SAL_CALL UpdateHandler::windowMinimized( const lang::EventObject& )
411 throw( uno::RuntimeException )
413 mbMinimized = true;
416 //--------------------------------------------------------------------
417 void SAL_CALL UpdateHandler::windowNormalized( const lang::EventObject& )
418 throw( uno::RuntimeException )
420 mbMinimized = false;
423 //--------------------------------------------------------------------
424 void SAL_CALL UpdateHandler::windowActivated( const lang::EventObject& )
425 throw( uno::RuntimeException )
429 //--------------------------------------------------------------------
430 void SAL_CALL UpdateHandler::windowDeactivated( const lang::EventObject& )
431 throw( uno::RuntimeException )
435 // XInteractionHandler
436 //------------------------------------------------------------------------------
437 void SAL_CALL UpdateHandler::handle( uno::Reference< task::XInteractionRequest > const & rRequest)
438 throw (uno::RuntimeException)
440 if ( !mxInteractionHdl.is() )
442 if( !mxContext.is() )
443 throw uno::RuntimeException( UNISTRING( "UpdateHandler:: empty component context" ), *this );
445 uno::Reference< lang::XMultiComponentFactory > xServiceManager(mxContext->getServiceManager());
447 if( !xServiceManager.is() )
448 throw uno::RuntimeException( UNISTRING( "UpdateHandler: unable to obtain service manager from component context" ), *this );
450 mxInteractionHdl = uno::Reference<task::XInteractionHandler> (
451 xServiceManager->createInstanceWithContext(
452 UNISTRING( "com.sun.star.task.InteractionHandler" ),
453 mxContext),
454 uno::UNO_QUERY_THROW);
455 if( !mxInteractionHdl.is() )
456 throw uno::RuntimeException( UNISTRING( "UpdateHandler:: could not get default interaction handler" ), *this );
458 uno::Reference< task::XInteractionRequestStringResolver > xStrResolver =
459 task::InteractionRequestStringResolver::create( mxContext );
460 beans::Optional< ::rtl::OUString > aErrorText = xStrResolver->getStringFromInformationalRequest( rRequest );
461 if ( aErrorText.IsPresent )
463 setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( aErrorText.Value ) );
465 uno::Sequence< uno::Reference< task::XInteractionContinuation > > xContinuations = rRequest->getContinuations();
466 if ( xContinuations.getLength() == 1 )
468 if ( meCurState == UPDATESTATE_CHECKING )
469 setState( UPDATESTATE_ERROR_CHECKING );
470 else if ( meCurState == UPDATESTATE_DOWNLOADING )
471 setState( UPDATESTATE_ERROR_DOWNLOADING );
473 xContinuations[0]->select();
475 else
476 mxInteractionHdl->handle( rRequest );
478 else
479 mxInteractionHdl->handle( rRequest );
482 //------------------------------------------------------------------------------
483 // XTerminateListener
484 //------------------------------------------------------------------------------
485 void SAL_CALL UpdateHandler::queryTermination( const lang::EventObject& )
486 throw ( frame::TerminationVetoException, uno::RuntimeException )
488 if ( mbShowsMessageBox )
490 uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
491 if ( xTopWindow.is() )
492 xTopWindow->toFront();
494 throw frame::TerminationVetoException(
495 UNISTRING("The office cannot be closed while displaying a warning!"),
496 uno::Reference<XInterface>(static_cast<frame::XTerminateListener*>(this), uno::UNO_QUERY));
498 else
499 setVisible( false );
502 //------------------------------------------------------------------------------
503 void SAL_CALL UpdateHandler::notifyTermination( const lang::EventObject& )
504 throw ( uno::RuntimeException )
506 osl::MutexGuard aGuard( maMutex );
508 if ( mxUpdDlg.is() )
510 uno::Reference< awt::XTopWindow > xTopWindow( mxUpdDlg, uno::UNO_QUERY );
511 if ( xTopWindow.is() )
512 xTopWindow->removeTopWindowListener( this );
514 uno::Reference< lang::XComponent > xComponent( mxUpdDlg, uno::UNO_QUERY );
515 if ( xComponent.is() )
516 xComponent->dispose();
518 mxUpdDlg.clear();
522 //--------------------------------------------------------------------
523 //--------------------------------------------------------------------
524 //--------------------------------------------------------------------
525 void UpdateHandler::updateState( UpdateState eState )
527 if ( meLastState == eState )
528 return;
530 if ( isVisible() )
531 {} // ToTop();
533 rtl::OUString sText;
535 switch ( eState )
537 case UPDATESTATE_CHECKING:
538 showControls( (1<<CANCEL_BUTTON) + (1<<THROBBER_CTRL) );
539 enableControls( 1<<CANCEL_BUTTON );
540 setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msChecking) ) );
541 setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( rtl::OUString() ) );
542 focusControl( CANCEL_BUTTON );
543 break;
544 case UPDATESTATE_ERROR_CHECKING:
545 showControls( 0 );
546 enableControls( 1 << CLOSE_BUTTON );
547 setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msCheckingError) ) );
548 focusControl( CLOSE_BUTTON );
549 break;
550 case UPDATESTATE_UPDATE_AVAIL:
551 showControls( 0 );
552 enableControls( ( 1 << CLOSE_BUTTON ) + ( 1 << DOWNLOAD_BUTTON ) );
553 setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msUpdFound) ) );
555 sText = substVariables(msDownloadWarning);
556 if ( msDescriptionMsg.getLength() )
557 sText += UNISTRING("\n\n") + msDescriptionMsg;
558 setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( sText ) );
560 setDownloadBtnLabel( false );
561 focusControl( DOWNLOAD_BUTTON );
562 break;
563 case UPDATESTATE_UPDATE_NO_DOWNLOAD:
564 showControls( 0 );
565 enableControls( ( 1 << CLOSE_BUTTON ) + ( 1 << DOWNLOAD_BUTTON ) );
566 setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msUpdFound) ) );
568 sText = substVariables(msDownloadNotAvail);
569 if ( msDescriptionMsg.getLength() )
570 sText += UNISTRING("\n\n") + msDescriptionMsg;
571 setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( sText ) );
573 setDownloadBtnLabel( true );
574 focusControl( DOWNLOAD_BUTTON );
575 break;
576 case UPDATESTATE_NO_UPDATE_AVAIL:
577 case UPDATESTATE_EXT_UPD_AVAIL: // will only be set, when there are no office updates avail
578 showControls( 0 );
579 enableControls( 1 << CLOSE_BUTTON );
580 setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msNoUpdFound) ) );
581 setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( rtl::OUString() ) );
582 focusControl( CLOSE_BUTTON );
583 break;
584 case UPDATESTATE_DOWNLOADING:
585 showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
586 enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) );
587 setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msDownloading) ) );
588 setControlProperty( TEXT_PERCENT, UNISTRING("Text"), uno::Any( substVariables(msPercent) ) );
589 setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( substVariables(msDownloadWarning) ) );
590 setControlProperty( CTRL_PROGRESS, UNISTRING("ProgressValue"), uno::Any( mnPercent ) );
591 focusControl( CLOSE_BUTTON );
592 break;
593 case UPDATESTATE_DOWNLOAD_PAUSED:
594 showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
595 enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) + (1<<RESUME_BUTTON) );
596 setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msDownloadPause) ) );
597 setControlProperty( TEXT_PERCENT, UNISTRING("Text"), uno::Any( substVariables(msPercent) ) );
598 setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( substVariables(msDownloadWarning) ) );
599 setControlProperty( CTRL_PROGRESS, UNISTRING("ProgressValue"), uno::Any( mnPercent ) );
600 focusControl( CLOSE_BUTTON );
601 break;
602 case UPDATESTATE_ERROR_DOWNLOADING:
603 showControls( (1<<PROGRESS_CTRL) + (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) );
604 enableControls( (1<<CLOSE_BUTTON) + (1<<CANCEL_BUTTON) );
605 setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msDownloadError) ) );
606 focusControl( CLOSE_BUTTON );
607 break;
608 case UPDATESTATE_DOWNLOAD_AVAIL:
609 showControls( 0 );
610 enableControls( (1<<CLOSE_BUTTON) + (1<<INSTALL_BUTTON) );
611 setControlProperty( TEXT_STATUS, UNISTRING("Text"), uno::Any( substVariables(msReady2Install) ) );
612 setControlProperty( TEXT_DESCRIPTION, UNISTRING("Text"), uno::Any( substVariables(msDownloadDescr) ) );
613 focusControl( INSTALL_BUTTON );
614 break;
615 case UPDATESTATE_AUTO_START:
616 case UPDATESTATES_COUNT:
617 //do nothing, only count!
618 break;
621 meLastState = eState;
624 //--------------------------------------------------------------------
625 void UpdateHandler::searchAndReplaceAll( rtl::OUString &rText,
626 const rtl::OUString &rWhat,
627 const rtl::OUString &rWith ) const
629 sal_Int32 nIndex = rText.indexOf( rWhat );
631 while ( nIndex != -1 )
633 rText = rText.replaceAt( nIndex, rWhat.getLength(), rWith );
634 nIndex = rText.indexOf( rWhat, nIndex );
638 //--------------------------------------------------------------------
639 rtl::OUString UpdateHandler::loadString( const uno::Reference< resource::XResourceBundle > xBundle,
640 sal_Int32 nResourceId ) const
642 rtl::OUString sString;
643 rtl::OUString sKey = UNISTRING( "string:" ) + rtl::OUString::valueOf( nResourceId );
647 OSL_VERIFY( xBundle->getByName( sKey ) >>= sString );
649 catch( const uno::Exception& )
651 OSL_ENSURE( false, "UpdateHandler::loadString: caught an exception!" );
652 sString = UNISTRING("Missing ") + sKey;
655 return sString;
658 rtl::OUString UpdateHandler::substVariables( const rtl::OUString &rSource ) const
660 rtl::OUString sString( rSource );
662 searchAndReplaceAll( sString, UNISTRING( "%NEXTVERSION" ), msNextVersion );
663 searchAndReplaceAll( sString, UNISTRING( "%DOWNLOAD_PATH" ), msDownloadPath );
664 searchAndReplaceAll( sString, UNISTRING( "%FILE_NAME" ), msDownloadFile );
665 searchAndReplaceAll( sString, UNISTRING( "%PERCENT" ), rtl::OUString::valueOf( mnPercent ) );
667 return sString;
670 //--------------------------------------------------------------------
671 void UpdateHandler::loadStrings()
673 if ( mbStringsLoaded )
674 return;
675 else
676 mbStringsLoaded = true;
678 uno::Reference< resource::XResourceBundleLoader > xLoader;
681 uno::Any aValue( mxContext->getValueByName(
682 UNISTRING( "/singletons/com.sun.star.resource.OfficeResourceLoader" ) ) );
683 OSL_VERIFY( aValue >>= xLoader );
685 catch( const uno::Exception& )
687 OSL_ENSURE( false, "UpdateHandler::loadStrings: could not create the resource loader!" );
690 if ( !xLoader.is() ) return;
692 uno::Reference< resource::XResourceBundle > xBundle;
696 xBundle = xLoader->loadBundle_Default( UNISTRING( "upd" ) );
698 catch( const resource::MissingResourceException& )
700 OSL_ENSURE( false, "UpdateHandler::loadStrings: missing the resource bundle!" );
703 if ( !xBundle.is() ) return;
705 msChecking = loadString( xBundle, RID_UPDATE_STR_CHECKING );
706 msCheckingError = loadString( xBundle, RID_UPDATE_STR_CHECKING_ERR );
707 msNoUpdFound = loadString( xBundle, RID_UPDATE_STR_NO_UPD_FOUND );
709 msUpdFound = loadString( xBundle, RID_UPDATE_STR_UPD_FOUND );
710 setFullVersion( msUpdFound );
712 msDlgTitle = loadString( xBundle, RID_UPDATE_STR_DLG_TITLE );
713 msDownloadPause = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_PAUSE );
714 msDownloadError = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_ERR );
715 msDownloadWarning = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_WARN );
716 msDownloadDescr = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_DESCR );
717 msDownloadNotAvail = loadString( xBundle, RID_UPDATE_STR_DOWNLOAD_UNAVAIL );
718 msDownloading = loadString( xBundle, RID_UPDATE_STR_DOWNLOADING );
719 msReady2Install = loadString( xBundle, RID_UPDATE_STR_READY_INSTALL );
720 msCancelTitle = loadString( xBundle, RID_UPDATE_STR_CANCEL_TITLE );
721 msCancelMessage = loadString( xBundle, RID_UPDATE_STR_CANCEL_DOWNLOAD );
722 msInstallMessage = loadString( xBundle, RID_UPDATE_STR_BEGIN_INSTALL );
723 msInstallNow = loadString( xBundle, RID_UPDATE_STR_INSTALL_NOW );
724 msInstallLater = loadString( xBundle, RID_UPDATE_STR_INSTALL_LATER );
725 msInstallError = loadString( xBundle, RID_UPDATE_STR_INSTALL_ERROR );
726 msOverwriteWarning = loadString( xBundle, RID_UPDATE_STR_OVERWRITE_WARNING );
727 msPercent = loadString( xBundle, RID_UPDATE_STR_PERCENT );
728 msReloadWarning = loadString( xBundle, RID_UPDATE_STR_RELOAD_WARNING );
729 msReloadReload = loadString( xBundle, RID_UPDATE_STR_RELOAD_RELOAD );
730 msReloadContinue = loadString( xBundle, RID_UPDATE_STR_RELOAD_CONTINUE );
732 msStatusFL = loadString( xBundle, RID_UPDATE_FT_STATUS );
733 msDescription = loadString( xBundle, RID_UPDATE_FT_DESCRIPTION );
735 msClose = loadString( xBundle, RID_UPDATE_BTN_CLOSE );
736 msDownload = loadString( xBundle, RID_UPDATE_BTN_DOWNLOAD );
737 msInstall = loadString( xBundle, RID_UPDATE_BTN_INSTALL );
738 msPauseBtn = loadString( xBundle, RID_UPDATE_BTN_PAUSE );
739 msResumeBtn = loadString( xBundle, RID_UPDATE_BTN_RESUME );
740 msCancelBtn = loadString( xBundle, RID_UPDATE_BTN_CANCEL );
742 // all update states before UPDATESTATE_UPDATE_AVAIL don't have a bubble
743 // so we can ignore them
744 for ( int i=0; i < (int)(UPDATESTATES_COUNT - UPDATESTATE_UPDATE_AVAIL); i++ )
746 msBubbleTexts[ i ] = loadString( xBundle, RID_UPDATE_BUBBLE_TEXT_START + i );
747 msBubbleTitles[ i ] = loadString( xBundle, RID_UPDATE_BUBBLE_T_TEXT_START + i );
750 for ( int i=0; i < BUTTON_COUNT; i++ )
752 msButtonIDs[ i ] = UNISTRING("BUTTON_") + rtl::OUString::valueOf( (sal_Int32) i );
757 //--------------------------------------------------------------------
758 void UpdateHandler::startThrobber( bool bStart )
760 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
761 uno::Reference< awt::XThrobber > xThrobber( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
763 if ( xThrobber.is() )
765 if ( bStart )
766 xThrobber->start();
767 else
768 xThrobber->stop();
771 uno::Reference< awt::XWindow > xWindow( xContainer->getControl( CTRL_THROBBER ), uno::UNO_QUERY );
772 if (xWindow.is() )
773 xWindow->setVisible( bStart );
776 //--------------------------------------------------------------------
777 void UpdateHandler::setControlProperty( const rtl::OUString &rCtrlName,
778 const rtl::OUString &rPropName,
779 const uno::Any &rPropValue )
781 if ( !mxUpdDlg.is() ) return;
783 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
784 uno::Reference< awt::XControl > xControl( xContainer->getControl( rCtrlName ), uno::UNO_QUERY_THROW );
785 uno::Reference< awt::XControlModel > xControlModel( xControl->getModel(), uno::UNO_QUERY_THROW );
786 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
788 try {
789 xPropSet->setPropertyValue( rPropName, rPropValue );
791 catch( const beans::UnknownPropertyException& )
793 OSL_ENSURE( false, "UpdateHandler::setControlProperty: caught an exception!" );
797 //--------------------------------------------------------------------
798 void UpdateHandler::showControl( const rtl::OUString &rCtrlName, bool bShow )
800 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
802 if ( !xContainer.is() )
804 OSL_ENSURE( false, "UpdateHandler::showControl: could not get control container!" );
805 return;
808 uno::Reference< awt::XWindow > xWindow( xContainer->getControl( rCtrlName ), uno::UNO_QUERY );
809 if ( xWindow.is() )
810 xWindow->setVisible( bShow );
813 //--------------------------------------------------------------------
814 void UpdateHandler::focusControl( DialogControls eID )
816 uno::Reference< awt::XControlContainer > xContainer( mxUpdDlg, uno::UNO_QUERY );
818 if ( !xContainer.is() )
820 OSL_ENSURE( false, "UpdateHandler::focusControl: could not get control container!" );
821 return;
824 OSL_ENSURE( (eID < BUTTON_COUNT), "UpdateHandler::focusControl: id to big!" );
826 uno::Reference< awt::XWindow > xWindow( xContainer->getControl( msButtonIDs[(short)eID] ), uno::UNO_QUERY );
827 if ( xWindow.is() )
828 xWindow->setFocus();
831 //--------------------------------------------------------------------
832 void UpdateHandler::insertControlModel( uno::Reference< awt::XControlModel > & rxDialogModel,
833 rtl::OUString const & rServiceName,
834 rtl::OUString const & rControlName,
835 awt::Rectangle const & rPosSize,
836 uno::Sequence< beans::NamedValue > const & rProps )
838 uno::Reference< lang::XMultiServiceFactory > xFactory (rxDialogModel, uno::UNO_QUERY_THROW);
839 uno::Reference< awt::XControlModel > xModel (xFactory->createInstance (rServiceName), uno::UNO_QUERY_THROW);
840 uno::Reference< beans::XPropertySet > xPropSet (xModel, uno::UNO_QUERY_THROW);
842 for (sal_Int32 i = 0, n = rProps.getLength(); i < n; i++)
844 xPropSet->setPropertyValue (rProps[i].Name, rProps[i].Value);
847 // @see awt/UnoControlDialogElement.idl
848 xPropSet->setPropertyValue( UNISTRING("Name"), uno::Any (rControlName) );
849 xPropSet->setPropertyValue( UNISTRING("PositionX"), uno::Any (rPosSize.X) );
850 xPropSet->setPropertyValue( UNISTRING("PositionY"), uno::Any (rPosSize.Y) );
851 xPropSet->setPropertyValue( UNISTRING("Height"), uno::Any (rPosSize.Height) );
852 xPropSet->setPropertyValue( UNISTRING("Width"), uno::Any (rPosSize.Width) );
854 // insert by Name into DialogModel container
855 uno::Reference< container::XNameContainer > xContainer (rxDialogModel, uno::UNO_QUERY_THROW);
856 xContainer->insertByName( rControlName, uno::Any (uno::Reference< uno::XInterface >(xModel, uno::UNO_QUERY)));
859 //--------------------------------------------------------------------
860 void UpdateHandler::setFullVersion( rtl::OUString& rString )
862 if( !mxContext.is() )
863 throw uno::RuntimeException( UNISTRING( "getProductName: empty component context" ), *this );
865 uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager() );
867 if( !xServiceManager.is() )
868 throw uno::RuntimeException( UNISTRING( "getProductName: unable to obtain service manager from component context" ), *this );
870 uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider(
871 xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.configuration.ConfigurationProvider" ), mxContext ),
872 uno::UNO_QUERY_THROW);
874 beans::PropertyValue aProperty;
875 aProperty.Name = UNISTRING( "nodepath" );
876 aProperty.Value = uno::makeAny( UNISTRING("org.openoffice.Setup/Product") );
878 uno::Sequence< uno::Any > aArgumentList( 1 );
879 aArgumentList[0] = uno::makeAny( aProperty );
881 uno::Reference< uno::XInterface > xConfigAccess;
882 xConfigAccess = xConfigurationProvider->createInstanceWithArguments( UNISTRING("com.sun.star.configuration.ConfigurationAccess"),
883 aArgumentList );
885 uno::Reference< container::XNameAccess > xNameAccess( xConfigAccess, uno::UNO_QUERY_THROW );
887 rtl::OUString aProductVersion;
888 rtl::OUString aProductFullVersion;
890 xNameAccess->getByName(UNISTRING("ooSetupVersion")) >>= aProductVersion;
891 aProductFullVersion = aProductVersion;
893 sal_Int32 nVerIndex = rString.indexOf( aProductVersion );
894 if ( nVerIndex != -1 )
896 rtl::OUString aPackageVersion = UNISTRING( "${$OOO_BASE_DIR/program/" SAL_CONFIGFILE("version") ":OOOPackageVersion}" );
897 rtl::Bootstrap::expandMacros( aPackageVersion );
899 if ( aPackageVersion.getLength() )
901 sal_Int32 nTokIndex = 0;
902 rtl::OUString aVersionMinor = aPackageVersion.getToken( 1, '.', nTokIndex );
903 rtl::OUString aVersionMicro;
905 if ( nTokIndex > 0 )
906 aVersionMicro = aPackageVersion.getToken( 0, '.', nTokIndex );
908 if ( aVersionMinor.getLength() == 0 )
909 aVersionMinor = UNISTRING( "0" );
910 if ( aVersionMicro.getLength() == 0 )
911 aVersionMicro = UNISTRING( "0" );
913 sal_Int32 nIndex = aProductFullVersion.indexOf( '.' );
914 if ( nIndex == -1 )
916 aProductFullVersion += UNISTRING( "." );
917 aProductFullVersion += aVersionMinor;
919 else
921 nIndex = aProductFullVersion.indexOf( '.', nIndex+1 );
923 if ( nIndex == -1 )
925 aProductFullVersion += UNISTRING( "." );
926 aProductFullVersion += aVersionMicro;
928 else
930 aProductFullVersion = aProductFullVersion.replaceAt( nIndex+1, aProductFullVersion.getLength()-nIndex-1, aVersionMicro );
933 rString = rString.replaceAt( nVerIndex, aProductVersion.getLength(), aProductFullVersion );
937 //--------------------------------------------------------------------
938 bool UpdateHandler::showWarning( const rtl::OUString &rWarningText ) const
940 bool bRet = false;
942 uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
943 if ( !xControl.is() ) return bRet;
945 uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
946 if ( !xPeer.is() ) return bRet;
948 uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
949 if ( !xToolkit.is() ) return bRet;
951 awt::WindowDescriptor aDescriptor;
953 sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
954 nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
955 nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
957 aDescriptor.Type = awt::WindowClass_MODALTOP;
958 aDescriptor.WindowServiceName = UNISTRING( "warningbox" );
959 aDescriptor.ParentIndex = -1;
960 aDescriptor.Parent = xPeer;
961 aDescriptor.Bounds = awt::Rectangle( 10, 10, 250, 150 );
962 aDescriptor.WindowAttributes = nWindowAttributes;
964 uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
965 if ( xMsgBox.is() )
967 mbShowsMessageBox = true;
968 sal_Int16 nRet;
969 // xMsgBox->setCaptionText( msCancelTitle );
970 xMsgBox->setMessageText( rWarningText );
971 nRet = xMsgBox->execute();
972 if ( nRet == 2 ) // RET_YES == 2
973 bRet = true;
974 mbShowsMessageBox = false;
977 uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
978 if ( xComponent.is() )
979 xComponent->dispose();
981 return bRet;
984 //--------------------------------------------------------------------
985 bool UpdateHandler::showWarning( const rtl::OUString &rWarningText,
986 const rtl::OUString &rBtnText_1,
987 const rtl::OUString &rBtnText_2 ) const
989 bool bRet = false;
991 uno::Reference< awt::XControl > xControl( mxUpdDlg, uno::UNO_QUERY );
992 if ( !xControl.is() ) return bRet;
994 uno::Reference< awt::XWindowPeer > xPeer = xControl->getPeer();
995 if ( !xPeer.is() ) return bRet;
997 uno::Reference< awt::XToolkit > xToolkit = xPeer->getToolkit();
998 if ( !xToolkit.is() ) return bRet;
1000 awt::WindowDescriptor aDescriptor;
1002 sal_Int32 nWindowAttributes = awt::WindowAttribute::BORDER | awt::WindowAttribute::MOVEABLE | awt::WindowAttribute::CLOSEABLE;
1003 nWindowAttributes |= awt::VclWindowPeerAttribute::YES_NO;
1004 nWindowAttributes |= awt::VclWindowPeerAttribute::DEF_NO;
1006 aDescriptor.Type = awt::WindowClass_MODALTOP;
1007 aDescriptor.WindowServiceName = UNISTRING( "warningbox" );
1008 aDescriptor.ParentIndex = -1;
1009 aDescriptor.Parent = xPeer;
1010 aDescriptor.Bounds = awt::Rectangle( 10, 10, 250, 150 );
1011 aDescriptor.WindowAttributes = nWindowAttributes;
1013 uno::Reference< awt::XMessageBox > xMsgBox( xToolkit->createWindow( aDescriptor ), uno::UNO_QUERY );
1014 if ( xMsgBox.is() )
1016 uno::Reference< awt::XVclContainer > xMsgBoxCtrls( xMsgBox, uno::UNO_QUERY );
1017 if ( xMsgBoxCtrls.is() )
1019 uno::Sequence< uno::Reference< awt::XWindow > > xChildren = xMsgBoxCtrls->getWindows();
1021 for ( long i=0; i < xChildren.getLength(); i++ )
1023 uno::Reference< awt::XVclWindowPeer > xMsgBoxCtrl( xChildren[i], uno::UNO_QUERY );
1024 if ( xMsgBoxCtrl.is() )
1026 bool bIsDefault = true;
1027 uno::Any aValue = xMsgBoxCtrl->getProperty( UNISTRING("DefaultButton") );
1028 aValue >>= bIsDefault;
1029 if ( bIsDefault )
1030 xMsgBoxCtrl->setProperty( UNISTRING("Text"), uno::Any( rBtnText_1 ) );
1031 else
1032 xMsgBoxCtrl->setProperty( UNISTRING("Text"), uno::Any( rBtnText_2 ) );
1037 sal_Int16 nRet;
1038 // xMsgBox->setCaptionText( msCancelTitle );
1039 mbShowsMessageBox = true;
1040 xMsgBox->setMessageText( rWarningText );
1041 nRet = xMsgBox->execute();
1042 if ( nRet == 2 ) // RET_YES == 2
1043 bRet = true;
1045 mbShowsMessageBox = false;
1048 uno::Reference< lang::XComponent > xComponent( xMsgBox, uno::UNO_QUERY );
1049 if ( xComponent.is() )
1050 xComponent->dispose();
1052 return bRet;
1055 //--------------------------------------------------------------------
1056 bool UpdateHandler::showOverwriteWarning( const rtl::OUString& rFileName ) const
1058 rtl::OUString aMsg( msReloadWarning );
1059 searchAndReplaceAll( aMsg, UNISTRING( "%FILENAME" ), rFileName );
1060 searchAndReplaceAll( aMsg, UNISTRING( "%DOWNLOAD_PATH" ), msDownloadPath );
1061 return showWarning( aMsg, msReloadContinue, msReloadReload );
1064 //--------------------------------------------------------------------
1065 bool UpdateHandler::showOverwriteWarning() const
1067 return showWarning( msOverwriteWarning );
1070 //--------------------------------------------------------------------
1071 #define BUTTON_HEIGHT 14
1072 #define BUTTON_WIDTH 50
1073 #define BUTTON_X_OFFSET 7
1074 #define BUTTON_Y_OFFSET 3
1075 #define LABEL_HEIGHT 10
1077 #define DIALOG_WIDTH 300
1078 #define DIALOG_BORDER 5
1079 #define INNER_BORDER 3
1080 #define TEXT_OFFSET 1
1081 #define BOX_HEIGHT1 ( LABEL_HEIGHT + 3*BUTTON_HEIGHT + 2*BUTTON_Y_OFFSET + 2*INNER_BORDER )
1082 #define BOX_HEIGHT2 50
1083 #define EDIT_WIDTH ( DIALOG_WIDTH - 2 * DIALOG_BORDER )
1084 #define BOX1_BTN_X ( DIALOG_BORDER + EDIT_WIDTH - BUTTON_WIDTH - INNER_BORDER )
1085 #define BOX1_BTN_Y ( DIALOG_BORDER + LABEL_HEIGHT + INNER_BORDER)
1086 #define THROBBER_WIDTH 14
1087 #define THROBBER_HEIGHT 14
1088 #define THROBBER_X_POS ( DIALOG_BORDER + 8 )
1089 #define THROBBER_Y_POS ( DIALOG_BORDER + 23 )
1090 #define BUTTON_BAR_HEIGHT 24
1091 #define LABEL_OFFSET ( LABEL_HEIGHT + 4 )
1092 #define DIALOG_HEIGHT ( BOX_HEIGHT1 + BOX_HEIGHT2 + LABEL_OFFSET + BUTTON_BAR_HEIGHT + 3 * DIALOG_BORDER )
1093 #define LABEL_Y_POS ( 2 * DIALOG_BORDER + BOX_HEIGHT1 )
1094 #define EDIT2_Y_POS ( LABEL_Y_POS + LABEL_HEIGHT )
1095 #define BUTTON_BAR_Y_POS ( EDIT2_Y_POS + DIALOG_BORDER + BOX_HEIGHT2 )
1096 #define BUTTON_Y_POS ( BUTTON_BAR_Y_POS + 8 )
1097 #define CLOSE_BTN_X ( DIALOG_WIDTH - DIALOG_BORDER - BUTTON_WIDTH )
1098 #define INSTALL_BTN_X ( CLOSE_BTN_X - 2 * BUTTON_X_OFFSET - BUTTON_WIDTH )
1099 #define DOWNLOAD_BTN_X ( INSTALL_BTN_X - BUTTON_X_OFFSET - BUTTON_WIDTH )
1100 #define PROGRESS_WIDTH 80
1101 #define PROGRESS_HEIGHT 10
1102 #define PROGRESS_X_POS ( DIALOG_BORDER + 8 )
1103 #define PROGRESS_Y_POS ( DIALOG_BORDER + 2*LABEL_OFFSET )
1105 //--------------------------------------------------------------------
1106 void UpdateHandler::showControls( short nControls )
1108 // The buttons from CANCEL_BUTTON to RESUME_BUTTON will be shown or
1109 // hidden on demand
1110 short nShiftMe;
1111 for ( int i = 0; i <= (int)RESUME_BUTTON; i++ )
1113 nShiftMe = (short)(nControls >> i);
1114 showControl( msButtonIDs[i], (bool)(nShiftMe & 0x01) );
1117 nShiftMe = (short)(nControls >> THROBBER_CTRL);
1118 startThrobber( (bool)(nShiftMe & 0x01) );
1120 nShiftMe = (short)(nControls >> PROGRESS_CTRL);
1121 showControl( CTRL_PROGRESS, (bool)(nShiftMe & 0x01) );
1122 showControl( TEXT_PERCENT, (bool)(nShiftMe & 0x01) );
1124 // Status text needs to be smaller, when there are buttons at the right side of the dialog
1125 if ( ( nControls & ( (1<<CANCEL_BUTTON) + (1<<PAUSE_BUTTON) + (1<<RESUME_BUTTON) ) ) != 0 )
1126 setControlProperty( TEXT_STATUS, UNISTRING("Width"), uno::Any( sal_Int32(EDIT_WIDTH - BUTTON_WIDTH - 2*INNER_BORDER - TEXT_OFFSET ) ) );
1127 else
1128 setControlProperty( TEXT_STATUS, UNISTRING("Width"), uno::Any( sal_Int32(EDIT_WIDTH - 2*TEXT_OFFSET ) ) );
1130 // Status text needs to be taller, when we show the progress bar
1131 if ( ( nControls & ( 1<<PROGRESS_CTRL ) ) != 0 )
1132 setControlProperty( TEXT_STATUS, UNISTRING("Height"), uno::Any( sal_Int32(LABEL_HEIGHT) ) );
1133 else
1134 setControlProperty( TEXT_STATUS, UNISTRING("Height"), uno::Any( sal_Int32(BOX_HEIGHT1 - 4*TEXT_OFFSET - LABEL_HEIGHT ) ) );
1137 //--------------------------------------------------------------------
1138 void UpdateHandler::createDialog()
1140 if ( !mxContext.is() )
1142 OSL_ASSERT( false );
1143 return;
1146 uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager() );
1148 if( xServiceManager.is() )
1150 uno::Reference< frame::XDesktop > xDesktop(
1151 xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.frame.Desktop"), mxContext ),
1152 uno::UNO_QUERY );
1153 if ( xDesktop.is() )
1154 xDesktop->addTerminateListener( this );
1157 loadStrings();
1159 uno::Reference< lang::XMultiComponentFactory > xFactory( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
1160 uno::Reference< awt::XControlModel > xControlModel( xFactory->createInstanceWithContext(
1161 UNISTRING("com.sun.star.awt.UnoControlDialogModel"),
1162 mxContext), uno::UNO_QUERY_THROW );
1164 // @see awt/UnoControlDialogModel.idl
1165 uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
1167 xPropSet->setPropertyValue( UNISTRING("Title"), uno::Any( msDlgTitle ) );
1168 xPropSet->setPropertyValue( UNISTRING("Closeable"), uno::Any( true ) );
1169 xPropSet->setPropertyValue( UNISTRING("Enabled"), uno::Any( true ) );
1170 xPropSet->setPropertyValue( UNISTRING("Moveable"), uno::Any( true ) );
1171 xPropSet->setPropertyValue( UNISTRING("Sizeable"), uno::Any( true ) );
1172 xPropSet->setPropertyValue( UNISTRING("DesktopAsParent"), uno::Any( true ) );
1173 xPropSet->setPropertyValue( UNISTRING("PositionX"), uno::Any(sal_Int32( 100 )) );
1174 xPropSet->setPropertyValue( UNISTRING("PositionY"), uno::Any(sal_Int32( 100 )) );
1175 xPropSet->setPropertyValue( UNISTRING("Width"), uno::Any(sal_Int32( DIALOG_WIDTH )) );
1176 xPropSet->setPropertyValue( UNISTRING("Height"), uno::Any(sal_Int32( DIALOG_HEIGHT )) );
1177 xPropSet->setPropertyValue( UNISTRING("HelpURL"), uno::Any( UNISTRING( "HID:" ) + rtl::OUString::valueOf( (sal_Int32) HID_CHECK_FOR_UPD_DLG ) ) );
1179 { // Label (fixed text) <status>
1180 uno::Sequence< beans::NamedValue > aProps(1);
1182 setProperty( aProps, 0, UNISTRING("Label"), uno::Any( msStatusFL ) );
1184 insertControlModel( xControlModel, FIXED_TEXT_MODEL, UNISTRING( "fixedLineStatus" ),
1185 awt::Rectangle( DIALOG_BORDER+1, DIALOG_BORDER, EDIT_WIDTH-2, LABEL_HEIGHT ),
1186 aProps );
1188 { // box around <status> text
1189 uno::Sequence< beans::NamedValue > aProps;
1191 insertControlModel( xControlModel, GROUP_BOX_MODEL, UNISTRING( "StatusBox" ),
1192 awt::Rectangle( DIALOG_BORDER, DIALOG_BORDER + LABEL_HEIGHT, EDIT_WIDTH, BOX_HEIGHT1 - LABEL_HEIGHT ),
1193 aProps );
1195 { // Text (multiline edit) <status>
1196 uno::Sequence< beans::NamedValue > aProps(7);
1198 setProperty( aProps, 0, UNISTRING("Text"), uno::Any( substVariables(msChecking) ) );
1199 setProperty( aProps, 1, UNISTRING("Border"), uno::Any( sal_Int16( 0 ) ) );
1200 setProperty( aProps, 2, UNISTRING("PaintTransparent"), uno::Any( true ) );
1201 setProperty( aProps, 3, UNISTRING("MultiLine"), uno::Any( true ) );
1202 setProperty( aProps, 4, UNISTRING("ReadOnly"), uno::Any( true ) );
1203 setProperty( aProps, 5, UNISTRING("AutoVScroll"), uno::Any( true ) );
1204 setProperty( aProps, 6, UNISTRING("HelpURL"), uno::Any( UNISTRING( "HID:" ) + rtl::OUString::valueOf( (sal_Int32) HID_CHECK_FOR_UPD_STATUS ) ) );
1206 insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_STATUS,
1207 awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
1208 DIALOG_BORDER + LABEL_HEIGHT + TEXT_OFFSET,
1209 EDIT_WIDTH - 2*TEXT_OFFSET,
1210 BOX_HEIGHT1 - 4*TEXT_OFFSET - LABEL_HEIGHT ),
1211 aProps );
1213 { // Text (edit) <percent>
1214 uno::Sequence< beans::NamedValue > aProps(4);
1216 setProperty( aProps, 0, UNISTRING("Text"), uno::Any( msPercent ) );
1217 setProperty( aProps, 1, UNISTRING("Border"), uno::Any( sal_Int16( 0 ) ) );
1218 setProperty( aProps, 2, UNISTRING("PaintTransparent"), uno::Any( true ) );
1219 setProperty( aProps, 3, UNISTRING("ReadOnly"), uno::Any( true ) );
1221 insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_PERCENT,
1222 awt::Rectangle( PROGRESS_X_POS + PROGRESS_WIDTH + DIALOG_BORDER,
1223 PROGRESS_Y_POS,
1224 EDIT_WIDTH - PROGRESS_WIDTH - BUTTON_WIDTH - 2*DIALOG_BORDER,
1225 LABEL_HEIGHT ),
1226 aProps );
1228 { // pause button
1229 uno::Sequence< beans::NamedValue > aProps(5);
1231 setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1232 setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1233 setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1234 setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msPauseBtn ) );
1235 setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( "HID:" ) + rtl::OUString::valueOf( (sal_Int32) HID_CHECK_FOR_UPD_PAUSE ) ) );
1237 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[PAUSE_BUTTON],
1238 awt::Rectangle( BOX1_BTN_X, BOX1_BTN_Y, BUTTON_WIDTH, BUTTON_HEIGHT ),
1239 aProps );
1241 { // resume button
1242 uno::Sequence< beans::NamedValue > aProps(5);
1244 setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1245 setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1246 setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1247 setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msResumeBtn ) );
1248 setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( "HID:" ) + rtl::OUString::valueOf( (sal_Int32) HID_CHECK_FOR_UPD_RESUME ) ) );
1250 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[RESUME_BUTTON],
1251 awt::Rectangle( BOX1_BTN_X,
1252 BOX1_BTN_Y + BUTTON_Y_OFFSET + BUTTON_HEIGHT,
1253 BUTTON_WIDTH,
1254 BUTTON_HEIGHT ),
1255 aProps );
1257 { // abort button
1258 uno::Sequence< beans::NamedValue > aProps(5);
1260 setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1261 setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1262 setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1263 setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msCancelBtn ) );
1264 setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( "HID:" ) + rtl::OUString::valueOf( (sal_Int32) HID_CHECK_FOR_UPD_CANCEL ) ) );
1266 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[CANCEL_BUTTON],
1267 awt::Rectangle( BOX1_BTN_X,
1268 BOX1_BTN_Y + (2*(BUTTON_HEIGHT+BUTTON_Y_OFFSET)),
1269 BUTTON_WIDTH,
1270 BUTTON_HEIGHT ),
1271 aProps );
1273 { // Label (FixedText) <description>
1274 uno::Sequence< beans::NamedValue > aProps(1);
1276 setProperty( aProps, 0, UNISTRING("Label"), uno::Any( msDescription ) );
1278 insertControlModel( xControlModel, FIXED_TEXT_MODEL, UNISTRING( "fixedTextDescription" ),
1279 awt::Rectangle( DIALOG_BORDER+1, LABEL_Y_POS, EDIT_WIDTH-2, LABEL_HEIGHT ),
1280 aProps );
1282 { // box around <description> text
1283 uno::Sequence< beans::NamedValue > aProps;
1285 insertControlModel( xControlModel, GROUP_BOX_MODEL, UNISTRING( "DescriptionBox" ),
1286 awt::Rectangle( DIALOG_BORDER, EDIT2_Y_POS, EDIT_WIDTH, BOX_HEIGHT2 ),
1287 aProps );
1289 { // Text (MultiLineEdit) <description>
1290 uno::Sequence< beans::NamedValue > aProps(7);
1292 setProperty( aProps, 0, UNISTRING("Text"), uno::Any( rtl::OUString() ) );
1293 setProperty( aProps, 1, UNISTRING("Border"), uno::Any( sal_Int16( 0 ) ) );
1294 setProperty( aProps, 2, UNISTRING("PaintTransparent"), uno::Any( true ) );
1295 setProperty( aProps, 3, UNISTRING("MultiLine"), uno::Any( true ) );
1296 setProperty( aProps, 4, UNISTRING("ReadOnly"), uno::Any( true ) );
1297 setProperty( aProps, 5, UNISTRING("AutoVScroll"), uno::Any( true ) );
1298 setProperty( aProps, 6, UNISTRING("HelpURL"), uno::Any( UNISTRING( "HID:" ) + rtl::OUString::valueOf( (sal_Int32) HID_CHECK_FOR_UPD_DESCRIPTION ) ) );
1300 insertControlModel( xControlModel, EDIT_FIELD_MODEL, TEXT_DESCRIPTION,
1301 awt::Rectangle( DIALOG_BORDER + TEXT_OFFSET,
1302 EDIT2_Y_POS + 2*TEXT_OFFSET,
1303 EDIT_WIDTH - 3*TEXT_OFFSET,
1304 BOX_HEIGHT2 - 3*TEXT_OFFSET ),
1305 aProps );
1307 { // @see awt/UnoControlFixedLineModel.idl
1308 uno::Sequence< beans::NamedValue > aProps(1);
1310 setProperty( aProps, 0, UNISTRING("Orientation"), uno::Any( sal_Int32( 0 ) ) );
1312 insertControlModel( xControlModel, FIXED_LINE_MODEL, UNISTRING("fixedLine"),
1313 awt::Rectangle( 0, BUTTON_BAR_Y_POS, DIALOG_WIDTH, 5 ),
1314 aProps );
1316 { // close button // @see awt/UnoControlButtonModel.idl
1317 uno::Sequence< beans::NamedValue > aProps(5);
1319 setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1320 setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1321 // [property] short PushButtonType
1322 // with own "ButtonActionListener"
1323 setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1324 // with default ActionListener => endDialog().
1325 // setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_CANCEL) ) );
1326 // [property] string Label // only if PushButtonType_STANDARD
1327 setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msClose ) );
1328 setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( "HID:" ) + rtl::OUString::valueOf( (sal_Int32) HID_CHECK_FOR_UPD_CLOSE ) ) );
1330 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[ CLOSE_BUTTON ],
1331 awt::Rectangle( CLOSE_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1332 aProps );
1334 { // install button
1335 uno::Sequence< beans::NamedValue > aProps(5);
1337 setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1338 setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1339 setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1340 setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msInstall ) );
1341 setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( "HID:" ) + rtl::OUString::valueOf( (sal_Int32) HID_CHECK_FOR_UPD_INSTALL ) ) );
1343 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[INSTALL_BUTTON],
1344 awt::Rectangle( INSTALL_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1345 aProps );
1347 { // download button
1348 uno::Sequence< beans::NamedValue > aProps(5);
1350 setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1351 setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1352 setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_STANDARD) ) );
1353 setProperty( aProps, 3, UNISTRING("Label"), uno::Any( msDownload ) );
1354 setProperty( aProps, 4, UNISTRING("HelpURL"), uno::Any( UNISTRING( "HID:" ) + rtl::OUString::valueOf( (sal_Int32) HID_CHECK_FOR_UPD_DOWNLOAD ) ) );
1356 insertControlModel ( xControlModel, BUTTON_MODEL, msButtonIDs[DOWNLOAD_BUTTON],
1357 awt::Rectangle( DOWNLOAD_BTN_X, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1358 aProps );
1360 { // help button
1361 uno::Sequence< beans::NamedValue > aProps(3);
1363 setProperty( aProps, 0, UNISTRING("DefaultButton"), uno::Any( false ) );
1364 setProperty( aProps, 1, UNISTRING("Enabled"), uno::Any( true ) );
1365 setProperty( aProps, 2, UNISTRING("PushButtonType"), uno::Any( sal_Int16(awt::PushButtonType_HELP) ) );
1367 insertControlModel( xControlModel, BUTTON_MODEL, msButtonIDs[HELP_BUTTON],
1368 awt::Rectangle( DIALOG_BORDER, BUTTON_Y_POS, BUTTON_WIDTH, BUTTON_HEIGHT ),
1369 aProps );
1371 { // @see awt/UnoControlThrobberModel.idl
1372 uno::Sequence< beans::NamedValue > aProps;
1374 insertControlModel( xControlModel, UNISTRING("com.sun.star.awt.UnoThrobberControlModel"), CTRL_THROBBER,
1375 awt::Rectangle( THROBBER_X_POS, THROBBER_Y_POS, THROBBER_WIDTH, THROBBER_HEIGHT),
1376 aProps );
1378 { // @see awt/UnoControlProgressBarModel.idl
1379 uno::Sequence< beans::NamedValue > aProps(4);
1380 setProperty( aProps, 0, UNISTRING("Enabled"), uno::Any( true ) );
1381 setProperty( aProps, 1, UNISTRING("ProgressValue"), uno::Any( sal_Int32( 0 ) ) );
1382 setProperty( aProps, 2, UNISTRING("ProgressValueMax"), uno::Any( sal_Int32( 100 ) ) );
1383 setProperty( aProps, 3, UNISTRING("ProgressValueMin"), uno::Any( sal_Int32( 0 ) ) );
1385 insertControlModel( xControlModel, UNISTRING("com.sun.star.awt.UnoControlProgressBarModel"), CTRL_PROGRESS,
1386 awt::Rectangle( PROGRESS_X_POS, PROGRESS_Y_POS, PROGRESS_WIDTH, PROGRESS_HEIGHT ),
1387 aProps);
1390 uno::Reference< awt::XControl > xControl(
1391 xFactory->createInstanceWithContext( UNISTRING("com.sun.star.awt.UnoControlDialog"), mxContext),
1392 uno::UNO_QUERY_THROW );
1393 xControl->setModel( xControlModel );
1395 if ( mbVisible == false )
1397 uno::Reference< awt::XWindow > xWindow( xControl, uno::UNO_QUERY );
1399 if ( xWindow.is() )
1400 xWindow->setVisible( false );
1403 xControl->createPeer( NULL, NULL );
1405 uno::Reference< awt::XControlContainer > xContainer (xControl, uno::UNO_QUERY);
1406 for ( int i = 0; i < HELP_BUTTON; i++ )
1408 uno::Reference< awt::XButton > xButton ( xContainer->getControl( msButtonIDs[i] ), uno::UNO_QUERY);
1409 if (xButton.is())
1411 xButton->setActionCommand( msButtonIDs[i] );
1412 xButton->addActionListener( this );
1417 mxUpdDlg.set( xControl, uno::UNO_QUERY_THROW );
1418 mnLastCtrlState = -1;