Update ooo320-m1
[ooovba.git] / shell / source / backends / desktopbe / desktopbecdef.cxx
blob3d668c53dc1a69395b77afc5bfb3b1545468376b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: desktopbecdef.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
34 #ifndef _COM_SUN_STAR_CONFIGURATION_BACKEND_XSCHEMASUPPLIER_HPP_
35 #include <com/sun/star/configuration/backend/XSingleLayerStratum.hpp>
36 #endif
37 #include <com/sun/star/registry/XRegistryKey.hpp>
39 #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
40 #include <cppuhelper/implementationentry.hxx>
41 #endif
42 #include <com/sun/star/uno/XComponentContext.hpp>
44 #include "uno/current_context.hxx"
46 namespace css = com::sun::star ;
47 namespace uno = css::uno ;
48 namespace lang = css::lang ;
49 namespace backend = css::configuration::backend ;
51 //==============================================================================
53 static uno::Reference<uno::XInterface> SAL_CALL createDesktopBackend(const uno::Reference<uno::XComponentContext>& xContext)
55 try {
56 uno::Reference< uno::XCurrentContext > xCurrentContext(uno::getCurrentContext());
58 if (xCurrentContext.is())
60 uno::Any aValue = xCurrentContext->getValueByName(
61 rtl::OUString::createFromAscii( "system.desktop-environment" ) );
63 rtl::OUString aDesktopEnvironment;
64 if ( aValue >>= aDesktopEnvironment )
66 rtl::OUString aDesktopService;
67 if ( aDesktopEnvironment.equalsIgnoreAsciiCaseAscii( "gnome" ) )
68 aDesktopService = rtl::OUString::createFromAscii( "com.sun.star.configuration.backend.GconfBackend" );
69 else if ( aDesktopEnvironment.equalsIgnoreAsciiCaseAscii( "kde" ) )
70 aDesktopService = rtl::OUString::createFromAscii( "com.sun.star.configuration.backend.KDEBackend" );
71 else
72 return uno::Reference<uno::XInterface>();
74 uno::Reference< lang::XMultiComponentFactory > xServiceManager = xContext->getServiceManager();
75 if( xServiceManager.is() )
77 return uno::Reference< backend::XSingleLayerStratum >::query(
78 xServiceManager->createInstanceWithContext( aDesktopService, xContext) );
82 } catch (uno::RuntimeException e) {
85 return uno::Reference<uno::XInterface>();
88 static rtl::OUString SAL_CALL getBackendName(void) {
89 return rtl::OUString(
90 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.configuration.backend.DesktopBackend") );
93 static uno::Sequence<rtl::OUString> SAL_CALL getBackendServiceNames(void)
95 uno::Sequence<rtl::OUString> aServices(2) ;
96 aServices[0] = rtl::OUString(
97 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.backend.DesktopBackend")) ;
98 aServices[1] = rtl::OUString(
99 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.backend.PlatformBackend")) ;
101 return aServices ;
104 static uno::Sequence<rtl::OUString> SAL_CALL getSupportedComponents(void)
106 const sal_Int32 nComponents = 7;
108 uno::Sequence<rtl::OUString> aSupportedComponentsList(nComponents) ;
110 aSupportedComponentsList[0] = rtl::OUString(
111 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.VCL")) ;
112 aSupportedComponentsList[1] = rtl::OUString(
113 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Inet")) ;
114 aSupportedComponentsList[2] = rtl::OUString(
115 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Common")) ;
116 aSupportedComponentsList[3] = rtl::OUString(
117 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Paths")) ;
119 aSupportedComponentsList[4] = rtl::OUString(
120 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.UserProfile")) ;
121 aSupportedComponentsList[5] = rtl::OUString(
122 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Recovery")) ;
123 aSupportedComponentsList[6] = rtl::OUString(
124 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Setup")) ;
126 return aSupportedComponentsList ;
128 //==============================================================================
130 static const cppu::ImplementationEntry kImplementations_entries[] =
133 createDesktopBackend,
134 getBackendName,
135 getBackendServiceNames,
136 cppu::createSingleComponentFactory,
137 NULL,
140 { NULL, NULL, NULL, NULL, NULL, 0 }
142 //------------------------------------------------------------------------------
144 extern "C" void SAL_CALL component_getImplementationEnvironment(
145 const sal_Char **aEnvTypeName,
146 uno_Environment ** /* aEnvironment */)
148 *aEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME ;
151 //------------------------------------------------------------------------------
153 extern "C" sal_Bool SAL_CALL component_writeInfo(void * /* pServiceManager */,
154 void *pRegistryKey)
156 using namespace ::com::sun::star::registry;
157 if (pRegistryKey)
161 uno::Reference< XRegistryKey > xImplKey = static_cast< XRegistryKey* >( pRegistryKey )->createKey(
162 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) + getBackendName()
165 // Register associated service names
166 uno::Reference< XRegistryKey > xServicesKey = xImplKey->createKey(
167 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") )
170 uno::Sequence<rtl::OUString> sServiceNames = getBackendServiceNames();
171 for (sal_Int32 i = 0 ; i < sServiceNames.getLength() ; ++ i)
172 xServicesKey->createKey(sServiceNames[i]);
174 // Register supported components
175 uno::Reference<XRegistryKey> xComponentKey = xImplKey->createKey(
176 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/DATA/SupportedComponents") )
179 xComponentKey->setAsciiListValue( getSupportedComponents() );
181 return sal_True;
184 catch( InvalidRegistryException& )
186 OSL_ENSURE(sal_False, "InvalidRegistryException caught");
190 return sal_False;
193 //------------------------------------------------------------------------------
195 extern "C" void *component_getFactory(const sal_Char *aImplementationName,
196 void *aServiceManager,
197 void *aRegistryKey)
199 return cppu::component_getFactoryHelper(
200 aImplementationName,
201 aServiceManager,
202 aRegistryKey,
203 kImplementations_entries) ;
205 //------------------------------------------------------------------------------