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