Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include <cstddef>
23 :
24 : #include "boost/noncopyable.hpp"
25 : #include "com/sun/star/beans/Optional.hpp"
26 : #include "com/sun/star/beans/PropertyVetoException.hpp"
27 : #include "com/sun/star/beans/UnknownPropertyException.hpp"
28 : #include "com/sun/star/beans/XPropertyChangeListener.hpp"
29 : #include "com/sun/star/beans/XPropertySet.hpp"
30 : #include "com/sun/star/beans/XPropertySetInfo.hpp"
31 : #include "com/sun/star/beans/XVetoableChangeListener.hpp"
32 : #include "com/sun/star/lang/IllegalArgumentException.hpp"
33 : #include "com/sun/star/lang/WrappedTargetException.hpp"
34 : #include "com/sun/star/lang/XMultiComponentFactory.hpp"
35 : #include "com/sun/star/lang/XServiceInfo.hpp"
36 : #include "com/sun/star/uno/Any.hxx"
37 : #include "com/sun/star/uno/Reference.hxx"
38 : #include "com/sun/star/uno/RuntimeException.hpp"
39 : #include "com/sun/star/uno/Sequence.hxx"
40 : #include "com/sun/star/uno/XComponentContext.hpp"
41 : #include "com/sun/star/uno/XCurrentContext.hpp"
42 : #include "cppuhelper/factory.hxx"
43 : #include "cppuhelper/implbase2.hxx"
44 : #include "cppuhelper/implementationentry.hxx"
45 : #include "cppuhelper/weak.hxx"
46 : #include "rtl/string.h"
47 : #include "rtl/ustring.h"
48 : #include "rtl/ustring.hxx"
49 : #include "sal/types.h"
50 : #include "uno/current_context.hxx"
51 : #include "uno/lbnames.h"
52 :
53 : #include "gconfaccess.hxx"
54 :
55 : namespace {
56 :
57 0 : OUString SAL_CALL getServiceImplementationName() {
58 : return OUString(
59 0 : "com.sun.star.comp.configuration.backend.GconfBackend");
60 : }
61 :
62 0 : css::uno::Sequence< OUString > SAL_CALL getServiceSupportedServiceNames() {
63 : OUString name(
64 0 : "com.sun.star.configuration.backend.GconfBackend");
65 0 : return css::uno::Sequence< OUString >(&name, 1);
66 : }
67 :
68 : class Service:
69 : public cppu::WeakImplHelper2<
70 : css::lang::XServiceInfo, css::beans::XPropertySet >,
71 : private boost::noncopyable
72 : {
73 : public:
74 : Service();
75 :
76 : private:
77 0 : virtual ~Service() {}
78 :
79 0 : virtual OUString SAL_CALL getImplementationName()
80 : throw (css::uno::RuntimeException)
81 0 : { return getServiceImplementationName(); }
82 :
83 0 : virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
84 : throw (css::uno::RuntimeException)
85 0 : { return ServiceName == getSupportedServiceNames()[0]; }
86 :
87 : virtual css::uno::Sequence< OUString > SAL_CALL
88 0 : getSupportedServiceNames() throw (css::uno::RuntimeException)
89 0 : { return getServiceSupportedServiceNames(); }
90 :
91 : virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
92 0 : getPropertySetInfo() throw (css::uno::RuntimeException)
93 0 : { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
94 :
95 : virtual void SAL_CALL setPropertyValue(
96 : OUString const &, css::uno::Any const &)
97 : throw (
98 : css::beans::UnknownPropertyException,
99 : css::beans::PropertyVetoException,
100 : css::lang::IllegalArgumentException,
101 : css::lang::WrappedTargetException, css::uno::RuntimeException);
102 :
103 : virtual css::uno::Any SAL_CALL getPropertyValue(
104 : OUString const & PropertyName)
105 : throw (
106 : css::beans::UnknownPropertyException,
107 : css::lang::WrappedTargetException, css::uno::RuntimeException);
108 :
109 0 : virtual void SAL_CALL addPropertyChangeListener(
110 : OUString const &,
111 : css::uno::Reference< css::beans::XPropertyChangeListener > const &)
112 : throw (
113 : css::beans::UnknownPropertyException,
114 : css::lang::WrappedTargetException, css::uno::RuntimeException)
115 0 : {}
116 :
117 0 : virtual void SAL_CALL removePropertyChangeListener(
118 : OUString const &,
119 : css::uno::Reference< css::beans::XPropertyChangeListener > const &)
120 : throw (
121 : css::beans::UnknownPropertyException,
122 : css::lang::WrappedTargetException, css::uno::RuntimeException)
123 0 : {}
124 :
125 0 : virtual void SAL_CALL addVetoableChangeListener(
126 : OUString const &,
127 : css::uno::Reference< css::beans::XVetoableChangeListener > const &)
128 : throw (
129 : css::beans::UnknownPropertyException,
130 : css::lang::WrappedTargetException, css::uno::RuntimeException)
131 0 : {}
132 :
133 0 : virtual void SAL_CALL removeVetoableChangeListener(
134 : OUString const &,
135 : css::uno::Reference< css::beans::XVetoableChangeListener > const &)
136 : throw (
137 : css::beans::UnknownPropertyException,
138 : css::lang::WrappedTargetException, css::uno::RuntimeException)
139 0 : {}
140 :
141 : bool enabled_;
142 : };
143 :
144 0 : Service::Service(): enabled_(false) {
145 : css::uno::Reference< css::uno::XCurrentContext > context(
146 0 : css::uno::getCurrentContext());
147 0 : if (context.is()) {
148 0 : OUString desktop;
149 0 : context->getValueByName(
150 0 : OUString("system.desktop-environment")) >>=
151 0 : desktop;
152 0 : enabled_ = desktop == "GNOME";
153 0 : }
154 0 : }
155 :
156 0 : void Service::setPropertyValue(OUString const &, css::uno::Any const &)
157 : throw (
158 : css::beans::UnknownPropertyException, css::beans::PropertyVetoException,
159 : css::lang::IllegalArgumentException, css::lang::WrappedTargetException,
160 : css::uno::RuntimeException)
161 : {
162 : throw css::lang::IllegalArgumentException(
163 : OUString("setPropertyValue not supported"),
164 0 : static_cast< cppu::OWeakObject * >(this), -1);
165 : }
166 :
167 0 : css::uno::Any Service::getPropertyValue(OUString const & PropertyName)
168 : throw (
169 : css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
170 : css::uno::RuntimeException)
171 : {
172 0 : for (std::size_t i = 0; i < gconfaccess::nConfigurationValues; ++i)
173 : {
174 0 : if (PropertyName.equalsAsciiL(
175 : gconfaccess::ConfigurationValues[i].OOoConfItem,
176 0 : gconfaccess::ConfigurationValues[i].nOOoConfItemLen))
177 : {
178 : return css::uno::makeAny(
179 : enabled_
180 : ? gconfaccess::getValue(gconfaccess::ConfigurationValues[i])
181 0 : : css::beans::Optional< css::uno::Any >());
182 : }
183 : }
184 : throw css::beans::UnknownPropertyException(
185 0 : PropertyName, static_cast< cppu::OWeakObject * >(this));
186 : }
187 :
188 0 : css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
189 : SAL_UNUSED_PARAMETER css::uno::Reference< css::uno::XComponentContext >
190 : const &)
191 : {
192 0 : return static_cast< cppu::OWeakObject * >(new Service);
193 : }
194 :
195 : static cppu::ImplementationEntry const services[] = {
196 : { &createInstance, &getServiceImplementationName,
197 : &getServiceSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
198 : 0 },
199 : { 0, 0, 0, 0, 0, 0 }
200 : };
201 :
202 : }
203 :
204 0 : extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL gconfbe1_component_getFactory(
205 : char const * pImplName, void * pServiceManager, void * pRegistryKey)
206 : {
207 : return cppu::component_getFactoryHelper(
208 0 : pImplName, pServiceManager, pRegistryKey, services);
209 : }
210 :
211 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|