LCOV - code coverage report
Current view: top level - shell/source/backends/desktopbe - desktopbackend.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 39 72 54.2 %
Date: 2015-06-13 12:38:46 Functions: 6 18 33.3 %
Legend: Lines: hit not hit

          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 "boost/noncopyable.hpp"
      23             : #include "com/sun/star/beans/Optional.hpp"
      24             : #include "com/sun/star/beans/PropertyVetoException.hpp"
      25             : #include "com/sun/star/beans/UnknownPropertyException.hpp"
      26             : #include "com/sun/star/beans/XPropertyChangeListener.hpp"
      27             : #include "com/sun/star/beans/XPropertySet.hpp"
      28             : #include "com/sun/star/beans/XPropertySetInfo.hpp"
      29             : #include "com/sun/star/beans/XVetoableChangeListener.hpp"
      30             : #include "com/sun/star/lang/IllegalArgumentException.hpp"
      31             : #include "com/sun/star/lang/WrappedTargetException.hpp"
      32             : #include "com/sun/star/lang/XMultiComponentFactory.hpp"
      33             : #include "com/sun/star/lang/XServiceInfo.hpp"
      34             : #include "com/sun/star/uno/Any.hxx"
      35             : #include "com/sun/star/uno/Exception.hpp"
      36             : #include "com/sun/star/uno/Reference.hxx"
      37             : #include "com/sun/star/uno/RuntimeException.hpp"
      38             : #include "com/sun/star/uno/Sequence.hxx"
      39             : #include "com/sun/star/uno/XComponentContext.hpp"
      40             : #include "com/sun/star/uno/XCurrentContext.hpp"
      41             : #include "cppuhelper/factory.hxx"
      42             : #include "cppuhelper/implbase2.hxx"
      43             : #include "cppuhelper/implementationentry.hxx"
      44             : #include "cppuhelper/weak.hxx"
      45             : #include "osl/diagnose.h"
      46             : #include "rtl/string.h"
      47             : #include "rtl/textenc.h"
      48             : #include "rtl/ustring.h"
      49             : #include "rtl/ustring.hxx"
      50             : #include "sal/types.h"
      51             : #include "uno/current_context.hxx"
      52             : 
      53             : namespace {
      54             : 
      55         132 : OUString SAL_CALL getDefaultImplementationName() {
      56             :     return OUString(
      57         132 :             "com.sun.star.comp.configuration.backend.DesktopBackend");
      58             : }
      59             : 
      60         132 : css::uno::Sequence< OUString > SAL_CALL getDefaultSupportedServiceNames() {
      61             :     OUString name(
      62         132 :             "com.sun.star.configuration.backend.DesktopBackend");
      63         132 :     return css::uno::Sequence< OUString >(&name, 1);
      64             : }
      65             : 
      66             : class Default:
      67             :     public cppu::WeakImplHelper2<
      68             :         css::lang::XServiceInfo, css::beans::XPropertySet >,
      69             :     private boost::noncopyable
      70             : {
      71             : public:
      72         132 :     Default() {}
      73             : 
      74             : private:
      75           0 :     virtual ~Default() {}
      76             : 
      77           0 :     virtual OUString SAL_CALL getImplementationName()
      78             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      79           0 :     { return getDefaultImplementationName(); }
      80             : 
      81           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
      82             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      83           0 :     { return ServiceName == getSupportedServiceNames()[0]; }
      84             : 
      85             :     virtual css::uno::Sequence< OUString > SAL_CALL
      86           0 :     getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      87           0 :     { return getDefaultSupportedServiceNames(); }
      88             : 
      89             :     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
      90           0 :     getPropertySetInfo() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      91           0 :     { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
      92             : 
      93             :     virtual void SAL_CALL setPropertyValue(
      94             :         OUString const &, css::uno::Any const &)
      95             :         throw (
      96             :             css::beans::UnknownPropertyException,
      97             :             css::beans::PropertyVetoException,
      98             :             css::lang::IllegalArgumentException,
      99             :             css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     100             : 
     101             :     virtual css::uno::Any SAL_CALL getPropertyValue(
     102             :         OUString const & PropertyName)
     103             :         throw (
     104             :             css::beans::UnknownPropertyException,
     105             :             css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     106             : 
     107           0 :     virtual void SAL_CALL addPropertyChangeListener(
     108             :         OUString const &,
     109             :         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
     110             :         throw (
     111             :             css::beans::UnknownPropertyException,
     112             :             css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     113           0 :     {}
     114             : 
     115           0 :     virtual void SAL_CALL removePropertyChangeListener(
     116             :         OUString const &,
     117             :         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
     118             :         throw (
     119             :             css::beans::UnknownPropertyException,
     120             :             css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     121           0 :     {}
     122             : 
     123           0 :     virtual void SAL_CALL addVetoableChangeListener(
     124             :         OUString const &,
     125             :         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
     126             :         throw (
     127             :             css::beans::UnknownPropertyException,
     128             :             css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     129           0 :     {}
     130             : 
     131           0 :     virtual void SAL_CALL removeVetoableChangeListener(
     132             :         OUString const &,
     133             :         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
     134             :         throw (
     135             :             css::beans::UnknownPropertyException,
     136             :             css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     137           0 :     {}
     138             : };
     139             : 
     140           0 : void Default::setPropertyValue(OUString const &, css::uno::Any const &)
     141             :     throw (
     142             :         css::beans::UnknownPropertyException, css::beans::PropertyVetoException,
     143             :         css::lang::IllegalArgumentException, css::lang::WrappedTargetException,
     144             :         css::uno::RuntimeException, std::exception)
     145             : {
     146             :     throw css::lang::IllegalArgumentException(
     147             :         OUString("setPropertyValue not supported"),
     148           0 :         static_cast< cppu::OWeakObject * >(this), -1);
     149             : }
     150             : 
     151         535 : css::uno::Any Default::getPropertyValue(OUString const & PropertyName)
     152             :     throw (
     153             :         css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
     154             :         css::uno::RuntimeException, std::exception)
     155             : {
     156        1477 :     if ( PropertyName == "EnableATToolSupport" ||
     157         814 :          PropertyName == "ExternalMailer" ||
     158         814 :          PropertyName == "SourceViewFontHeight" ||
     159         814 :          PropertyName == "SourceViewFontName" ||
     160         683 :          PropertyName == "TemplatePathVariable" ||
     161         421 :          PropertyName == "WorkPathVariable" ||
     162         283 :          PropertyName == "ooInetFTPProxyName" ||
     163         274 :          PropertyName == "ooInetFTPProxyPort" ||
     164         265 :          PropertyName == "ooInetHTTPProxyName" ||
     165         256 :          PropertyName == "ooInetHTTPProxyPort" ||
     166         247 :          PropertyName == "ooInetHTTPSProxyName" ||
     167         238 :          PropertyName == "ooInetHTTPSProxyPort" ||
     168         229 :          PropertyName == "ooInetNoProxy" ||
     169         215 :          PropertyName == "ooInetProxyType" ||
     170         691 :          PropertyName == "givenname" ||
     171          52 :          PropertyName == "sn" )
     172             :     {
     173        1070 :         return css::uno::makeAny(css::beans::Optional< css::uno::Any >());
     174             :     }
     175             :     throw css::beans::UnknownPropertyException(
     176           0 :         PropertyName, static_cast< cppu::OWeakObject * >(this));
     177             : }
     178             : 
     179           0 : css::uno::Reference< css::uno::XInterface > createBackend(
     180             :     css::uno::Reference< css::uno::XComponentContext > const & context,
     181             :     OUString const & name)
     182             : {
     183             :     try {
     184             :         return css::uno::Reference< css::lang::XMultiComponentFactory >(
     185           0 :             context->getServiceManager(), css::uno::UNO_SET_THROW)->
     186           0 :             createInstanceWithContext(name, context);
     187           0 :     } catch (css::uno::RuntimeException &) {
     188             :         // Assuming these exceptions are real errors:
     189           0 :         throw;
     190           0 :     } catch (const css::uno::Exception & e) {
     191             :         // Assuming these exceptions indicate that the service is not installed:
     192             :         OSL_TRACE(
     193             :             "createInstance(%s) failed with %s",
     194             :             OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr(),
     195             :             OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
     196           0 :         return css::uno::Reference< css::uno::XInterface >();
     197             :     }
     198             : }
     199             : 
     200         132 : css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
     201             :     css::uno::Reference< css::uno::XComponentContext > const & context)
     202             : {
     203         132 :     OUString desktop;
     204             :     css::uno::Reference< css::uno::XCurrentContext > current(
     205         264 :         css::uno::getCurrentContext());
     206         132 :     if (current.is()) {
     207         132 :         current->getValueByName(
     208         264 :             OUString("system.desktop-environment")) >>=
     209         132 :             desktop;
     210             :     }
     211             : 
     212             :     // Fall back to the default if the specific backend is not available:
     213         264 :     css::uno::Reference< css::uno::XInterface > backend;
     214         132 :     if ( desktop == "GNOME" ) {
     215           0 :         backend = createBackend(
     216             :             context,
     217             :             OUString(
     218           0 :                     "com.sun.star.configuration.backend.GconfBackend"));
     219         132 :     } else if ( desktop == "KDE" ) {
     220           0 :         backend = createBackend(
     221             :             context,
     222             :             OUString(
     223           0 :                     "com.sun.star.configuration.backend.KDEBackend"));
     224         132 :     } else if ( desktop == "KDE4" ) {
     225           0 :         backend = createBackend(
     226             :             context,
     227             :             OUString(
     228           0 :                     "com.sun.star.configuration.backend.KDE4Backend"));
     229             :     }
     230         132 :     return backend.is()
     231         264 :         ? backend : static_cast< cppu::OWeakObject * >(new Default);
     232             : }
     233             : 
     234             : static cppu::ImplementationEntry const services[] = {
     235             :     { &createInstance, &getDefaultImplementationName,
     236             :       &getDefaultSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
     237             :       0 },
     238             :     { 0, 0, 0, 0, 0, 0 }
     239             : };
     240             : 
     241             : }
     242             : 
     243         132 : extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL desktopbe1_component_getFactory(
     244             :     char const * pImplName, void * pServiceManager, void * pRegistryKey)
     245             : {
     246             :     return cppu::component_getFactoryHelper(
     247         132 :         pImplName, pServiceManager, pRegistryKey, services);
     248             : }
     249             : 
     250             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11