xref: /trunk/main/shell/source/backends/kdebe/kdebackend.cxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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 "boost/noncopyable.hpp"
28 #include "com/sun/star/beans/Optional.hpp"
29 #include "com/sun/star/beans/PropertyVetoException.hpp"
30 #include "com/sun/star/beans/UnknownPropertyException.hpp"
31 #include "com/sun/star/beans/XPropertyChangeListener.hpp"
32 #include "com/sun/star/beans/XPropertySet.hpp"
33 #include "com/sun/star/beans/XPropertySetInfo.hpp"
34 #include "com/sun/star/beans/XVetoableChangeListener.hpp"
35 #include "com/sun/star/lang/IllegalArgumentException.hpp"
36 #include "com/sun/star/lang/WrappedTargetException.hpp"
37 #include "com/sun/star/lang/XMultiComponentFactory.hpp"
38 #include "com/sun/star/lang/XServiceInfo.hpp"
39 #include "com/sun/star/lang/WrappedTargetException.hpp"
40 #include "com/sun/star/uno/Any.hxx"
41 #include "com/sun/star/uno/Reference.hxx"
42 #include "com/sun/star/uno/RuntimeException.hpp"
43 #include "com/sun/star/uno/Sequence.hxx"
44 #include "com/sun/star/uno/XComponentContext.hpp"
45 #include "com/sun/star/uno/XCurrentContext.hpp"
46 #include "cppuhelper/factory.hxx"
47 #include "cppuhelper/implbase2.hxx"
48 #include "cppuhelper/implementationentry.hxx"
49 #include "cppuhelper/weak.hxx"
50 #include "rtl/string.h"
51 #include "rtl/ustring.h"
52 #include "rtl/ustring.hxx"
53 #include "sal/types.h"
54 #include "uno/current_context.hxx"
55 #include "uno/lbnames.h"
56 
57 #include "kde_headers.h"
58 
59 #include "kdeaccess.hxx"
60 
61 namespace {
62 
63 namespace css = com::sun::star;
64 
65 rtl::OUString SAL_CALL getServiceImplementationName() {
66     return rtl::OUString(
67         RTL_CONSTASCII_USTRINGPARAM(
68             "com.sun.star.comp.configuration.backend.KDEBackend"));
69 }
70 
71 css::uno::Sequence< rtl::OUString > SAL_CALL getServiceSupportedServiceNames() {
72     rtl::OUString name(
73         RTL_CONSTASCII_USTRINGPARAM(
74             "com.sun.star.configuration.backend.KDEBackend"));
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:
87     virtual ~Service() {}
88 
89     virtual rtl::OUString SAL_CALL getImplementationName()
90     { return getServiceImplementationName(); }
91 
92     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
93     { return ServiceName == getSupportedServiceNames()[0]; }
94 
95     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
96     getSupportedServiceNames()
97     { return getServiceSupportedServiceNames(); }
98 
99     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
100     getPropertySetInfo()
101     { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
102 
103     virtual void SAL_CALL setPropertyValue(
104         rtl::OUString const &, css::uno::Any const &);
105 
106     virtual css::uno::Any SAL_CALL getPropertyValue(
107         rtl::OUString const & PropertyName);
108 
109     virtual void SAL_CALL addPropertyChangeListener(
110         rtl::OUString const &,
111         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
112     {}
113 
114     virtual void SAL_CALL removePropertyChangeListener(
115         rtl::OUString const &,
116         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
117     {}
118 
119     virtual void SAL_CALL addVetoableChangeListener(
120         rtl::OUString const &,
121         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
122     {}
123 
124     virtual void SAL_CALL removeVetoableChangeListener(
125         rtl::OUString const &,
126         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
127     {}
128 
129     bool enabled_;
130 };
131 
132 Service::Service(): enabled_(false) {
133     css::uno::Reference< css::uno::XCurrentContext > context(
134         css::uno::getCurrentContext());
135     if (context.is()) {
136         rtl::OUString desktop;
137         context->getValueByName(
138             rtl::OUString(
139                 RTL_CONSTASCII_USTRINGPARAM("system.desktop-environment"))) >>=
140             desktop;
141         enabled_ = desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("KDE")) &&
142             KApplication::kApplication() != 0;
143     }
144 }
145 
146 void Service::setPropertyValue(rtl::OUString const &, css::uno::Any const &)
147 {
148     throw css::lang::IllegalArgumentException(
149         rtl::OUString(
150             RTL_CONSTASCII_USTRINGPARAM("setPropertyValue not supported")),
151         static_cast< cppu::OWeakObject * >(this), -1);
152 }
153 
154 css::uno::Any Service::getPropertyValue(rtl::OUString const & PropertyName)
155 {
156     if (PropertyName.equalsAsciiL(
157             RTL_CONSTASCII_STRINGPARAM("EnableATToolSupport")) ||
158         PropertyName.equalsAsciiL(
159             RTL_CONSTASCII_STRINGPARAM("ExternalMailer")) ||
160         PropertyName.equalsAsciiL(
161             RTL_CONSTASCII_STRINGPARAM("SourceViewFontHeight")) ||
162         PropertyName.equalsAsciiL(
163             RTL_CONSTASCII_STRINGPARAM("SourceViewFontName")) ||
164         PropertyName.equalsAsciiL(
165             RTL_CONSTASCII_STRINGPARAM("WorkPathVariable")) ||
166         PropertyName.equalsAsciiL(
167             RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyName")) ||
168         PropertyName.equalsAsciiL(
169             RTL_CONSTASCII_STRINGPARAM("ooInetFTPProxyPort")) ||
170         PropertyName.equalsAsciiL(
171             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyName")) ||
172         PropertyName.equalsAsciiL(
173             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPProxyPort")) ||
174         PropertyName.equalsAsciiL(
175             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyName")) ||
176         PropertyName.equalsAsciiL(
177             RTL_CONSTASCII_STRINGPARAM("ooInetHTTPSProxyPort")) ||
178         PropertyName.equalsAsciiL(
179             RTL_CONSTASCII_STRINGPARAM("ooInetNoProxy")) ||
180         PropertyName.equalsAsciiL(
181             RTL_CONSTASCII_STRINGPARAM("ooInetProxyType")))
182     {
183         return css::uno::makeAny(
184             enabled_
185             ? kdeaccess::getValue(PropertyName)
186             : css::beans::Optional< css::uno::Any >());
187     }
188     throw css::beans::UnknownPropertyException(
189         PropertyName, static_cast< cppu::OWeakObject * >(this));
190 }
191 
192 css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
193     css::uno::Reference< css::uno::XComponentContext > const &)
194 {
195     return static_cast< cppu::OWeakObject * >(new Service);
196 }
197 
198 static cppu::ImplementationEntry const services[] = {
199     { &createInstance, &getServiceImplementationName,
200       &getServiceSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
201       0 },
202     { 0, 0, 0, 0, 0, 0 }
203 };
204 
205 }
206 
207 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
208     char const * pImplName, void * pServiceManager, void * pRegistryKey)
209 {
210     return cppu::component_getFactoryHelper(
211         pImplName, pServiceManager, pRegistryKey, services);
212 }
213 
214 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
215 component_getImplementationEnvironment(
216     char const ** ppEnvTypeName, uno_Environment **)
217 {
218     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
219 }
220