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 <cstddef>
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 "gconfaccess.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.GconfBackend"));
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.GconfBackend"));
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("GNOME"))
164 // ORBit-2 versions < 2.8 cause a deadlock with the gtk+ VCL plugin
165 // But ORBit-2 version 2.8 was released in 2003 and ORBit is almost obsolete now.
166 /* &&
167 ((orbit_major_version == 2 && orbit_minor_version >= 8) ||
168 orbit_major_version > 2)*/;
169
170 }
171 }
172
setPropertyValue(rtl::OUString const &,css::uno::Any const &)173 void Service::setPropertyValue(rtl::OUString const &, css::uno::Any const &)
174 throw (
175 css::beans::UnknownPropertyException, css::beans::PropertyVetoException,
176 css::lang::IllegalArgumentException, css::lang::WrappedTargetException,
177 css::uno::RuntimeException)
178 {
179 throw css::lang::IllegalArgumentException(
180 rtl::OUString(
181 RTL_CONSTASCII_USTRINGPARAM("setPropertyValue not supported")),
182 static_cast< cppu::OWeakObject * >(this), -1);
183 }
184
getPropertyValue(rtl::OUString const & PropertyName)185 css::uno::Any Service::getPropertyValue(rtl::OUString const & PropertyName)
186 throw (
187 css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
188 css::uno::RuntimeException)
189 {
190 for (std::size_t i = 0; i < gconfaccess::nConfigurationValues; ++i) {
191 if (PropertyName.equalsAscii(
192 gconfaccess::ConfigurationValues[i].OOoConfItem))
193 {
194 return css::uno::makeAny(
195 enabled_
196 ? gconfaccess::getValue(gconfaccess::ConfigurationValues[i])
197 : css::beans::Optional< css::uno::Any >());
198 }
199 }
200 throw css::beans::UnknownPropertyException(
201 PropertyName, static_cast< cppu::OWeakObject * >(this));
202 }
203
createInstance(css::uno::Reference<css::uno::XComponentContext> const &)204 css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
205 css::uno::Reference< css::uno::XComponentContext > const &)
206 {
207 return static_cast< cppu::OWeakObject * >(new Service);
208 }
209
210 static cppu::ImplementationEntry const services[] = {
211 { &createInstance, &getServiceImplementationName,
212 &getServiceSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
213 0 },
214 { 0, 0, 0, 0, 0, 0 }
215 };
216
217 }
218
component_getFactory(char const * pImplName,void * pServiceManager,void * pRegistryKey)219 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
220 char const * pImplName, void * pServiceManager, void * pRegistryKey)
221 {
222 return cppu::component_getFactoryHelper(
223 pImplName, pServiceManager, pRegistryKey, services);
224 }
225
226 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
component_getImplementationEnvironment(char const ** ppEnvTypeName,uno_Environment **)227 component_getImplementationEnvironment(
228 char const ** ppEnvTypeName, uno_Environment **)
229 {
230 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
231 }
232