1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_shell.hxx"
25 #include "sal/config.h"
26 
27 #include "kapplication.h"
28 
29 #include "boost/noncopyable.hpp"
30 #include "com/sun/star/beans/Optional.hpp"
31 #include "com/sun/star/beans/PropertyVetoException.hpp"
32 #include "com/sun/star/beans/UnknownPropertyException.hpp"
33 #include "com/sun/star/beans/XPropertyChangeListener.hpp"
34 #include "com/sun/star/beans/XPropertySet.hpp"
35 #include "com/sun/star/beans/XPropertySetInfo.hpp"
36 #include "com/sun/star/beans/XVetoableChangeListener.hpp"
37 #include "com/sun/star/lang/IllegalArgumentException.hpp"
38 #include "com/sun/star/lang/WrappedTargetException.hpp"
39 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
40 #include "com/sun/star/lang/XServiceInfo.hpp"
41 #include "com/sun/star/lang/WrappedTargetException.hpp"
42 #include "com/sun/star/uno/Any.hxx"
43 #include "com/sun/star/uno/Reference.hxx"
44 #include "com/sun/star/uno/RuntimeException.hpp"
45 #include "com/sun/star/uno/Sequence.hxx"
46 #include "com/sun/star/uno/XComponentContext.hpp"
47 #include "com/sun/star/uno/XCurrentContext.hpp"
48 #include "cppuhelper/factory.hxx"
49 #include "cppuhelper/implbase2.hxx"
50 #include "cppuhelper/implementationentry.hxx"
51 #include "cppuhelper/weak.hxx"
52 #include "rtl/string.h"
53 #include "rtl/ustring.h"
54 #include "rtl/ustring.hxx"
55 #include "sal/types.h"
56 #include "uno/current_context.hxx"
57 #include "uno/lbnames.h"
58 
59 #include "kde4access.hxx"
60 
61 namespace {
62 
63 namespace css = com::sun::star;
64 
getServiceImplementationName()65 rtl::OUString SAL_CALL getServiceImplementationName() {
66     return rtl::OUString(
67         RTL_CONSTASCII_USTRINGPARAM(
68             "com.sun.star.comp.configuration.backend.KDE4Backend"));
69 }
70 
getServiceSupportedServiceNames()71 css::uno::Sequence< rtl::OUString > SAL_CALL getServiceSupportedServiceNames() {
72     rtl::OUString name(
73         RTL_CONSTASCII_USTRINGPARAM(
74             "com.sun.star.configuration.backend.KDE4Backend"));
75     return css::uno::Sequence< rtl::OUString >(&name, 1);
76 }
77 
78 class Service:
79     public cppu::WeakImplHelper2<
80         css::lang::XServiceInfo, css::beans::XPropertySet >,
81     private boost::noncopyable
82 {
83 public:
84     Service();
85 
86 private:
~Service()87     virtual ~Service() {}
88 
getImplementationName()89     virtual rtl::OUString SAL_CALL getImplementationName()
90         throw (css::uno::RuntimeException)
91     { return getServiceImplementationName(); }
92 
supportsService(rtl::OUString const & ServiceName)93     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
94         throw (css::uno::RuntimeException)
95     { return ServiceName == getSupportedServiceNames()[0]; }
96 
97     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()98     getSupportedServiceNames() throw (css::uno::RuntimeException)
99     { return getServiceSupportedServiceNames(); }
100 
101     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
getPropertySetInfo()102     getPropertySetInfo() throw (css::uno::RuntimeException)
103     { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
104 
105     virtual void SAL_CALL setPropertyValue(
106         rtl::OUString const &, css::uno::Any const &)
107         throw (
108             css::beans::UnknownPropertyException,
109             css::beans::PropertyVetoException,
110             css::lang::IllegalArgumentException,
111             css::lang::WrappedTargetException, css::uno::RuntimeException);
112 
113     virtual css::uno::Any SAL_CALL getPropertyValue(
114         rtl::OUString const & PropertyName)
115         throw (
116             css::beans::UnknownPropertyException,
117             css::lang::WrappedTargetException, css::uno::RuntimeException);
118 
addPropertyChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XPropertyChangeListener> const &)119     virtual void SAL_CALL addPropertyChangeListener(
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     {}
126 
removePropertyChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XPropertyChangeListener> const &)127     virtual void SAL_CALL removePropertyChangeListener(
128         rtl::OUString const &,
129         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
130         throw (
131             css::beans::UnknownPropertyException,
132             css::lang::WrappedTargetException, css::uno::RuntimeException)
133     {}
134 
addVetoableChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XVetoableChangeListener> const &)135     virtual void SAL_CALL addVetoableChangeListener(
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     {}
142 
removeVetoableChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XVetoableChangeListener> const &)143     virtual void SAL_CALL removeVetoableChangeListener(
144         rtl::OUString const &,
145         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
146         throw (
147             css::beans::UnknownPropertyException,
148             css::lang::WrappedTargetException, css::uno::RuntimeException)
149     {}
150 
151     bool enabled_;
152 };
153 
Service()154 Service::Service(): enabled_(false) {
155     css::uno::Reference< css::uno::XCurrentContext > context(
156         css::uno::getCurrentContext());
157     if (context.is()) {
158         rtl::OUString desktop;
159         context->getValueByName(
160             rtl::OUString(
161                 RTL_CONSTASCII_USTRINGPARAM("system.desktop-environment"))) >>=
162             desktop;
163         enabled_ = desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("KDE4")) &&
164             KApplication::kApplication() != 0;
165     }
166 }
167 
setPropertyValue(rtl::OUString const &,css::uno::Any const &)168 void Service::setPropertyValue(rtl::OUString const &, css::uno::Any const &)
169     throw (
170         css::beans::UnknownPropertyException, css::beans::PropertyVetoException,
171         css::lang::IllegalArgumentException, css::lang::WrappedTargetException,
172         css::uno::RuntimeException)
173 {
174     throw css::lang::IllegalArgumentException(
175         rtl::OUString(
176             RTL_CONSTASCII_USTRINGPARAM("setPropertyValue not supported")),
177         static_cast< cppu::OWeakObject * >(this), -1);
178 }
179 
getPropertyValue(rtl::OUString const & PropertyName)180 css::uno::Any Service::getPropertyValue(rtl::OUString const & PropertyName)
181     throw (
182         css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
183         css::uno::RuntimeException)
184 {
185     if (PropertyName.equalsAsciiL(
186             RTL_CONSTASCII_STRINGPARAM("EnableATToolSupport")) ||
187         PropertyName.equalsAsciiL(
188             RTL_CONSTASCII_STRINGPARAM("ExternalMailer")) ||
189         PropertyName.equalsAsciiL(
190             RTL_CONSTASCII_STRINGPARAM("SourceViewFontHeight")) ||
191         PropertyName.equalsAsciiL(
192             RTL_CONSTASCII_STRINGPARAM("SourceViewFontName")) ||
193         PropertyName.equalsAsciiL(
194             RTL_CONSTASCII_STRINGPARAM("WorkPathVariable")) ||
195         PropertyName.equalsAsciiL(
196             RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyName")) ||
197         PropertyName.equalsAsciiL(
198             RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyPort")) ||
199         PropertyName.equalsAsciiL(
200             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyName")) ||
201         PropertyName.equalsAsciiL(
202             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyPort")) ||
203         PropertyName.equalsAsciiL(
204             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyName")) ||
205         PropertyName.equalsAsciiL(
206             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyPort")) ||
207         PropertyName.equalsAsciiL(
208             RTL_CONSTASCII_STRINGPARAM("ooInetNoProxy")) ||
209         PropertyName.equalsAsciiL(
210             RTL_CONSTASCII_STRINGPARAM("ooInetProxyType")))
211     {
212         return css::uno::makeAny(
213             enabled_
214             ? kde4access::getValue(PropertyName)
215             : css::beans::Optional< css::uno::Any >());
216     }
217     throw css::beans::UnknownPropertyException(
218         PropertyName, static_cast< cppu::OWeakObject * >(this));
219 }
220 
createInstance(css::uno::Reference<css::uno::XComponentContext> const &)221 css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
222     css::uno::Reference< css::uno::XComponentContext > const &)
223 {
224     return static_cast< cppu::OWeakObject * >(new Service);
225 }
226 
227 static cppu::ImplementationEntry const services[] = {
228     { &createInstance, &getServiceImplementationName,
229       &getServiceSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
230       0 },
231     { 0, 0, 0, 0, 0, 0 }
232 };
233 
234 }
235 
component_getFactory(char const * pImplName,void * pServiceManager,void * pRegistryKey)236 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
237     char const * pImplName, void * pServiceManager, void * pRegistryKey)
238 {
239     return cppu::component_getFactoryHelper(
240         pImplName, pServiceManager, pRegistryKey, services);
241 }
242 
243 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
component_getImplementationEnvironment(char const ** ppEnvTypeName,uno_Environment **)244 component_getImplementationEnvironment(
245     char const ** ppEnvTypeName, uno_Environment **)
246 {
247     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
248 }
249