xref: /AOO41X/main/desktop/source/deployment/gui/dp_gui_theextmgr.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 "vcl/svapp.hxx"
32*cdf0e10cSrcweir #include "vcl/msgbox.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include "vos/mutex.hxx"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include "toolkit/helper/vclunohelper.hxx"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include "dp_gui_dialog2.hxx"
41*cdf0e10cSrcweir #include "dp_gui_extensioncmdqueue.hxx"
42*cdf0e10cSrcweir #include "dp_gui_theextmgr.hxx"
43*cdf0e10cSrcweir #include "dp_gui_theextmgr.hxx"
44*cdf0e10cSrcweir #include "dp_identifier.hxx"
45*cdf0e10cSrcweir #include "dp_update.hxx"
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #define USER_PACKAGE_MANAGER    OUSTR("user")
50*cdf0e10cSrcweir #define SHARED_PACKAGE_MANAGER  OUSTR("shared")
51*cdf0e10cSrcweir #define BUNDLED_PACKAGE_MANAGER OUSTR("bundled")
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir using namespace ::com::sun::star;
54*cdf0e10cSrcweir using ::rtl::OUString;
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir namespace dp_gui {
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir //------------------------------------------------------------------------------
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir ::rtl::Reference< TheExtensionManager > TheExtensionManager::s_ExtMgr;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir //------------------------------------------------------------------------------
63*cdf0e10cSrcweir //                             TheExtensionManager
64*cdf0e10cSrcweir //------------------------------------------------------------------------------
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir TheExtensionManager::TheExtensionManager( Window *pParent,
67*cdf0e10cSrcweir                                           const uno::Reference< uno::XComponentContext > &xContext ) :
68*cdf0e10cSrcweir     m_xContext( xContext ),
69*cdf0e10cSrcweir     m_pParent( pParent ),
70*cdf0e10cSrcweir     m_pExtMgrDialog( NULL ),
71*cdf0e10cSrcweir     m_pUpdReqDialog( NULL ),
72*cdf0e10cSrcweir     m_pExecuteCmdQueue( NULL )
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir     m_xExtensionManager = deployment::ExtensionManager::get( xContext );
75*cdf0e10cSrcweir     m_xExtensionManager->addModifyListener( this );
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xConfig(
78*cdf0e10cSrcweir         xContext->getServiceManager()->createInstanceWithContext(
79*cdf0e10cSrcweir             OUSTR("com.sun.star.configuration.ConfigurationProvider"), xContext ), uno::UNO_QUERY_THROW);
80*cdf0e10cSrcweir     uno::Any args[1];
81*cdf0e10cSrcweir     beans::PropertyValue aValue( OUSTR("nodepath"), 0, uno::Any( OUSTR("/org.openoffice.Office.OptionsDialog/Nodes") ),
82*cdf0e10cSrcweir                                  beans::PropertyState_DIRECT_VALUE );
83*cdf0e10cSrcweir     args[0] <<= aValue;
84*cdf0e10cSrcweir     m_xNameAccessNodes = uno::Reference< container::XNameAccess >(
85*cdf0e10cSrcweir         xConfig->createInstanceWithArguments( OUSTR("com.sun.star.configuration.ConfigurationAccess"),
86*cdf0e10cSrcweir                                               uno::Sequence< uno::Any >( args, 1 )), uno::UNO_QUERY_THROW);
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     // get the 'get more extensions here' url
89*cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xNameAccessRepositories;
90*cdf0e10cSrcweir     beans::PropertyValue aValue2( OUSTR("nodepath"), 0, uno::Any( OUSTR("/org.openoffice.Office.ExtensionManager/ExtensionRepositories") ),
91*cdf0e10cSrcweir                                   beans::PropertyState_DIRECT_VALUE );
92*cdf0e10cSrcweir     args[0] <<= aValue2;
93*cdf0e10cSrcweir     xNameAccessRepositories = uno::Reference< container::XNameAccess > (
94*cdf0e10cSrcweir         xConfig->createInstanceWithArguments( OUSTR("com.sun.star.configuration.ConfigurationAccess"),
95*cdf0e10cSrcweir                                               uno::Sequence< uno::Any >( args, 1 )), uno::UNO_QUERY_THROW);
96*cdf0e10cSrcweir     try
97*cdf0e10cSrcweir     {   //throws css::container::NoSuchElementException, css::lang::WrappedTargetException
98*cdf0e10cSrcweir         uno::Any value = xNameAccessRepositories->getByName( OUSTR( "WebsiteLink" ) );
99*cdf0e10cSrcweir         m_sGetExtensionsURL = value.get< OUString > ();
100*cdf0e10cSrcweir      }
101*cdf0e10cSrcweir     catch ( uno::Exception& )
102*cdf0e10cSrcweir     {}
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     if ( dp_misc::office_is_running() )
105*cdf0e10cSrcweir     {
106*cdf0e10cSrcweir 		// the registration should be done after the construction has been ended
107*cdf0e10cSrcweir 		// otherwise an exception prevents object creation, but it is registered as a listener
108*cdf0e10cSrcweir         m_xDesktop.set( xContext->getServiceManager()->createInstanceWithContext(
109*cdf0e10cSrcweir                             OUSTR("com.sun.star.frame.Desktop"), xContext ), uno::UNO_QUERY );
110*cdf0e10cSrcweir         if ( m_xDesktop.is() )
111*cdf0e10cSrcweir             m_xDesktop->addTerminateListener( this );
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir //------------------------------------------------------------------------------
116*cdf0e10cSrcweir TheExtensionManager::~TheExtensionManager()
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir     if ( m_pUpdReqDialog )
119*cdf0e10cSrcweir         delete m_pUpdReqDialog;
120*cdf0e10cSrcweir     if ( m_pExtMgrDialog )
121*cdf0e10cSrcweir         delete m_pExtMgrDialog;
122*cdf0e10cSrcweir     if ( m_pExecuteCmdQueue )
123*cdf0e10cSrcweir         delete m_pExecuteCmdQueue;
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir //------------------------------------------------------------------------------
127*cdf0e10cSrcweir void TheExtensionManager::createDialog( const bool bCreateUpdDlg )
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir     const ::vos::OGuard guard( Application::GetSolarMutex() );
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     if ( bCreateUpdDlg )
132*cdf0e10cSrcweir     {
133*cdf0e10cSrcweir         if ( !m_pUpdReqDialog )
134*cdf0e10cSrcweir         {
135*cdf0e10cSrcweir             m_pUpdReqDialog = new UpdateRequiredDialog( NULL, this );
136*cdf0e10cSrcweir             delete m_pExecuteCmdQueue;
137*cdf0e10cSrcweir             m_pExecuteCmdQueue = new ExtensionCmdQueue( (DialogHelper*) m_pUpdReqDialog, this, m_xContext );
138*cdf0e10cSrcweir             createPackageList();
139*cdf0e10cSrcweir         }
140*cdf0e10cSrcweir     }
141*cdf0e10cSrcweir     else if ( !m_pExtMgrDialog )
142*cdf0e10cSrcweir     {
143*cdf0e10cSrcweir         m_pExtMgrDialog = new ExtMgrDialog( m_pParent, this );
144*cdf0e10cSrcweir         delete m_pExecuteCmdQueue;
145*cdf0e10cSrcweir         m_pExecuteCmdQueue = new ExtensionCmdQueue( (DialogHelper*) m_pExtMgrDialog, this, m_xContext );
146*cdf0e10cSrcweir         m_pExtMgrDialog->setGetExtensionsURL( m_sGetExtensionsURL );
147*cdf0e10cSrcweir         createPackageList();
148*cdf0e10cSrcweir     }
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir //------------------------------------------------------------------------------
152*cdf0e10cSrcweir void TheExtensionManager::Show()
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir     const ::vos::OGuard guard( Application::GetSolarMutex() );
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     getDialog()->Show();
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir //------------------------------------------------------------------------------
160*cdf0e10cSrcweir void TheExtensionManager::SetText( const ::rtl::OUString &rTitle )
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir     const ::vos::OGuard guard( Application::GetSolarMutex() );
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir     getDialog()->SetText( rTitle );
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir //------------------------------------------------------------------------------
168*cdf0e10cSrcweir void TheExtensionManager::ToTop( sal_uInt16 nFlags )
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir     const ::vos::OGuard guard( Application::GetSolarMutex() );
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     getDialog()->ToTop( nFlags );
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir //------------------------------------------------------------------------------
176*cdf0e10cSrcweir bool TheExtensionManager::Close()
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir     if ( m_pExtMgrDialog )
179*cdf0e10cSrcweir         return m_pExtMgrDialog->Close();
180*cdf0e10cSrcweir     else if ( m_pUpdReqDialog )
181*cdf0e10cSrcweir         return m_pUpdReqDialog->Close();
182*cdf0e10cSrcweir     else
183*cdf0e10cSrcweir         return true;
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir //------------------------------------------------------------------------------
187*cdf0e10cSrcweir sal_Int16 TheExtensionManager::execute()
188*cdf0e10cSrcweir {
189*cdf0e10cSrcweir     sal_Int16 nRet = 0;
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     if ( m_pUpdReqDialog )
192*cdf0e10cSrcweir     {
193*cdf0e10cSrcweir         nRet = m_pUpdReqDialog->Execute();
194*cdf0e10cSrcweir         delete m_pUpdReqDialog;
195*cdf0e10cSrcweir         m_pUpdReqDialog = NULL;
196*cdf0e10cSrcweir     }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     return nRet;
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir //------------------------------------------------------------------------------
202*cdf0e10cSrcweir bool TheExtensionManager::isVisible()
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir     return getDialog()->IsVisible();
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir //------------------------------------------------------------------------------
208*cdf0e10cSrcweir bool TheExtensionManager::checkUpdates( bool /* bShowUpdateOnly */, bool /*bParentVisible*/ )
209*cdf0e10cSrcweir {
210*cdf0e10cSrcweir     std::vector< uno::Reference< deployment::XPackage >  > vEntries;
211*cdf0e10cSrcweir     uno::Sequence< uno::Sequence< uno::Reference< deployment::XPackage > > > xAllPackages;
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir     try {
214*cdf0e10cSrcweir         xAllPackages = m_xExtensionManager->getAllExtensions( uno::Reference< task::XAbortChannel >(),
215*cdf0e10cSrcweir                                                               uno::Reference< ucb::XCommandEnvironment >() );
216*cdf0e10cSrcweir     } catch ( deployment::DeploymentException & ) {
217*cdf0e10cSrcweir         return false;
218*cdf0e10cSrcweir     } catch ( ucb::CommandFailedException & ) {
219*cdf0e10cSrcweir         return false;
220*cdf0e10cSrcweir     } catch ( ucb::CommandAbortedException & ) {
221*cdf0e10cSrcweir         return false;
222*cdf0e10cSrcweir     } catch ( lang::IllegalArgumentException & e ) {
223*cdf0e10cSrcweir         throw uno::RuntimeException( e.Message, e.Context );
224*cdf0e10cSrcweir     }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < xAllPackages.getLength(); ++i )
227*cdf0e10cSrcweir     {
228*cdf0e10cSrcweir 		uno::Reference< deployment::XPackage > xPackage = dp_misc::getExtensionWithHighestVersion(xAllPackages[i]);
229*cdf0e10cSrcweir 		OSL_ASSERT(xPackage.is());
230*cdf0e10cSrcweir         if ( xPackage.is() )
231*cdf0e10cSrcweir         {
232*cdf0e10cSrcweir 			vEntries.push_back( xPackage );
233*cdf0e10cSrcweir         }
234*cdf0e10cSrcweir     }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir     m_pExecuteCmdQueue->checkForUpdates( vEntries );
237*cdf0e10cSrcweir     return true;
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir //------------------------------------------------------------------------------
241*cdf0e10cSrcweir bool TheExtensionManager::installPackage( const OUString &rPackageURL, bool bWarnUser )
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     if ( rPackageURL.getLength() == 0 )
244*cdf0e10cSrcweir         return false;
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir     createDialog( false );
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir     bool bInstall = true;
249*cdf0e10cSrcweir     bool bInstallForAll = false;
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir     // DV! missing function is read only repository from extension manager
252*cdf0e10cSrcweir     if ( !bWarnUser && ! m_xExtensionManager->isReadOnlyRepository( SHARED_PACKAGE_MANAGER ) )
253*cdf0e10cSrcweir         bInstall = getDialogHelper()->installForAllUsers( bInstallForAll );
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir     if ( !bInstall )
256*cdf0e10cSrcweir         return false;
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     if ( bInstallForAll )
259*cdf0e10cSrcweir         m_pExecuteCmdQueue->addExtension( rPackageURL, SHARED_PACKAGE_MANAGER, false );
260*cdf0e10cSrcweir     else
261*cdf0e10cSrcweir         m_pExecuteCmdQueue->addExtension( rPackageURL, USER_PACKAGE_MANAGER, bWarnUser );
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir     return true;
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir //------------------------------------------------------------------------------
267*cdf0e10cSrcweir bool TheExtensionManager::queryTermination()
268*cdf0e10cSrcweir {
269*cdf0e10cSrcweir     if ( dp_misc::office_is_running() )
270*cdf0e10cSrcweir         return true;
271*cdf0e10cSrcweir     // the standalone application unopkg must not close ( and quit ) the dialog
272*cdf0e10cSrcweir     // when there are still actions in the queue
273*cdf0e10cSrcweir     return true;
274*cdf0e10cSrcweir }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir //------------------------------------------------------------------------------
277*cdf0e10cSrcweir void TheExtensionManager::terminateDialog()
278*cdf0e10cSrcweir {
279*cdf0e10cSrcweir     if ( ! dp_misc::office_is_running() )
280*cdf0e10cSrcweir     {
281*cdf0e10cSrcweir         const ::vos::OGuard guard( Application::GetSolarMutex() );
282*cdf0e10cSrcweir         delete m_pExtMgrDialog;
283*cdf0e10cSrcweir         m_pExtMgrDialog = NULL;
284*cdf0e10cSrcweir         delete m_pUpdReqDialog;
285*cdf0e10cSrcweir         m_pUpdReqDialog = NULL;
286*cdf0e10cSrcweir         Application::Quit();
287*cdf0e10cSrcweir     }
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir //------------------------------------------------------------------------------
291*cdf0e10cSrcweir void TheExtensionManager::createPackageList()
292*cdf0e10cSrcweir {
293*cdf0e10cSrcweir     uno::Sequence< uno::Sequence< uno::Reference< deployment::XPackage > > > xAllPackages;
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir     try {
296*cdf0e10cSrcweir         xAllPackages = m_xExtensionManager->getAllExtensions( uno::Reference< task::XAbortChannel >(),
297*cdf0e10cSrcweir                                                               uno::Reference< ucb::XCommandEnvironment >() );
298*cdf0e10cSrcweir     } catch ( deployment::DeploymentException & ) {
299*cdf0e10cSrcweir         return;
300*cdf0e10cSrcweir     } catch ( ucb::CommandFailedException & ) {
301*cdf0e10cSrcweir         return;
302*cdf0e10cSrcweir     } catch ( ucb::CommandAbortedException & ) {
303*cdf0e10cSrcweir         return;
304*cdf0e10cSrcweir     } catch ( lang::IllegalArgumentException & e ) {
305*cdf0e10cSrcweir         throw uno::RuntimeException( e.Message, e.Context );
306*cdf0e10cSrcweir     }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < xAllPackages.getLength(); ++i )
309*cdf0e10cSrcweir     {
310*cdf0e10cSrcweir         uno::Sequence< uno::Reference< deployment::XPackage > > xPackageList = xAllPackages[i];
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir         for ( sal_Int32 j = 0; j < xPackageList.getLength(); ++j )
313*cdf0e10cSrcweir         {
314*cdf0e10cSrcweir             uno::Reference< deployment::XPackage > xPackage = xPackageList[j];
315*cdf0e10cSrcweir             if ( xPackage.is() )
316*cdf0e10cSrcweir             {
317*cdf0e10cSrcweir                 PackageState eState = getPackageState( xPackage );
318*cdf0e10cSrcweir                 getDialogHelper()->addPackageToList( xPackage );
319*cdf0e10cSrcweir                 // When the package is enabled, we can stop here, otherwise we have to look for
320*cdf0e10cSrcweir                 // another version of this package
321*cdf0e10cSrcweir                 if ( ( eState == REGISTERED ) || ( eState == NOT_AVAILABLE ) )
322*cdf0e10cSrcweir                     break;
323*cdf0e10cSrcweir             }
324*cdf0e10cSrcweir         }
325*cdf0e10cSrcweir     }
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir     uno::Sequence< uno::Reference< deployment::XPackage > > xNoLicPackages;
328*cdf0e10cSrcweir     xNoLicPackages = m_xExtensionManager->getExtensionsWithUnacceptedLicenses( SHARED_PACKAGE_MANAGER,
329*cdf0e10cSrcweir                                                                                uno::Reference< ucb::XCommandEnvironment >() );
330*cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < xNoLicPackages.getLength(); ++i )
331*cdf0e10cSrcweir     {
332*cdf0e10cSrcweir         uno::Reference< deployment::XPackage > xPackage = xNoLicPackages[i];
333*cdf0e10cSrcweir         if ( xPackage.is() )
334*cdf0e10cSrcweir         {
335*cdf0e10cSrcweir             getDialogHelper()->addPackageToList( xPackage, true );
336*cdf0e10cSrcweir         }
337*cdf0e10cSrcweir     }
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir //------------------------------------------------------------------------------
341*cdf0e10cSrcweir PackageState TheExtensionManager::getPackageState( const uno::Reference< deployment::XPackage > &xPackage ) const
342*cdf0e10cSrcweir {
343*cdf0e10cSrcweir     try {
344*cdf0e10cSrcweir         beans::Optional< beans::Ambiguous< sal_Bool > > option(
345*cdf0e10cSrcweir             xPackage->isRegistered( uno::Reference< task::XAbortChannel >(),
346*cdf0e10cSrcweir                                     uno::Reference< ucb::XCommandEnvironment >() ) );
347*cdf0e10cSrcweir         if ( option.IsPresent )
348*cdf0e10cSrcweir         {
349*cdf0e10cSrcweir             ::beans::Ambiguous< sal_Bool > const & reg = option.Value;
350*cdf0e10cSrcweir             if ( reg.IsAmbiguous )
351*cdf0e10cSrcweir                 return AMBIGUOUS;
352*cdf0e10cSrcweir             else
353*cdf0e10cSrcweir                 return reg.Value ? REGISTERED : NOT_REGISTERED;
354*cdf0e10cSrcweir         }
355*cdf0e10cSrcweir         else
356*cdf0e10cSrcweir             return NOT_AVAILABLE;
357*cdf0e10cSrcweir     }
358*cdf0e10cSrcweir     catch ( uno::RuntimeException & ) {
359*cdf0e10cSrcweir         throw;
360*cdf0e10cSrcweir     }
361*cdf0e10cSrcweir     catch ( uno::Exception & exc) {
362*cdf0e10cSrcweir         (void) exc;
363*cdf0e10cSrcweir         OSL_ENSURE( 0, ::rtl::OUStringToOString( exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
364*cdf0e10cSrcweir         return NOT_AVAILABLE;
365*cdf0e10cSrcweir     }
366*cdf0e10cSrcweir }
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir //------------------------------------------------------------------------------
369*cdf0e10cSrcweir bool TheExtensionManager::isReadOnly( const uno::Reference< deployment::XPackage > &xPackage ) const
370*cdf0e10cSrcweir {
371*cdf0e10cSrcweir     if ( m_xExtensionManager.is() && xPackage.is() )
372*cdf0e10cSrcweir     {
373*cdf0e10cSrcweir         return m_xExtensionManager->isReadOnlyRepository( xPackage->getRepositoryName() );
374*cdf0e10cSrcweir     }
375*cdf0e10cSrcweir     else
376*cdf0e10cSrcweir         return true;
377*cdf0e10cSrcweir }
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir //------------------------------------------------------------------------------
380*cdf0e10cSrcweir // The function investigates if the extension supports options.
381*cdf0e10cSrcweir bool TheExtensionManager::supportsOptions( const uno::Reference< deployment::XPackage > &xPackage ) const
382*cdf0e10cSrcweir {
383*cdf0e10cSrcweir     bool bOptions = false;
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir     if ( ! xPackage->isBundle() )
386*cdf0e10cSrcweir         return false;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir     beans::Optional< OUString > aId = xPackage->getIdentifier();
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir     //a bundle must always have an id
391*cdf0e10cSrcweir     OSL_ASSERT( aId.IsPresent );
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir     //iterate over all available nodes
394*cdf0e10cSrcweir     uno::Sequence< OUString > seqNames = m_xNameAccessNodes->getElementNames();
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir     for ( int i = 0; i < seqNames.getLength(); i++ )
397*cdf0e10cSrcweir     {
398*cdf0e10cSrcweir         uno::Any anyNode = m_xNameAccessNodes->getByName( seqNames[i] );
399*cdf0e10cSrcweir         //If we have a node then then it must contain the set of leaves. This is part of OptionsDialog.xcs
400*cdf0e10cSrcweir         uno::Reference< XInterface> xIntNode = anyNode.get< uno::Reference< XInterface > >();
401*cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xNode( xIntNode, uno::UNO_QUERY_THROW );
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir         uno::Any anyLeaves = xNode->getByName( OUSTR("Leaves") );
404*cdf0e10cSrcweir         uno::Reference< XInterface > xIntLeaves = anyLeaves.get< uno::Reference< XInterface > >();
405*cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xLeaves( xIntLeaves, uno::UNO_QUERY_THROW );
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir         //iterate over all available leaves
408*cdf0e10cSrcweir         uno::Sequence< OUString > seqLeafNames = xLeaves->getElementNames();
409*cdf0e10cSrcweir         for ( int j = 0; j < seqLeafNames.getLength(); j++ )
410*cdf0e10cSrcweir         {
411*cdf0e10cSrcweir             uno::Any anyLeaf = xLeaves->getByName( seqLeafNames[j] );
412*cdf0e10cSrcweir             uno::Reference< XInterface > xIntLeaf = anyLeaf.get< uno::Reference< XInterface > >();
413*cdf0e10cSrcweir             uno::Reference< beans::XPropertySet > xLeaf( xIntLeaf, uno::UNO_QUERY_THROW );
414*cdf0e10cSrcweir             //investigate the Id property if it matches the extension identifier which
415*cdf0e10cSrcweir             //has been passed in.
416*cdf0e10cSrcweir             uno::Any anyValue = xLeaf->getPropertyValue( OUSTR("Id") );
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir             OUString sId = anyValue.get< OUString >();
419*cdf0e10cSrcweir             if ( sId == aId.Value )
420*cdf0e10cSrcweir             {
421*cdf0e10cSrcweir                 bOptions = true;
422*cdf0e10cSrcweir                 break;
423*cdf0e10cSrcweir             }
424*cdf0e10cSrcweir         }
425*cdf0e10cSrcweir         if ( bOptions )
426*cdf0e10cSrcweir             break;
427*cdf0e10cSrcweir     }
428*cdf0e10cSrcweir     return bOptions;
429*cdf0e10cSrcweir }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir //------------------------------------------------------------------------------
432*cdf0e10cSrcweir // XEventListener
433*cdf0e10cSrcweir void TheExtensionManager::disposing( lang::EventObject const & rEvt )
434*cdf0e10cSrcweir     throw ( uno::RuntimeException )
435*cdf0e10cSrcweir {
436*cdf0e10cSrcweir     bool shutDown = (rEvt.Source == m_xDesktop);
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir     if ( shutDown && m_xDesktop.is() )
439*cdf0e10cSrcweir     {
440*cdf0e10cSrcweir         m_xDesktop->removeTerminateListener( this );
441*cdf0e10cSrcweir         m_xDesktop.clear();
442*cdf0e10cSrcweir     }
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir     if ( shutDown )
445*cdf0e10cSrcweir     {
446*cdf0e10cSrcweir         if ( dp_misc::office_is_running() )
447*cdf0e10cSrcweir         {
448*cdf0e10cSrcweir             const ::vos::OGuard guard( Application::GetSolarMutex() );
449*cdf0e10cSrcweir             delete m_pExtMgrDialog;
450*cdf0e10cSrcweir             m_pExtMgrDialog = NULL;
451*cdf0e10cSrcweir             delete m_pUpdReqDialog;
452*cdf0e10cSrcweir             m_pUpdReqDialog = NULL;
453*cdf0e10cSrcweir         }
454*cdf0e10cSrcweir         s_ExtMgr.clear();
455*cdf0e10cSrcweir     }
456*cdf0e10cSrcweir }
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir //------------------------------------------------------------------------------
459*cdf0e10cSrcweir // XTerminateListener
460*cdf0e10cSrcweir void TheExtensionManager::queryTermination( ::lang::EventObject const & )
461*cdf0e10cSrcweir     throw ( frame::TerminationVetoException, uno::RuntimeException )
462*cdf0e10cSrcweir {
463*cdf0e10cSrcweir     DialogHelper *pDialogHelper = getDialogHelper();
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir     if ( m_pExecuteCmdQueue->isBusy() || ( pDialogHelper && pDialogHelper->isBusy() ) )
466*cdf0e10cSrcweir     {
467*cdf0e10cSrcweir         ToTop( TOTOP_RESTOREWHENMIN );
468*cdf0e10cSrcweir         throw frame::TerminationVetoException(
469*cdf0e10cSrcweir             OUSTR("The office cannot be closed while the Extension Manager is running"),
470*cdf0e10cSrcweir             uno::Reference<XInterface>(static_cast<frame::XTerminateListener*>(this), uno::UNO_QUERY));
471*cdf0e10cSrcweir     }
472*cdf0e10cSrcweir     else
473*cdf0e10cSrcweir     {
474*cdf0e10cSrcweir         if ( m_pExtMgrDialog )
475*cdf0e10cSrcweir             m_pExtMgrDialog->Close();
476*cdf0e10cSrcweir         if ( m_pUpdReqDialog )
477*cdf0e10cSrcweir             m_pUpdReqDialog->Close();
478*cdf0e10cSrcweir     }
479*cdf0e10cSrcweir }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir //------------------------------------------------------------------------------
482*cdf0e10cSrcweir void TheExtensionManager::notifyTermination( ::lang::EventObject const & rEvt )
483*cdf0e10cSrcweir     throw ( uno::RuntimeException )
484*cdf0e10cSrcweir {
485*cdf0e10cSrcweir     disposing( rEvt );
486*cdf0e10cSrcweir }
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir //------------------------------------------------------------------------------
489*cdf0e10cSrcweir // XModifyListener
490*cdf0e10cSrcweir void TheExtensionManager::modified( ::lang::EventObject const & /*rEvt*/ )
491*cdf0e10cSrcweir     throw ( uno::RuntimeException )
492*cdf0e10cSrcweir {
493*cdf0e10cSrcweir     getDialogHelper()->prepareChecking();
494*cdf0e10cSrcweir     createPackageList();
495*cdf0e10cSrcweir     getDialogHelper()->checkEntries();
496*cdf0e10cSrcweir }
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir //------------------------------------------------------------------------------
499*cdf0e10cSrcweir ::rtl::Reference< TheExtensionManager > TheExtensionManager::get( const uno::Reference< uno::XComponentContext > &xContext,
500*cdf0e10cSrcweir                                                                   const uno::Reference< awt::XWindow > &xParent,
501*cdf0e10cSrcweir                                                                   const OUString & extensionURL )
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir     if ( s_ExtMgr.is() )
504*cdf0e10cSrcweir     {
505*cdf0e10cSrcweir         OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
506*cdf0e10cSrcweir         if ( extensionURL.getLength() )
507*cdf0e10cSrcweir             s_ExtMgr->installPackage( extensionURL, true );
508*cdf0e10cSrcweir         return s_ExtMgr;
509*cdf0e10cSrcweir     }
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir     Window * pParent = DIALOG_NO_PARENT;
512*cdf0e10cSrcweir     if ( xParent.is() )
513*cdf0e10cSrcweir         pParent = VCLUnoHelper::GetWindow(xParent);
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir     ::rtl::Reference<TheExtensionManager> that( new TheExtensionManager( pParent, xContext ) );
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir     const ::vos::OGuard guard( Application::GetSolarMutex() );
518*cdf0e10cSrcweir     if ( ! s_ExtMgr.is() )
519*cdf0e10cSrcweir     {
520*cdf0e10cSrcweir         OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
521*cdf0e10cSrcweir         s_ExtMgr = that;
522*cdf0e10cSrcweir     }
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir     if ( extensionURL.getLength() )
525*cdf0e10cSrcweir         s_ExtMgr->installPackage( extensionURL, true );
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir     return s_ExtMgr;
528*cdf0e10cSrcweir }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir } //namespace dp_gui
531*cdf0e10cSrcweir 
532