summaryrefslogtreecommitdiffstats
path: root/shell/source/backends/desktopbe/desktopbackend.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'shell/source/backends/desktopbe/desktopbackend.cxx')
-rw-r--r--shell/source/backends/desktopbe/desktopbackend.cxx248
1 files changed, 248 insertions, 0 deletions
diff --git a/shell/source/backends/desktopbe/desktopbackend.cxx b/shell/source/backends/desktopbe/desktopbackend.cxx
new file mode 100644
index 000000000000..bdc45e737687
--- /dev/null
+++ b/shell/source/backends/desktopbe/desktopbackend.cxx
@@ -0,0 +1,248 @@
+/*************************************************************************
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2009 by Sun Microsystems, Inc.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: code,v $
+*
+* $Revision: 1.4 $
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+************************************************************************/
+
+#include "precompiled_shell.hxx"
+#include "sal/config.h"
+
+#include "boost/noncopyable.hpp"
+#include "com/sun/star/container/NoSuchElementException.hpp"
+#include "com/sun/star/container/XNameAccess.hpp"
+#include "com/sun/star/lang/XMultiComponentFactory.hpp"
+#include "com/sun/star/lang/XServiceInfo.hpp"
+#include "com/sun/star/lang/WrappedTargetException.hpp"
+#include "com/sun/star/uno/Any.hxx"
+#include "com/sun/star/uno/Exception.hpp"
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "com/sun/star/uno/Type.hxx"
+#include "com/sun/star/uno/XComponentContext.hpp"
+#include "com/sun/star/uno/XCurrentContext.hpp"
+#include "cppu/unotype.hxx"
+#include "cppuhelper/factory.hxx"
+#include "cppuhelper/implbase2.hxx"
+#include "cppuhelper/implementationentry.hxx"
+#include "cppuhelper/weak.hxx"
+#include "osl/diagnose.h"
+#include "rtl/string.h"
+#include "rtl/textenc.h"
+#include "rtl/ustring.h"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+#include "uno/current_context.hxx"
+#include "uno/lbnames.h"
+
+namespace {
+
+namespace css = com::sun::star;
+
+rtl::OUString SAL_CALL getDefaultImplementationName() {
+ return rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.comp.configuration.backend.DesktopBackend"));
+}
+
+css::uno::Sequence< rtl::OUString > SAL_CALL getDefaultSupportedServiceNames() {
+ rtl::OUString name(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.configuration.backend.DesktopBackend"));
+ return css::uno::Sequence< rtl::OUString >(&name, 1);
+}
+
+class Default:
+ public cppu::WeakImplHelper2<
+ css::lang::XServiceInfo, css::container::XNameAccess >,
+ private boost::noncopyable
+{
+public:
+ Default() {}
+
+private:
+ virtual ~Default() {}
+
+ virtual rtl::OUString SAL_CALL getImplementationName()
+ throw (css::uno::RuntimeException)
+ { return getDefaultImplementationName(); }
+
+ virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
+ throw (css::uno::RuntimeException)
+ { return ServiceName == getSupportedServiceNames()[0]; }
+
+ virtual css::uno::Sequence< rtl::OUString > SAL_CALL
+ getSupportedServiceNames() throw (css::uno::RuntimeException)
+ { return getDefaultSupportedServiceNames(); }
+
+ virtual css::uno::Type SAL_CALL getElementType()
+ throw (css::uno::RuntimeException)
+ { return cppu::UnoType< cppu::UnoVoidType >::get(); }
+
+ virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException)
+ { return true; }
+
+ virtual css::uno::Any SAL_CALL getByName(rtl::OUString const & aName)
+ throw (
+ css::container::NoSuchElementException,
+ css::lang::WrappedTargetException, css::uno::RuntimeException);
+
+ virtual css::uno::Sequence< rtl::OUString > SAL_CALL getElementNames()
+ throw (css::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL hasByName(rtl::OUString const & aName)
+ throw (css::uno::RuntimeException);
+};
+
+css::uno::Any Default::getByName(rtl::OUString const & aName)
+ throw (
+ css::container::NoSuchElementException,
+ css::lang::WrappedTargetException, css::uno::RuntimeException)
+{
+ if (!hasByName(aName)) {
+ throw css::container::NoSuchElementException(
+ aName, static_cast< cppu::OWeakObject * >(this));
+ }
+ return css::uno::makeAny(cppu::UnoType< cppu::UnoVoidType >::get());
+}
+
+css::uno::Sequence< rtl::OUString > Default::getElementNames()
+ throw (css::uno::RuntimeException)
+{
+ css::uno::Sequence< rtl::OUString > names(13);
+ names[0] = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("EnableATToolSupport"));
+ names[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ExternalMailer"));
+ names[2] = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("SourceViewFontHeight"));
+ names[3] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SourceViewFontName"));
+ names[4] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WorkPathVariable"));
+ names[5] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetFTPProxyName"));
+ names[6] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetFTPProxyPort"));
+ names[7] = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPProxyName"));
+ names[8] = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPProxyPort"));
+ names[9] = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPSProxyName"));
+ names[10] = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("ooInetHTTPSProxyPort"));
+ names[11] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetNoProxy"));
+ names[12] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooInetProxyType"));
+ return names;
+}
+
+sal_Bool Default::hasByName(rtl::OUString const & aName)
+ throw (css::uno::RuntimeException)
+{
+ css::uno::Sequence< rtl::OUString > names(getElementNames());
+ for (sal_Int32 i = 0; i < names.getLength(); ++i) {
+ if (aName == names[i]) {
+ return true;
+ }
+ }
+ return false;
+}
+
+css::uno::Reference< css::uno::XInterface > createBackend(
+ css::uno::Reference< css::uno::XComponentContext > const & context,
+ rtl::OUString const & name)
+{
+ try {
+ return css::uno::Reference< css::lang::XMultiComponentFactory >(
+ context->getServiceManager(), css::uno::UNO_SET_THROW)->
+ createInstanceWithContext(name, context);
+ } catch (css::uno::RuntimeException &) {
+ // Assuming these exceptions are real errors:
+ throw;
+ } catch (css::uno::Exception & e) {
+ // Assuming these exceptions indicate that the service is not installed:
+ OSL_TRACE(
+ "createInstance(%s) failed with %s",
+ rtl::OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr(),
+ rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
+ return css::uno::Reference< css::uno::XInterface >();
+ }
+}
+
+css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
+ css::uno::Reference< css::uno::XComponentContext > const & context)
+{
+ rtl::OUString desktop;
+ css::uno::Reference< css::uno::XCurrentContext > current(
+ css::uno::getCurrentContext());
+ if (current.is()) {
+ current->getValueByName(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("system.desktop-environment"))) >>=
+ desktop;
+ }
+ // Fall back to the default if the specific backend is not available:
+ css::uno::Reference< css::uno::XInterface > backend;
+ if (desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("GNOME"))) {
+ backend = createBackend(
+ context,
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.configuration.backend.GconfBackend")));
+ } else if (desktop.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("KDE"))) {
+ backend = createBackend(
+ context,
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.configuration.backend.KDEBackend")));
+ } //TODO: KDE4?
+ return backend.is()
+ ? backend : static_cast< cppu::OWeakObject * >(new Default);
+}
+
+static cppu::ImplementationEntry const services[] = {
+ { &createInstance, &getDefaultImplementationName,
+ &getDefaultSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
+ 0 },
+ { 0, 0, 0, 0, 0, 0 }
+};
+
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
+ char const * pImplName, void * pServiceManager, void * pRegistryKey)
+{
+ return cppu::component_getFactoryHelper(
+ pImplName, pServiceManager, pRegistryKey, services);
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
+component_getImplementationEnvironment(
+ char const ** ppEnvTypeName, uno_Environment **)
+{
+ *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(
+ void * pServiceManager, void * pRegistryKey)
+{
+ return component_writeInfoHelper(pServiceManager, pRegistryKey, services);
+}