Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include "boost/noncopyable.hpp"
23 : #include "com/sun/star/beans/Optional.hpp"
24 : #include "com/sun/star/beans/PropertyVetoException.hpp"
25 : #include "com/sun/star/beans/UnknownPropertyException.hpp"
26 : #include "com/sun/star/beans/XPropertyChangeListener.hpp"
27 : #include "com/sun/star/beans/XPropertySet.hpp"
28 : #include "com/sun/star/beans/XPropertySetInfo.hpp"
29 : #include "com/sun/star/beans/XVetoableChangeListener.hpp"
30 : #include "com/sun/star/lang/IllegalArgumentException.hpp"
31 : #include "com/sun/star/lang/WrappedTargetException.hpp"
32 : #include "com/sun/star/lang/XMultiComponentFactory.hpp"
33 : #include "com/sun/star/lang/XServiceInfo.hpp"
34 : #include "com/sun/star/lang/WrappedTargetException.hpp"
35 : #include "com/sun/star/uno/Any.hxx"
36 : #include "com/sun/star/uno/Exception.hpp"
37 : #include "com/sun/star/uno/Reference.hxx"
38 : #include "com/sun/star/uno/RuntimeException.hpp"
39 : #include "com/sun/star/uno/Sequence.hxx"
40 : #include "com/sun/star/uno/XComponentContext.hpp"
41 : #include "com/sun/star/uno/XCurrentContext.hpp"
42 : #include "cppuhelper/factory.hxx"
43 : #include "cppuhelper/implbase2.hxx"
44 : #include "cppuhelper/implementationentry.hxx"
45 : #include "cppuhelper/weak.hxx"
46 : #include "osl/diagnose.h"
47 : #include "rtl/string.h"
48 : #include "rtl/textenc.h"
49 : #include "rtl/ustring.h"
50 : #include "rtl/ustring.hxx"
51 : #include "sal/types.h"
52 : #include "uno/current_context.hxx"
53 : #include "uno/lbnames.h"
54 :
55 : namespace {
56 :
57 0 : rtl::OUString SAL_CALL getDefaultImplementationName() {
58 : return rtl::OUString(
59 : RTL_CONSTASCII_USTRINGPARAM(
60 0 : "com.sun.star.comp.configuration.backend.DesktopBackend"));
61 : }
62 :
63 0 : css::uno::Sequence< rtl::OUString > SAL_CALL getDefaultSupportedServiceNames() {
64 : rtl::OUString name(
65 : RTL_CONSTASCII_USTRINGPARAM(
66 0 : "com.sun.star.configuration.backend.DesktopBackend"));
67 0 : return css::uno::Sequence< rtl::OUString >(&name, 1);
68 : }
69 :
70 : class Default:
71 : public cppu::WeakImplHelper2<
72 : css::lang::XServiceInfo, css::beans::XPropertySet >,
73 : private boost::noncopyable
74 : {
75 : public:
76 0 : Default() {}
77 :
78 : private:
79 0 : virtual ~Default() {}
80 :
81 0 : virtual rtl::OUString SAL_CALL getImplementationName()
82 : throw (css::uno::RuntimeException)
83 0 : { return getDefaultImplementationName(); }
84 :
85 0 : virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
86 : throw (css::uno::RuntimeException)
87 0 : { return ServiceName == getSupportedServiceNames()[0]; }
88 :
89 : virtual css::uno::Sequence< rtl::OUString > SAL_CALL
90 0 : getSupportedServiceNames() throw (css::uno::RuntimeException)
91 0 : { return getDefaultSupportedServiceNames(); }
92 :
93 : virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
94 0 : getPropertySetInfo() throw (css::uno::RuntimeException)
95 0 : { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
96 :
97 : virtual void SAL_CALL setPropertyValue(
98 : rtl::OUString const &, css::uno::Any const &)
99 : throw (
100 : css::beans::UnknownPropertyException,
101 : css::beans::PropertyVetoException,
102 : css::lang::IllegalArgumentException,
103 : css::lang::WrappedTargetException, css::uno::RuntimeException);
104 :
105 : virtual css::uno::Any SAL_CALL getPropertyValue(
106 : rtl::OUString const & PropertyName)
107 : throw (
108 : css::beans::UnknownPropertyException,
109 : css::lang::WrappedTargetException, css::uno::RuntimeException);
110 :
111 0 : virtual void SAL_CALL addPropertyChangeListener(
112 : rtl::OUString const &,
113 : css::uno::Reference< css::beans::XPropertyChangeListener > const &)
114 : throw (
115 : css::beans::UnknownPropertyException,
116 : css::lang::WrappedTargetException, css::uno::RuntimeException)
117 0 : {}
118 :
119 0 : virtual void SAL_CALL removePropertyChangeListener(
120 : rtl::OUString const &,
121 : css::uno::Reference< css::beans::XPropertyChangeListener > const &)
122 : throw (
123 : css::beans::UnknownPropertyException,
124 : css::lang::WrappedTargetException, css::uno::RuntimeException)
125 0 : {}
126 :
127 0 : virtual void SAL_CALL addVetoableChangeListener(
128 : rtl::OUString const &,
129 : css::uno::Reference< css::beans::XVetoableChangeListener > const &)
130 : throw (
131 : css::beans::UnknownPropertyException,
132 : css::lang::WrappedTargetException, css::uno::RuntimeException)
133 0 : {}
134 :
135 0 : virtual void SAL_CALL removeVetoableChangeListener(
136 : rtl::OUString const &,
137 : css::uno::Reference< css::beans::XVetoableChangeListener > const &)
138 : throw (
139 : css::beans::UnknownPropertyException,
140 : css::lang::WrappedTargetException, css::uno::RuntimeException)
141 0 : {}
142 : };
143 :
144 0 : void Default::setPropertyValue(rtl::OUString const &, css::uno::Any const &)
145 : throw (
146 : css::beans::UnknownPropertyException, css::beans::PropertyVetoException,
147 : css::lang::IllegalArgumentException, css::lang::WrappedTargetException,
148 : css::uno::RuntimeException)
149 : {
150 : throw css::lang::IllegalArgumentException(
151 : rtl::OUString(
152 : RTL_CONSTASCII_USTRINGPARAM("setPropertyValue not supported")),
153 0 : static_cast< cppu::OWeakObject * >(this), -1);
154 : }
155 :
156 0 : css::uno::Any Default::getPropertyValue(rtl::OUString const & PropertyName)
157 : throw (
158 : css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
159 : css::uno::RuntimeException)
160 : {
161 0 : if ( PropertyName == "EnableATToolSupport" || PropertyName == "ExternalMailer" || PropertyName == "SourceViewFontHeight"
162 0 : || PropertyName == "SourceViewFontName" || PropertyName == "WorkPathVariable" || PropertyName == "ooInetFTPProxyName"
163 0 : || PropertyName == "ooInetFTPProxyPort" || PropertyName == "ooInetHTTPProxyName" || PropertyName == "ooInetHTTPProxyPort"
164 0 : || PropertyName == "ooInetHTTPSProxyName" || PropertyName == "ooInetHTTPSProxyPort" || PropertyName == "ooInetNoProxy"
165 0 : || PropertyName == "ooInetProxyType" || PropertyName == "givenname" || PropertyName == "sn" )
166 : {
167 0 : return css::uno::makeAny(css::beans::Optional< css::uno::Any >());
168 : }
169 : throw css::beans::UnknownPropertyException(
170 0 : PropertyName, static_cast< cppu::OWeakObject * >(this));
171 : }
172 :
173 0 : css::uno::Reference< css::uno::XInterface > createBackend(
174 : css::uno::Reference< css::uno::XComponentContext > const & context,
175 : rtl::OUString const & name)
176 : {
177 : try {
178 : return css::uno::Reference< css::lang::XMultiComponentFactory >(
179 0 : context->getServiceManager(), css::uno::UNO_SET_THROW)->
180 0 : createInstanceWithContext(name, context);
181 0 : } catch (css::uno::RuntimeException &) {
182 : // Assuming these exceptions are real errors:
183 0 : throw;
184 0 : } catch (const css::uno::Exception & e) {
185 : // Assuming these exceptions indicate that the service is not installed:
186 : OSL_TRACE(
187 : "createInstance(%s) failed with %s",
188 : rtl::OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr(),
189 : rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
190 0 : return css::uno::Reference< css::uno::XInterface >();
191 : }
192 : }
193 :
194 0 : css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
195 : css::uno::Reference< css::uno::XComponentContext > const & context)
196 : {
197 0 : rtl::OUString desktop;
198 : css::uno::Reference< css::uno::XCurrentContext > current(
199 0 : css::uno::getCurrentContext());
200 0 : if (current.is()) {
201 0 : current->getValueByName(
202 : rtl::OUString(
203 0 : RTL_CONSTASCII_USTRINGPARAM("system.desktop-environment"))) >>=
204 0 : desktop;
205 : }
206 :
207 : // Fall back to the default if the specific backend is not available:
208 0 : css::uno::Reference< css::uno::XInterface > backend;
209 0 : if ( desktop == "GNOME" ) {
210 : backend = createBackend(
211 : context,
212 : rtl::OUString(
213 : RTL_CONSTASCII_USTRINGPARAM(
214 0 : "com.sun.star.configuration.backend.GconfBackend")));
215 0 : } else if ( desktop == "KDE" ) {
216 : backend = createBackend(
217 : context,
218 : rtl::OUString(
219 : RTL_CONSTASCII_USTRINGPARAM(
220 0 : "com.sun.star.configuration.backend.KDEBackend")));
221 0 : } else if ( desktop == "KDE4" ) {
222 : backend = createBackend(
223 : context,
224 : rtl::OUString(
225 : RTL_CONSTASCII_USTRINGPARAM(
226 0 : "com.sun.star.configuration.backend.KDE4Backend")));
227 : }
228 0 : return backend.is()
229 0 : ? backend : static_cast< cppu::OWeakObject * >(new Default);
230 : }
231 :
232 : static cppu::ImplementationEntry const services[] = {
233 : { &createInstance, &getDefaultImplementationName,
234 : &getDefaultSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
235 : 0 },
236 : { 0, 0, 0, 0, 0, 0 }
237 : };
238 :
239 : }
240 :
241 0 : extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL desktopbe1_component_getFactory(
242 : char const * pImplName, void * pServiceManager, void * pRegistryKey)
243 : {
244 : return cppu::component_getFactoryHelper(
245 0 : pImplName, pServiceManager, pRegistryKey, services);
246 : }
247 :
248 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|