Update ooo320-m1
[ooovba.git] / desktop / source / deployment / gui / dp_gui_dialog2.cxx
blob4430b5b4445146c7dca61b0d59a51039dcf3713d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dp_gui_dialog2.cxx,v $
11 * $Revision: 1.8.4.8 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_desktop.hxx"
35 #include "dp_gui.hrc"
36 #include "svtools/controldims.hrc"
37 #include "svtools/svtools.hrc"
39 #include "dp_gui.h"
40 #include "dp_gui_dialog2.hxx"
41 #include "dp_gui_extlistbox.hxx"
42 #include "dp_gui_shared.hxx"
43 #include "dp_gui_theextmgr.hxx"
44 #include "dp_misc.h"
46 #include "vcl/ctrl.hxx"
47 #include "vcl/menu.hxx"
48 #include "vcl/msgbox.hxx"
49 #include "vcl/scrbar.hxx"
50 #include "vcl/svapp.hxx"
52 #include "vos/mutex.hxx"
54 #include "svtools/extensionlistbox.hxx"
56 #include "sfx2/sfxdlg.hxx"
58 #include "comphelper/anytostring.hxx"
59 #include "cppuhelper/exc_hlp.hxx"
60 #include "cppuhelper/bootstrap.hxx"
62 #include "comphelper/processfactory.hxx"
63 #include "ucbhelper/content.hxx"
64 #include "unotools/collatorwrapper.hxx"
66 #include "com/sun/star/beans/StringPair.hpp"
68 #include "com/sun/star/i18n/CollatorOptions.hpp"
70 #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
71 #include "com/sun/star/system/XSystemShellExecute.hpp"
73 #include "com/sun/star/ui/dialogs/ExecutableDialogResults.hpp"
74 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
75 #include "com/sun/star/ui/dialogs/XFilePicker.hpp"
76 #include "com/sun/star/ui/dialogs/XFilterManager.hpp"
78 #include "com/sun/star/uno/Any.hxx"
79 #include "com/sun/star/uno/XComponentContext.hpp"
81 #include "com/sun/star/deployment/thePackageManagerFactory.hpp"
83 #include <map>
84 #include <vector>
85 #include <boost/shared_ptr.hpp>
87 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
89 using namespace ::com::sun::star;
90 using namespace ::com::sun::star::system;
92 using ::rtl::OUString;
95 namespace dp_gui {
97 #define ICON_OFFSET 50
98 #define TOP_OFFSET 3
99 #define LINE_SIZE 4
100 #define PROGRESS_WIDTH 60
101 #define PROGRESS_HEIGHT 14
103 //------------------------------------------------------------------------------
104 struct StrAllFiles : public rtl::StaticWithInit< const OUString, StrAllFiles >
106 const OUString operator () () {
107 const ::vos::OGuard guard( Application::GetSolarMutex() );
108 ::std::auto_ptr< ResMgr > const resmgr( ResMgr::CreateResMgr( "fps_office" ) );
109 OSL_ASSERT( resmgr.get() != 0 );
110 String ret( ResId( STR_FILTERNAME_ALL, *resmgr.get() ) );
111 return ret;
115 //------------------------------------------------------------------------------
116 UpdateListEntry::UpdateListEntry( const uno::Reference< deployment::XPackage > &xPackage,
117 const uno::Reference< deployment::XPackageManager > &xPackageManager ) :
118 m_xPackage( xPackage ),
119 m_xPackageManager( xPackageManager )
122 //------------------------------------------------------------------------------
123 UpdateListEntry::~UpdateListEntry()
126 //------------------------------------------------------------------------------
127 // ExtBoxWithBtns_Impl
128 //------------------------------------------------------------------------------
130 enum MENU_COMMAND
132 CMD_NONE = 0,
133 CMD_REMOVE = 1,
134 CMD_ENABLE,
135 CMD_DISABLE,
136 CMD_UPDATE
139 class ExtBoxWithBtns_Impl : public ExtensionBox_Impl
141 Size m_aOutputSize;
142 bool m_bInterfaceLocked;
144 PushButton *m_pOptionsBtn;
145 PushButton *m_pEnableBtn;
146 PushButton *m_pRemoveBtn;
148 ExtMgrDialog *m_pParent;
150 void SetButtonPos( const Rectangle& rRect );
151 void SetButtonStatus( const TEntry_Impl pEntry );
152 bool HandleTabKey( bool bReverse );
153 MENU_COMMAND ShowPopupMenu( const Point &rPos, const long nPos );
155 //-----------------
156 DECL_DLLPRIVATE_LINK( ScrollHdl, ScrollBar * );
158 DECL_DLLPRIVATE_LINK( HandleOptionsBtn, void * );
159 DECL_DLLPRIVATE_LINK( HandleEnableBtn, void * );
160 DECL_DLLPRIVATE_LINK( HandleRemoveBtn, void * );
161 DECL_DLLPRIVATE_LINK( HandleHyperlink, svt::FixedHyperlink * );
163 public:
164 ExtBoxWithBtns_Impl( ExtMgrDialog* pParent, TheExtensionManager *pManager );
165 ~ExtBoxWithBtns_Impl();
167 virtual void MouseButtonDown( const MouseEvent& rMEvt );
168 virtual long Notify( NotifyEvent& rNEvt );
170 const Size GetMinOutputSizePixel() const;
172 virtual void RecalcAll();
173 virtual void selectEntry( const long nPos );
174 //-----------------
175 void enableButtons( bool bEnable );
178 //------------------------------------------------------------------------------
179 ExtBoxWithBtns_Impl::ExtBoxWithBtns_Impl( ExtMgrDialog* pParent, TheExtensionManager *pManager ) :
180 ExtensionBox_Impl( pParent, pManager ),
181 m_bInterfaceLocked( false ),
182 m_pOptionsBtn( NULL ),
183 m_pEnableBtn( NULL ),
184 m_pRemoveBtn( NULL ),
185 m_pParent( pParent )
187 m_pOptionsBtn = new PushButton( this, WB_TABSTOP );
188 m_pEnableBtn = new PushButton( this, WB_TABSTOP );
189 m_pRemoveBtn = new PushButton( this, WB_TABSTOP );
191 SetHelpId( HID_EXTENSION_MANAGER_LISTBOX );
192 m_pOptionsBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_OPTIONS );
193 m_pEnableBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_DISABLE );
194 m_pRemoveBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_REMOVE );
196 m_pOptionsBtn->SetClickHdl( LINK( this, ExtBoxWithBtns_Impl, HandleOptionsBtn ) );
197 m_pEnableBtn->SetClickHdl( LINK( this, ExtBoxWithBtns_Impl, HandleEnableBtn ) );
198 m_pRemoveBtn->SetClickHdl( LINK( this, ExtBoxWithBtns_Impl, HandleRemoveBtn ) );
200 m_pOptionsBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_OPTIONS ) );
201 m_pEnableBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_DISABLE ) );
202 m_pRemoveBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_REMOVE ) );
204 Size aSize = LogicToPixel( Size( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ),
205 MapMode( MAP_APPFONT ) );
206 m_pOptionsBtn->SetSizePixel( aSize );
207 m_pEnableBtn->SetSizePixel( aSize );
208 m_pRemoveBtn->SetSizePixel( aSize );
210 SetExtraSize( aSize.Height() + 2 * TOP_OFFSET );
212 SetScrollHdl( LINK( this, ExtBoxWithBtns_Impl, ScrollHdl ) );
215 //------------------------------------------------------------------------------
216 ExtBoxWithBtns_Impl::~ExtBoxWithBtns_Impl()
218 delete m_pOptionsBtn;
219 delete m_pEnableBtn;
220 delete m_pRemoveBtn;
223 //------------------------------------------------------------------------------
224 //------------------------------------------------------------------------------
225 //------------------------------------------------------------------------------
226 const Size ExtBoxWithBtns_Impl::GetMinOutputSizePixel() const
228 Size aMinSize( ExtensionBox_Impl::GetMinOutputSizePixel() );
229 long nHeight = aMinSize.Height();
230 nHeight += m_pOptionsBtn->GetSizePixel().Height();
231 nHeight += 2 * TOP_OFFSET;
232 long nWidth = m_pOptionsBtn->GetSizePixel().Width();
233 nWidth *= 3;
234 nWidth += 5*TOP_OFFSET + 20;
236 return Size( nWidth, nHeight );
239 // -----------------------------------------------------------------------
240 void ExtBoxWithBtns_Impl::RecalcAll()
242 ExtensionBox_Impl::RecalcAll();
244 const sal_Int32 nActive = getSelIndex();
246 if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
247 SetButtonPos( GetEntryRect( nActive ) );
248 else
250 m_pOptionsBtn->Hide();
251 m_pEnableBtn->Hide();
252 m_pRemoveBtn->Hide();
257 //------------------------------------------------------------------------------
258 //This function may be called with nPos < 0
259 void ExtBoxWithBtns_Impl::selectEntry( const long nPos )
261 if ( HasActive() && ( nPos == getSelIndex() ) )
262 return;
264 ExtensionBox_Impl::selectEntry( nPos );
266 if ( ( nPos >= 0 ) && ( nPos < GetEntryCount() ) )
268 if ( IsReallyVisible() )
270 SetButtonPos( GetEntryRect( nPos ) );
272 SetButtonStatus( GetEntryData( nPos) );
274 else
276 m_pOptionsBtn->Hide();
277 m_pEnableBtn->Hide();
278 m_pRemoveBtn->Hide();
282 // -----------------------------------------------------------------------
283 void ExtBoxWithBtns_Impl::SetButtonPos( const Rectangle& rRect )
285 Size aBtnSize( m_pOptionsBtn->GetSizePixel() );
286 Point aBtnPos( rRect.Left() + ICON_OFFSET,
287 rRect.Bottom() - TOP_OFFSET - aBtnSize.Height() );
289 m_pOptionsBtn->SetPosPixel( aBtnPos );
290 aBtnPos.X() = rRect.Right() - TOP_OFFSET - aBtnSize.Width();
291 m_pRemoveBtn->SetPosPixel( aBtnPos );
292 aBtnPos.X() -= ( TOP_OFFSET + aBtnSize.Width() );
293 m_pEnableBtn->SetPosPixel( aBtnPos );
296 // -----------------------------------------------------------------------
297 void ExtBoxWithBtns_Impl::SetButtonStatus( const TEntry_Impl pEntry )
299 if ( ( pEntry->m_eState == REGISTERED ) || ( pEntry->m_eState == NOT_AVAILABLE ) )
301 m_pEnableBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_DISABLE ) );
302 m_pEnableBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_DISABLE );
304 else
306 m_pEnableBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_ENABLE ) );
307 m_pEnableBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_ENABLE );
310 if ( ( pEntry->m_eState == NOT_AVAILABLE ) || pEntry->m_bMissingDeps )
311 m_pEnableBtn->Hide();
312 else
314 m_pEnableBtn->Enable( !pEntry->m_bLocked );
315 m_pEnableBtn->Show();
318 if ( pEntry->m_bHasOptions )
320 m_pOptionsBtn->Enable( pEntry->m_bHasOptions );
321 m_pOptionsBtn->Show();
323 else
324 m_pOptionsBtn->Hide();
326 m_pRemoveBtn->Show();
327 m_pRemoveBtn->Enable( !pEntry->m_bLocked );
330 // -----------------------------------------------------------------------
331 bool ExtBoxWithBtns_Impl::HandleTabKey( bool bReverse )
333 sal_Int32 nIndex = getSelIndex();
335 if ( nIndex == EXTENSION_LISTBOX_ENTRY_NOTFOUND )
336 return false;
338 PushButton *pNext = NULL;
340 if ( m_pOptionsBtn->HasFocus() ) {
341 if ( !bReverse && !GetEntryData( nIndex )->m_bLocked )
342 pNext = m_pEnableBtn;
344 else if ( m_pEnableBtn->HasFocus() ) {
345 if ( !bReverse )
346 pNext = m_pRemoveBtn;
347 else if ( GetEntryData( nIndex )->m_bHasOptions )
348 pNext = m_pOptionsBtn;
350 else if ( m_pRemoveBtn->HasFocus() ) {
351 if ( bReverse )
352 pNext = m_pEnableBtn;
354 else {
355 if ( !bReverse ) {
356 if ( GetEntryData( nIndex )->m_bHasOptions )
357 pNext = m_pOptionsBtn;
358 else if ( ! GetEntryData( nIndex )->m_bLocked )
359 pNext = m_pEnableBtn;
360 } else {
361 if ( ! GetEntryData( nIndex )->m_bLocked )
362 pNext = m_pRemoveBtn;
363 else if ( GetEntryData( nIndex )->m_bHasOptions )
364 pNext = m_pOptionsBtn;
368 if ( pNext )
370 pNext->GrabFocus();
371 return true;
373 else
374 return false;
377 // -----------------------------------------------------------------------
378 MENU_COMMAND ExtBoxWithBtns_Impl::ShowPopupMenu( const Point & rPos, const long nPos )
380 if ( nPos >= (long) getItemCount() )
381 return CMD_NONE;
383 PopupMenu aPopup;
385 aPopup.InsertItem( CMD_UPDATE, DialogHelper::getResourceString( RID_CTX_ITEM_CHECK_UPDATE ) );
387 if ( ! GetEntryData( nPos )->m_bLocked )
389 if ( GetEntryData( nPos )->m_eState == REGISTERED )
390 aPopup.InsertItem( CMD_DISABLE, DialogHelper::getResourceString( RID_CTX_ITEM_DISABLE ) );
391 else if ( GetEntryData( nPos )->m_eState != NOT_AVAILABLE )
392 aPopup.InsertItem( CMD_ENABLE, DialogHelper::getResourceString( RID_CTX_ITEM_ENABLE ) );
394 aPopup.InsertItem( CMD_REMOVE, DialogHelper::getResourceString( RID_CTX_ITEM_REMOVE ) );
397 return (MENU_COMMAND) aPopup.Execute( this, rPos );
400 //------------------------------------------------------------------------------
401 void ExtBoxWithBtns_Impl::MouseButtonDown( const MouseEvent& rMEvt )
403 if ( m_bInterfaceLocked )
404 return;
406 const Point aMousePos( rMEvt.GetPosPixel() );
407 const long nPos = PointToPos( aMousePos );
409 if ( rMEvt.IsRight() )
411 switch( ShowPopupMenu( aMousePos, nPos ) )
413 case CMD_NONE: break;
414 case CMD_ENABLE: m_pParent->enablePackage( GetEntryData( nPos )->m_xPackageManager,
415 GetEntryData( nPos )->m_xPackage, true );
416 break;
417 case CMD_DISABLE: m_pParent->enablePackage( GetEntryData( nPos )->m_xPackageManager,
418 GetEntryData( nPos )->m_xPackage, false );
419 break;
420 case CMD_UPDATE: m_pParent->updatePackage( GetEntryData( nPos )->m_xPackageManager,
421 GetEntryData( nPos )->m_xPackage );
422 break;
423 case CMD_REMOVE: m_pParent->removePackage( GetEntryData( nPos )->m_xPackageManager,
424 GetEntryData( nPos )->m_xPackage );
425 break;
428 else if ( rMEvt.IsLeft() )
430 if ( rMEvt.IsMod1() && HasActive() )
431 selectEntry( EXTENSION_LISTBOX_ENTRY_NOTFOUND ); // Selecting an not existing entry will deselect the current one
432 else
433 selectEntry( nPos );
437 //------------------------------------------------------------------------------
438 long ExtBoxWithBtns_Impl::Notify( NotifyEvent& rNEvt )
440 bool bHandled = false;
442 if ( rNEvt.GetType() == EVENT_KEYINPUT )
444 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
445 KeyCode aKeyCode = pKEvt->GetKeyCode();
446 USHORT nKeyCode = aKeyCode.GetCode();
448 if ( nKeyCode == KEY_TAB )
449 bHandled = HandleTabKey( aKeyCode.IsShift() );
452 if ( !bHandled )
453 return ExtensionBox_Impl::Notify( rNEvt );
454 else
455 return true;
458 //------------------------------------------------------------------------------
459 void ExtBoxWithBtns_Impl::enableButtons( bool bEnable )
461 m_bInterfaceLocked = ! bEnable;
463 if ( bEnable )
465 sal_Int32 nIndex = getSelIndex();
466 if ( nIndex != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
467 SetButtonStatus( GetEntryData( nIndex ) );
469 else
471 m_pOptionsBtn->Enable( false );
472 m_pRemoveBtn->Enable( false );
473 m_pEnableBtn->Enable( false );
477 // -----------------------------------------------------------------------
478 IMPL_LINK( ExtBoxWithBtns_Impl, ScrollHdl, ScrollBar*, pScrBar )
480 long nDelta = pScrBar->GetDelta();
482 Point aNewOptPt( m_pOptionsBtn->GetPosPixel() - Point( 0, nDelta ) );
483 Point aNewRemPt( m_pRemoveBtn->GetPosPixel() - Point( 0, nDelta ) );
484 Point aNewEnPt( m_pEnableBtn->GetPosPixel() - Point( 0, nDelta ) );
486 DoScroll( nDelta );
488 m_pOptionsBtn->SetPosPixel( aNewOptPt );
489 m_pRemoveBtn->SetPosPixel( aNewRemPt );
490 m_pEnableBtn->SetPosPixel( aNewEnPt );
492 return 1;
495 // -----------------------------------------------------------------------
496 IMPL_LINK( ExtBoxWithBtns_Impl, HandleOptionsBtn, void*, EMPTYARG )
498 const sal_Int32 nActive = getSelIndex();
500 if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
502 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
504 if ( pFact )
506 OUString sExtensionId = GetEntryData( nActive )->m_xPackage->getIdentifier().Value;
507 VclAbstractDialog* pDlg = pFact->CreateOptionsDialog( this, sExtensionId, rtl::OUString() );
509 pDlg->Execute();
511 delete pDlg;
515 return 1;
518 // -----------------------------------------------------------------------
519 IMPL_LINK( ExtBoxWithBtns_Impl, HandleEnableBtn, void*, EMPTYARG )
521 const sal_Int32 nActive = getSelIndex();
523 if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
525 TEntry_Impl pEntry = GetEntryData( nActive );
526 const bool bEnable( pEntry->m_eState != REGISTERED );
528 m_pParent->enablePackage( pEntry->m_xPackageManager,
529 pEntry->m_xPackage,
530 bEnable );
533 return 1;
536 // -----------------------------------------------------------------------
537 IMPL_LINK( ExtBoxWithBtns_Impl, HandleRemoveBtn, void*, EMPTYARG )
539 const sal_Int32 nActive = getSelIndex();
541 if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
543 TEntry_Impl pEntry = GetEntryData( nActive );
544 m_pParent->removePackage( pEntry->m_xPackageManager,
545 pEntry->m_xPackage );
548 return 1;
551 //------------------------------------------------------------------------------
552 // DialogHelper
553 //------------------------------------------------------------------------------
554 DialogHelper::DialogHelper( const uno::Reference< uno::XComponentContext > &xContext,
555 Dialog *pWindow ) :
556 m_pVCLWindow( pWindow ),
557 m_nEventID( 0 ),
558 m_bIsBusy( false )
560 m_xContext = xContext;
563 //------------------------------------------------------------------------------
564 DialogHelper::~DialogHelper()
566 if ( m_nEventID )
567 Application::RemoveUserEvent( m_nEventID );
570 //------------------------------------------------------------------------------
571 ResId DialogHelper::getResId( USHORT nId )
573 const ::vos::OGuard guard( Application::GetSolarMutex() );
574 return ResId( nId, *DeploymentGuiResMgr::get() );
577 //------------------------------------------------------------------------------
578 String DialogHelper::getResourceString( USHORT id )
580 // init with non-acquired solar mutex:
581 BrandName::get();
582 const ::vos::OGuard guard( Application::GetSolarMutex() );
583 String ret( ResId( id, *DeploymentGuiResMgr::get() ) );
584 if (ret.SearchAscii( "%PRODUCTNAME" ) != STRING_NOTFOUND) {
585 ret.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
587 return ret;
590 //------------------------------------------------------------------------------
591 bool DialogHelper::IsSharedPkgMgr( const uno::Reference< deployment::XPackageManager > &xPackageManager )
593 if ( xPackageManager->getContext().equals( OUSTR("shared") ) )
594 return true;
595 else
596 return false;
599 //------------------------------------------------------------------------------
600 bool DialogHelper::continueOnSharedExtension( const uno::Reference< deployment::XPackageManager > &xPackageManager,
601 Window *pParent,
602 const USHORT nResID,
603 bool &bHadWarning )
605 if ( !bHadWarning && IsSharedPkgMgr( xPackageManager ) )
607 const ::vos::OGuard guard( Application::GetSolarMutex() );
608 WarningBox aInfoBox( pParent, getResId( nResID ) );
609 String aMsgText = aInfoBox.GetMessText();
610 aMsgText.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
611 aInfoBox.SetMessText( aMsgText );
613 bHadWarning = true;
615 if ( RET_OK == aInfoBox.Execute() )
616 return true;
617 else
618 return false;
620 else
621 return true;
624 //------------------------------------------------------------------------------
625 void DialogHelper::openWebBrowser( const OUString & sURL, const OUString &sTitle ) const
627 if ( ! sURL.getLength() ) // Nothing to do, when the URL is empty
628 return;
630 try
632 uno::Reference< XSystemShellExecute > xSystemShellExecute(
633 m_xContext->getServiceManager()->createInstanceWithContext( OUSTR( "com.sun.star.system.SystemShellExecute" ), m_xContext), uno::UNO_QUERY_THROW);
634 //throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException
635 xSystemShellExecute->execute( sURL, OUString(), SystemShellExecuteFlags::DEFAULTS );
637 catch ( uno::Exception& )
639 uno::Any exc( ::cppu::getCaughtException() );
640 OUString msg( ::comphelper::anyToString( exc ) );
641 const ::vos::OGuard guard( Application::GetSolarMutex() );
642 ErrorBox aErrorBox( NULL, WB_OK, msg );
643 aErrorBox.SetText( sTitle );
644 aErrorBox.Execute();
648 //------------------------------------------------------------------------------
649 bool DialogHelper::installExtensionWarn( const OUString &rExtensionName ) const
651 const ::vos::OGuard guard( Application::GetSolarMutex() );
652 WarningBox aInfo( m_pVCLWindow, getResId( RID_WARNINGBOX_INSTALL_EXTENSION ) );
654 String sText( aInfo.GetMessText() );
655 sText.SearchAndReplaceAllAscii( "%NAME", rExtensionName );
656 aInfo.SetMessText( sText );
658 return ( RET_OK == aInfo.Execute() );
661 //------------------------------------------------------------------------------
662 bool DialogHelper::installForAllUsers( bool &bInstallForAll ) const
664 const ::vos::OGuard guard( Application::GetSolarMutex() );
665 QueryBox aQuery( m_pVCLWindow, getResId( RID_QUERYBOX_INSTALL_FOR_ALL ) );
667 String sMsgText = aQuery.GetMessText();
668 sMsgText.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
669 aQuery.SetMessText( sMsgText );
671 USHORT nYesBtnID = aQuery.GetButtonId( 0 );
672 USHORT nNoBtnID = aQuery.GetButtonId( 1 );
674 if ( nYesBtnID != BUTTONDIALOG_BUTTON_NOTFOUND )
675 aQuery.SetButtonText( nYesBtnID, getResourceString( RID_STR_INSTALL_FOR_ME ) );
676 if ( nNoBtnID != BUTTONDIALOG_BUTTON_NOTFOUND )
677 aQuery.SetButtonText( nNoBtnID, getResourceString( RID_STR_INSTALL_FOR_ALL ) );
679 short nRet = aQuery.Execute();
681 if ( nRet == RET_CANCEL )
682 return false;
684 bInstallForAll = ( nRet == RET_NO );
685 return true;
688 //------------------------------------------------------------------------------
689 void DialogHelper::PostUserEvent( const Link& rLink, void* pCaller )
691 if ( m_nEventID )
692 Application::RemoveUserEvent( m_nEventID );
694 m_nEventID = Application::PostUserEvent( rLink, pCaller );
697 //------------------------------------------------------------------------------
698 // ExtMgrDialog
699 //------------------------------------------------------------------------------
700 ExtMgrDialog::ExtMgrDialog( Window *pParent, TheExtensionManager *pManager ) :
701 ModelessDialog( pParent, getResId( RID_DLG_EXTENSION_MANAGER ) ),
702 DialogHelper( pManager->getContext(), (Dialog*) this ),
703 m_aAddBtn( this, getResId( RID_EM_BTN_ADD ) ),
704 m_aUpdateBtn( this, getResId( RID_EM_BTN_CHECK_UPDATES ) ),
705 m_aCloseBtn( this, getResId( RID_EM_BTN_CLOSE ) ),
706 m_aHelpBtn( this, getResId( RID_EM_BTN_HELP ) ),
707 m_aDivider( this ),
708 m_aGetExtensions( this, getResId( RID_EM_FT_GET_EXTENSIONS ) ),
709 m_aProgressText( this, getResId( RID_EM_FT_PROGRESS ) ),
710 m_aProgressBar( this, WB_BORDER + WB_3DLOOK ),
711 m_aCancelBtn( this, getResId( RID_EM_BTN_CANCEL ) ),
712 m_sAddPackages( getResourceString( RID_STR_ADD_PACKAGES ) ),
713 m_bHasProgress( false ),
714 m_bProgressChanged( false ),
715 m_bStartProgress( false ),
716 m_bStopProgress( false ),
717 m_bUpdateWarning( false ),
718 m_bEnableWarning( false ),
719 m_bDisableWarning( false ),
720 m_bDeleteWarning( false ),
721 m_nProgress( 0 ),
722 m_pManager( pManager )
724 // free local resources (RID < 256):
725 FreeResource();
727 m_pExtensionBox = new ExtBoxWithBtns_Impl( this, pManager );
728 m_pExtensionBox->SetHyperlinkHdl( LINK( this, ExtMgrDialog, HandleHyperlink ) );
730 m_aAddBtn.SetClickHdl( LINK( this, ExtMgrDialog, HandleAddBtn ) );
731 m_aUpdateBtn.SetClickHdl( LINK( this, ExtMgrDialog, HandleUpdateBtn ) );
732 m_aGetExtensions.SetClickHdl( LINK( this, ExtMgrDialog, HandleHyperlink ) );
733 m_aCancelBtn.SetClickHdl( LINK( this, ExtMgrDialog, HandleCancelBtn ) );
735 // resize update button
736 Size aBtnSize = m_aUpdateBtn.GetSizePixel();
737 String sTitle = m_aUpdateBtn.GetText();
738 long nWidth = m_aUpdateBtn.GetCtrlTextWidth( sTitle );
739 nWidth += 2 * m_aUpdateBtn.GetTextHeight();
740 if ( nWidth > aBtnSize.Width() )
741 m_aUpdateBtn.SetSizePixel( Size( nWidth, aBtnSize.Height() ) );
743 // minimum size:
744 SetMinOutputSizePixel(
745 Size( // width:
746 (3 * m_aHelpBtn.GetSizePixel().Width()) +
747 m_aUpdateBtn.GetSizePixel().Width() +
748 (5 * RSC_SP_DLG_INNERBORDER_LEFT ),
749 // height:
750 (1 * m_aHelpBtn.GetSizePixel().Height()) +
751 (1 * m_aGetExtensions.GetSizePixel().Height()) +
752 (1 * m_pExtensionBox->GetMinOutputSizePixel().Height()) +
753 (3 * RSC_SP_DLG_INNERBORDER_LEFT) ) );
755 m_aDivider.Show();
756 m_aProgressBar.Hide();
758 m_aUpdateBtn.Enable( false );
760 m_aTimeoutTimer.SetTimeout( 500 ); // mSec
761 m_aTimeoutTimer.SetTimeoutHdl( LINK( this, ExtMgrDialog, TimeOutHdl ) );
764 //------------------------------------------------------------------------------
765 ExtMgrDialog::~ExtMgrDialog()
767 m_aTimeoutTimer.Stop();
768 delete m_pExtensionBox;
771 //------------------------------------------------------------------------------
772 void ExtMgrDialog::selectEntry( long nPos )
774 m_pExtensionBox->selectEntry( nPos );
777 //------------------------------------------------------------------------------
778 void ExtMgrDialog::setGetExtensionsURL( const ::rtl::OUString &rURL )
780 m_aGetExtensions.SetURL( rURL );
783 //------------------------------------------------------------------------------
784 long ExtMgrDialog::addPackageToList( const uno::Reference< deployment::XPackage > &xPackage,
785 const uno::Reference< deployment::XPackageManager > &xPackageManager )
787 m_aUpdateBtn.Enable( true );
788 return m_pExtensionBox->addEntry( xPackage, xPackageManager );
791 //------------------------------------------------------------------------------
792 void ExtMgrDialog::prepareChecking( const uno::Reference< deployment::XPackageManager > &xPackageManager )
794 if ( xPackageManager.is() )
795 m_pExtensionBox->prepareChecking( xPackageManager );
798 //------------------------------------------------------------------------------
799 void ExtMgrDialog::checkEntries()
801 const ::vos::OGuard guard( Application::GetSolarMutex() );
802 m_pExtensionBox->checkEntries();
805 //------------------------------------------------------------------------------
806 bool ExtMgrDialog::removeExtensionWarn( const OUString &rExtensionName ) const
808 const ::vos::OGuard guard( Application::GetSolarMutex() );
809 WarningBox aInfo( const_cast< ExtMgrDialog* >(this), getResId( RID_WARNINGBOX_REMOVE_EXTENSION ) );
811 String sText( aInfo.GetMessText() );
812 sText.SearchAndReplaceAllAscii( "%NAME", rExtensionName );
813 aInfo.SetMessText( sText );
815 return ( RET_OK == aInfo.Execute() );
818 //------------------------------------------------------------------------------
819 bool ExtMgrDialog::enablePackage( const uno::Reference< deployment::XPackageManager > &xPackageManager,
820 const uno::Reference< deployment::XPackage > &xPackage,
821 bool bEnable )
823 if ( !xPackageManager.is() || !xPackage.is() )
824 return false;
826 if ( bEnable )
828 if ( ! continueOnSharedExtension( xPackageManager, this, RID_WARNINGBOX_ENABLE_SHARED_EXTENSION, m_bEnableWarning ) )
829 return false;
831 else
833 if ( ! continueOnSharedExtension( xPackageManager, this, RID_WARNINGBOX_DISABLE_SHARED_EXTENSION, m_bDisableWarning ) )
834 return false;
837 m_pManager->enablePackage( xPackage, bEnable );
839 return true;
842 //------------------------------------------------------------------------------
843 bool ExtMgrDialog::removePackage( const uno::Reference< deployment::XPackageManager > &xPackageManager,
844 const uno::Reference< deployment::XPackage > &xPackage )
846 if ( !xPackageManager.is() || !xPackage.is() )
847 return false;
849 if ( !IsSharedPkgMgr( xPackageManager ) || m_bDeleteWarning )
851 if ( ! removeExtensionWarn( xPackage->getDisplayName() ) )
852 return false;
855 if ( ! continueOnSharedExtension( xPackageManager, this, RID_WARNINGBOX_REMOVE_SHARED_EXTENSION, m_bDeleteWarning ) )
856 return false;
858 m_pManager->removePackage( xPackageManager, xPackage );
860 return true;
863 //------------------------------------------------------------------------------
864 bool ExtMgrDialog::updatePackage( const uno::Reference< deployment::XPackageManager > &xPackageManager,
865 const uno::Reference< deployment::XPackage > &xPackage )
867 if ( !xPackageManager.is() || !xPackage.is() )
868 return false;
870 std::vector< TUpdateListEntry > vEntries;
871 TUpdateListEntry pEntry( new UpdateListEntry( xPackage, xPackageManager ) );
872 vEntries.push_back( pEntry );
874 m_pManager->updatePackages( vEntries );
876 return true;
879 //------------------------------------------------------------------------------
880 uno::Sequence< OUString > ExtMgrDialog::raiseAddPicker( const uno::Reference< deployment::XPackageManager > &xPackageManager )
882 const uno::Any mode( static_cast< sal_Int16 >( ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE ) );
883 const uno::Reference< uno::XComponentContext > xContext( m_pManager->getContext() );
884 const uno::Reference< ui::dialogs::XFilePicker > xFilePicker(
885 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
886 OUSTR("com.sun.star.ui.dialogs.FilePicker"),
887 uno::Sequence< uno::Any >( &mode, 1 ), xContext ), uno::UNO_QUERY_THROW );
888 xFilePicker->setTitle( m_sAddPackages );
890 if ( m_sLastFolderURL.Len() )
891 xFilePicker->setDisplayDirectory( m_sLastFolderURL );
893 // collect and set filter list:
894 typedef ::std::map< OUString, OUString > t_string2string;
895 t_string2string title2filter;
896 OUString sDefaultFilter( StrAllFiles::get() );
898 const uno::Sequence< uno::Reference< deployment::XPackageTypeInfo > > packageTypes( xPackageManager->getSupportedPackageTypes() );
900 for ( sal_Int32 pos = 0; pos < packageTypes.getLength(); ++pos )
902 uno::Reference< deployment::XPackageTypeInfo > const & xPackageType = packageTypes[ pos ];
903 const OUString filter( xPackageType->getFileFilter() );
904 if (filter.getLength() > 0)
906 const OUString title( xPackageType->getShortDescription() );
907 const ::std::pair< t_string2string::iterator, bool > insertion(
908 title2filter.insert( t_string2string::value_type( title, filter ) ) );
909 if ( ! insertion.second )
910 { // already existing, append extensions:
911 ::rtl::OUStringBuffer buf;
912 buf.append( insertion.first->second );
913 buf.append( static_cast<sal_Unicode>(';') );
914 buf.append( filter );
915 insertion.first->second = buf.makeStringAndClear();
917 if ( xPackageType->getMediaType() == OUSTR( "application/vnd.sun.star.package-bundle" ) )
918 sDefaultFilter = title;
922 const uno::Reference< ui::dialogs::XFilterManager > xFilterManager( xFilePicker, uno::UNO_QUERY_THROW );
923 // All files at top:
924 xFilterManager->appendFilter( StrAllFiles::get(), OUSTR("*.*") );
925 // then supported ones:
926 t_string2string::const_iterator iPos( title2filter.begin() );
927 const t_string2string::const_iterator iEnd( title2filter.end() );
928 for ( ; iPos != iEnd; ++iPos ) {
929 try {
930 xFilterManager->appendFilter( iPos->first, iPos->second );
932 catch (lang::IllegalArgumentException & exc) {
933 OSL_ENSURE( 0, ::rtl::OUStringToOString(
934 exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
935 (void) exc;
938 xFilterManager->setCurrentFilter( sDefaultFilter );
940 if ( xFilePicker->execute() != ui::dialogs::ExecutableDialogResults::OK )
941 return uno::Sequence<OUString>(); // cancelled
943 m_sLastFolderURL = xFilePicker->getDisplayDirectory();
944 uno::Sequence< OUString > files( xFilePicker->getFiles() );
945 OSL_ASSERT( files.getLength() > 0 );
946 return files;
949 //------------------------------------------------------------------------------
950 IMPL_LINK( ExtMgrDialog, HandleCancelBtn, void*, EMPTYARG )
952 // m_dialog->m_cmdEnv->m_aborted = true;
953 if ( m_xAbortChannel.is() )
957 m_xAbortChannel->sendAbort();
959 catch ( uno::RuntimeException & )
961 OSL_ENSURE( 0, "### unexpected RuntimeException!" );
964 return 1;
967 // ------------------------------------------------------------------------------
968 IMPL_LINK( ExtMgrDialog, startProgress, void*, _bLockInterface )
970 ::osl::MutexGuard aGuard( m_aMutex );
971 bool bLockInterface = (bool) _bLockInterface;
973 if ( m_bStartProgress && !m_bHasProgress )
974 m_aTimeoutTimer.Start();
976 if ( m_bStopProgress )
978 if ( m_aProgressBar.IsVisible() )
979 m_aProgressBar.SetValue( 100 );
980 m_xAbortChannel.clear();
982 OSL_TRACE( " startProgress handler: stop\n" );
984 else
986 OSL_TRACE( " startProgress handler: start\n" );
989 m_aCancelBtn.Enable( bLockInterface );
990 m_aAddBtn.Enable( !bLockInterface );
991 m_aUpdateBtn.Enable( !bLockInterface && m_pExtensionBox->getItemCount() );
992 m_pExtensionBox->enableButtons( !bLockInterface );
994 clearEventID();
996 return 0;
999 // ------------------------------------------------------------------------------
1000 void ExtMgrDialog::showProgress( bool _bStart )
1002 ::osl::MutexGuard aGuard( m_aMutex );
1004 bool bStart = _bStart;
1006 if ( bStart )
1008 m_nProgress = 0;
1009 m_bStartProgress = true;
1010 OSL_TRACE( "showProgress start\n" );
1012 else
1014 m_nProgress = 100;
1015 m_bStopProgress = true;
1016 OSL_TRACE( "showProgress stop!\n" );
1019 DialogHelper::PostUserEvent( LINK( this, ExtMgrDialog, startProgress ), (void*) bStart );
1022 // -----------------------------------------------------------------------
1023 void ExtMgrDialog::updateProgress( const long nProgress )
1025 ::osl::MutexGuard aGuard( m_aMutex );
1027 m_nProgress = nProgress;
1030 // -----------------------------------------------------------------------
1031 void ExtMgrDialog::updateProgress( const OUString &rText,
1032 const uno::Reference< task::XAbortChannel > &xAbortChannel)
1034 ::osl::MutexGuard aGuard( m_aMutex );
1036 m_xAbortChannel = xAbortChannel;
1037 m_sProgressText = rText;
1038 m_bProgressChanged = true;
1041 //------------------------------------------------------------------------------
1042 void ExtMgrDialog::updatePackageInfo( const uno::Reference< deployment::XPackage > &xPackage )
1044 m_pExtensionBox->updateEntry( xPackage );
1047 // -----------------------------------------------------------------------
1048 IMPL_LINK( ExtMgrDialog, HandleAddBtn, void*, EMPTYARG )
1050 setBusy( true );
1052 uno::Reference< deployment::XPackageManager > xUserPkgMgr = m_pManager->getUserPkgMgr();
1053 uno::Sequence< OUString > aFileList = raiseAddPicker( xUserPkgMgr );
1055 if ( aFileList.getLength() )
1057 m_pManager->installPackage( aFileList[0] );
1060 setBusy( false );
1061 return 1;
1064 // -----------------------------------------------------------------------
1065 IMPL_LINK( ExtMgrDialog, HandleUpdateBtn, void*, EMPTYARG )
1067 m_pManager->checkUpdates( false, true );
1069 return 1;
1072 // -----------------------------------------------------------------------
1073 IMPL_LINK( ExtMgrDialog, HandleHyperlink, svt::FixedHyperlink*, pHyperlink )
1075 openWebBrowser( pHyperlink->GetURL(), GetText() );
1077 return 1;
1080 // -----------------------------------------------------------------------
1081 IMPL_LINK( ExtMgrDialog, TimeOutHdl, Timer*, EMPTYARG )
1083 if ( m_bStopProgress )
1085 m_bHasProgress = false;
1086 m_bStopProgress = false;
1087 m_aProgressText.Hide();
1088 m_aProgressBar.Hide();
1089 m_aCancelBtn.Hide();
1091 else
1093 if ( m_bProgressChanged )
1095 m_bProgressChanged = false;
1096 m_aProgressText.SetText( m_sProgressText );
1099 if ( m_bStartProgress )
1101 m_bStartProgress = false;
1102 m_bHasProgress = true;
1103 m_aProgressBar.Show();
1104 m_aProgressText.Show();
1105 m_aCancelBtn.Enable();
1106 m_aCancelBtn.Show();
1109 if ( m_aProgressBar.IsVisible() )
1110 m_aProgressBar.SetValue( (USHORT) m_nProgress );
1112 m_aTimeoutTimer.Start();
1115 return 1;
1118 //------------------------------------------------------------------------------
1119 // VCL::Window / Dialog
1120 void ExtMgrDialog::Resize()
1122 Size aTotalSize( GetOutputSizePixel() );
1123 Size aBtnSize( m_aHelpBtn.GetSizePixel() );
1124 Size aUpdBtnSize( m_aUpdateBtn.GetSizePixel() );
1126 Point aPos( RSC_SP_DLG_INNERBORDER_LEFT,
1127 aTotalSize.Height() - RSC_SP_DLG_INNERBORDER_BOTTOM - aBtnSize.Height() );
1129 m_aHelpBtn.SetPosPixel( aPos );
1131 aPos.X() = aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - aBtnSize.Width();
1132 m_aCloseBtn.SetPosPixel( aPos );
1134 aPos.X() -= ( RSC_SP_CTRL_X + aUpdBtnSize.Width() );
1135 m_aUpdateBtn.SetPosPixel( aPos );
1137 aPos.X() -= ( RSC_SP_CTRL_GROUP_Y + aBtnSize.Width() );
1138 m_aAddBtn.SetPosPixel( aPos );
1140 Size aDivSize( aTotalSize.Width(), LINE_SIZE );
1141 aPos = Point( 0, aPos.Y() - LINE_SIZE - RSC_SP_DLG_INNERBORDER_BOTTOM );
1142 m_aDivider.SetPosSizePixel( aPos, aDivSize );
1144 Size aFTSize( m_aGetExtensions.CalcMinimumSize() );
1145 aPos = Point( RSC_SP_DLG_INNERBORDER_LEFT, aPos.Y() - RSC_CD_FIXEDTEXT_HEIGHT - 2*RSC_SP_DLG_INNERBORDER_BOTTOM );
1147 m_aGetExtensions.SetPosSizePixel( aPos, aFTSize );
1149 aPos.X() = aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - aBtnSize.Width();
1150 m_aCancelBtn.SetPosPixel( Point( aPos.X(), aPos.Y() - ((aBtnSize.Height()-aFTSize.Height())/2) ) );
1152 // Calc progress height
1153 long nProgressHeight = aFTSize.Height();
1155 if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
1157 ImplControlValue aValue;
1158 bool bNativeOK;
1159 Region aControlRegion( Rectangle( (const Point&)Point(), m_aProgressBar.GetSizePixel() ) );
1160 Region aNativeControlRegion, aNativeContentRegion;
1161 if( (bNativeOK = GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
1162 CTRL_STATE_ENABLED, aValue, rtl::OUString(),
1163 aNativeControlRegion, aNativeContentRegion ) ) != FALSE )
1165 nProgressHeight = aNativeControlRegion.GetBoundRect().GetHeight();
1169 if ( nProgressHeight < PROGRESS_HEIGHT )
1170 nProgressHeight = PROGRESS_HEIGHT;
1172 aPos.X() -= ( RSC_SP_CTRL_GROUP_Y + PROGRESS_WIDTH );
1173 m_aProgressBar.SetPosSizePixel( Point( aPos.X(), aPos.Y() - ((nProgressHeight-aFTSize.Height())/2) ),
1174 Size( PROGRESS_WIDTH, nProgressHeight ) );
1176 Rectangle aRect1( m_aGetExtensions.GetPosPixel(), m_aGetExtensions.GetSizePixel() );
1177 Rectangle aRect2( m_aProgressBar.GetPosPixel(), m_aProgressBar.GetSizePixel() );
1179 aFTSize.Width() = ( aRect2.Left() - aRect1.Right() ) - 2*RSC_SP_DLG_INNERBORDER_LEFT;
1180 aPos.X() = aRect1.Right() + RSC_SP_DLG_INNERBORDER_LEFT;
1181 m_aProgressText.SetPosSizePixel( aPos, aFTSize );
1183 Size aSize( aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_LEFT - RSC_SP_DLG_INNERBORDER_RIGHT,
1184 aTotalSize.Height() - 2*aBtnSize.Height() - LINE_SIZE -
1185 RSC_SP_DLG_INNERBORDER_TOP - 3*RSC_SP_DLG_INNERBORDER_BOTTOM );
1187 m_pExtensionBox->SetSizePixel( aSize );
1189 //------------------------------------------------------------------------------
1190 // VCL::Window / Dialog
1192 long ExtMgrDialog::Notify( NotifyEvent& rNEvt )
1194 bool bHandled = false;
1196 if ( rNEvt.GetType() == EVENT_KEYINPUT )
1198 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
1199 KeyCode aKeyCode = pKEvt->GetKeyCode();
1200 USHORT nKeyCode = aKeyCode.GetCode();
1202 if ( nKeyCode == KEY_TAB )
1204 if ( aKeyCode.IsShift() ) {
1205 if ( m_aAddBtn.HasFocus() ) {
1206 m_pExtensionBox->GrabFocus();
1207 bHandled = true;
1209 } else {
1210 if ( m_aGetExtensions.HasFocus() ) {
1211 m_pExtensionBox->GrabFocus();
1212 bHandled = true;
1216 if ( aKeyCode.GetGroup() == KEYGROUP_CURSOR )
1217 bHandled = m_pExtensionBox->Notify( rNEvt );
1219 // VCLEVENT_WINDOW_CLOSE
1220 if ( !bHandled )
1221 return ModelessDialog::Notify( rNEvt );
1222 else
1223 return true;
1226 //------------------------------------------------------------------------------
1227 BOOL ExtMgrDialog::Close()
1229 bool bRet = m_pManager->queryTermination();
1230 if ( bRet )
1232 bRet = ModelessDialog::Close();
1233 m_pManager->terminateDialog();
1235 return bRet;
1238 //------------------------------------------------------------------------------
1239 // UpdateRequiredDialog
1240 //------------------------------------------------------------------------------
1241 UpdateRequiredDialog::UpdateRequiredDialog( Window *pParent, TheExtensionManager *pManager ) :
1242 ModalDialog( pParent, getResId( RID_DLG_UPDATE_REQUIRED ) ),
1243 DialogHelper( pManager->getContext(), (Dialog*) this ),
1244 m_aUpdateNeeded( this, getResId( RID_EM_FT_MSG ) ),
1245 m_aUpdateBtn( this, getResId( RID_EM_BTN_CHECK_UPDATES ) ),
1246 m_aCloseBtn( this, getResId( RID_EM_BTN_CLOSE ) ),
1247 m_aHelpBtn( this, getResId( RID_EM_BTN_HELP ) ),
1248 m_aCancelBtn( this, getResId( RID_EM_BTN_CANCEL ) ),
1249 m_aDivider( this ),
1250 m_aProgressText( this, getResId( RID_EM_FT_PROGRESS ) ),
1251 m_aProgressBar( this, WB_BORDER + WB_3DLOOK ),
1252 m_sAddPackages( getResourceString( RID_STR_ADD_PACKAGES ) ),
1253 m_sCloseText( getResourceString( RID_STR_CLOSE_BTN ) ),
1254 m_bHasProgress( false ),
1255 m_bProgressChanged( false ),
1256 m_bStartProgress( false ),
1257 m_bStopProgress( false ),
1258 m_bUpdateWarning( false ),
1259 m_bDisableWarning( false ),
1260 m_bHasLockedEntries( false ),
1261 m_nProgress( 0 ),
1262 m_pManager( pManager )
1264 // free local resources (RID < 256):
1265 FreeResource();
1267 m_pExtensionBox = new ExtensionBox_Impl( this, pManager );
1268 m_pExtensionBox->SetHyperlinkHdl( LINK( this, UpdateRequiredDialog, HandleHyperlink ) );
1270 m_aUpdateBtn.SetClickHdl( LINK( this, UpdateRequiredDialog, HandleUpdateBtn ) );
1271 m_aCloseBtn.SetClickHdl( LINK( this, UpdateRequiredDialog, HandleCloseBtn ) );
1272 m_aCancelBtn.SetClickHdl( LINK( this, UpdateRequiredDialog, HandleCancelBtn ) );
1274 String aText = m_aUpdateNeeded.GetText();
1275 aText.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
1276 m_aUpdateNeeded.SetText( aText );
1278 // resize update button
1279 Size aBtnSize = m_aUpdateBtn.GetSizePixel();
1280 String sTitle = m_aUpdateBtn.GetText();
1281 long nWidth = m_aUpdateBtn.GetCtrlTextWidth( sTitle );
1282 nWidth += 2 * m_aUpdateBtn.GetTextHeight();
1283 if ( nWidth > aBtnSize.Width() )
1284 m_aUpdateBtn.SetSizePixel( Size( nWidth, aBtnSize.Height() ) );
1286 // resize update button
1287 aBtnSize = m_aCloseBtn.GetSizePixel();
1288 sTitle = m_aCloseBtn.GetText();
1289 nWidth = m_aCloseBtn.GetCtrlTextWidth( sTitle );
1290 nWidth += 2 * m_aCloseBtn.GetTextHeight();
1291 if ( nWidth > aBtnSize.Width() )
1292 m_aCloseBtn.SetSizePixel( Size( nWidth, aBtnSize.Height() ) );
1294 // minimum size:
1295 SetMinOutputSizePixel(
1296 Size( // width:
1297 (5 * m_aHelpBtn.GetSizePixel().Width()) +
1298 (5 * RSC_SP_DLG_INNERBORDER_LEFT ),
1299 // height:
1300 (1 * m_aHelpBtn.GetSizePixel().Height()) +
1301 (1 * m_aUpdateNeeded.GetSizePixel().Height()) +
1302 (1 * m_pExtensionBox->GetMinOutputSizePixel().Height()) +
1303 (3 * RSC_SP_DLG_INNERBORDER_LEFT) ) );
1305 m_aDivider.Show();
1306 m_aProgressBar.Hide();
1307 m_aUpdateBtn.Enable( false );
1308 m_aCloseBtn.GrabFocus();
1310 m_aTimeoutTimer.SetTimeout( 50 ); // mSec
1311 m_aTimeoutTimer.SetTimeoutHdl( LINK( this, UpdateRequiredDialog, TimeOutHdl ) );
1314 //------------------------------------------------------------------------------
1315 UpdateRequiredDialog::~UpdateRequiredDialog()
1317 m_aTimeoutTimer.Stop();
1319 delete m_pExtensionBox;
1322 //------------------------------------------------------------------------------
1323 long UpdateRequiredDialog::addPackageToList( const uno::Reference< deployment::XPackage > &xPackage,
1324 const uno::Reference< deployment::XPackageManager > &xPackageManager )
1326 // We will only add entries to the list with unsatisfied dependencies
1327 if ( !checkDependencies( xPackage ) )
1329 m_bHasLockedEntries |= (bool) xPackageManager->isReadOnly();
1330 m_aUpdateBtn.Enable( true );
1331 return m_pExtensionBox->addEntry( xPackage, xPackageManager );
1333 return 0;
1336 //------------------------------------------------------------------------------
1337 void UpdateRequiredDialog::prepareChecking( const uno::Reference< deployment::XPackageManager > &xPackageManager )
1339 if ( xPackageManager.is() )
1340 m_pExtensionBox->prepareChecking( xPackageManager );
1343 //------------------------------------------------------------------------------
1344 void UpdateRequiredDialog::checkEntries()
1346 const ::vos::OGuard guard( Application::GetSolarMutex() );
1347 m_pExtensionBox->checkEntries();
1349 if ( ! hasActiveEntries() )
1351 m_aCloseBtn.SetText( m_sCloseText );
1352 m_aCloseBtn.GrabFocus();
1356 //------------------------------------------------------------------------------
1357 bool UpdateRequiredDialog::enablePackage( const uno::Reference< deployment::XPackageManager > &,
1358 const uno::Reference< deployment::XPackage > &xPackage,
1359 bool bEnable )
1361 m_pManager->enablePackage( xPackage, bEnable );
1363 return true;
1366 //------------------------------------------------------------------------------
1367 IMPL_LINK( UpdateRequiredDialog, HandleCancelBtn, void*, EMPTYARG )
1369 // m_dialog->m_cmdEnv->m_aborted = true;
1370 if ( m_xAbortChannel.is() )
1374 m_xAbortChannel->sendAbort();
1376 catch ( uno::RuntimeException & )
1378 OSL_ENSURE( 0, "### unexpected RuntimeException!" );
1381 return 1;
1384 // ------------------------------------------------------------------------------
1385 IMPL_LINK( UpdateRequiredDialog, startProgress, void*, _bLockInterface )
1387 ::osl::MutexGuard aGuard( m_aMutex );
1388 bool bLockInterface = (bool) _bLockInterface;
1390 if ( m_bStartProgress && !m_bHasProgress )
1391 m_aTimeoutTimer.Start();
1393 if ( m_bStopProgress )
1395 if ( m_aProgressBar.IsVisible() )
1396 m_aProgressBar.SetValue( 100 );
1397 m_xAbortChannel.clear();
1398 OSL_TRACE( " startProgress handler: stop\n" );
1400 else
1402 OSL_TRACE( " startProgress handler: start\n" );
1405 m_aCancelBtn.Enable( bLockInterface );
1406 m_aUpdateBtn.Enable( false );
1407 clearEventID();
1409 return 0;
1412 // ------------------------------------------------------------------------------
1413 void UpdateRequiredDialog::showProgress( bool _bStart )
1415 ::osl::MutexGuard aGuard( m_aMutex );
1417 bool bStart = _bStart;
1419 if ( bStart )
1421 m_nProgress = 0;
1422 m_bStartProgress = true;
1423 OSL_TRACE( "showProgress start\n" );
1425 else
1427 m_nProgress = 100;
1428 m_bStopProgress = true;
1429 OSL_TRACE( "showProgress stop!\n" );
1432 DialogHelper::PostUserEvent( LINK( this, UpdateRequiredDialog, startProgress ), (void*) bStart );
1435 // -----------------------------------------------------------------------
1436 void UpdateRequiredDialog::updateProgress( const long nProgress )
1438 ::osl::MutexGuard aGuard( m_aMutex );
1440 m_nProgress = nProgress;
1443 // -----------------------------------------------------------------------
1444 void UpdateRequiredDialog::updateProgress( const OUString &rText,
1445 const uno::Reference< task::XAbortChannel > &xAbortChannel)
1447 ::osl::MutexGuard aGuard( m_aMutex );
1449 m_xAbortChannel = xAbortChannel;
1450 m_sProgressText = rText;
1451 m_bProgressChanged = true;
1454 //------------------------------------------------------------------------------
1455 void UpdateRequiredDialog::updatePackageInfo( const uno::Reference< deployment::XPackage > &xPackage )
1457 // We will remove all updated packages with satisfied dependencies, but
1458 // we will show all disabled entries so the user sees the result
1459 // of the 'disable all' button
1460 if ( isEnabled( xPackage ) && checkDependencies( xPackage ) )
1461 m_pExtensionBox->removeEntry( xPackage );
1462 else
1463 m_pExtensionBox->updateEntry( xPackage );
1465 if ( ! hasActiveEntries() )
1467 m_aCloseBtn.SetText( m_sCloseText );
1468 m_aCloseBtn.GrabFocus();
1472 // -----------------------------------------------------------------------
1473 IMPL_LINK( UpdateRequiredDialog, HandleUpdateBtn, void*, EMPTYARG )
1475 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1477 std::vector< TUpdateListEntry > vUpdateEntries;
1478 sal_Int32 nCount = m_pExtensionBox->GetEntryCount();
1480 for ( sal_Int32 i = 0; i < nCount; ++i )
1482 TEntry_Impl pEntry = m_pExtensionBox->GetEntryData( i );
1483 TUpdateListEntry pUpdateEntry( new UpdateListEntry( pEntry->m_xPackage,
1484 pEntry->m_xPackageManager ) );
1485 vUpdateEntries.push_back( pUpdateEntry );
1488 aGuard.clear();
1490 m_pManager->updatePackages( vUpdateEntries );
1492 return 1;
1495 // -----------------------------------------------------------------------
1496 IMPL_LINK( UpdateRequiredDialog, HandleCloseBtn, void*, EMPTYARG )
1498 ::osl::MutexGuard aGuard( m_aMutex );
1500 if ( !isBusy() )
1502 if ( m_bHasLockedEntries )
1503 EndDialog( -1 );
1504 else if ( hasActiveEntries() )
1505 disableAllEntries();
1506 else
1507 EndDialog( 0 );
1510 return 1;
1513 // -----------------------------------------------------------------------
1514 IMPL_LINK( UpdateRequiredDialog, HandleHyperlink, svt::FixedHyperlink*, pHyperlink )
1516 openWebBrowser( pHyperlink->GetURL(), GetText() );
1518 return 1;
1521 // -----------------------------------------------------------------------
1522 IMPL_LINK( UpdateRequiredDialog, TimeOutHdl, Timer*, EMPTYARG )
1524 if ( m_bStopProgress )
1526 m_bHasProgress = false;
1527 m_bStopProgress = false;
1528 m_aProgressText.Hide();
1529 m_aProgressBar.Hide();
1530 m_aCancelBtn.Hide();
1532 else
1534 if ( m_bProgressChanged )
1536 m_bProgressChanged = false;
1537 m_aProgressText.SetText( m_sProgressText );
1540 if ( m_bStartProgress )
1542 m_bStartProgress = false;
1543 m_bHasProgress = true;
1544 m_aProgressBar.Show();
1545 m_aProgressText.Show();
1546 m_aCancelBtn.Enable();
1547 m_aCancelBtn.Show();
1550 if ( m_aProgressBar.IsVisible() )
1551 m_aProgressBar.SetValue( (USHORT) m_nProgress );
1553 m_aTimeoutTimer.Start();
1556 return 1;
1559 //------------------------------------------------------------------------------
1560 // VCL::Window / Dialog
1561 void UpdateRequiredDialog::Resize()
1563 Size aTotalSize( GetOutputSizePixel() );
1564 Size aBtnSize( m_aHelpBtn.GetSizePixel() );
1566 Point aPos( RSC_SP_DLG_INNERBORDER_LEFT,
1567 aTotalSize.Height() - RSC_SP_DLG_INNERBORDER_BOTTOM - aBtnSize.Height() );
1569 m_aHelpBtn.SetPosPixel( aPos );
1571 aPos.X() = aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - m_aCloseBtn.GetSizePixel().Width();
1572 m_aCloseBtn.SetPosPixel( aPos );
1574 aPos.X() -= ( RSC_SP_CTRL_X + m_aUpdateBtn.GetSizePixel().Width() );
1575 m_aUpdateBtn.SetPosPixel( aPos );
1577 Size aDivSize( aTotalSize.Width(), LINE_SIZE );
1578 aPos = Point( 0, aPos.Y() - LINE_SIZE - RSC_SP_DLG_INNERBORDER_BOTTOM );
1579 m_aDivider.SetPosSizePixel( aPos, aDivSize );
1581 // Calc fixed text size
1582 aPos = Point( RSC_SP_DLG_INNERBORDER_LEFT, RSC_SP_DLG_INNERBORDER_TOP );
1583 Size aFTSize = m_aUpdateNeeded.CalcMinimumSize( aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - RSC_SP_DLG_INNERBORDER_LEFT );
1584 m_aUpdateNeeded.SetPosSizePixel( aPos, aFTSize );
1586 // Calc list box size
1587 Size aSize( aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_LEFT - RSC_SP_DLG_INNERBORDER_RIGHT,
1588 aTotalSize.Height() - 2*aBtnSize.Height() - LINE_SIZE -
1589 2*RSC_SP_DLG_INNERBORDER_TOP - 3*RSC_SP_DLG_INNERBORDER_BOTTOM - aFTSize.Height() );
1590 aPos.Y() += aFTSize.Height()+RSC_SP_DLG_INNERBORDER_TOP;
1592 m_pExtensionBox->SetPosSizePixel( aPos, aSize );
1594 aPos.X() = aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - aBtnSize.Width();
1595 aPos.Y() += aSize.Height()+RSC_SP_DLG_INNERBORDER_TOP;
1596 m_aCancelBtn.SetPosPixel( aPos );
1598 // Calc progress height
1599 aFTSize = m_aProgressText.GetSizePixel();
1600 long nProgressHeight = aFTSize.Height();
1602 if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
1604 ImplControlValue aValue;
1605 bool bNativeOK;
1606 Region aControlRegion( Rectangle( (const Point&)Point(), m_aProgressBar.GetSizePixel() ) );
1607 Region aNativeControlRegion, aNativeContentRegion;
1608 if( (bNativeOK = GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
1609 CTRL_STATE_ENABLED, aValue, rtl::OUString(),
1610 aNativeControlRegion, aNativeContentRegion ) ) != FALSE )
1612 nProgressHeight = aNativeControlRegion.GetBoundRect().GetHeight();
1616 if ( nProgressHeight < PROGRESS_HEIGHT )
1617 nProgressHeight = PROGRESS_HEIGHT;
1619 aPos.X() -= ( RSC_SP_CTRL_GROUP_Y + PROGRESS_WIDTH );
1620 m_aProgressBar.SetPosSizePixel( Point( aPos.X(), aPos.Y() + ((aBtnSize.Height()-nProgressHeight)/2) ),
1621 Size( PROGRESS_WIDTH, nProgressHeight ) );
1623 aFTSize.Width() = aPos.X() - 2*RSC_SP_DLG_INNERBORDER_LEFT;
1624 aPos.X() = RSC_SP_DLG_INNERBORDER_LEFT;
1625 aPos.Y() += ( aBtnSize.Height() - aFTSize.Height() - 1 ) / 2;
1626 m_aProgressText.SetPosSizePixel( aPos, aFTSize );
1629 //------------------------------------------------------------------------------
1630 // VCL::Dialog
1631 short UpdateRequiredDialog::Execute()
1633 if ( m_bHasLockedEntries )
1635 // Set other text, disable update btn, remove not shared entries from list;
1636 m_aUpdateNeeded.SetText( DialogHelper::getResourceString( RID_STR_NO_ADMIN_PRIVILEGE ) );
1637 m_aCloseBtn.SetText( DialogHelper::getResourceString( RID_STR_EXIT_BTN ) );
1638 m_aUpdateBtn.Enable( false );
1639 m_pExtensionBox->RemoveUnlocked();
1640 Resize();
1643 return Dialog::Execute();
1646 //------------------------------------------------------------------------------
1647 // VCL::Dialog
1648 BOOL UpdateRequiredDialog::Close()
1650 ::osl::MutexGuard aGuard( m_aMutex );
1652 if ( !isBusy() )
1654 if ( m_bHasLockedEntries )
1655 EndDialog( -1 );
1656 else if ( hasActiveEntries() )
1657 disableAllEntries();
1658 else
1659 EndDialog( 0 );
1662 return false;
1665 //------------------------------------------------------------------------------
1666 // Check dependencies of all packages
1667 //------------------------------------------------------------------------------
1668 bool UpdateRequiredDialog::isEnabled( const uno::Reference< deployment::XPackage > &xPackage ) const
1670 bool bRegistered = false;
1671 try {
1672 beans::Optional< beans::Ambiguous< sal_Bool > > option( xPackage->isRegistered( uno::Reference< task::XAbortChannel >(),
1673 uno::Reference< ucb::XCommandEnvironment >() ) );
1674 if ( option.IsPresent )
1676 ::beans::Ambiguous< sal_Bool > const & reg = option.Value;
1677 if ( reg.IsAmbiguous )
1678 bRegistered = false;
1679 else
1680 bRegistered = reg.Value ? true : false;
1682 else
1683 bRegistered = false;
1685 catch ( uno::RuntimeException & ) { throw; }
1686 catch ( uno::Exception & exc) {
1687 (void) exc;
1688 OSL_ENSURE( 0, ::rtl::OUStringToOString( exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
1689 bRegistered = false;
1692 return bRegistered;
1695 //------------------------------------------------------------------------------
1696 bool UpdateRequiredDialog::checkDependencies( const uno::Reference< deployment::XPackage > &xPackage ) const
1698 if ( isEnabled( xPackage ) )
1700 bool bDependenciesValid = false;
1701 try {
1702 bDependenciesValid = xPackage->checkDependencies( uno::Reference< ucb::XCommandEnvironment >() );
1704 catch ( deployment::DeploymentException & ) {}
1705 if ( ! bDependenciesValid )
1707 return false;
1710 return true;
1713 //------------------------------------------------------------------------------
1714 bool UpdateRequiredDialog::hasActiveEntries()
1716 ::osl::MutexGuard aGuard( m_aMutex );
1718 bool bRet = false;
1719 long nCount = m_pExtensionBox->GetEntryCount();
1720 for ( long nIndex = 0; nIndex < nCount; nIndex++ )
1722 TEntry_Impl pEntry = m_pExtensionBox->GetEntryData( nIndex );
1724 if ( !checkDependencies( pEntry->m_xPackage ) )
1726 bRet = true;
1727 break;
1731 return bRet;
1734 //------------------------------------------------------------------------------
1735 void UpdateRequiredDialog::disableAllEntries()
1737 ::osl::MutexGuard aGuard( m_aMutex );
1739 setBusy( true );
1741 long nCount = m_pExtensionBox->GetEntryCount();
1742 for ( long nIndex = 0; nIndex < nCount; nIndex++ )
1744 TEntry_Impl pEntry = m_pExtensionBox->GetEntryData( nIndex );
1745 enablePackage( pEntry->m_xPackageManager, pEntry->m_xPackage, false );
1748 setBusy( false );
1750 if ( ! hasActiveEntries() )
1751 m_aCloseBtn.SetText( m_sCloseText );
1754 //=================================================================================
1755 // UpdateRequiredDialogService
1756 //=================================================================================
1757 UpdateRequiredDialogService::UpdateRequiredDialogService( uno::Sequence< uno::Any > const&,
1758 uno::Reference< uno::XComponentContext > const& xComponentContext )
1759 : m_xComponentContext( xComponentContext )
1763 //------------------------------------------------------------------------------
1764 // XExecutableDialog
1765 //------------------------------------------------------------------------------
1766 void UpdateRequiredDialogService::setTitle( OUString const & ) throw ( uno::RuntimeException )
1770 //------------------------------------------------------------------------------
1771 sal_Int16 UpdateRequiredDialogService::execute() throw ( uno::RuntimeException )
1773 ::rtl::Reference< ::dp_gui::TheExtensionManager > xManager( TheExtensionManager::get(
1774 m_xComponentContext,
1775 uno::Reference< awt::XWindow >(),
1776 OUString() ) );
1777 xManager->createDialog( true );
1778 sal_Int16 nRet = xManager->execute();
1780 return nRet;
1783 //------------------------------------------------------------------------------
1784 //------------------------------------------------------------------------------
1785 //------------------------------------------------------------------------------
1786 SelectedPackage::~SelectedPackage() {}
1788 } //namespace dp_gui