1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir *
3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir *
5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir *
7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir *
9*cdf0e10cSrcweir * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir *
11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir *
15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir *
21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir *
26*cdf0e10cSrcweir ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "precompiled_shell.hxx"
29*cdf0e10cSrcweir #include "sal/config.h"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <cstddef>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "boost/noncopyable.hpp"
34*cdf0e10cSrcweir #include "com/sun/star/beans/Optional.hpp"
35*cdf0e10cSrcweir #include "com/sun/star/beans/PropertyVetoException.hpp"
36*cdf0e10cSrcweir #include "com/sun/star/beans/UnknownPropertyException.hpp"
37*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertyChangeListener.hpp"
38*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
39*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySetInfo.hpp"
40*cdf0e10cSrcweir #include "com/sun/star/beans/XVetoableChangeListener.hpp"
41*cdf0e10cSrcweir #include "com/sun/star/lang/IllegalArgumentException.hpp"
42*cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetException.hpp"
43*cdf0e10cSrcweir #include "com/sun/star/lang/XMultiComponentFactory.hpp"
44*cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp"
45*cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetException.hpp"
46*cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
47*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
48*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
49*cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
50*cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
51*cdf0e10cSrcweir #include "com/sun/star/uno/XCurrentContext.hpp"
52*cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
53*cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx"
54*cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx"
55*cdf0e10cSrcweir #include "cppuhelper/weak.hxx"
56*cdf0e10cSrcweir #include "rtl/string.h"
57*cdf0e10cSrcweir #include "rtl/ustring.h"
58*cdf0e10cSrcweir #include "rtl/ustring.hxx"
59*cdf0e10cSrcweir #include "sal/types.h"
60*cdf0e10cSrcweir #include "uno/current_context.hxx"
61*cdf0e10cSrcweir #include "uno/lbnames.h"
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #include "gconfaccess.hxx"
64*cdf0e10cSrcweir #include "orbit.h"
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir namespace {
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir namespace css = com::sun::star;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir rtl::OUString SAL_CALL getServiceImplementationName() {
71*cdf0e10cSrcweir     return rtl::OUString(
72*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
73*cdf0e10cSrcweir             "com.sun.star.comp.configuration.backend.GconfBackend"));
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > SAL_CALL getServiceSupportedServiceNames() {
77*cdf0e10cSrcweir     rtl::OUString name(
78*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
79*cdf0e10cSrcweir             "com.sun.star.configuration.backend.GconfBackend"));
80*cdf0e10cSrcweir     return css::uno::Sequence< rtl::OUString >(&name, 1);
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir class Service:
84*cdf0e10cSrcweir     public cppu::WeakImplHelper2<
85*cdf0e10cSrcweir         css::lang::XServiceInfo, css::beans::XPropertySet >,
86*cdf0e10cSrcweir     private boost::noncopyable
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir public:
89*cdf0e10cSrcweir     Service();
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir private:
92*cdf0e10cSrcweir     virtual ~Service() {}
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir     virtual rtl::OUString SAL_CALL getImplementationName()
95*cdf0e10cSrcweir         throw (css::uno::RuntimeException)
96*cdf0e10cSrcweir     { return getServiceImplementationName(); }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
99*cdf0e10cSrcweir         throw (css::uno::RuntimeException)
100*cdf0e10cSrcweir     { return ServiceName == getSupportedServiceNames()[0]; }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
103*cdf0e10cSrcweir     getSupportedServiceNames() throw (css::uno::RuntimeException)
104*cdf0e10cSrcweir     { return getServiceSupportedServiceNames(); }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
107*cdf0e10cSrcweir     getPropertySetInfo() throw (css::uno::RuntimeException)
108*cdf0e10cSrcweir     { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir     virtual void SAL_CALL setPropertyValue(
111*cdf0e10cSrcweir         rtl::OUString const &, css::uno::Any const &)
112*cdf0e10cSrcweir         throw (
113*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
114*cdf0e10cSrcweir             css::beans::PropertyVetoException,
115*cdf0e10cSrcweir             css::lang::IllegalArgumentException,
116*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException);
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     virtual css::uno::Any SAL_CALL getPropertyValue(
119*cdf0e10cSrcweir         rtl::OUString const & PropertyName)
120*cdf0e10cSrcweir         throw (
121*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
122*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException);
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir     virtual void SAL_CALL addPropertyChangeListener(
125*cdf0e10cSrcweir         rtl::OUString const &,
126*cdf0e10cSrcweir         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
127*cdf0e10cSrcweir         throw (
128*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
129*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
130*cdf0e10cSrcweir     {}
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     virtual void SAL_CALL removePropertyChangeListener(
133*cdf0e10cSrcweir         rtl::OUString const &,
134*cdf0e10cSrcweir         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
135*cdf0e10cSrcweir         throw (
136*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
137*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
138*cdf0e10cSrcweir     {}
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     virtual void SAL_CALL addVetoableChangeListener(
141*cdf0e10cSrcweir         rtl::OUString const &,
142*cdf0e10cSrcweir         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
143*cdf0e10cSrcweir         throw (
144*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
145*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
146*cdf0e10cSrcweir     {}
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     virtual void SAL_CALL removeVetoableChangeListener(
149*cdf0e10cSrcweir         rtl::OUString const &,
150*cdf0e10cSrcweir         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
151*cdf0e10cSrcweir         throw (
152*cdf0e10cSrcweir             css::beans::UnknownPropertyException,
153*cdf0e10cSrcweir             css::lang::WrappedTargetException, css::uno::RuntimeException)
154*cdf0e10cSrcweir     {}
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     bool enabled_;
157*cdf0e10cSrcweir };
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir Service::Service(): enabled_(false) {
160*cdf0e10cSrcweir     css::uno::Reference< css::uno::XCurrentContext > context(
161*cdf0e10cSrcweir         css::uno::getCurrentContext());
162*cdf0e10cSrcweir     if (context.is()) {
163*cdf0e10cSrcweir         rtl::OUString desktop;
164*cdf0e10cSrcweir         context->getValueByName(
165*cdf0e10cSrcweir             rtl::OUString(
166*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("system.desktop-environment"))) >>=
167*cdf0e10cSrcweir             desktop;
168*cdf0e10cSrcweir         enabled_ = desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("GNOME")) &&
169*cdf0e10cSrcweir             ((orbit_major_version == 2 && orbit_minor_version >= 8) ||
170*cdf0e10cSrcweir              orbit_major_version > 2);
171*cdf0e10cSrcweir             // ORBit-2 versions < 2.8 cause a deadlock with the gtk+ VCL plugin
172*cdf0e10cSrcweir     }
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir void Service::setPropertyValue(rtl::OUString const &, css::uno::Any const &)
176*cdf0e10cSrcweir     throw (
177*cdf0e10cSrcweir         css::beans::UnknownPropertyException, css::beans::PropertyVetoException,
178*cdf0e10cSrcweir         css::lang::IllegalArgumentException, css::lang::WrappedTargetException,
179*cdf0e10cSrcweir         css::uno::RuntimeException)
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir     throw css::lang::IllegalArgumentException(
182*cdf0e10cSrcweir         rtl::OUString(
183*cdf0e10cSrcweir             RTL_CONSTASCII_USTRINGPARAM("setPropertyValue not supported")),
184*cdf0e10cSrcweir         static_cast< cppu::OWeakObject * >(this), -1);
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir css::uno::Any Service::getPropertyValue(rtl::OUString const & PropertyName)
188*cdf0e10cSrcweir     throw (
189*cdf0e10cSrcweir         css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
190*cdf0e10cSrcweir         css::uno::RuntimeException)
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir     for (std::size_t i = 0; i < gconfaccess::nConfigurationValues; ++i) {
193*cdf0e10cSrcweir         if (PropertyName.equalsAscii(
194*cdf0e10cSrcweir                 gconfaccess::ConfigurationValues[i].OOoConfItem))
195*cdf0e10cSrcweir         {
196*cdf0e10cSrcweir             return css::uno::makeAny(
197*cdf0e10cSrcweir                 enabled_
198*cdf0e10cSrcweir                 ? gconfaccess::getValue(gconfaccess::ConfigurationValues[i])
199*cdf0e10cSrcweir                 : css::beans::Optional< css::uno::Any >());
200*cdf0e10cSrcweir         }
201*cdf0e10cSrcweir     }
202*cdf0e10cSrcweir     throw css::beans::UnknownPropertyException(
203*cdf0e10cSrcweir         PropertyName, static_cast< cppu::OWeakObject * >(this));
204*cdf0e10cSrcweir }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
207*cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > const &)
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir     return static_cast< cppu::OWeakObject * >(new Service);
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir static cppu::ImplementationEntry const services[] = {
213*cdf0e10cSrcweir     { &createInstance, &getServiceImplementationName,
214*cdf0e10cSrcweir       &getServiceSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
215*cdf0e10cSrcweir       0 },
216*cdf0e10cSrcweir     { 0, 0, 0, 0, 0, 0 }
217*cdf0e10cSrcweir };
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
222*cdf0e10cSrcweir     char const * pImplName, void * pServiceManager, void * pRegistryKey)
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir     return cppu::component_getFactoryHelper(
225*cdf0e10cSrcweir         pImplName, pServiceManager, pRegistryKey, services);
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
229*cdf0e10cSrcweir component_getImplementationEnvironment(
230*cdf0e10cSrcweir     char const ** ppEnvTypeName, uno_Environment **)
231*cdf0e10cSrcweir {
232*cdf0e10cSrcweir     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
233*cdf0e10cSrcweir }
234