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 #include "orbit.h"
61
62 namespace {
63
64 namespace css = com::sun::star;
65
getServiceImplementationName()66 rtl::OUString SAL_CALL getServiceImplementationName() {
67 return rtl::OUString(
68 RTL_CONSTASCII_USTRINGPARAM(
69 "com.sun.star.comp.configuration.backend.GconfBackend"));
70 }
71
getServiceSupportedServiceNames()72 css::uno::Sequence< rtl::OUString > SAL_CALL getServiceSupportedServiceNames() {
73 rtl::OUString name(
74 RTL_CONSTASCII_USTRINGPARAM(
75 "com.sun.star.configuration.backend.GconfBackend"));
76 return css::uno::Sequence< rtl::OUString >(&name, 1);
77 }
78
79 class Service:
80 public cppu::WeakImplHelper2<
81 css::lang::XServiceInfo, css::beans::XPropertySet >,
82 private boost::noncopyable
83 {
84 public:
85 Service();
86
87 private:
~Service()88 virtual ~Service() {}
89
getImplementationName()90 virtual rtl::OUString SAL_CALL getImplementationName()
91 throw (css::uno::RuntimeException)
92 { return getServiceImplementationName(); }
93
supportsService(rtl::OUString const & ServiceName)94 virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
95 throw (css::uno::RuntimeException)
96 { return ServiceName == getSupportedServiceNames()[0]; }
97
98 virtual css::uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()99 getSupportedServiceNames() throw (css::uno::RuntimeException)
100 { return getServiceSupportedServiceNames(); }
101
102 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
getPropertySetInfo()103 getPropertySetInfo() throw (css::uno::RuntimeException)
104 { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
105
106 virtual void SAL_CALL setPropertyValue(
107 rtl::OUString const &, css::uno::Any const &)
108 throw (
109 css::beans::UnknownPropertyException,
110 css::beans::PropertyVetoException,
111 css::lang::IllegalArgumentException,
112 css::lang::WrappedTargetException, css::uno::RuntimeException);
113
114 virtual css::uno::Any SAL_CALL getPropertyValue(
115 rtl::OUString const & PropertyName)
116 throw (
117 css::beans::UnknownPropertyException,
118 css::lang::WrappedTargetException, css::uno::RuntimeException);
119
addPropertyChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XPropertyChangeListener> const &)120 virtual void SAL_CALL addPropertyChangeListener(
121 rtl::OUString const &,
122 css::uno::Reference< css::beans::XPropertyChangeListener > const &)
123 throw (
124 css::beans::UnknownPropertyException,
125 css::lang::WrappedTargetException, css::uno::RuntimeException)
126 {}
127
removePropertyChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XPropertyChangeListener> const &)128 virtual void SAL_CALL removePropertyChangeListener(
129 rtl::OUString const &,
130 css::uno::Reference< css::beans::XPropertyChangeListener > const &)
131 throw (
132 css::beans::UnknownPropertyException,
133 css::lang::WrappedTargetException, css::uno::RuntimeException)
134 {}
135
addVetoableChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XVetoableChangeListener> const &)136 virtual void SAL_CALL addVetoableChangeListener(
137 rtl::OUString const &,
138 css::uno::Reference< css::beans::XVetoableChangeListener > const &)
139 throw (
140 css::beans::UnknownPropertyException,
141 css::lang::WrappedTargetException, css::uno::RuntimeException)
142 {}
143
removeVetoableChangeListener(rtl::OUString const &,css::uno::Reference<css::beans::XVetoableChangeListener> const &)144 virtual void SAL_CALL removeVetoableChangeListener(
145 rtl::OUString const &,
146 css::uno::Reference< css::beans::XVetoableChangeListener > const &)
147 throw (
148 css::beans::UnknownPropertyException,
149 css::lang::WrappedTargetException, css::uno::RuntimeException)
150 {}
151
152 bool enabled_;
153 };
154
Service()155 Service::Service(): enabled_(false) {
156 css::uno::Reference< css::uno::XCurrentContext > context(
157 css::uno::getCurrentContext());
158 if (context.is()) {
159 rtl::OUString desktop;
160 context->getValueByName(
161 rtl::OUString(
162 RTL_CONSTASCII_USTRINGPARAM("system.desktop-environment"))) >>=
163 desktop;
164 enabled_ = desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("GNOME")) &&
165 ((orbit_major_version == 2 && orbit_minor_version >= 8) ||
166 orbit_major_version > 2);
167 // ORBit-2 versions < 2.8 cause a deadlock with the gtk+ VCL plugin
168 }
169 }
170
setPropertyValue(rtl::OUString const &,css::uno::Any const &)171 void Service::setPropertyValue(rtl::OUString const &, css::uno::Any const &)
172 throw (
173 css::beans::UnknownPropertyException, css::beans::PropertyVetoException,
174 css::lang::IllegalArgumentException, css::lang::WrappedTargetException,
175 css::uno::RuntimeException)
176 {
177 throw css::lang::IllegalArgumentException(
178 rtl::OUString(
179 RTL_CONSTASCII_USTRINGPARAM("setPropertyValue not supported")),
180 static_cast< cppu::OWeakObject * >(this), -1);
181 }
182
getPropertyValue(rtl::OUString const & PropertyName)183 css::uno::Any Service::getPropertyValue(rtl::OUString const & PropertyName)
184 throw (
185 css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
186 css::uno::RuntimeException)
187 {
188 for (std::size_t i = 0; i < gconfaccess::nConfigurationValues; ++i) {
189 if (PropertyName.equalsAscii(
190 gconfaccess::ConfigurationValues[i].OOoConfItem))
191 {
192 return css::uno::makeAny(
193 enabled_
194 ? gconfaccess::getValue(gconfaccess::ConfigurationValues[i])
195 : css::beans::Optional< css::uno::Any >());
196 }
197 }
198 throw css::beans::UnknownPropertyException(
199 PropertyName, static_cast< cppu::OWeakObject * >(this));
200 }
201
createInstance(css::uno::Reference<css::uno::XComponentContext> const &)202 css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
203 css::uno::Reference< css::uno::XComponentContext > const &)
204 {
205 return static_cast< cppu::OWeakObject * >(new Service);
206 }
207
208 static cppu::ImplementationEntry const services[] = {
209 { &createInstance, &getServiceImplementationName,
210 &getServiceSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
211 0 },
212 { 0, 0, 0, 0, 0, 0 }
213 };
214
215 }
216
component_getFactory(char const * pImplName,void * pServiceManager,void * pRegistryKey)217 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
218 char const * pImplName, void * pServiceManager, void * pRegistryKey)
219 {
220 return cppu::component_getFactoryHelper(
221 pImplName, pServiceManager, pRegistryKey, services);
222 }
223
224 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
component_getImplementationEnvironment(char const ** ppEnvTypeName,uno_Environment **)225 component_getImplementationEnvironment(
226 char const ** ppEnvTypeName, uno_Environment **)
227 {
228 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
229 }
230