1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_desktop.hxx"
24
25 #include "dp_gui.hrc"
26 #include "svtools/controldims.hrc"
27 #include "svtools/svtools.hrc"
28
29 #include "dp_gui.h"
30 #include "dp_gui_dialog2.hxx"
31 #include "dp_gui_extlistbox.hxx"
32 #include "dp_gui_shared.hxx"
33 #include "dp_gui_theextmgr.hxx"
34 #include "dp_gui_extensioncmdqueue.hxx"
35 #include "dp_misc.h"
36 #include "dp_ucb.h"
37 #include "dp_update.hxx"
38 #include "dp_identifier.hxx"
39 #include "dp_descriptioninfoset.hxx"
40
41 #include "vcl/ctrl.hxx"
42 #include "vcl/menu.hxx"
43 #include "vcl/msgbox.hxx"
44 #include "vcl/scrbar.hxx"
45 #include "vcl/svapp.hxx"
46
47 #include "vos/mutex.hxx"
48
49 #include "svtools/extensionlistbox.hxx"
50
51 #include "sfx2/sfxdlg.hxx"
52
53 #include "comphelper/anytostring.hxx"
54 #include "cppuhelper/exc_hlp.hxx"
55 #include "cppuhelper/bootstrap.hxx"
56
57 #include "comphelper/processfactory.hxx"
58 #include "ucbhelper/content.hxx"
59 #include "unotools/collatorwrapper.hxx"
60
61 #include "com/sun/star/beans/StringPair.hpp"
62
63 #include "com/sun/star/i18n/CollatorOptions.hpp"
64
65 #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
66 #include "com/sun/star/system/SystemShellExecute.hpp"
67
68 #include "com/sun/star/ui/dialogs/ExecutableDialogResults.hpp"
69 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
70 #include "com/sun/star/ui/dialogs/XFilePicker.hpp"
71 #include "com/sun/star/ui/dialogs/XFilterManager.hpp"
72
73 #include "com/sun/star/uno/Any.hxx"
74 #include "com/sun/star/uno/XComponentContext.hpp"
75
76 #include <map>
77 #include <vector>
78 #include <boost/shared_ptr.hpp>
79
80 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
81
82 using namespace ::com::sun::star;
83 using namespace ::com::sun::star::system;
84
85 using ::rtl::OUString;
86
87 namespace dp_gui {
88
89 #define TOP_OFFSET 5
90 #define LINE_SIZE 4
91 #define PROGRESS_WIDTH 60
92 #define PROGRESS_HEIGHT 14
93
94 //------------------------------------------------------------------------------
95 struct StrAllFiles : public rtl::StaticWithInit< const OUString, StrAllFiles >
96 {
operator ()dp_gui::StrAllFiles97 const OUString operator () () {
98 const ::vos::OGuard guard( Application::GetSolarMutex() );
99 ::std::auto_ptr< ResMgr > const resmgr( ResMgr::CreateResMgr( "fps_office" ) );
100 OSL_ASSERT( resmgr.get() != 0 );
101 String ret( ResId( STR_FILTERNAME_ALL, *resmgr.get() ) );
102 return ret;
103 }
104 };
105
106 //------------------------------------------------------------------------------
107 // ExtBoxWithBtns_Impl
108 //------------------------------------------------------------------------------
109
110 enum MENU_COMMAND
111 {
112 CMD_NONE = 0,
113 CMD_REMOVE = 1,
114 CMD_ENABLE,
115 CMD_DISABLE,
116 CMD_UPDATE,
117 CMD_SHOW_LICENSE
118 };
119
120 class ExtBoxWithBtns_Impl : public ExtensionBox_Impl
121 {
122 Size m_aOutputSize;
123 bool m_bInterfaceLocked;
124
125 PushButton *m_pOptionsBtn;
126 PushButton *m_pEnableBtn;
127 PushButton *m_pRemoveBtn;
128
129 ExtMgrDialog *m_pParent;
130
131 void SetButtonPos( const Rectangle& rRect );
132 void SetButtonStatus( const TEntry_Impl pEntry );
133 bool HandleTabKey( bool bReverse );
134 MENU_COMMAND ShowPopupMenu( const Point &rPos, const long nPos );
135
136 //-----------------
137 DECL_DLLPRIVATE_LINK( ScrollHdl, ScrollBar * );
138
139 DECL_DLLPRIVATE_LINK( HandleOptionsBtn, void * );
140 DECL_DLLPRIVATE_LINK( HandleEnableBtn, void * );
141 DECL_DLLPRIVATE_LINK( HandleRemoveBtn, void * );
142 DECL_DLLPRIVATE_LINK( HandleHyperlink, svt::FixedHyperlink * );
143
144 public:
145 ExtBoxWithBtns_Impl( ExtMgrDialog* pParent, TheExtensionManager *pManager );
146 ~ExtBoxWithBtns_Impl();
147
148 virtual void MouseButtonDown( const MouseEvent& rMEvt );
149 virtual long Notify( NotifyEvent& rNEvt );
150
151 const Size GetMinOutputSizePixel() const;
152
153 virtual void RecalcAll();
154 virtual void selectEntry( const long nPos );
155 //-----------------
156 void enableButtons( bool bEnable );
157 };
158
159 //------------------------------------------------------------------------------
ExtBoxWithBtns_Impl(ExtMgrDialog * pParent,TheExtensionManager * pManager)160 ExtBoxWithBtns_Impl::ExtBoxWithBtns_Impl( ExtMgrDialog* pParent, TheExtensionManager *pManager ) :
161 ExtensionBox_Impl( pParent, pManager ),
162 m_bInterfaceLocked( false ),
163 m_pOptionsBtn( NULL ),
164 m_pEnableBtn( NULL ),
165 m_pRemoveBtn( NULL ),
166 m_pParent( pParent )
167 {
168 m_pOptionsBtn = new PushButton( this, WB_TABSTOP );
169 m_pEnableBtn = new PushButton( this, WB_TABSTOP );
170 m_pRemoveBtn = new PushButton( this, WB_TABSTOP );
171
172 SetHelpId( HID_EXTENSION_MANAGER_LISTBOX );
173 m_pOptionsBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_OPTIONS );
174 m_pEnableBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_DISABLE );
175 m_pRemoveBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_REMOVE );
176
177 m_pOptionsBtn->SetClickHdl( LINK( this, ExtBoxWithBtns_Impl, HandleOptionsBtn ) );
178 m_pEnableBtn->SetClickHdl( LINK( this, ExtBoxWithBtns_Impl, HandleEnableBtn ) );
179 m_pRemoveBtn->SetClickHdl( LINK( this, ExtBoxWithBtns_Impl, HandleRemoveBtn ) );
180
181 m_pOptionsBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_OPTIONS ) );
182 m_pEnableBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_DISABLE ) );
183 m_pRemoveBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_REMOVE ) );
184
185 Size aSize = LogicToPixel( Size( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ),
186 MapMode( MAP_APPFONT ) );
187 m_pOptionsBtn->SetSizePixel( aSize );
188 m_pEnableBtn->SetSizePixel( aSize );
189 m_pRemoveBtn->SetSizePixel( aSize );
190
191 SetExtraSize( aSize.Height() + 2 * TOP_OFFSET );
192
193 SetScrollHdl( LINK( this, ExtBoxWithBtns_Impl, ScrollHdl ) );
194 }
195
196 //------------------------------------------------------------------------------
~ExtBoxWithBtns_Impl()197 ExtBoxWithBtns_Impl::~ExtBoxWithBtns_Impl()
198 {
199 delete m_pOptionsBtn;
200 delete m_pEnableBtn;
201 delete m_pRemoveBtn;
202 }
203
204 //------------------------------------------------------------------------------
205 //------------------------------------------------------------------------------
206 //------------------------------------------------------------------------------
GetMinOutputSizePixel() const207 const Size ExtBoxWithBtns_Impl::GetMinOutputSizePixel() const
208 {
209 Size aMinSize( ExtensionBox_Impl::GetMinOutputSizePixel() );
210 long nHeight = aMinSize.Height();
211 nHeight += m_pOptionsBtn->GetSizePixel().Height();
212 nHeight += 2 * TOP_OFFSET;
213 long nWidth = m_pOptionsBtn->GetSizePixel().Width();
214 nWidth *= 3;
215 nWidth += 5*TOP_OFFSET + 20;
216
217 return Size( nWidth, nHeight );
218 }
219
220 // -----------------------------------------------------------------------
RecalcAll()221 void ExtBoxWithBtns_Impl::RecalcAll()
222 {
223 const sal_Int32 nActive = getSelIndex();
224
225 if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
226 {
227 SetButtonStatus( GetEntryData( nActive) );
228 }
229 else
230 {
231 m_pOptionsBtn->Hide();
232 m_pEnableBtn->Hide();
233 m_pRemoveBtn->Hide();
234 }
235
236 ExtensionBox_Impl::RecalcAll();
237
238 if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
239 SetButtonPos( GetEntryRect( nActive ) );
240 }
241
242
243 //------------------------------------------------------------------------------
244 //This function may be called with nPos < 0
selectEntry(const long nPos)245 void ExtBoxWithBtns_Impl::selectEntry( const long nPos )
246 {
247 if ( HasActive() && ( nPos == getSelIndex() ) )
248 return;
249
250 ExtensionBox_Impl::selectEntry( nPos );
251 }
252
253 // -----------------------------------------------------------------------
SetButtonPos(const Rectangle & rRect)254 void ExtBoxWithBtns_Impl::SetButtonPos( const Rectangle& rRect )
255 {
256 Size aBtnSize( m_pOptionsBtn->GetSizePixel() );
257 Point aBtnPos( rRect.Left() + ICON_OFFSET,
258 rRect.Bottom() - TOP_OFFSET - aBtnSize.Height() );
259
260 m_pOptionsBtn->SetPosPixel( aBtnPos );
261 aBtnPos.X() = rRect.Right() - TOP_OFFSET - aBtnSize.Width();
262 m_pRemoveBtn->SetPosPixel( aBtnPos );
263 aBtnPos.X() -= ( TOP_OFFSET + aBtnSize.Width() );
264 m_pEnableBtn->SetPosPixel( aBtnPos );
265 }
266
267 // -----------------------------------------------------------------------
SetButtonStatus(const TEntry_Impl pEntry)268 void ExtBoxWithBtns_Impl::SetButtonStatus( const TEntry_Impl pEntry )
269 {
270 bool bShowOptionBtn = true;
271
272 pEntry->m_bHasButtons = false;
273 if ( ( pEntry->m_eState == REGISTERED ) || ( pEntry->m_eState == NOT_AVAILABLE ) )
274 {
275 m_pEnableBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_DISABLE ) );
276 m_pEnableBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_DISABLE );
277 }
278 else
279 {
280 m_pEnableBtn->SetText( DialogHelper::getResourceString( RID_CTX_ITEM_ENABLE ) );
281 m_pEnableBtn->SetHelpId( HID_EXTENSION_MANAGER_LISTBOX_ENABLE );
282 bShowOptionBtn = false;
283 }
284
285 if ( ( !pEntry->m_bUser || ( pEntry->m_eState == NOT_AVAILABLE ) || pEntry->m_bMissingDeps )
286 && !pEntry->m_bMissingLic )
287 m_pEnableBtn->Hide();
288 else
289 {
290 m_pEnableBtn->Enable( !pEntry->m_bLocked );
291 m_pEnableBtn->Show();
292 pEntry->m_bHasButtons = true;
293 }
294
295 if ( pEntry->m_bHasOptions && bShowOptionBtn )
296 {
297 m_pOptionsBtn->Enable( pEntry->m_bHasOptions );
298 m_pOptionsBtn->Show();
299 pEntry->m_bHasButtons = true;
300 }
301 else
302 m_pOptionsBtn->Hide();
303
304 if ( pEntry->m_bUser || pEntry->m_bShared )
305 {
306 m_pRemoveBtn->Enable( !pEntry->m_bLocked );
307 m_pRemoveBtn->Show();
308 pEntry->m_bHasButtons = true;
309 }
310 else
311 m_pRemoveBtn->Hide();
312 }
313
314 // -----------------------------------------------------------------------
HandleTabKey(bool bReverse)315 bool ExtBoxWithBtns_Impl::HandleTabKey( bool bReverse )
316 {
317 sal_Int32 nIndex = getSelIndex();
318
319 if ( nIndex == EXTENSION_LISTBOX_ENTRY_NOTFOUND )
320 return false;
321
322 PushButton *pNext = NULL;
323
324 if ( m_pOptionsBtn->HasFocus() ) {
325 if ( !bReverse && !GetEntryData( nIndex )->m_bLocked )
326 pNext = m_pEnableBtn;
327 }
328 else if ( m_pEnableBtn->HasFocus() ) {
329 if ( !bReverse )
330 pNext = m_pRemoveBtn;
331 else if ( GetEntryData( nIndex )->m_bHasOptions )
332 pNext = m_pOptionsBtn;
333 }
334 else if ( m_pRemoveBtn->HasFocus() ) {
335 if ( bReverse )
336 pNext = m_pEnableBtn;
337 }
338 else {
339 if ( !bReverse ) {
340 if ( GetEntryData( nIndex )->m_bHasOptions )
341 pNext = m_pOptionsBtn;
342 else if ( ! GetEntryData( nIndex )->m_bLocked )
343 pNext = m_pEnableBtn;
344 } else {
345 if ( ! GetEntryData( nIndex )->m_bLocked )
346 pNext = m_pRemoveBtn;
347 else if ( GetEntryData( nIndex )->m_bHasOptions )
348 pNext = m_pOptionsBtn;
349 }
350 }
351
352 if ( pNext )
353 {
354 pNext->GrabFocus();
355 return true;
356 }
357 else
358 return false;
359 }
360
361 // -----------------------------------------------------------------------
ShowPopupMenu(const Point & rPos,const long nPos)362 MENU_COMMAND ExtBoxWithBtns_Impl::ShowPopupMenu( const Point & rPos, const long nPos )
363 {
364 if ( nPos >= (long) getItemCount() )
365 return CMD_NONE;
366
367 PopupMenu aPopup;
368
369 aPopup.InsertItem( CMD_UPDATE, DialogHelper::getResourceString( RID_CTX_ITEM_CHECK_UPDATE ) );
370
371 if ( ! GetEntryData( nPos )->m_bLocked )
372 {
373 if ( GetEntryData( nPos )->m_bUser )
374 {
375 if ( GetEntryData( nPos )->m_eState == REGISTERED )
376 aPopup.InsertItem( CMD_DISABLE, DialogHelper::getResourceString( RID_CTX_ITEM_DISABLE ) );
377 else if ( GetEntryData( nPos )->m_eState != NOT_AVAILABLE )
378 aPopup.InsertItem( CMD_ENABLE, DialogHelper::getResourceString( RID_CTX_ITEM_ENABLE ) );
379 }
380 aPopup.InsertItem( CMD_REMOVE, DialogHelper::getResourceString( RID_CTX_ITEM_REMOVE ) );
381 }
382
383 if ( GetEntryData( nPos )->m_sLicenseText.Len() )
384 aPopup.InsertItem( CMD_SHOW_LICENSE, DialogHelper::getResourceString( RID_STR_SHOW_LICENSE_CMD ) );
385
386 return (MENU_COMMAND) aPopup.Execute( this, rPos );
387 }
388
389 //------------------------------------------------------------------------------
MouseButtonDown(const MouseEvent & rMEvt)390 void ExtBoxWithBtns_Impl::MouseButtonDown( const MouseEvent& rMEvt )
391 {
392 if ( m_bInterfaceLocked )
393 return;
394
395 const Point aMousePos( rMEvt.GetPosPixel() );
396 const long nPos = PointToPos( aMousePos );
397
398 if ( rMEvt.IsRight() )
399 {
400 switch( ShowPopupMenu( aMousePos, nPos ) )
401 {
402 case CMD_NONE: break;
403 case CMD_ENABLE: m_pParent->enablePackage( GetEntryData( nPos )->m_xPackage, true );
404 break;
405 case CMD_DISABLE: m_pParent->enablePackage( GetEntryData( nPos )->m_xPackage, false );
406 break;
407 case CMD_UPDATE: m_pParent->updatePackage( GetEntryData( nPos )->m_xPackage );
408 break;
409 case CMD_REMOVE: m_pParent->removePackage( GetEntryData( nPos )->m_xPackage );
410 break;
411 case CMD_SHOW_LICENSE:
412 {
413 ShowLicenseDialog aLicenseDlg( m_pParent, GetEntryData( nPos )->m_xPackage );
414 aLicenseDlg.Execute();
415 break;
416 }
417 }
418 }
419 else if ( rMEvt.IsLeft() )
420 {
421 if ( rMEvt.IsMod1() && HasActive() )
422 selectEntry( EXTENSION_LISTBOX_ENTRY_NOTFOUND ); // Selecting an not existing entry will deselect the current one
423 else
424 selectEntry( nPos );
425 }
426 }
427
428 //------------------------------------------------------------------------------
Notify(NotifyEvent & rNEvt)429 long ExtBoxWithBtns_Impl::Notify( NotifyEvent& rNEvt )
430 {
431 bool bHandled = false;
432
433 if ( rNEvt.GetType() == EVENT_KEYINPUT )
434 {
435 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
436 KeyCode aKeyCode = pKEvt->GetKeyCode();
437 sal_uInt16 nKeyCode = aKeyCode.GetCode();
438
439 if ( nKeyCode == KEY_TAB )
440 bHandled = HandleTabKey( aKeyCode.IsShift() );
441 }
442
443 if ( !bHandled )
444 return ExtensionBox_Impl::Notify( rNEvt );
445 else
446 return true;
447 }
448
449 //------------------------------------------------------------------------------
enableButtons(bool bEnable)450 void ExtBoxWithBtns_Impl::enableButtons( bool bEnable )
451 {
452 m_bInterfaceLocked = ! bEnable;
453
454 if ( bEnable )
455 {
456 sal_Int32 nIndex = getSelIndex();
457 if ( nIndex != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
458 SetButtonStatus( GetEntryData( nIndex ) );
459 }
460 else
461 {
462 m_pOptionsBtn->Enable( false );
463 m_pRemoveBtn->Enable( false );
464 m_pEnableBtn->Enable( false );
465 }
466 }
467
468 // -----------------------------------------------------------------------
IMPL_LINK(ExtBoxWithBtns_Impl,ScrollHdl,ScrollBar *,pScrBar)469 IMPL_LINK( ExtBoxWithBtns_Impl, ScrollHdl, ScrollBar*, pScrBar )
470 {
471 long nDelta = pScrBar->GetDelta();
472
473 Point aNewOptPt( m_pOptionsBtn->GetPosPixel() - Point( 0, nDelta ) );
474 Point aNewRemPt( m_pRemoveBtn->GetPosPixel() - Point( 0, nDelta ) );
475 Point aNewEnPt( m_pEnableBtn->GetPosPixel() - Point( 0, nDelta ) );
476
477 DoScroll( nDelta );
478
479 m_pOptionsBtn->SetPosPixel( aNewOptPt );
480 m_pRemoveBtn->SetPosPixel( aNewRemPt );
481 m_pEnableBtn->SetPosPixel( aNewEnPt );
482
483 return 1;
484 }
485
486 // -----------------------------------------------------------------------
IMPL_LINK(ExtBoxWithBtns_Impl,HandleOptionsBtn,void *,EMPTYARG)487 IMPL_LINK( ExtBoxWithBtns_Impl, HandleOptionsBtn, void*, EMPTYARG )
488 {
489 const sal_Int32 nActive = getSelIndex();
490
491 if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
492 {
493 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
494
495 if ( pFact )
496 {
497 OUString sExtensionId = GetEntryData( nActive )->m_xPackage->getIdentifier().Value;
498 VclAbstractDialog* pDlg = pFact->CreateOptionsDialog( this, sExtensionId, rtl::OUString() );
499
500 pDlg->Execute();
501
502 delete pDlg;
503 }
504 }
505
506 return 1;
507 }
508
509 // -----------------------------------------------------------------------
IMPL_LINK(ExtBoxWithBtns_Impl,HandleEnableBtn,void *,EMPTYARG)510 IMPL_LINK( ExtBoxWithBtns_Impl, HandleEnableBtn, void*, EMPTYARG )
511 {
512 const sal_Int32 nActive = getSelIndex();
513
514 if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
515 {
516 TEntry_Impl pEntry = GetEntryData( nActive );
517
518 if ( pEntry->m_bMissingLic )
519 m_pParent->acceptLicense( pEntry->m_xPackage );
520 else
521 {
522 const bool bEnable( pEntry->m_eState != REGISTERED );
523 m_pParent->enablePackage( pEntry->m_xPackage, bEnable );
524 }
525 }
526
527 return 1;
528 }
529
530 // -----------------------------------------------------------------------
IMPL_LINK(ExtBoxWithBtns_Impl,HandleRemoveBtn,void *,EMPTYARG)531 IMPL_LINK( ExtBoxWithBtns_Impl, HandleRemoveBtn, void*, EMPTYARG )
532 {
533 const sal_Int32 nActive = getSelIndex();
534
535 if ( nActive != EXTENSION_LISTBOX_ENTRY_NOTFOUND )
536 {
537 TEntry_Impl pEntry = GetEntryData( nActive );
538 m_pParent->removePackage( pEntry->m_xPackage );
539 }
540
541 return 1;
542 }
543
544 //------------------------------------------------------------------------------
545 // DialogHelper
546 //------------------------------------------------------------------------------
DialogHelper(const uno::Reference<uno::XComponentContext> & xContext,Dialog * pWindow)547 DialogHelper::DialogHelper( const uno::Reference< uno::XComponentContext > &xContext,
548 Dialog *pWindow ) :
549 m_pVCLWindow( pWindow ),
550 m_nEventID( 0 ),
551 m_bIsBusy( false )
552 {
553 m_xContext = xContext;
554 }
555
556 //------------------------------------------------------------------------------
~DialogHelper()557 DialogHelper::~DialogHelper()
558 {
559 if ( m_nEventID )
560 Application::RemoveUserEvent( m_nEventID );
561 }
562
563 //------------------------------------------------------------------------------
getResId(sal_uInt16 nId)564 ResId DialogHelper::getResId( sal_uInt16 nId )
565 {
566 const ::vos::OGuard guard( Application::GetSolarMutex() );
567 return ResId( nId, *DeploymentGuiResMgr::get() );
568 }
569
570 //------------------------------------------------------------------------------
getResourceString(sal_uInt16 id)571 String DialogHelper::getResourceString( sal_uInt16 id )
572 {
573 // init with non-acquired solar mutex:
574 BrandName::get();
575 const ::vos::OGuard guard( Application::GetSolarMutex() );
576 String ret( ResId( id, *DeploymentGuiResMgr::get() ) );
577 if (ret.SearchAscii( "%PRODUCTNAME" ) != STRING_NOTFOUND) {
578 ret.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
579 }
580 return ret;
581 }
582
583 //------------------------------------------------------------------------------
IsSharedPkgMgr(const uno::Reference<deployment::XPackage> & xPackage)584 bool DialogHelper::IsSharedPkgMgr( const uno::Reference< deployment::XPackage > &xPackage )
585 {
586 if ( xPackage->getRepositoryName().equals( OUSTR("shared") ) )
587 return true;
588 else
589 return false;
590 }
591
592 //------------------------------------------------------------------------------
continueOnSharedExtension(const uno::Reference<deployment::XPackage> & xPackage,Window * pParent,const sal_uInt16 nResID,bool & bHadWarning)593 bool DialogHelper::continueOnSharedExtension( const uno::Reference< deployment::XPackage > &xPackage,
594 Window *pParent,
595 const sal_uInt16 nResID,
596 bool &bHadWarning )
597 {
598 if ( !bHadWarning && IsSharedPkgMgr( xPackage ) )
599 {
600 const ::vos::OGuard guard( Application::GetSolarMutex() );
601 WarningBox aInfoBox( pParent, getResId( nResID ) );
602 String aMsgText = aInfoBox.GetMessText();
603 aMsgText.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
604 aInfoBox.SetMessText( aMsgText );
605
606 bHadWarning = true;
607
608 if ( RET_OK == aInfoBox.Execute() )
609 return true;
610 else
611 return false;
612 }
613 else
614 return true;
615 }
616
617 //------------------------------------------------------------------------------
openWebBrowser(const OUString & sURL,const OUString & sTitle) const618 void DialogHelper::openWebBrowser( const OUString & sURL, const OUString &sTitle ) const
619 {
620 if ( ! sURL.getLength() ) // Nothing to do, when the URL is empty
621 return;
622
623 try
624 {
625 uno::Reference< XSystemShellExecute > xSystemShellExecute(
626 com::sun::star::system::SystemShellExecute::create( m_xContext ) );
627 //throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException
628 xSystemShellExecute->execute( sURL, OUString(), SystemShellExecuteFlags::DEFAULTS );
629 }
630 catch ( uno::Exception& )
631 {
632 uno::Any exc( ::cppu::getCaughtException() );
633 OUString msg( ::comphelper::anyToString( exc ) );
634 const ::vos::OGuard guard( Application::GetSolarMutex() );
635 ErrorBox aErrorBox( NULL, WB_OK, msg );
636 aErrorBox.SetText( sTitle );
637 aErrorBox.Execute();
638 }
639 }
640
641 //------------------------------------------------------------------------------
installExtensionWarn(const OUString & rExtensionName) const642 bool DialogHelper::installExtensionWarn( const OUString &rExtensionName ) const
643 {
644 const ::vos::OGuard guard( Application::GetSolarMutex() );
645 WarningBox aInfo( m_pVCLWindow, getResId( RID_WARNINGBOX_INSTALL_EXTENSION ) );
646
647 String sText( aInfo.GetMessText() );
648 sText.SearchAndReplaceAllAscii( "%NAME", rExtensionName );
649 aInfo.SetMessText( sText );
650
651 return ( RET_OK == aInfo.Execute() );
652 }
653
654 //------------------------------------------------------------------------------
installForAllUsers(bool & bInstallForAll) const655 bool DialogHelper::installForAllUsers( bool &bInstallForAll ) const
656 {
657 const ::vos::OGuard guard( Application::GetSolarMutex() );
658 QueryBox aQuery( m_pVCLWindow, getResId( RID_QUERYBOX_INSTALL_FOR_ALL ) );
659
660 String sMsgText = aQuery.GetMessText();
661 sMsgText.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
662 aQuery.SetMessText( sMsgText );
663
664 sal_uInt16 nYesBtnID = aQuery.GetButtonId( 0 );
665 sal_uInt16 nNoBtnID = aQuery.GetButtonId( 1 );
666
667 if ( nYesBtnID != BUTTONDIALOG_BUTTON_NOTFOUND )
668 aQuery.SetButtonText( nYesBtnID, getResourceString( RID_STR_INSTALL_FOR_ME ) );
669 if ( nNoBtnID != BUTTONDIALOG_BUTTON_NOTFOUND )
670 aQuery.SetButtonText( nNoBtnID, getResourceString( RID_STR_INSTALL_FOR_ALL ) );
671
672 short nRet = aQuery.Execute();
673
674 if ( nRet == RET_CANCEL )
675 return false;
676
677 bInstallForAll = ( nRet == RET_NO );
678 return true;
679 }
680
681 //------------------------------------------------------------------------------
PostUserEvent(const Link & rLink,void * pCaller)682 void DialogHelper::PostUserEvent( const Link& rLink, void* pCaller )
683 {
684 if ( m_nEventID )
685 Application::RemoveUserEvent( m_nEventID );
686
687 m_nEventID = Application::PostUserEvent( rLink, pCaller );
688 }
689
690 //------------------------------------------------------------------------------
691 // ExtMgrDialog
692 //------------------------------------------------------------------------------
ExtMgrDialog(Window * pParent,TheExtensionManager * pManager)693 ExtMgrDialog::ExtMgrDialog( Window *pParent, TheExtensionManager *pManager ) :
694 ModelessDialog( pParent, getResId( RID_DLG_EXTENSION_MANAGER ) ),
695 DialogHelper( pManager->getContext(), (Dialog*) this ),
696 m_aAddBtn( this, getResId( RID_EM_BTN_ADD ) ),
697 m_aUpdateBtn( this, getResId( RID_EM_BTN_CHECK_UPDATES ) ),
698 m_aCloseBtn( this, getResId( RID_EM_BTN_CLOSE ) ),
699 m_aHelpBtn( this, getResId( RID_EM_BTN_HELP ) ),
700 m_aDivider( this ),
701 m_aGetExtensions( this, getResId( RID_EM_FT_GET_EXTENSIONS ) ),
702 m_aProgressText( this, getResId( RID_EM_FT_PROGRESS ) ),
703 m_aProgressBar( this, WB_BORDER + WB_3DLOOK ),
704 m_aCancelBtn( this, getResId( RID_EM_BTN_CANCEL ) ),
705 m_sAddPackages( getResourceString( RID_STR_ADD_PACKAGES ) ),
706 m_bHasProgress( false ),
707 m_bProgressChanged( false ),
708 m_bStartProgress( false ),
709 m_bStopProgress( false ),
710 m_bUpdateWarning( false ),
711 m_bEnableWarning( false ),
712 m_bDisableWarning( false ),
713 m_bDeleteWarning( false ),
714 m_nProgress( 0 ),
715 m_pManager( pManager )
716 {
717 // free local resources (RID < 256):
718 FreeResource();
719
720 m_pExtensionBox = new ExtBoxWithBtns_Impl( this, pManager );
721 m_pExtensionBox->SetHyperlinkHdl( LINK( this, ExtMgrDialog, HandleHyperlink ) );
722
723 m_aAddBtn.SetClickHdl( LINK( this, ExtMgrDialog, HandleAddBtn ) );
724 m_aUpdateBtn.SetClickHdl( LINK( this, ExtMgrDialog, HandleUpdateBtn ) );
725 m_aGetExtensions.SetClickHdl( LINK( this, ExtMgrDialog, HandleHyperlink ) );
726 m_aCancelBtn.SetClickHdl( LINK( this, ExtMgrDialog, HandleCancelBtn ) );
727
728 // resize update button
729 Size aBtnSize = m_aUpdateBtn.GetSizePixel();
730 String sTitle = m_aUpdateBtn.GetText();
731 long nWidth = m_aUpdateBtn.GetCtrlTextWidth( sTitle );
732 nWidth += 2 * m_aUpdateBtn.GetTextHeight();
733 if ( nWidth > aBtnSize.Width() )
734 m_aUpdateBtn.SetSizePixel( Size( nWidth, aBtnSize.Height() ) );
735
736 // minimum size:
737 SetMinOutputSizePixel(
738 Size( // width:
739 (3 * m_aHelpBtn.GetSizePixel().Width()) +
740 m_aUpdateBtn.GetSizePixel().Width() +
741 (5 * RSC_SP_DLG_INNERBORDER_LEFT ),
742 // height:
743 (1 * m_aHelpBtn.GetSizePixel().Height()) +
744 (1 * m_aGetExtensions.GetSizePixel().Height()) +
745 (1 * m_pExtensionBox->GetMinOutputSizePixel().Height()) +
746 (3 * RSC_SP_DLG_INNERBORDER_LEFT) ) );
747
748 m_aDivider.Show();
749 m_aProgressBar.Hide();
750
751 m_aUpdateBtn.Enable( false );
752
753 m_aTimeoutTimer.SetTimeout( 500 ); // mSec
754 m_aTimeoutTimer.SetTimeoutHdl( LINK( this, ExtMgrDialog, TimeOutHdl ) );
755 }
756
757 //------------------------------------------------------------------------------
~ExtMgrDialog()758 ExtMgrDialog::~ExtMgrDialog()
759 {
760 m_aTimeoutTimer.Stop();
761 delete m_pExtensionBox;
762 }
763
764 //------------------------------------------------------------------------------
setGetExtensionsURL(const::rtl::OUString & rURL)765 void ExtMgrDialog::setGetExtensionsURL( const ::rtl::OUString &rURL )
766 {
767 m_aGetExtensions.SetURL( rURL );
768 }
769
770 //------------------------------------------------------------------------------
addPackageToList(const uno::Reference<deployment::XPackage> & xPackage,bool bLicenseMissing)771 long ExtMgrDialog::addPackageToList( const uno::Reference< deployment::XPackage > &xPackage,
772 bool bLicenseMissing )
773 {
774 m_aUpdateBtn.Enable( true );
775 return m_pExtensionBox->addEntry( xPackage, bLicenseMissing );
776 }
777
778 //------------------------------------------------------------------------------
prepareChecking()779 void ExtMgrDialog::prepareChecking()
780 {
781 m_pExtensionBox->prepareChecking();
782 }
783
784 //------------------------------------------------------------------------------
checkEntries()785 void ExtMgrDialog::checkEntries()
786 {
787 const ::vos::OGuard guard( Application::GetSolarMutex() );
788 m_pExtensionBox->checkEntries();
789 }
790
791 //------------------------------------------------------------------------------
removeExtensionWarn(const OUString & rExtensionName) const792 bool ExtMgrDialog::removeExtensionWarn( const OUString &rExtensionName ) const
793 {
794 const ::vos::OGuard guard( Application::GetSolarMutex() );
795 WarningBox aInfo( const_cast< ExtMgrDialog* >(this), getResId( RID_WARNINGBOX_REMOVE_EXTENSION ) );
796
797 String sText( aInfo.GetMessText() );
798 sText.SearchAndReplaceAllAscii( "%NAME", rExtensionName );
799 aInfo.SetMessText( sText );
800
801 return ( RET_OK == aInfo.Execute() );
802 }
803
804 //------------------------------------------------------------------------------
enablePackage(const uno::Reference<deployment::XPackage> & xPackage,bool bEnable)805 bool ExtMgrDialog::enablePackage( const uno::Reference< deployment::XPackage > &xPackage,
806 bool bEnable )
807 {
808 if ( !xPackage.is() )
809 return false;
810
811 if ( bEnable )
812 {
813 if ( ! continueOnSharedExtension( xPackage, this, RID_WARNINGBOX_ENABLE_SHARED_EXTENSION, m_bEnableWarning ) )
814 return false;
815 }
816 else
817 {
818 if ( ! continueOnSharedExtension( xPackage, this, RID_WARNINGBOX_DISABLE_SHARED_EXTENSION, m_bDisableWarning ) )
819 return false;
820 }
821
822 m_pManager->getCmdQueue()->enableExtension( xPackage, bEnable );
823
824 return true;
825 }
826
827 //------------------------------------------------------------------------------
removePackage(const uno::Reference<deployment::XPackage> & xPackage)828 bool ExtMgrDialog::removePackage( const uno::Reference< deployment::XPackage > &xPackage )
829 {
830 if ( !xPackage.is() )
831 return false;
832
833 if ( !IsSharedPkgMgr( xPackage ) || m_bDeleteWarning )
834 {
835 if ( ! removeExtensionWarn( xPackage->getDisplayName() ) )
836 return false;
837 }
838
839 if ( ! continueOnSharedExtension( xPackage, this, RID_WARNINGBOX_REMOVE_SHARED_EXTENSION, m_bDeleteWarning ) )
840 return false;
841
842 m_pManager->getCmdQueue()->removeExtension( xPackage );
843
844 return true;
845 }
846
847 //------------------------------------------------------------------------------
updatePackage(const uno::Reference<deployment::XPackage> & xPackage)848 bool ExtMgrDialog::updatePackage( const uno::Reference< deployment::XPackage > &xPackage )
849 {
850 if ( !xPackage.is() )
851 return false;
852
853 // get the extension with highest version
854 uno::Sequence<uno::Reference<deployment::XPackage> > seqExtensions =
855 m_pManager->getExtensionManager()->getExtensionsWithSameIdentifier(
856 dp_misc::getIdentifier(xPackage), xPackage->getName(), uno::Reference<ucb::XCommandEnvironment>());
857 uno::Reference<deployment::XPackage> extension =
858 dp_misc::getExtensionWithHighestVersion(seqExtensions);
859 OSL_ASSERT(extension.is());
860 std::vector< css::uno::Reference< css::deployment::XPackage > > vEntries;
861 vEntries.push_back(extension);
862
863 m_pManager->getCmdQueue()->checkForUpdates( vEntries );
864
865 return true;
866 }
867
868 //------------------------------------------------------------------------------
acceptLicense(const uno::Reference<deployment::XPackage> & xPackage)869 bool ExtMgrDialog::acceptLicense( const uno::Reference< deployment::XPackage > &xPackage )
870 {
871 if ( !xPackage.is() )
872 return false;
873
874 m_pManager->getCmdQueue()->acceptLicense( xPackage );
875
876 return true;
877 }
878
879 //------------------------------------------------------------------------------
raiseAddPicker()880 uno::Sequence< OUString > ExtMgrDialog::raiseAddPicker()
881 {
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 );
889
890 if ( m_sLastFolderURL.Len() )
891 xFilePicker->setDisplayDirectory( m_sLastFolderURL );
892
893 // collect and set filter list:
894 typedef ::std::map< OUString, OUString > t_string2string;
895 t_string2string title2filter;
896 OUString sDefaultFilter( StrAllFiles::get() );
897
898 const uno::Sequence< uno::Reference< deployment::XPackageTypeInfo > > packageTypes(
899 m_pManager->getExtensionManager()->getSupportedPackageTypes() );
900
901 for ( sal_Int32 pos = 0; pos < packageTypes.getLength(); ++pos )
902 {
903 uno::Reference< deployment::XPackageTypeInfo > const & xPackageType = packageTypes[ pos ];
904 const OUString filter( xPackageType->getFileFilter() );
905 if (filter.getLength() > 0)
906 {
907 const OUString title( xPackageType->getShortDescription() );
908 const ::std::pair< t_string2string::iterator, bool > insertion(
909 title2filter.insert( t_string2string::value_type( title, filter ) ) );
910 if ( ! insertion.second )
911 { // already existing, append extensions:
912 ::rtl::OUStringBuffer buf;
913 buf.append( insertion.first->second );
914 buf.append( static_cast<sal_Unicode>(';') );
915 buf.append( filter );
916 insertion.first->second = buf.makeStringAndClear();
917 }
918 if ( xPackageType->getMediaType() == OUSTR( "application/vnd.sun.star.package-bundle" ) )
919 sDefaultFilter = title;
920 }
921 }
922
923 const uno::Reference< ui::dialogs::XFilterManager > xFilterManager( xFilePicker, uno::UNO_QUERY_THROW );
924 // All files at top:
925 xFilterManager->appendFilter( StrAllFiles::get(), OUSTR("*.*") );
926 // then supported ones:
927 t_string2string::const_iterator iPos( title2filter.begin() );
928 const t_string2string::const_iterator iEnd( title2filter.end() );
929 for ( ; iPos != iEnd; ++iPos ) {
930 try {
931 xFilterManager->appendFilter( iPos->first, iPos->second );
932 }
933 catch (lang::IllegalArgumentException & exc) {
934 OSL_ENSURE( 0, ::rtl::OUStringToOString(
935 exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
936 (void) exc;
937 }
938 }
939 xFilterManager->setCurrentFilter( sDefaultFilter );
940
941 if ( xFilePicker->execute() != ui::dialogs::ExecutableDialogResults::OK )
942 return uno::Sequence<OUString>(); // canceled
943
944 m_sLastFolderURL = xFilePicker->getDisplayDirectory();
945 uno::Sequence< OUString > files( xFilePicker->getFiles() );
946 OSL_ASSERT( files.getLength() > 0 );
947 return files;
948 }
949
950 //------------------------------------------------------------------------------
IMPL_LINK(ExtMgrDialog,HandleCancelBtn,void *,EMPTYARG)951 IMPL_LINK( ExtMgrDialog, HandleCancelBtn, void*, EMPTYARG )
952 {
953 // m_dialog->m_cmdEnv->m_aborted = true;
954 if ( m_xAbortChannel.is() )
955 {
956 try
957 {
958 m_xAbortChannel->sendAbort();
959 }
960 catch ( uno::RuntimeException & )
961 {
962 OSL_ENSURE( 0, "### unexpected RuntimeException!" );
963 }
964 }
965 return 1;
966 }
967
968 // ------------------------------------------------------------------------------
IMPL_LINK(ExtMgrDialog,startProgress,void *,_bLockInterface)969 IMPL_LINK( ExtMgrDialog, startProgress, void*, _bLockInterface )
970 {
971 ::osl::MutexGuard aGuard( m_aMutex );
972 bool bLockInterface = (bool) _bLockInterface;
973
974 if ( m_bStartProgress && !m_bHasProgress )
975 m_aTimeoutTimer.Start();
976
977 if ( m_bStopProgress )
978 {
979 if ( m_aProgressBar.IsVisible() )
980 m_aProgressBar.SetValue( 100 );
981 m_xAbortChannel.clear();
982
983 OSL_TRACE( " startProgress handler: stop\n" );
984 }
985 else
986 {
987 OSL_TRACE( " startProgress handler: start\n" );
988 }
989
990 m_aCancelBtn.Enable( bLockInterface );
991 m_aAddBtn.Enable( !bLockInterface );
992 m_aUpdateBtn.Enable( !bLockInterface && m_pExtensionBox->getItemCount() );
993 m_pExtensionBox->enableButtons( !bLockInterface );
994
995 clearEventID();
996
997 return 0;
998 }
999
1000 // ------------------------------------------------------------------------------
showProgress(bool _bStart)1001 void ExtMgrDialog::showProgress( bool _bStart )
1002 {
1003 ::osl::MutexGuard aGuard( m_aMutex );
1004
1005 bool bStart = _bStart;
1006
1007 if ( bStart )
1008 {
1009 m_nProgress = 0;
1010 m_bStartProgress = true;
1011 OSL_TRACE( "showProgress start\n" );
1012 }
1013 else
1014 {
1015 m_nProgress = 100;
1016 m_bStopProgress = true;
1017 OSL_TRACE( "showProgress stop!\n" );
1018 }
1019
1020 DialogHelper::PostUserEvent( LINK( this, ExtMgrDialog, startProgress ), (void*) bStart );
1021 }
1022
1023 // -----------------------------------------------------------------------
updateProgress(const long nProgress)1024 void ExtMgrDialog::updateProgress( const long nProgress )
1025 {
1026 ::osl::MutexGuard aGuard( m_aMutex );
1027
1028 m_nProgress = nProgress;
1029 }
1030
1031 // -----------------------------------------------------------------------
updateProgress(const OUString & rText,const uno::Reference<task::XAbortChannel> & xAbortChannel)1032 void ExtMgrDialog::updateProgress( const OUString &rText,
1033 const uno::Reference< task::XAbortChannel > &xAbortChannel)
1034 {
1035 ::osl::MutexGuard aGuard( m_aMutex );
1036
1037 m_xAbortChannel = xAbortChannel;
1038 m_sProgressText = rText;
1039 m_bProgressChanged = true;
1040 }
1041
1042 //------------------------------------------------------------------------------
updatePackageInfo(const uno::Reference<deployment::XPackage> & xPackage)1043 void ExtMgrDialog::updatePackageInfo( const uno::Reference< deployment::XPackage > &xPackage )
1044 {
1045 m_pExtensionBox->updateEntry( xPackage );
1046 }
1047
1048 // -----------------------------------------------------------------------
IMPL_LINK(ExtMgrDialog,HandleAddBtn,void *,EMPTYARG)1049 IMPL_LINK( ExtMgrDialog, HandleAddBtn, void*, EMPTYARG )
1050 {
1051 setBusy( true );
1052
1053 uno::Sequence< OUString > aFileList = raiseAddPicker();
1054
1055 if ( aFileList.getLength() )
1056 {
1057 m_pManager->installPackage( aFileList[0] );
1058 }
1059
1060 setBusy( false );
1061 return 1;
1062 }
1063
1064 // -----------------------------------------------------------------------
IMPL_LINK(ExtMgrDialog,HandleUpdateBtn,void *,EMPTYARG)1065 IMPL_LINK( ExtMgrDialog, HandleUpdateBtn, void*, EMPTYARG )
1066 {
1067 m_pManager->checkUpdates( false, true );
1068
1069 return 1;
1070 }
1071
1072 // -----------------------------------------------------------------------
IMPL_LINK(ExtMgrDialog,HandleHyperlink,svt::FixedHyperlink *,pHyperlink)1073 IMPL_LINK( ExtMgrDialog, HandleHyperlink, svt::FixedHyperlink*, pHyperlink )
1074 {
1075 openWebBrowser( pHyperlink->GetURL(), GetText() );
1076
1077 return 1;
1078 }
1079
1080 // -----------------------------------------------------------------------
IMPL_LINK(ExtMgrDialog,TimeOutHdl,Timer *,EMPTYARG)1081 IMPL_LINK( ExtMgrDialog, TimeOutHdl, Timer*, EMPTYARG )
1082 {
1083 if ( m_bStopProgress )
1084 {
1085 m_bHasProgress = false;
1086 m_bStopProgress = false;
1087 m_aProgressText.Hide();
1088 m_aProgressBar.Hide();
1089 m_aCancelBtn.Hide();
1090 }
1091 else
1092 {
1093 if ( m_bProgressChanged )
1094 {
1095 m_bProgressChanged = false;
1096 m_aProgressText.SetText( m_sProgressText );
1097 }
1098
1099 if ( m_bStartProgress )
1100 {
1101 m_bStartProgress = false;
1102 m_bHasProgress = true;
1103 m_aProgressBar.Show();
1104 m_aProgressText.Show();
1105 m_aCancelBtn.Enable();
1106 m_aCancelBtn.Show();
1107 }
1108
1109 if ( m_aProgressBar.IsVisible() )
1110 m_aProgressBar.SetValue( (sal_uInt16) m_nProgress );
1111
1112 m_aTimeoutTimer.Start();
1113 }
1114
1115 return 1;
1116 }
1117
1118 //------------------------------------------------------------------------------
1119 // VCL::Window / Dialog
Resize()1120 void ExtMgrDialog::Resize()
1121 {
1122 Size aTotalSize( GetOutputSizePixel() );
1123 Size aBtnSize( m_aHelpBtn.GetSizePixel() );
1124 Size aUpdBtnSize( m_aUpdateBtn.GetSizePixel() );
1125
1126 Point aPos( RSC_SP_DLG_INNERBORDER_LEFT,
1127 aTotalSize.Height() - RSC_SP_DLG_INNERBORDER_BOTTOM - aBtnSize.Height() );
1128
1129 m_aHelpBtn.SetPosPixel( aPos );
1130
1131 aPos.X() = aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - aBtnSize.Width();
1132 m_aCloseBtn.SetPosPixel( aPos );
1133
1134 aPos.X() -= ( RSC_SP_CTRL_X + aUpdBtnSize.Width() );
1135 m_aUpdateBtn.SetPosPixel( aPos );
1136
1137 aPos.X() -= ( RSC_SP_CTRL_GROUP_Y + aBtnSize.Width() );
1138 m_aAddBtn.SetPosPixel( aPos );
1139
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 );
1143
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 - 4 );
1146
1147 m_aGetExtensions.SetPosSizePixel( aPos, aFTSize );
1148
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) ) );
1151
1152 // Calc progress height
1153 long nProgressHeight = aFTSize.Height();
1154
1155 if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
1156 {
1157 ImplControlValue aValue;
1158 bool bNativeOK;
1159 Rectangle aControlRegion( Point( 0, 0 ), m_aProgressBar.GetSizePixel() );
1160 Rectangle aNativeControlRegion, aNativeContentRegion;
1161 if( (bNativeOK = GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
1162 CTRL_STATE_ENABLED, aValue, rtl::OUString(),
1163 aNativeControlRegion, aNativeContentRegion ) ) != sal_False )
1164 {
1165 nProgressHeight = aNativeControlRegion.GetHeight();
1166 }
1167 }
1168
1169 if ( nProgressHeight < PROGRESS_HEIGHT )
1170 nProgressHeight = PROGRESS_HEIGHT;
1171
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 ) );
1175
1176 Rectangle aRect1( m_aGetExtensions.GetPosPixel(), m_aGetExtensions.GetSizePixel() );
1177 Rectangle aRect2( m_aProgressBar.GetPosPixel(), m_aProgressBar.GetSizePixel() );
1178
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 );
1182
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 );
1186
1187 m_pExtensionBox->SetSizePixel( aSize );
1188 }
1189 //------------------------------------------------------------------------------
1190 // VCL::Window / Dialog
1191
Notify(NotifyEvent & rNEvt)1192 long ExtMgrDialog::Notify( NotifyEvent& rNEvt )
1193 {
1194 bool bHandled = false;
1195
1196 if ( rNEvt.GetType() == EVENT_KEYINPUT )
1197 {
1198 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
1199 KeyCode aKeyCode = pKEvt->GetKeyCode();
1200 sal_uInt16 nKeyCode = aKeyCode.GetCode();
1201
1202 if ( nKeyCode == KEY_TAB )
1203 {
1204 if ( aKeyCode.IsShift() ) {
1205 if ( m_aAddBtn.HasFocus() ) {
1206 m_pExtensionBox->GrabFocus();
1207 bHandled = true;
1208 }
1209 } else {
1210 if ( m_aGetExtensions.HasFocus() ) {
1211 m_pExtensionBox->GrabFocus();
1212 bHandled = true;
1213 }
1214 }
1215 }
1216 if ( aKeyCode.GetGroup() == KEYGROUP_CURSOR )
1217 bHandled = m_pExtensionBox->Notify( rNEvt );
1218 }
1219 // VCLEVENT_WINDOW_CLOSE
1220 if ( !bHandled )
1221 return ModelessDialog::Notify( rNEvt );
1222 else
1223 return true;
1224 }
1225
1226 //------------------------------------------------------------------------------
Close()1227 sal_Bool ExtMgrDialog::Close()
1228 {
1229 bool bRet = m_pManager->queryTermination();
1230 if ( bRet )
1231 {
1232 bRet = ModelessDialog::Close();
1233 m_pManager->terminateDialog();
1234 }
1235 return bRet;
1236 }
1237
1238 //------------------------------------------------------------------------------
1239 // UpdateRequiredDialog
1240 //------------------------------------------------------------------------------
UpdateRequiredDialog(Window * pParent,TheExtensionManager * pManager)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 )
1263 {
1264 // free local resources (RID < 256):
1265 FreeResource();
1266
1267 m_pExtensionBox = new ExtensionBox_Impl( this, pManager );
1268 m_pExtensionBox->SetHyperlinkHdl( LINK( this, UpdateRequiredDialog, HandleHyperlink ) );
1269
1270 m_aUpdateBtn.SetClickHdl( LINK( this, UpdateRequiredDialog, HandleUpdateBtn ) );
1271 m_aCloseBtn.SetClickHdl( LINK( this, UpdateRequiredDialog, HandleCloseBtn ) );
1272 m_aCancelBtn.SetClickHdl( LINK( this, UpdateRequiredDialog, HandleCancelBtn ) );
1273
1274 String aText = m_aUpdateNeeded.GetText();
1275 aText.SearchAndReplaceAllAscii( "%PRODUCTNAME", BrandName::get() );
1276 m_aUpdateNeeded.SetText( aText );
1277
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() ) );
1285
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() ) );
1293
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) ) );
1304
1305 m_aDivider.Show();
1306 m_aProgressBar.Hide();
1307 m_aUpdateBtn.Enable( false );
1308 m_aCloseBtn.GrabFocus();
1309
1310 m_aTimeoutTimer.SetTimeout( 50 ); // mSec
1311 m_aTimeoutTimer.SetTimeoutHdl( LINK( this, UpdateRequiredDialog, TimeOutHdl ) );
1312 }
1313
1314 //------------------------------------------------------------------------------
~UpdateRequiredDialog()1315 UpdateRequiredDialog::~UpdateRequiredDialog()
1316 {
1317 m_aTimeoutTimer.Stop();
1318
1319 delete m_pExtensionBox;
1320 }
1321
1322 //------------------------------------------------------------------------------
addPackageToList(const uno::Reference<deployment::XPackage> & xPackage,bool bLicenseMissing)1323 long UpdateRequiredDialog::addPackageToList( const uno::Reference< deployment::XPackage > &xPackage,
1324 bool bLicenseMissing )
1325 {
1326 // We will only add entries to the list with unsatisfied dependencies
1327 if ( !bLicenseMissing && !checkDependencies( xPackage ) )
1328 {
1329 m_bHasLockedEntries |= m_pManager->isReadOnly( xPackage );
1330 m_aUpdateBtn.Enable( true );
1331 return m_pExtensionBox->addEntry( xPackage );
1332 }
1333 return 0;
1334 }
1335
1336 //------------------------------------------------------------------------------
prepareChecking()1337 void UpdateRequiredDialog::prepareChecking()
1338 {
1339 m_pExtensionBox->prepareChecking();
1340 }
1341
1342 //------------------------------------------------------------------------------
checkEntries()1343 void UpdateRequiredDialog::checkEntries()
1344 {
1345 const ::vos::OGuard guard( Application::GetSolarMutex() );
1346 m_pExtensionBox->checkEntries();
1347
1348 if ( ! hasActiveEntries() )
1349 {
1350 m_aCloseBtn.SetText( m_sCloseText );
1351 m_aCloseBtn.GrabFocus();
1352 }
1353 }
1354
1355 //------------------------------------------------------------------------------
enablePackage(const uno::Reference<deployment::XPackage> & xPackage,bool bEnable)1356 bool UpdateRequiredDialog::enablePackage( const uno::Reference< deployment::XPackage > &xPackage,
1357 bool bEnable )
1358 {
1359 m_pManager->getCmdQueue()->enableExtension( xPackage, bEnable );
1360
1361 return true;
1362 }
1363
1364 //------------------------------------------------------------------------------
IMPL_LINK(UpdateRequiredDialog,HandleCancelBtn,void *,EMPTYARG)1365 IMPL_LINK( UpdateRequiredDialog, HandleCancelBtn, void*, EMPTYARG )
1366 {
1367 // m_dialog->m_cmdEnv->m_aborted = true;
1368 if ( m_xAbortChannel.is() )
1369 {
1370 try
1371 {
1372 m_xAbortChannel->sendAbort();
1373 }
1374 catch ( uno::RuntimeException & )
1375 {
1376 OSL_ENSURE( 0, "### unexpected RuntimeException!" );
1377 }
1378 }
1379 return 1;
1380 }
1381
1382 // ------------------------------------------------------------------------------
IMPL_LINK(UpdateRequiredDialog,startProgress,void *,_bLockInterface)1383 IMPL_LINK( UpdateRequiredDialog, startProgress, void*, _bLockInterface )
1384 {
1385 ::osl::MutexGuard aGuard( m_aMutex );
1386 bool bLockInterface = (bool) _bLockInterface;
1387
1388 if ( m_bStartProgress && !m_bHasProgress )
1389 m_aTimeoutTimer.Start();
1390
1391 if ( m_bStopProgress )
1392 {
1393 if ( m_aProgressBar.IsVisible() )
1394 m_aProgressBar.SetValue( 100 );
1395 m_xAbortChannel.clear();
1396 OSL_TRACE( " startProgress handler: stop\n" );
1397 }
1398 else
1399 {
1400 OSL_TRACE( " startProgress handler: start\n" );
1401 }
1402
1403 m_aCancelBtn.Enable( bLockInterface );
1404 m_aUpdateBtn.Enable( false );
1405 clearEventID();
1406
1407 return 0;
1408 }
1409
1410 // ------------------------------------------------------------------------------
showProgress(bool _bStart)1411 void UpdateRequiredDialog::showProgress( bool _bStart )
1412 {
1413 ::osl::MutexGuard aGuard( m_aMutex );
1414
1415 bool bStart = _bStart;
1416
1417 if ( bStart )
1418 {
1419 m_nProgress = 0;
1420 m_bStartProgress = true;
1421 OSL_TRACE( "showProgress start\n" );
1422 }
1423 else
1424 {
1425 m_nProgress = 100;
1426 m_bStopProgress = true;
1427 OSL_TRACE( "showProgress stop!\n" );
1428 }
1429
1430 DialogHelper::PostUserEvent( LINK( this, UpdateRequiredDialog, startProgress ), (void*) bStart );
1431 }
1432
1433 // -----------------------------------------------------------------------
updateProgress(const long nProgress)1434 void UpdateRequiredDialog::updateProgress( const long nProgress )
1435 {
1436 ::osl::MutexGuard aGuard( m_aMutex );
1437
1438 m_nProgress = nProgress;
1439 }
1440
1441 // -----------------------------------------------------------------------
updateProgress(const OUString & rText,const uno::Reference<task::XAbortChannel> & xAbortChannel)1442 void UpdateRequiredDialog::updateProgress( const OUString &rText,
1443 const uno::Reference< task::XAbortChannel > &xAbortChannel)
1444 {
1445 ::osl::MutexGuard aGuard( m_aMutex );
1446
1447 m_xAbortChannel = xAbortChannel;
1448 m_sProgressText = rText;
1449 m_bProgressChanged = true;
1450 }
1451
1452 //------------------------------------------------------------------------------
updatePackageInfo(const uno::Reference<deployment::XPackage> & xPackage)1453 void UpdateRequiredDialog::updatePackageInfo( const uno::Reference< deployment::XPackage > &xPackage )
1454 {
1455 // We will remove all updated packages with satisfied dependencies, but
1456 // we will show all disabled entries so the user sees the result
1457 // of the 'disable all' button
1458 if ( isEnabled( xPackage ) && checkDependencies( xPackage ) )
1459 m_pExtensionBox->removeEntry( xPackage );
1460 else
1461 m_pExtensionBox->updateEntry( xPackage );
1462
1463 if ( ! hasActiveEntries() )
1464 {
1465 m_aCloseBtn.SetText( m_sCloseText );
1466 m_aCloseBtn.GrabFocus();
1467 }
1468 }
1469
1470 // -----------------------------------------------------------------------
IMPL_LINK(UpdateRequiredDialog,HandleUpdateBtn,void *,EMPTYARG)1471 IMPL_LINK( UpdateRequiredDialog, HandleUpdateBtn, void*, EMPTYARG )
1472 {
1473 ::osl::ClearableMutexGuard aGuard( m_aMutex );
1474
1475 std::vector< uno::Reference< deployment::XPackage > > vUpdateEntries;
1476 sal_Int32 nCount = m_pExtensionBox->GetEntryCount();
1477
1478 for ( sal_Int32 i = 0; i < nCount; ++i )
1479 {
1480 TEntry_Impl pEntry = m_pExtensionBox->GetEntryData( i );
1481 vUpdateEntries.push_back( pEntry->m_xPackage );
1482 }
1483
1484 aGuard.clear();
1485
1486 m_pManager->getCmdQueue()->checkForUpdates( vUpdateEntries );
1487
1488 return 1;
1489 }
1490
1491 // -----------------------------------------------------------------------
IMPL_LINK(UpdateRequiredDialog,HandleCloseBtn,void *,EMPTYARG)1492 IMPL_LINK( UpdateRequiredDialog, HandleCloseBtn, void*, EMPTYARG )
1493 {
1494 ::osl::MutexGuard aGuard( m_aMutex );
1495
1496 if ( !isBusy() )
1497 {
1498 if ( m_bHasLockedEntries )
1499 EndDialog( -1 );
1500 else if ( hasActiveEntries() )
1501 disableAllEntries();
1502 else
1503 EndDialog( 0 );
1504 }
1505
1506 return 1;
1507 }
1508
1509 // -----------------------------------------------------------------------
IMPL_LINK(UpdateRequiredDialog,HandleHyperlink,svt::FixedHyperlink *,pHyperlink)1510 IMPL_LINK( UpdateRequiredDialog, HandleHyperlink, svt::FixedHyperlink*, pHyperlink )
1511 {
1512 openWebBrowser( pHyperlink->GetURL(), GetText() );
1513
1514 return 1;
1515 }
1516
1517 // -----------------------------------------------------------------------
IMPL_LINK(UpdateRequiredDialog,TimeOutHdl,Timer *,EMPTYARG)1518 IMPL_LINK( UpdateRequiredDialog, TimeOutHdl, Timer*, EMPTYARG )
1519 {
1520 if ( m_bStopProgress )
1521 {
1522 m_bHasProgress = false;
1523 m_bStopProgress = false;
1524 m_aProgressText.Hide();
1525 m_aProgressBar.Hide();
1526 m_aCancelBtn.Hide();
1527 }
1528 else
1529 {
1530 if ( m_bProgressChanged )
1531 {
1532 m_bProgressChanged = false;
1533 m_aProgressText.SetText( m_sProgressText );
1534 }
1535
1536 if ( m_bStartProgress )
1537 {
1538 m_bStartProgress = false;
1539 m_bHasProgress = true;
1540 m_aProgressBar.Show();
1541 m_aProgressText.Show();
1542 m_aCancelBtn.Enable();
1543 m_aCancelBtn.Show();
1544 }
1545
1546 if ( m_aProgressBar.IsVisible() )
1547 m_aProgressBar.SetValue( (sal_uInt16) m_nProgress );
1548
1549 m_aTimeoutTimer.Start();
1550 }
1551
1552 return 1;
1553 }
1554
1555 //------------------------------------------------------------------------------
1556 // VCL::Window / Dialog
Resize()1557 void UpdateRequiredDialog::Resize()
1558 {
1559 Size aTotalSize( GetOutputSizePixel() );
1560 Size aBtnSize( m_aHelpBtn.GetSizePixel() );
1561
1562 Point aPos( RSC_SP_DLG_INNERBORDER_LEFT,
1563 aTotalSize.Height() - RSC_SP_DLG_INNERBORDER_BOTTOM - aBtnSize.Height() );
1564
1565 m_aHelpBtn.SetPosPixel( aPos );
1566
1567 aPos.X() = aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - m_aCloseBtn.GetSizePixel().Width();
1568 m_aCloseBtn.SetPosPixel( aPos );
1569
1570 aPos.X() -= ( RSC_SP_CTRL_X + m_aUpdateBtn.GetSizePixel().Width() );
1571 m_aUpdateBtn.SetPosPixel( aPos );
1572
1573 Size aDivSize( aTotalSize.Width(), LINE_SIZE );
1574 aPos = Point( 0, aPos.Y() - LINE_SIZE - RSC_SP_DLG_INNERBORDER_BOTTOM );
1575 m_aDivider.SetPosSizePixel( aPos, aDivSize );
1576
1577 // Calc fixed text size
1578 aPos = Point( RSC_SP_DLG_INNERBORDER_LEFT, RSC_SP_DLG_INNERBORDER_TOP );
1579 Size aFTSize = m_aUpdateNeeded.CalcMinimumSize( aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - RSC_SP_DLG_INNERBORDER_LEFT );
1580 m_aUpdateNeeded.SetPosSizePixel( aPos, aFTSize );
1581
1582 // Calc list box size
1583 Size aSize( aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_LEFT - RSC_SP_DLG_INNERBORDER_RIGHT,
1584 aTotalSize.Height() - 2*aBtnSize.Height() - LINE_SIZE -
1585 2*RSC_SP_DLG_INNERBORDER_TOP - 3*RSC_SP_DLG_INNERBORDER_BOTTOM - aFTSize.Height() );
1586 aPos.Y() += aFTSize.Height()+RSC_SP_DLG_INNERBORDER_TOP;
1587
1588 m_pExtensionBox->SetPosSizePixel( aPos, aSize );
1589
1590 aPos.X() = aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_RIGHT - aBtnSize.Width();
1591 aPos.Y() += aSize.Height()+RSC_SP_DLG_INNERBORDER_TOP;
1592 m_aCancelBtn.SetPosPixel( aPos );
1593
1594 // Calc progress height
1595 aFTSize = m_aProgressText.GetSizePixel();
1596 long nProgressHeight = aFTSize.Height();
1597
1598 if( IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
1599 {
1600 ImplControlValue aValue;
1601 bool bNativeOK;
1602 Rectangle aControlRegion( Point( 0, 0 ), m_aProgressBar.GetSizePixel() );
1603 Rectangle aNativeControlRegion, aNativeContentRegion;
1604 if( (bNativeOK = GetNativeControlRegion( CTRL_PROGRESS, PART_ENTIRE_CONTROL, aControlRegion,
1605 CTRL_STATE_ENABLED, aValue, rtl::OUString(),
1606 aNativeControlRegion, aNativeContentRegion ) ) != sal_False )
1607 {
1608 nProgressHeight = aNativeControlRegion.GetHeight();
1609 }
1610 }
1611
1612 if ( nProgressHeight < PROGRESS_HEIGHT )
1613 nProgressHeight = PROGRESS_HEIGHT;
1614
1615 aPos.X() -= ( RSC_SP_CTRL_GROUP_Y + PROGRESS_WIDTH );
1616 m_aProgressBar.SetPosSizePixel( Point( aPos.X(), aPos.Y() + ((aBtnSize.Height()-nProgressHeight)/2) ),
1617 Size( PROGRESS_WIDTH, nProgressHeight ) );
1618
1619 aFTSize.Width() = aPos.X() - 2*RSC_SP_DLG_INNERBORDER_LEFT;
1620 aPos.X() = RSC_SP_DLG_INNERBORDER_LEFT;
1621 aPos.Y() += ( aBtnSize.Height() - aFTSize.Height() - 1 ) / 2;
1622 m_aProgressText.SetPosSizePixel( aPos, aFTSize );
1623 }
1624
1625 //------------------------------------------------------------------------------
1626 // VCL::Dialog
Execute()1627 short UpdateRequiredDialog::Execute()
1628 {
1629 //ToDo
1630 //I believe m_bHasLockedEntries was used to prevent showing extensions which cannot
1631 //be disabled because they are in a read only repository. However, disabling extensions
1632 //is now always possible because the registration data of all repositories
1633 //are in the user installation.
1634 //Therfore all extensions could be displayed and all the handling around m_bHasLockedEntries
1635 //could be removed.
1636 if ( m_bHasLockedEntries )
1637 {
1638 // Set other text, disable update btn, remove not shared entries from list;
1639 m_aUpdateNeeded.SetText( DialogHelper::getResourceString( RID_STR_NO_ADMIN_PRIVILEGE ) );
1640 m_aCloseBtn.SetText( DialogHelper::getResourceString( RID_STR_EXIT_BTN ) );
1641 m_aUpdateBtn.Enable( false );
1642 m_pExtensionBox->RemoveUnlocked();
1643 Resize();
1644 }
1645
1646 return Dialog::Execute();
1647 }
1648
1649 //------------------------------------------------------------------------------
1650 // VCL::Dialog
Close()1651 sal_Bool UpdateRequiredDialog::Close()
1652 {
1653 ::osl::MutexGuard aGuard( m_aMutex );
1654
1655 if ( !isBusy() )
1656 {
1657 if ( m_bHasLockedEntries )
1658 EndDialog( -1 );
1659 else if ( hasActiveEntries() )
1660 disableAllEntries();
1661 else
1662 EndDialog( 0 );
1663 }
1664
1665 return false;
1666 }
1667
1668 //------------------------------------------------------------------------------
1669 // Check dependencies of all packages
1670 //------------------------------------------------------------------------------
isEnabled(const uno::Reference<deployment::XPackage> & xPackage) const1671 bool UpdateRequiredDialog::isEnabled( const uno::Reference< deployment::XPackage > &xPackage ) const
1672 {
1673 bool bRegistered = false;
1674 try {
1675 beans::Optional< beans::Ambiguous< sal_Bool > > option( xPackage->isRegistered( uno::Reference< task::XAbortChannel >(),
1676 uno::Reference< ucb::XCommandEnvironment >() ) );
1677 if ( option.IsPresent )
1678 {
1679 ::beans::Ambiguous< sal_Bool > const & reg = option.Value;
1680 if ( reg.IsAmbiguous )
1681 bRegistered = false;
1682 else
1683 bRegistered = reg.Value ? true : false;
1684 }
1685 else
1686 bRegistered = false;
1687 }
1688 catch ( uno::RuntimeException & ) { throw; }
1689 catch ( uno::Exception & exc) {
1690 (void) exc;
1691 OSL_ENSURE( 0, ::rtl::OUStringToOString( exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
1692 bRegistered = false;
1693 }
1694
1695 return bRegistered;
1696 }
1697
1698 //------------------------------------------------------------------------------
1699 //Checks the dependencies no matter if the extension is enabled or disabled!
checkDependencies(const uno::Reference<deployment::XPackage> & xPackage) const1700 bool UpdateRequiredDialog::checkDependencies( const uno::Reference< deployment::XPackage > &xPackage ) const
1701 {
1702 bool bDependenciesValid = false;
1703 try {
1704 bDependenciesValid = xPackage->checkDependencies( uno::Reference< ucb::XCommandEnvironment >() );
1705 }
1706 catch ( deployment::DeploymentException & ) {}
1707 return bDependenciesValid;
1708 }
1709
1710 //------------------------------------------------------------------------------
hasActiveEntries()1711 bool UpdateRequiredDialog::hasActiveEntries()
1712 {
1713 ::osl::MutexGuard aGuard( m_aMutex );
1714
1715 bool bRet = false;
1716 long nCount = m_pExtensionBox->GetEntryCount();
1717 for ( long nIndex = 0; nIndex < nCount; nIndex++ )
1718 {
1719 TEntry_Impl pEntry = m_pExtensionBox->GetEntryData( nIndex );
1720
1721 if ( isEnabled(pEntry->m_xPackage) && !checkDependencies( pEntry->m_xPackage ) )
1722 {
1723 bRet = true;
1724 break;
1725 }
1726 }
1727
1728 return bRet;
1729 }
1730
1731 //------------------------------------------------------------------------------
disableAllEntries()1732 void UpdateRequiredDialog::disableAllEntries()
1733 {
1734 ::osl::MutexGuard aGuard( m_aMutex );
1735
1736 setBusy( true );
1737
1738 long nCount = m_pExtensionBox->GetEntryCount();
1739 for ( long nIndex = 0; nIndex < nCount; nIndex++ )
1740 {
1741 TEntry_Impl pEntry = m_pExtensionBox->GetEntryData( nIndex );
1742 enablePackage( pEntry->m_xPackage, false );
1743 }
1744
1745 setBusy( false );
1746
1747 if ( ! hasActiveEntries() )
1748 m_aCloseBtn.SetText( m_sCloseText );
1749 }
1750
1751 //------------------------------------------------------------------------------
1752 // ShowLicenseDialog
1753 //------------------------------------------------------------------------------
ShowLicenseDialog(Window * pParent,const uno::Reference<deployment::XPackage> & xPackage)1754 ShowLicenseDialog::ShowLicenseDialog( Window * pParent,
1755 const uno::Reference< deployment::XPackage > &xPackage ) :
1756 ModalDialog( pParent, DialogHelper::getResId( RID_DLG_SHOW_LICENSE ) ),
1757 m_aLicenseText( this, DialogHelper::getResId( ML_LICENSE ) ),
1758 m_aCloseBtn( this, DialogHelper::getResId( RID_EM_BTN_CLOSE ) )
1759 {
1760 FreeResource();
1761
1762 OUString aText = xPackage->getLicenseText();
1763 m_aLicenseText.SetText( aText );
1764 }
1765
1766 //------------------------------------------------------------------------------
~ShowLicenseDialog()1767 ShowLicenseDialog::~ShowLicenseDialog()
1768 {}
1769
1770 //------------------------------------------------------------------------------
Resize()1771 void ShowLicenseDialog::Resize()
1772 {
1773 Size aTotalSize( GetOutputSizePixel() );
1774 Size aTextSize( aTotalSize.Width() - RSC_SP_DLG_INNERBORDER_LEFT - RSC_SP_DLG_INNERBORDER_RIGHT,
1775 aTotalSize.Height() - RSC_SP_DLG_INNERBORDER_TOP - 2*RSC_SP_DLG_INNERBORDER_BOTTOM
1776 - m_aCloseBtn.GetSizePixel().Height() );
1777
1778 m_aLicenseText.SetPosSizePixel( Point( RSC_SP_DLG_INNERBORDER_LEFT, RSC_SP_DLG_INNERBORDER_TOP ),
1779 aTextSize );
1780
1781 Point aBtnPos( (aTotalSize.Width() - m_aCloseBtn.GetSizePixel().Width())/2,
1782 aTotalSize.Height() - RSC_SP_DLG_INNERBORDER_BOTTOM
1783 - m_aCloseBtn.GetSizePixel().Height() );
1784 m_aCloseBtn.SetPosPixel( aBtnPos );
1785 }
1786
1787 //=================================================================================
1788 // UpdateRequiredDialogService
1789 //=================================================================================
UpdateRequiredDialogService(uno::Sequence<uno::Any> const &,uno::Reference<uno::XComponentContext> const & xComponentContext)1790 UpdateRequiredDialogService::UpdateRequiredDialogService( uno::Sequence< uno::Any > const&,
1791 uno::Reference< uno::XComponentContext > const& xComponentContext )
1792 : m_xComponentContext( xComponentContext )
1793 {
1794 }
1795
1796 //------------------------------------------------------------------------------
1797 // XExecutableDialog
1798 //------------------------------------------------------------------------------
setTitle(OUString const &)1799 void UpdateRequiredDialogService::setTitle( OUString const & ) throw ( uno::RuntimeException )
1800 {
1801 }
1802
1803 //------------------------------------------------------------------------------
execute()1804 sal_Int16 UpdateRequiredDialogService::execute() throw ( uno::RuntimeException )
1805 {
1806 ::rtl::Reference< ::dp_gui::TheExtensionManager > xManager( TheExtensionManager::get(
1807 m_xComponentContext,
1808 uno::Reference< awt::XWindow >(),
1809 OUString() ) );
1810 xManager->createDialog( true );
1811 sal_Int16 nRet = xManager->execute();
1812
1813 return nRet;
1814 }
1815
1816 //------------------------------------------------------------------------------
1817 //------------------------------------------------------------------------------
1818 //------------------------------------------------------------------------------
~SelectedPackage()1819 SelectedPackage::~SelectedPackage() {}
1820
1821 } //namespace dp_gui
1822
1823 /* vim: set noet sw=4 ts=4: */
1824