1 /*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27 
28 #include "precompiled_shell.hxx"
29 #include "sal/config.h"
30 
31 #include "boost/noncopyable.hpp"
32 #include "com/sun/star/beans/Optional.hpp"
33 #include "com/sun/star/beans/PropertyVetoException.hpp"
34 #include "com/sun/star/beans/UnknownPropertyException.hpp"
35 #include "com/sun/star/beans/XPropertyChangeListener.hpp"
36 #include "com/sun/star/beans/XPropertySet.hpp"
37 #include "com/sun/star/beans/XPropertySetInfo.hpp"
38 #include "com/sun/star/beans/XVetoableChangeListener.hpp"
39 #include "com/sun/star/lang/IllegalArgumentException.hpp"
40 #include "com/sun/star/lang/WrappedTargetException.hpp"
41 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
42 #include "com/sun/star/lang/XServiceInfo.hpp"
43 #include "com/sun/star/lang/WrappedTargetException.hpp"
44 #include "com/sun/star/uno/Any.hxx"
45 #include "com/sun/star/uno/Reference.hxx"
46 #include "com/sun/star/uno/RuntimeException.hpp"
47 #include "com/sun/star/uno/Sequence.hxx"
48 #include "com/sun/star/uno/XComponentContext.hpp"
49 #include "com/sun/star/uno/XCurrentContext.hpp"
50 #include "cppuhelper/factory.hxx"
51 #include "cppuhelper/implbase2.hxx"
52 #include "cppuhelper/implementationentry.hxx"
53 #include "cppuhelper/weak.hxx"
54 #include "rtl/string.h"
55 #include "rtl/ustring.h"
56 #include "rtl/ustring.hxx"
57 #include "sal/types.h"
58 #include "uno/current_context.hxx"
59 #include "uno/lbnames.h"
60 
61 #include "kde_headers.h"
62 
63 #include "kdeaccess.hxx"
64 
65 namespace {
66 
67 namespace css = com::sun::star;
68 
69 rtl::OUString SAL_CALL getServiceImplementationName() {
70     return rtl::OUString(
71         RTL_CONSTASCII_USTRINGPARAM(
72             "com.sun.star.comp.configuration.backend.KDEBackend"));
73 }
74 
75 css::uno::Sequence< rtl::OUString > SAL_CALL getServiceSupportedServiceNames() {
76     rtl::OUString name(
77         RTL_CONSTASCII_USTRINGPARAM(
78             "com.sun.star.configuration.backend.KDEBackend"));
79     return css::uno::Sequence< rtl::OUString >(&name, 1);
80 }
81 
82 class Service:
83     public cppu::WeakImplHelper2<
84         css::lang::XServiceInfo, css::beans::XPropertySet >,
85     private boost::noncopyable
86 {
87 public:
88     Service();
89 
90 private:
91     virtual ~Service() {}
92 
93     virtual rtl::OUString SAL_CALL getImplementationName()
94         throw (css::uno::RuntimeException)
95     { return getServiceImplementationName(); }
96 
97     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
98         throw (css::uno::RuntimeException)
99     { return ServiceName == getSupportedServiceNames()[0]; }
100 
101     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
102     getSupportedServiceNames() throw (css::uno::RuntimeException)
103     { return getServiceSupportedServiceNames(); }
104 
105     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
106     getPropertySetInfo() throw (css::uno::RuntimeException)
107     { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
108 
109     virtual void SAL_CALL setPropertyValue(
110         rtl::OUString const &, css::uno::Any const &)
111         throw (
112             css::beans::UnknownPropertyException,
113             css::beans::PropertyVetoException,
114             css::lang::IllegalArgumentException,
115             css::lang::WrappedTargetException, css::uno::RuntimeException);
116 
117     virtual css::uno::Any SAL_CALL getPropertyValue(
118         rtl::OUString const & PropertyName)
119         throw (
120             css::beans::UnknownPropertyException,
121             css::lang::WrappedTargetException, css::uno::RuntimeException);
122 
123     virtual void SAL_CALL addPropertyChangeListener(
124         rtl::OUString const &,
125         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
126         throw (
127             css::beans::UnknownPropertyException,
128             css::lang::WrappedTargetException, css::uno::RuntimeException)
129     {}
130 
131     virtual void SAL_CALL removePropertyChangeListener(
132         rtl::OUString const &,
133         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
134         throw (
135             css::beans::UnknownPropertyException,
136             css::lang::WrappedTargetException, css::uno::RuntimeException)
137     {}
138 
139     virtual void SAL_CALL addVetoableChangeListener(
140         rtl::OUString const &,
141         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
142         throw (
143             css::beans::UnknownPropertyException,
144             css::lang::WrappedTargetException, css::uno::RuntimeException)
145     {}
146 
147     virtual void SAL_CALL removeVetoableChangeListener(
148         rtl::OUString const &,
149         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
150         throw (
151             css::beans::UnknownPropertyException,
152             css::lang::WrappedTargetException, css::uno::RuntimeException)
153     {}
154 
155     bool enabled_;
156 };
157 
158 Service::Service(): enabled_(false) {
159     css::uno::Reference< css::uno::XCurrentContext > context(
160         css::uno::getCurrentContext());
161     if (context.is()) {
162         rtl::OUString desktop;
163         context->getValueByName(
164             rtl::OUString(
165                 RTL_CONSTASCII_USTRINGPARAM("system.desktop-environment"))) >>=
166             desktop;
167         enabled_ = desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("KDE")) &&
168             KApplication::kApplication() != 0;
169     }
170 }
171 
172 void Service::setPropertyValue(rtl::OUString const &, css::uno::Any const &)
173     throw (
174         css::beans::UnknownPropertyException, css::beans::PropertyVetoException,
175         css::lang::IllegalArgumentException, css::lang::WrappedTargetException,
176         css::uno::RuntimeException)
177 {
178     throw css::lang::IllegalArgumentException(
179         rtl::OUString(
180             RTL_CONSTASCII_USTRINGPARAM("setPropertyValue not supported")),
181         static_cast< cppu::OWeakObject * >(this), -1);
182 }
183 
184 css::uno::Any Service::getPropertyValue(rtl::OUString const & PropertyName)
185     throw (
186         css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
187         css::uno::RuntimeException)
188 {
189     if (PropertyName.equalsAsciiL(
190             RTL_CONSTASCII_STRINGPARAM("EnableATToolSupport")) ||
191         PropertyName.equalsAsciiL(
192             RTL_CONSTASCII_STRINGPARAM("ExternalMailer")) ||
193         PropertyName.equalsAsciiL(
194             RTL_CONSTASCII_STRINGPARAM("SourceViewFontHeight")) ||
195         PropertyName.equalsAsciiL(
196             RTL_CONSTASCII_STRINGPARAM("SourceViewFontName")) ||
197         PropertyName.equalsAsciiL(
198             RTL_CONSTASCII_STRINGPARAM("WorkPathVariable")) ||
199         PropertyName.equalsAsciiL(
200             RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyName")) ||
201         PropertyName.equalsAsciiL(
202             RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyPort")) ||
203         PropertyName.equalsAsciiL(
204             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyName")) ||
205         PropertyName.equalsAsciiL(
206             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyPort")) ||
207         PropertyName.equalsAsciiL(
208             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyName")) ||
209         PropertyName.equalsAsciiL(
210             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyPort")) ||
211         PropertyName.equalsAsciiL(
212             RTL_CONSTASCII_STRINGPARAM("ooInetNoProxy")) ||
213         PropertyName.equalsAsciiL(
214             RTL_CONSTASCII_STRINGPARAM("ooInetProxyType")))
215     {
216         return css::uno::makeAny(
217             enabled_
218             ? kdeaccess::getValue(PropertyName)
219             : css::beans::Optional< css::uno::Any >());
220     }
221     throw css::beans::UnknownPropertyException(
222         PropertyName, static_cast< cppu::OWeakObject * >(this));
223 }
224 
225 css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
226     css::uno::Reference< css::uno::XComponentContext > const &)
227 {
228     return static_cast< cppu::OWeakObject * >(new Service);
229 }
230 
231 static cppu::ImplementationEntry const services[] = {
232     { &createInstance, &getServiceImplementationName,
233       &getServiceSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
234       0 },
235     { 0, 0, 0, 0, 0, 0 }
236 };
237 
238 }
239 
240 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
241     char const * pImplName, void * pServiceManager, void * pRegistryKey)
242 {
243     return cppu::component_getFactoryHelper(
244         pImplName, pServiceManager, pRegistryKey, services);
245 }
246 
247 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
248 component_getImplementationEnvironment(
249     char const ** ppEnvTypeName, uno_Environment **)
250 {
251     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
252 }
253