Bump version to 5.0-14
[LibreOffice.git] / shell / source / backends / gconfbe / gconfbackend.cxx
blob71fbdd63137c1eeb83d563edd853e6092ae24333
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sal/config.h"
22 #include <cstddef>
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"
52 #include "gconfaccess.hxx"
54 namespace {
56 OUString SAL_CALL getServiceImplementationName() {
57 return OUString(
58 "com.sun.star.comp.configuration.backend.GconfBackend");
61 css::uno::Sequence< OUString > SAL_CALL getServiceSupportedServiceNames() {
62 OUString name(
63 "com.sun.star.configuration.backend.GconfBackend");
64 return css::uno::Sequence< OUString >(&name, 1);
67 class Service:
68 public cppu::WeakImplHelper2<
69 css::lang::XServiceInfo, css::beans::XPropertySet >,
70 private boost::noncopyable
72 public:
73 Service();
75 private:
76 virtual ~Service() {}
78 virtual OUString SAL_CALL getImplementationName()
79 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
80 { return getServiceImplementationName(); }
82 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
83 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
84 { return ServiceName == getSupportedServiceNames()[0]; }
86 virtual css::uno::Sequence< OUString > SAL_CALL
87 getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
88 { return getServiceSupportedServiceNames(); }
90 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
91 getPropertySetInfo() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
92 { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
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;
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;
108 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
116 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
124 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
132 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
140 bool enabled_;
143 Service::Service(): enabled_(false) {
144 css::uno::Reference< css::uno::XCurrentContext > context(
145 css::uno::getCurrentContext());
146 if (context.is()) {
147 OUString desktop;
148 context->getValueByName(
149 OUString("system.desktop-environment")) >>=
150 desktop;
151 enabled_ = desktop == "GNOME";
155 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)
161 throw css::lang::IllegalArgumentException(
162 OUString("setPropertyValue not supported"),
163 static_cast< cppu::OWeakObject * >(this), -1);
166 css::uno::Any Service::getPropertyValue(OUString const & PropertyName)
167 throw (
168 css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
169 css::uno::RuntimeException, std::exception)
171 for (std::size_t i = 0; i < gconfaccess::nConfigurationValues; ++i)
173 if (PropertyName.equalsAsciiL(
174 gconfaccess::ConfigurationValues[i].OOoConfItem,
175 gconfaccess::ConfigurationValues[i].nOOoConfItemLen))
177 return css::uno::makeAny(
178 enabled_
179 ? gconfaccess::getValue(gconfaccess::ConfigurationValues[i])
180 : css::beans::Optional< css::uno::Any >());
183 throw css::beans::UnknownPropertyException(
184 PropertyName, static_cast< cppu::OWeakObject * >(this));
187 css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
188 SAL_UNUSED_PARAMETER css::uno::Reference< css::uno::XComponentContext >
189 const &)
191 return static_cast< cppu::OWeakObject * >(new Service);
194 static cppu::ImplementationEntry const services[] = {
195 { &createInstance, &getServiceImplementationName,
196 &getServiceSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
197 0 },
198 { 0, 0, 0, 0, 0, 0 }
203 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL gconfbe1_component_getFactory(
204 char const * pImplName, void * pServiceManager, void * pRegistryKey)
206 return cppu::component_getFactoryHelper(
207 pImplName, pServiceManager, pRegistryKey, services);
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */