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