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