bump product version to 5.0.4.1
[LibreOffice.git] / shell / source / backends / desktopbe / desktopbackend.cxx
blob57851af87a0bb5a6d94f91c5a4ac769491d35c60
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sal/config.h"
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"
53 namespace {
55 OUString SAL_CALL getDefaultImplementationName() {
56 return OUString(
57 "com.sun.star.comp.configuration.backend.DesktopBackend");
60 css::uno::Sequence< OUString > SAL_CALL getDefaultSupportedServiceNames() {
61 OUString name(
62 "com.sun.star.configuration.backend.DesktopBackend");
63 return css::uno::Sequence< OUString >(&name, 1);
66 class Default:
67 public cppu::WeakImplHelper2<
68 css::lang::XServiceInfo, css::beans::XPropertySet >,
69 private boost::noncopyable
71 public:
72 Default() {}
74 private:
75 virtual ~Default() {}
77 virtual OUString SAL_CALL getImplementationName()
78 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
79 { return getDefaultImplementationName(); }
81 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
82 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
83 { return ServiceName == getSupportedServiceNames()[0]; }
85 virtual css::uno::Sequence< OUString > SAL_CALL
86 getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
87 { return getDefaultSupportedServiceNames(); }
89 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
90 getPropertySetInfo() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
91 { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
93 virtual void SAL_CALL setPropertyValue(
94 OUString const &, css::uno::Any const &)
95 throw (
96 css::beans::UnknownPropertyException,
97 css::beans::PropertyVetoException,
98 css::lang::IllegalArgumentException,
99 css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
101 virtual css::uno::Any SAL_CALL getPropertyValue(
102 OUString const & PropertyName)
103 throw (
104 css::beans::UnknownPropertyException,
105 css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
107 virtual void SAL_CALL addPropertyChangeListener(
108 OUString const &,
109 css::uno::Reference< css::beans::XPropertyChangeListener > const &)
110 throw (
111 css::beans::UnknownPropertyException,
112 css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
115 virtual void SAL_CALL removePropertyChangeListener(
116 OUString const &,
117 css::uno::Reference< css::beans::XPropertyChangeListener > const &)
118 throw (
119 css::beans::UnknownPropertyException,
120 css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
123 virtual void SAL_CALL addVetoableChangeListener(
124 OUString const &,
125 css::uno::Reference< css::beans::XVetoableChangeListener > const &)
126 throw (
127 css::beans::UnknownPropertyException,
128 css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
131 virtual void SAL_CALL removeVetoableChangeListener(
132 OUString const &,
133 css::uno::Reference< css::beans::XVetoableChangeListener > const &)
134 throw (
135 css::beans::UnknownPropertyException,
136 css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
140 void Default::setPropertyValue(OUString const &, css::uno::Any const &)
141 throw (
142 css::beans::UnknownPropertyException, css::beans::PropertyVetoException,
143 css::lang::IllegalArgumentException, css::lang::WrappedTargetException,
144 css::uno::RuntimeException, std::exception)
146 throw css::lang::IllegalArgumentException(
147 OUString("setPropertyValue not supported"),
148 static_cast< cppu::OWeakObject * >(this), -1);
151 css::uno::Any Default::getPropertyValue(OUString const & PropertyName)
152 throw (
153 css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
154 css::uno::RuntimeException, std::exception)
156 if ( PropertyName == "EnableATToolSupport" ||
157 PropertyName == "ExternalMailer" ||
158 PropertyName == "SourceViewFontHeight" ||
159 PropertyName == "SourceViewFontName" ||
160 PropertyName == "TemplatePathVariable" ||
161 PropertyName == "WorkPathVariable" ||
162 PropertyName == "ooInetFTPProxyName" ||
163 PropertyName == "ooInetFTPProxyPort" ||
164 PropertyName == "ooInetHTTPProxyName" ||
165 PropertyName == "ooInetHTTPProxyPort" ||
166 PropertyName == "ooInetHTTPSProxyName" ||
167 PropertyName == "ooInetHTTPSProxyPort" ||
168 PropertyName == "ooInetNoProxy" ||
169 PropertyName == "ooInetProxyType" ||
170 PropertyName == "givenname" ||
171 PropertyName == "sn" )
173 return css::uno::makeAny(css::beans::Optional< css::uno::Any >());
175 throw css::beans::UnknownPropertyException(
176 PropertyName, static_cast< cppu::OWeakObject * >(this));
179 css::uno::Reference< css::uno::XInterface > createBackend(
180 css::uno::Reference< css::uno::XComponentContext > const & context,
181 OUString const & name)
183 try {
184 return css::uno::Reference< css::lang::XMultiComponentFactory >(
185 context->getServiceManager(), css::uno::UNO_SET_THROW)->
186 createInstanceWithContext(name, context);
187 } catch (css::uno::RuntimeException &) {
188 // Assuming these exceptions are real errors:
189 throw;
190 } catch (const css::uno::Exception & e) {
191 // Assuming these exceptions indicate that the service is not installed:
192 OSL_TRACE(
193 "createInstance(%s) failed with %s",
194 OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr(),
195 OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
196 return css::uno::Reference< css::uno::XInterface >();
200 css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
201 css::uno::Reference< css::uno::XComponentContext > const & context)
203 OUString desktop;
204 css::uno::Reference< css::uno::XCurrentContext > current(
205 css::uno::getCurrentContext());
206 if (current.is()) {
207 current->getValueByName(
208 OUString("system.desktop-environment")) >>=
209 desktop;
212 // Fall back to the default if the specific backend is not available:
213 css::uno::Reference< css::uno::XInterface > backend;
214 if ( desktop == "GNOME" ) {
215 backend = createBackend(
216 context,
217 OUString(
218 "com.sun.star.configuration.backend.GconfBackend"));
219 } else if ( desktop == "KDE" ) {
220 backend = createBackend(
221 context,
222 OUString(
223 "com.sun.star.configuration.backend.KDEBackend"));
224 } else if ( desktop == "KDE4" ) {
225 backend = createBackend(
226 context,
227 OUString(
228 "com.sun.star.configuration.backend.KDE4Backend"));
230 return backend.is()
231 ? backend : static_cast< cppu::OWeakObject * >(new Default);
234 static cppu::ImplementationEntry const services[] = {
235 { &createInstance, &getDefaultImplementationName,
236 &getDefaultSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
237 0 },
238 { 0, 0, 0, 0, 0, 0 }
243 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL desktopbe1_component_getFactory(
244 char const * pImplName, void * pServiceManager, void * pRegistryKey)
246 return cppu::component_getFactoryHelper(
247 pImplName, pServiceManager, pRegistryKey, services);
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */