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