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