1*f8e2c85aSAndrew Rist /**************************************************************
2*f8e2c85aSAndrew Rist  *
3*f8e2c85aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f8e2c85aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f8e2c85aSAndrew Rist  * distributed with this work for additional information
6*f8e2c85aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f8e2c85aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f8e2c85aSAndrew Rist  * "License"); you may not use this file except in compliance
9*f8e2c85aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f8e2c85aSAndrew Rist  *
11*f8e2c85aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f8e2c85aSAndrew Rist  *
13*f8e2c85aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f8e2c85aSAndrew Rist  * software distributed under the License is distributed on an
15*f8e2c85aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f8e2c85aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*f8e2c85aSAndrew Rist  * specific language governing permissions and limitations
18*f8e2c85aSAndrew Rist  * under the License.
19*f8e2c85aSAndrew Rist  *
20*f8e2c85aSAndrew Rist  *************************************************************/
21*f8e2c85aSAndrew Rist 
22*f8e2c85aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_shell.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "boost/noncopyable.hpp"
28cdf0e10cSrcweir #include "com/sun/star/beans/Optional.hpp"
29cdf0e10cSrcweir #include "com/sun/star/beans/PropertyVetoException.hpp"
30cdf0e10cSrcweir #include "com/sun/star/beans/UnknownPropertyException.hpp"
31cdf0e10cSrcweir #include "com/sun/star/beans/XPropertyChangeListener.hpp"
32cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
33cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySetInfo.hpp"
34cdf0e10cSrcweir #include "com/sun/star/beans/XVetoableChangeListener.hpp"
35cdf0e10cSrcweir #include "com/sun/star/lang/IllegalArgumentException.hpp"
36cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetException.hpp"
37cdf0e10cSrcweir #include "com/sun/star/lang/XMultiComponentFactory.hpp"
38cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp"
39cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetException.hpp"
40cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
41cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
42cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
43cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
44cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
45cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
46cdf0e10cSrcweir #include "com/sun/star/uno/XCurrentContext.hpp"
47cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
48cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx"
49cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx"
50cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
51cdf0e10cSrcweir #include "osl/diagnose.h"
52cdf0e10cSrcweir #include "rtl/string.h"
53cdf0e10cSrcweir #include "rtl/textenc.h"
54cdf0e10cSrcweir #include "rtl/ustring.h"
55cdf0e10cSrcweir #include "rtl/ustring.hxx"
56cdf0e10cSrcweir #include "sal/types.h"
57cdf0e10cSrcweir #include "uno/current_context.hxx"
58cdf0e10cSrcweir #include "uno/lbnames.h"
59cdf0e10cSrcweir 
60cdf0e10cSrcweir namespace {
61cdf0e10cSrcweir 
62cdf0e10cSrcweir namespace css = com::sun::star;
63cdf0e10cSrcweir 
getDefaultImplementationName()64cdf0e10cSrcweir rtl::OUString SAL_CALL getDefaultImplementationName() {
65cdf0e10cSrcweir     return rtl::OUString(
66cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
67cdf0e10cSrcweir             "com.sun.star.comp.configuration.backend.DesktopBackend"));
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
getDefaultSupportedServiceNames()70cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > SAL_CALL getDefaultSupportedServiceNames() {
71cdf0e10cSrcweir     rtl::OUString name(
72cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
73cdf0e10cSrcweir             "com.sun.star.configuration.backend.DesktopBackend"));
74cdf0e10cSrcweir     return css::uno::Sequence< rtl::OUString >(&name, 1);
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir class Default:
78cdf0e10cSrcweir     public cppu::WeakImplHelper2<
79cdf0e10cSrcweir         css::lang::XServiceInfo, css::beans::XPropertySet >,
80cdf0e10cSrcweir     private boost::noncopyable
81cdf0e10cSrcweir {
82cdf0e10cSrcweir public:
Default()83cdf0e10cSrcweir     Default() {}
84cdf0e10cSrcweir 
85cdf0e10cSrcweir private:
~Default()86cdf0e10cSrcweir     virtual ~Default() {}
87cdf0e10cSrcweir 
getImplementationName()88cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getImplementationName()
89cdf0e10cSrcweir         throw (css::uno::RuntimeException)
90cdf0e10cSrcweir     { return getDefaultImplementationName(); }
91cdf0e10cSrcweir 
supportsService(rtl::OUString const & ServiceName)92cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
93cdf0e10cSrcweir         throw (css::uno::RuntimeException)
94cdf0e10cSrcweir     { return ServiceName == getSupportedServiceNames()[0]; }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()97cdf0e10cSrcweir     getSupportedServiceNames() throw (css::uno::RuntimeException)
98cdf0e10cSrcweir     { return getDefaultSupportedServiceNames(); }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
getPropertySetInfo()101cdf0e10cSrcweir     getPropertySetInfo() throw (css::uno::RuntimeException)
102cdf0e10cSrcweir     { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     virtual void SAL_CALL setPropertyValue(
105cdf0e10cSrcweir         rtl::OUString const &, css::uno::Any const &)
106cdf0e10cSrcweir         throw (
107cdf0e10cSrcweir             css::beans::UnknownPropertyException,
108cdf0e10cSrcweir             css::beans::PropertyVetoException,
109cdf0e10cSrcweir             css::lang::IllegalArgumentException,
110cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException);
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     virtual css::uno::Any SAL_CALL getPropertyValue(
113cdf0e10cSrcweir         rtl::OUString const & PropertyName)
114cdf0e10cSrcweir         throw (
115cdf0e10cSrcweir             css::beans::UnknownPropertyException,
116cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException);
117cdf0e10cSrcweir 
addPropertyChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XPropertyChangeListener> const &)118cdf0e10cSrcweir     virtual void SAL_CALL addPropertyChangeListener(
119cdf0e10cSrcweir         rtl::OUString const &,
120cdf0e10cSrcweir         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
121cdf0e10cSrcweir         throw (
122cdf0e10cSrcweir             css::beans::UnknownPropertyException,
123cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
124cdf0e10cSrcweir     {}
125cdf0e10cSrcweir 
removePropertyChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XPropertyChangeListener> const &)126cdf0e10cSrcweir     virtual void SAL_CALL removePropertyChangeListener(
127cdf0e10cSrcweir         rtl::OUString const &,
128cdf0e10cSrcweir         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
129cdf0e10cSrcweir         throw (
130cdf0e10cSrcweir             css::beans::UnknownPropertyException,
131cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
132cdf0e10cSrcweir     {}
133cdf0e10cSrcweir 
addVetoableChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XVetoableChangeListener> const &)134cdf0e10cSrcweir     virtual void SAL_CALL addVetoableChangeListener(
135cdf0e10cSrcweir         rtl::OUString const &,
136cdf0e10cSrcweir         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
137cdf0e10cSrcweir         throw (
138cdf0e10cSrcweir             css::beans::UnknownPropertyException,
139cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
140cdf0e10cSrcweir     {}
141cdf0e10cSrcweir 
removeVetoableChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XVetoableChangeListener> const &)142cdf0e10cSrcweir     virtual void SAL_CALL removeVetoableChangeListener(
143cdf0e10cSrcweir         rtl::OUString const &,
144cdf0e10cSrcweir         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
145cdf0e10cSrcweir         throw (
146cdf0e10cSrcweir             css::beans::UnknownPropertyException,
147cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
148cdf0e10cSrcweir     {}
149cdf0e10cSrcweir };
150cdf0e10cSrcweir 
setPropertyValue(rtl::OUString const &,css::uno::Any const &)151cdf0e10cSrcweir void Default::setPropertyValue(rtl::OUString const &, css::uno::Any const &)
152cdf0e10cSrcweir     throw (
153cdf0e10cSrcweir         css::beans::UnknownPropertyException, css::beans::PropertyVetoException,
154cdf0e10cSrcweir         css::lang::IllegalArgumentException, css::lang::WrappedTargetException,
155cdf0e10cSrcweir         css::uno::RuntimeException)
156cdf0e10cSrcweir {
157cdf0e10cSrcweir     throw css::lang::IllegalArgumentException(
158cdf0e10cSrcweir         rtl::OUString(
159cdf0e10cSrcweir             RTL_CONSTASCII_USTRINGPARAM("setPropertyValue not supported")),
160cdf0e10cSrcweir         static_cast< cppu::OWeakObject * >(this), -1);
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
getPropertyValue(rtl::OUString const & PropertyName)163cdf0e10cSrcweir css::uno::Any Default::getPropertyValue(rtl::OUString const & PropertyName)
164cdf0e10cSrcweir     throw (
165cdf0e10cSrcweir         css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
166cdf0e10cSrcweir         css::uno::RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     if (PropertyName.equalsAsciiL(
169cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("EnableATToolSupport")) ||
170cdf0e10cSrcweir         PropertyName.equalsAsciiL(
171cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ExternalMailer")) ||
172cdf0e10cSrcweir         PropertyName.equalsAsciiL(
173cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("SourceViewFontHeight")) ||
174cdf0e10cSrcweir         PropertyName.equalsAsciiL(
175cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("SourceViewFontName")) ||
176cdf0e10cSrcweir         PropertyName.equalsAsciiL(
177cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("WorkPathVariable")) ||
178cdf0e10cSrcweir         PropertyName.equalsAsciiL(
179cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyName")) ||
180cdf0e10cSrcweir         PropertyName.equalsAsciiL(
181cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyPort")) ||
182cdf0e10cSrcweir         PropertyName.equalsAsciiL(
183cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyName")) ||
184cdf0e10cSrcweir         PropertyName.equalsAsciiL(
185cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyPort")) ||
186cdf0e10cSrcweir         PropertyName.equalsAsciiL(
187cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyName")) ||
188cdf0e10cSrcweir         PropertyName.equalsAsciiL(
189cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyPort")) ||
190cdf0e10cSrcweir         PropertyName.equalsAsciiL(
191cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetNoProxy")) ||
192cdf0e10cSrcweir         PropertyName.equalsAsciiL(
193cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("ooInetProxyType")))
194cdf0e10cSrcweir     {
195cdf0e10cSrcweir         return css::uno::makeAny(css::beans::Optional< css::uno::Any >());
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir     throw css::beans::UnknownPropertyException(
198cdf0e10cSrcweir         PropertyName, static_cast< cppu::OWeakObject * >(this));
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
createBackend(css::uno::Reference<css::uno::XComponentContext> const & context,rtl::OUString const & name)201cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > createBackend(
202cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const & context,
203cdf0e10cSrcweir     rtl::OUString const & name)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     try {
206cdf0e10cSrcweir         return css::uno::Reference< css::lang::XMultiComponentFactory >(
207cdf0e10cSrcweir             context->getServiceManager(), css::uno::UNO_SET_THROW)->
208cdf0e10cSrcweir             createInstanceWithContext(name, context);
209cdf0e10cSrcweir     } catch (css::uno::RuntimeException &) {
210cdf0e10cSrcweir         // Assuming these exceptions are real errors:
211cdf0e10cSrcweir         throw;
212cdf0e10cSrcweir     } catch (css::uno::Exception & e) {
213cdf0e10cSrcweir         // Assuming these exceptions indicate that the service is not installed:
214cdf0e10cSrcweir         OSL_TRACE(
215cdf0e10cSrcweir             "createInstance(%s) failed with %s",
216cdf0e10cSrcweir             rtl::OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr(),
217cdf0e10cSrcweir             rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
218cdf0e10cSrcweir         return css::uno::Reference< css::uno::XInterface >();
219cdf0e10cSrcweir     }
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
createInstance(css::uno::Reference<css::uno::XComponentContext> const & context)222cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
223cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const & context)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     rtl::OUString desktop;
226cdf0e10cSrcweir     css::uno::Reference< css::uno::XCurrentContext > current(
227cdf0e10cSrcweir         css::uno::getCurrentContext());
228cdf0e10cSrcweir     if (current.is()) {
229cdf0e10cSrcweir         current->getValueByName(
230cdf0e10cSrcweir             rtl::OUString(
231cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("system.desktop-environment"))) >>=
232cdf0e10cSrcweir             desktop;
233cdf0e10cSrcweir     }
234cdf0e10cSrcweir     // Fall back to the default if the specific backend is not available:
235cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > backend;
236cdf0e10cSrcweir     if (desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("GNOME"))) {
237cdf0e10cSrcweir         backend = createBackend(
238cdf0e10cSrcweir             context,
239cdf0e10cSrcweir             rtl::OUString(
240cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
241cdf0e10cSrcweir                     "com.sun.star.configuration.backend.GconfBackend")));
242cdf0e10cSrcweir     } else if (desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("KDE"))) {
243cdf0e10cSrcweir         backend = createBackend(
244cdf0e10cSrcweir             context,
245cdf0e10cSrcweir             rtl::OUString(
246cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
247cdf0e10cSrcweir                     "com.sun.star.configuration.backend.KDEBackend")));
248cdf0e10cSrcweir     } else if (desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("KDE4"))) {
249cdf0e10cSrcweir         backend = createBackend(
250cdf0e10cSrcweir             context,
251cdf0e10cSrcweir             rtl::OUString(
252cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
253cdf0e10cSrcweir                     "com.sun.star.configuration.backend.KDE4Backend")));
254cdf0e10cSrcweir     }
255cdf0e10cSrcweir     return backend.is()
256cdf0e10cSrcweir         ? backend : static_cast< cppu::OWeakObject * >(new Default);
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir static cppu::ImplementationEntry const services[] = {
260cdf0e10cSrcweir     { &createInstance, &getDefaultImplementationName,
261cdf0e10cSrcweir       &getDefaultSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
262cdf0e10cSrcweir       0 },
263cdf0e10cSrcweir     { 0, 0, 0, 0, 0, 0 }
264cdf0e10cSrcweir };
265cdf0e10cSrcweir 
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
component_getFactory(char const * pImplName,void * pServiceManager,void * pRegistryKey)268cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
269cdf0e10cSrcweir     char const * pImplName, void * pServiceManager, void * pRegistryKey)
270cdf0e10cSrcweir {
271cdf0e10cSrcweir     return cppu::component_getFactoryHelper(
272cdf0e10cSrcweir         pImplName, pServiceManager, pRegistryKey, services);
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
275cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
component_getImplementationEnvironment(char const ** ppEnvTypeName,uno_Environment **)276cdf0e10cSrcweir component_getImplementationEnvironment(
277cdf0e10cSrcweir     char const ** ppEnvTypeName, uno_Environment **)
278cdf0e10cSrcweir {
279cdf0e10cSrcweir     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
280cdf0e10cSrcweir }
281