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