update credits
[LibreOffice.git] / framework / source / uiconfiguration / moduleuicfgsupplier.cxx
blobc268cfb0213b303095d88804dfc544fe610c15d3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <uiconfiguration/moduleuicfgsupplier.hxx>
21 #include <threadhelp/resetableguard.hxx>
22 #include <services.h>
24 #include <com/sun/star/lang/DisposedException.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/container/XNameAccess.hpp>
27 #include <com/sun/star/embed/ElementModes.hpp>
28 #include <com/sun/star/frame/ModuleManager.hpp>
29 #include <com/sun/star/io/XOutputStream.hpp>
30 #include <com/sun/star/io/XInputStream.hpp>
31 #include <com/sun/star/io/XSeekable.hpp>
32 #include <com/sun/star/embed/XPackageStructureCreator.hpp>
34 #include <rtl/logfile.hxx>
35 #include <cppuhelper/implbase1.hxx>
36 #include <vcl/svapp.hxx>
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::io;
40 using namespace com::sun::star::lang;
41 using namespace com::sun::star::container;
42 using namespace com::sun::star::beans;
43 using namespace com::sun::star::embed;
44 using namespace ::com::sun::star::ui;
45 using namespace ::com::sun::star::frame;
47 namespace framework
50 class RootStorageWrapper : public ::cppu::WeakImplHelper1< com::sun::star::embed::XTransactedObject >
52 public:
53 // XInterface, XTypeProvider
54 RootStorageWrapper( const Reference< XTransactedObject >& xRootCommit ) : m_xRootCommit( xRootCommit ) {}
55 virtual ~RootStorageWrapper() {}
57 // XTransactedObject
58 virtual void SAL_CALL commit() throw ( com::sun::star::io::IOException, com::sun::star::lang::WrappedTargetException )
60 m_xRootCommit->commit();
63 virtual void SAL_CALL revert() throw ( com::sun::star::io::IOException, com::sun::star::lang::WrappedTargetException )
65 m_xRootCommit->revert();
68 private:
69 Reference< XTransactedObject > m_xRootCommit;
72 //*****************************************************************************************************************
73 // XInterface, XTypeProvider, XServiceInfo
74 //*****************************************************************************************************************
75 DEFINE_XINTERFACE_4 ( ModuleUIConfigurationManagerSupplier ,
76 OWeakObject ,
77 DIRECT_INTERFACE( css::lang::XTypeProvider ),
78 DIRECT_INTERFACE( css::lang::XServiceInfo ),
79 DIRECT_INTERFACE( css::lang::XComponent ),
80 DIRECT_INTERFACE( ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier )
83 DEFINE_XTYPEPROVIDER_4 ( ModuleUIConfigurationManagerSupplier ,
84 css::lang::XTypeProvider ,
85 css::lang::XServiceInfo ,
86 css::lang::XComponent ,
87 ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier
90 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( ModuleUIConfigurationManagerSupplier ,
91 ::cppu::OWeakObject ,
92 DECLARE_ASCII("com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ),
93 IMPLEMENTATIONNAME_MODULEUICONFIGURATIONMANAGERSUPPLIER
96 DEFINE_INIT_SERVICE ( ModuleUIConfigurationManagerSupplier, {} )
100 ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier( const Reference< XMultiServiceFactory >& xServiceManager ) :
101 ThreadHelpBase( &Application::GetSolarMutex() )
102 , m_bDisposed( false )
103 //TODO_AS , m_bInit( false )
104 , m_xModuleMgr( ModuleManager::create( comphelper::getComponentContext(xServiceManager) ) )
105 , m_xServiceManager( xServiceManager )
106 , m_aListenerContainer( m_aLock.getShareableOslMutex() )
108 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier" );
111 // Retrieve known modules and insert them into our boost::unordered_map to speed-up access time.
112 Reference< XNameAccess > xNameAccess( m_xModuleMgr, UNO_QUERY_THROW );
113 const Sequence< OUString > aNameSeq = xNameAccess->getElementNames();
114 const OUString* pNameSeq = aNameSeq.getConstArray();
115 for ( sal_Int32 n = 0; n < aNameSeq.getLength(); n++ )
116 m_aModuleToModuleUICfgMgrMap.insert( ModuleToModuleCfgMgr::value_type( pNameSeq[n], Reference< XUIConfigurationManager >() ));
118 catch(...)
123 ModuleUIConfigurationManagerSupplier::~ModuleUIConfigurationManagerSupplier()
125 m_xUserRootCommit.clear();
127 // dispose all our module user interface configuration managers
128 ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.begin();
129 while ( pIter != m_aModuleToModuleUICfgMgrMap.end() )
131 Reference< XComponent > xComponent( pIter->second, UNO_QUERY );
132 if ( xComponent.is() )
133 xComponent->dispose();
134 ++pIter;
138 // XComponent
139 void SAL_CALL ModuleUIConfigurationManagerSupplier::dispose()
140 throw ( RuntimeException )
142 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::dispose" );
143 Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
145 css::lang::EventObject aEvent( xThis );
146 m_aListenerContainer.disposeAndClear( aEvent );
149 ResetableGuard aGuard( m_aLock );
150 m_bDisposed = true;
154 void SAL_CALL ModuleUIConfigurationManagerSupplier::addEventListener( const Reference< XEventListener >& xListener )
155 throw ( RuntimeException )
157 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::addEventListener" );
159 ResetableGuard aGuard( m_aLock );
161 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
162 if ( m_bDisposed )
163 throw DisposedException();
166 m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
169 void SAL_CALL ModuleUIConfigurationManagerSupplier::removeEventListener( const Reference< XEventListener >& xListener )
170 throw ( RuntimeException )
172 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::removeEventListener" );
173 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
174 m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener );
177 // XModuleUIConfigurationManagerSupplier
178 Reference< XUIConfigurationManager > SAL_CALL ModuleUIConfigurationManagerSupplier::getUIConfigurationManager( const OUString& ModuleIdentifier )
179 throw ( NoSuchElementException, RuntimeException)
181 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleUIConfigurationManagerSupplier::getUIConfigurationManager" );
182 ResetableGuard aGuard( m_aLock );
184 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
185 if ( m_bDisposed )
186 throw DisposedException();
188 ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.find( ModuleIdentifier );
189 if ( pIter == m_aModuleToModuleUICfgMgrMap.end() )
190 throw NoSuchElementException();
191 //TODO_AS impl_initStorages();
193 // Create instance on demand
194 if ( !pIter->second.is() )
196 OUString sShort;
199 Sequence< PropertyValue > lProps;
200 Reference< XNameAccess > xCont(m_xModuleMgr, UNO_QUERY);
201 xCont->getByName(ModuleIdentifier) >>= lProps;
202 for (sal_Int32 i=0; i<lProps.getLength(); ++i)
204 if ( lProps[i].Name == "ooSetupFactoryShortName" )
206 lProps[i].Value >>= sShort;
207 break;
211 catch( const Exception& )
213 sShort = OUString();
216 if (sShort.isEmpty())
217 throw NoSuchElementException();
218 PropertyValue aArg;
219 Sequence< Any > aArgs( 2 );
220 aArg.Name = OUString( "ModuleShortName" );
221 aArg.Value <<= sShort;
222 aArgs[0] <<= aArg;
223 aArg.Name = OUString( "ModuleIdentifier" );
224 aArg.Value <<= ModuleIdentifier;
225 aArgs[1] <<= aArg;
227 pIter->second.set( m_xServiceManager->createInstanceWithArguments(SERVICENAME_MODULEUICONFIGURATIONMANAGER, aArgs ),UNO_QUERY );
230 return pIter->second;
233 } // namespace framework
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */