xref: /AOO41X/main/shell/source/backends/desktopbe/desktopbackend.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 #include "precompiled_shell.hxx"
29*cdf0e10cSrcweir #include "sal/config.h"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "boost/noncopyable.hpp"
32*cdf0e10cSrcweir #include "com/sun/star/beans/Optional.hpp"
33*cdf0e10cSrcweir #include "com/sun/star/beans/PropertyVetoException.hpp"
34*cdf0e10cSrcweir #include "com/sun/star/beans/UnknownPropertyException.hpp"
35*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertyChangeListener.hpp"
36*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
37*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySetInfo.hpp"
38*cdf0e10cSrcweir #include "com/sun/star/beans/XVetoableChangeListener.hpp"
39*cdf0e10cSrcweir #include "com/sun/star/lang/IllegalArgumentException.hpp"
40*cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetException.hpp"
41*cdf0e10cSrcweir #include "com/sun/star/lang/XMultiComponentFactory.hpp"
42*cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp"
43*cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetException.hpp"
44*cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
45*cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
46*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
47*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
48*cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
49*cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
50*cdf0e10cSrcweir #include "com/sun/star/uno/XCurrentContext.hpp"
51*cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
52*cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx"
53*cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx"
54*cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
55*cdf0e10cSrcweir #include "osl/diagnose.h"
56*cdf0e10cSrcweir #include "rtl/string.h"
57*cdf0e10cSrcweir #include "rtl/textenc.h"
58*cdf0e10cSrcweir #include "rtl/ustring.h"
59*cdf0e10cSrcweir #include "rtl/ustring.hxx"
60*cdf0e10cSrcweir #include "sal/types.h"
61*cdf0e10cSrcweir #include "uno/current_context.hxx"
62*cdf0e10cSrcweir #include "uno/lbnames.h"
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir namespace {
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir namespace css = com::sun::star;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir rtl::OUString SAL_CALL getDefaultImplementationName() {
69*cdf0e10cSrcweir     return rtl::OUString(
70*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
71*cdf0e10cSrcweir             "com.sun.star.comp.configuration.backend.DesktopBackend"));
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > SAL_CALL getDefaultSupportedServiceNames() {
75*cdf0e10cSrcweir     rtl::OUString name(
76*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
77*cdf0e10cSrcweir             "com.sun.star.configuration.backend.DesktopBackend"));
78*cdf0e10cSrcweir     return css::uno::Sequence< rtl::OUString >(&name, 1);
79*cdf0e10cSrcweir }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir class Default:
82*cdf0e10cSrcweir     public cppu::WeakImplHelper2<
83*cdf0e10cSrcweir         css::lang::XServiceInfo, css::beans::XPropertySet >,
84*cdf0e10cSrcweir     private boost::noncopyable
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir public:
87*cdf0e10cSrcweir     Default() {}
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir private:
90*cdf0e10cSrcweir     virtual ~Default() {}
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getImplementationName()
93*cdf0e10cSrcweir         throw (css::uno::RuntimeException)
94*cdf0e10cSrcweir     { return getDefaultImplementationName(); }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
97*cdf0e10cSrcweir         throw (css::uno::RuntimeException)
98*cdf0e10cSrcweir     { return ServiceName == getSupportedServiceNames()[0]; }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
101*cdf0e10cSrcweir     getSupportedServiceNames() throw (css::uno::RuntimeException)
102*cdf0e10cSrcweir     { return getDefaultSupportedServiceNames(); }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
105*cdf0e10cSrcweir     getPropertySetInfo() throw (css::uno::RuntimeException)
106*cdf0e10cSrcweir     { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     virtual void SAL_CALL setPropertyValue(
109*cdf0e10cSrcweir         rtl::OUString const &, css::uno::Any const &)
110*cdf0e10cSrcweir         throw (
111*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
112*cdf0e10cSrcweir             css::beans::PropertyVetoException,
113*cdf0e10cSrcweir             css::lang::IllegalArgumentException,
114*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException);
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     virtual css::uno::Any SAL_CALL getPropertyValue(
117*cdf0e10cSrcweir         rtl::OUString const & PropertyName)
118*cdf0e10cSrcweir         throw (
119*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
120*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     virtual void SAL_CALL addPropertyChangeListener(
123*cdf0e10cSrcweir         rtl::OUString const &,
124*cdf0e10cSrcweir         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
125*cdf0e10cSrcweir         throw (
126*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
127*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
128*cdf0e10cSrcweir     {}
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     virtual void SAL_CALL removePropertyChangeListener(
131*cdf0e10cSrcweir         rtl::OUString const &,
132*cdf0e10cSrcweir         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
133*cdf0e10cSrcweir         throw (
134*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
135*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
136*cdf0e10cSrcweir     {}
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir     virtual void SAL_CALL addVetoableChangeListener(
139*cdf0e10cSrcweir         rtl::OUString const &,
140*cdf0e10cSrcweir         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
141*cdf0e10cSrcweir         throw (
142*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
143*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
144*cdf0e10cSrcweir     {}
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     virtual void SAL_CALL removeVetoableChangeListener(
147*cdf0e10cSrcweir         rtl::OUString const &,
148*cdf0e10cSrcweir         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
149*cdf0e10cSrcweir         throw (
150*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
151*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
152*cdf0e10cSrcweir     {}
153*cdf0e10cSrcweir };
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir void Default::setPropertyValue(rtl::OUString const &, css::uno::Any const &)
156*cdf0e10cSrcweir     throw (
157*cdf0e10cSrcweir         css::beans::UnknownPropertyException, css::beans::PropertyVetoException,
158*cdf0e10cSrcweir         css::lang::IllegalArgumentException, css::lang::WrappedTargetException,
159*cdf0e10cSrcweir         css::uno::RuntimeException)
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir     throw css::lang::IllegalArgumentException(
162*cdf0e10cSrcweir         rtl::OUString(
163*cdf0e10cSrcweir             RTL_CONSTASCII_USTRINGPARAM("setPropertyValue not supported")),
164*cdf0e10cSrcweir         static_cast< cppu::OWeakObject * >(this), -1);
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir css::uno::Any Default::getPropertyValue(rtl::OUString const & PropertyName)
168*cdf0e10cSrcweir     throw (
169*cdf0e10cSrcweir         css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
170*cdf0e10cSrcweir         css::uno::RuntimeException)
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir     if (PropertyName.equalsAsciiL(
173*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("EnableATToolSupport")) ||
174*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
175*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ExternalMailer")) ||
176*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
177*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("SourceViewFontHeight")) ||
178*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
179*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("SourceViewFontName")) ||
180*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
181*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("WorkPathVariable")) ||
182*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
183*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyName")) ||
184*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
185*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyPort")) ||
186*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
187*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyName")) ||
188*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
189*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyPort")) ||
190*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
191*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyName")) ||
192*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
193*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyPort")) ||
194*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
195*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetNoProxy")) ||
196*cdf0e10cSrcweir         PropertyName.equalsAsciiL(
197*cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetProxyType")))
198*cdf0e10cSrcweir     {
199*cdf0e10cSrcweir         return css::uno::makeAny(css::beans::Optional< css::uno::Any >());
200*cdf0e10cSrcweir     }
201*cdf0e10cSrcweir     throw css::beans::UnknownPropertyException(
202*cdf0e10cSrcweir         PropertyName, static_cast< cppu::OWeakObject * >(this));
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > createBackend(
206*cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const & context,
207*cdf0e10cSrcweir     rtl::OUString const & name)
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir     try {
210*cdf0e10cSrcweir         return css::uno::Reference< css::lang::XMultiComponentFactory >(
211*cdf0e10cSrcweir             context->getServiceManager(), css::uno::UNO_SET_THROW)->
212*cdf0e10cSrcweir             createInstanceWithContext(name, context);
213*cdf0e10cSrcweir     } catch (css::uno::RuntimeException &) {
214*cdf0e10cSrcweir         // Assuming these exceptions are real errors:
215*cdf0e10cSrcweir         throw;
216*cdf0e10cSrcweir     } catch (css::uno::Exception & e) {
217*cdf0e10cSrcweir         // Assuming these exceptions indicate that the service is not installed:
218*cdf0e10cSrcweir         OSL_TRACE(
219*cdf0e10cSrcweir             "createInstance(%s) failed with %s",
220*cdf0e10cSrcweir             rtl::OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr(),
221*cdf0e10cSrcweir             rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
222*cdf0e10cSrcweir         return css::uno::Reference< css::uno::XInterface >();
223*cdf0e10cSrcweir     }
224*cdf0e10cSrcweir }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
227*cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const & context)
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir     rtl::OUString desktop;
230*cdf0e10cSrcweir     css::uno::Reference< css::uno::XCurrentContext > current(
231*cdf0e10cSrcweir         css::uno::getCurrentContext());
232*cdf0e10cSrcweir     if (current.is()) {
233*cdf0e10cSrcweir         current->getValueByName(
234*cdf0e10cSrcweir             rtl::OUString(
235*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("system.desktop-environment"))) >>=
236*cdf0e10cSrcweir             desktop;
237*cdf0e10cSrcweir     }
238*cdf0e10cSrcweir     // Fall back to the default if the specific backend is not available:
239*cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > backend;
240*cdf0e10cSrcweir     if (desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("GNOME"))) {
241*cdf0e10cSrcweir         backend = createBackend(
242*cdf0e10cSrcweir             context,
243*cdf0e10cSrcweir             rtl::OUString(
244*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
245*cdf0e10cSrcweir                     "com.sun.star.configuration.backend.GconfBackend")));
246*cdf0e10cSrcweir     } else if (desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("KDE"))) {
247*cdf0e10cSrcweir         backend = createBackend(
248*cdf0e10cSrcweir             context,
249*cdf0e10cSrcweir             rtl::OUString(
250*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
251*cdf0e10cSrcweir                     "com.sun.star.configuration.backend.KDEBackend")));
252*cdf0e10cSrcweir     } else if (desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("KDE4"))) {
253*cdf0e10cSrcweir         backend = createBackend(
254*cdf0e10cSrcweir             context,
255*cdf0e10cSrcweir             rtl::OUString(
256*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
257*cdf0e10cSrcweir                     "com.sun.star.configuration.backend.KDE4Backend")));
258*cdf0e10cSrcweir     }
259*cdf0e10cSrcweir     return backend.is()
260*cdf0e10cSrcweir         ? backend : static_cast< cppu::OWeakObject * >(new Default);
261*cdf0e10cSrcweir }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir static cppu::ImplementationEntry const services[] = {
264*cdf0e10cSrcweir     { &createInstance, &getDefaultImplementationName,
265*cdf0e10cSrcweir       &getDefaultSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
266*cdf0e10cSrcweir       0 },
267*cdf0e10cSrcweir     { 0, 0, 0, 0, 0, 0 }
268*cdf0e10cSrcweir };
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
273*cdf0e10cSrcweir     char const * pImplName, void * pServiceManager, void * pRegistryKey)
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir     return cppu::component_getFactoryHelper(
276*cdf0e10cSrcweir         pImplName, pServiceManager, pRegistryKey, services);
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
280*cdf0e10cSrcweir component_getImplementationEnvironment(
281*cdf0e10cSrcweir     char const ** ppEnvTypeName, uno_Environment **)
282*cdf0e10cSrcweir {
283*cdf0e10cSrcweir     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
284*cdf0e10cSrcweir }
285