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