1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "kapplication.h"
24 #include "boost/noncopyable.hpp"
25 #include "com/sun/star/beans/Optional.hpp"
26 #include "com/sun/star/beans/PropertyVetoException.hpp"
27 #include "com/sun/star/beans/UnknownPropertyException.hpp"
28 #include "com/sun/star/beans/XPropertyChangeListener.hpp"
29 #include "com/sun/star/beans/XPropertySet.hpp"
30 #include "com/sun/star/beans/XPropertySetInfo.hpp"
31 #include "com/sun/star/beans/XVetoableChangeListener.hpp"
32 #include "com/sun/star/lang/IllegalArgumentException.hpp"
33 #include "com/sun/star/lang/WrappedTargetException.hpp"
34 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
35 #include "com/sun/star/lang/XServiceInfo.hpp"
36 #include "com/sun/star/uno/Any.hxx"
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 "rtl/string.h"
47 #include "rtl/ustring.h"
48 #include "rtl/ustring.hxx"
49 #include "sal/types.h"
50 #include "uno/current_context.hxx"
52 #include "kde4access.hxx"
56 OUString SAL_CALL
getServiceImplementationName() {
58 "com.sun.star.comp.configuration.backend.KDE4Backend");
61 css::uno::Sequence
< OUString
> SAL_CALL
getServiceSupportedServiceNames() {
63 "com.sun.star.configuration.backend.KDE4Backend");
64 return css::uno::Sequence
< OUString
>(&name
, 1);
68 public cppu::WeakImplHelper2
<
69 css::lang::XServiceInfo
, css::beans::XPropertySet
>,
70 private boost::noncopyable
78 virtual OUString SAL_CALL
getImplementationName()
79 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
80 { return getServiceImplementationName(); }
82 virtual sal_Bool SAL_CALL
supportsService(OUString
const & ServiceName
)
83 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
84 { return ServiceName
== getSupportedServiceNames()[0]; }
86 virtual css::uno::Sequence
< OUString
> SAL_CALL
87 getSupportedServiceNames() throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
88 { return getServiceSupportedServiceNames(); }
90 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
91 getPropertySetInfo() throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
92 { return css::uno::Reference
< css::beans::XPropertySetInfo
>(); }
94 virtual void SAL_CALL
setPropertyValue(
95 OUString
const &, css::uno::Any
const &)
97 css::beans::UnknownPropertyException
,
98 css::beans::PropertyVetoException
,
99 css::lang::IllegalArgumentException
,
100 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
102 virtual css::uno::Any SAL_CALL
getPropertyValue(
103 OUString
const & PropertyName
)
105 css::beans::UnknownPropertyException
,
106 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
108 virtual void SAL_CALL
addPropertyChangeListener(
110 css::uno::Reference
< css::beans::XPropertyChangeListener
> const &)
112 css::beans::UnknownPropertyException
,
113 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
116 virtual void SAL_CALL
removePropertyChangeListener(
118 css::uno::Reference
< css::beans::XPropertyChangeListener
> const &)
120 css::beans::UnknownPropertyException
,
121 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
124 virtual void SAL_CALL
addVetoableChangeListener(
126 css::uno::Reference
< css::beans::XVetoableChangeListener
> const &)
128 css::beans::UnknownPropertyException
,
129 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
132 virtual void SAL_CALL
removeVetoableChangeListener(
134 css::uno::Reference
< css::beans::XVetoableChangeListener
> const &)
136 css::beans::UnknownPropertyException
,
137 css::lang::WrappedTargetException
, css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
143 Service::Service(): enabled_(false) {
144 css::uno::Reference
< css::uno::XCurrentContext
> context(
145 css::uno::getCurrentContext());
148 context
->getValueByName(
149 OUString("system.desktop-environment")) >>=
151 enabled_
= desktop
== "KDE4" && KApplication::kApplication() != 0;
155 void Service::setPropertyValue(OUString
const &, css::uno::Any
const &)
157 css::beans::UnknownPropertyException
, css::beans::PropertyVetoException
,
158 css::lang::IllegalArgumentException
, css::lang::WrappedTargetException
,
159 css::uno::RuntimeException
, std::exception
)
161 throw css::lang::IllegalArgumentException(
162 OUString("setPropertyValue not supported"),
163 static_cast< cppu::OWeakObject
* >(this), -1);
166 css::uno::Any
Service::getPropertyValue(OUString
const & PropertyName
)
168 css::beans::UnknownPropertyException
, css::lang::WrappedTargetException
,
169 css::uno::RuntimeException
, std::exception
)
171 if (PropertyName
== "EnableATToolSupport" || PropertyName
== "ExternalMailer" || PropertyName
== "SourceViewFontHeight"
172 || PropertyName
== "SourceViewFontName" || PropertyName
== "WorkPathVariable" || PropertyName
== "ooInetFTPProxyName"
173 || PropertyName
== "ooInetFTPProxyPort" || PropertyName
== "ooInetHTTPProxyName" || PropertyName
== "ooInetHTTPProxyPort"
174 || PropertyName
== "ooInetHTTPSProxyName" || PropertyName
== "ooInetHTTPSProxyPort" || PropertyName
== "ooInetNoProxy"
175 || PropertyName
== "ooInetProxyType" || PropertyName
== "TemplatePathVariable" )
177 return css::uno::makeAny(
179 ? kde4access::getValue(PropertyName
)
180 : css::beans::Optional
< css::uno::Any
>());
181 } else if (PropertyName
== "givenname" || PropertyName
== "sn") {
182 return css::uno::makeAny(css::beans::Optional
< css::uno::Any
>());
183 //TODO: obtain values from KDE?
185 throw css::beans::UnknownPropertyException(
186 PropertyName
, static_cast< cppu::OWeakObject
* >(this));
189 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
createInstance(
190 css::uno::Reference
< css::uno::XComponentContext
> const &)
192 return static_cast< cppu::OWeakObject
* >(new Service
);
195 static cppu::ImplementationEntry
const services
[] = {
196 { &createInstance
, &getServiceImplementationName
,
197 &getServiceSupportedServiceNames
, &cppu::createSingleComponentFactory
, 0,
204 extern "C" SAL_DLLPUBLIC_EXPORT
void * SAL_CALL
kde4be1_component_getFactory(
205 char const * pImplName
, void * pServiceManager
, void * pRegistryKey
)
207 return cppu::component_getFactoryHelper(
208 pImplName
, pServiceManager
, pRegistryKey
, services
);
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */