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