LCOV - code coverage report
Current view: top level - shell/source/backends/desktopbe - desktopbackend.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 58 48.3 %
Date: 2012-08-25 Functions: 6 18 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 41 105 39.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            : *
       4                 :            : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            : *
       6                 :            : * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            : *
       8                 :            : * OpenOffice.org - a multi-platform office productivity suite
       9                 :            : *
      10                 :            : * This file is part of OpenOffice.org.
      11                 :            : *
      12                 :            : * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            : * it under the terms of the GNU Lesser General Public License version 3
      14                 :            : * only, as published by the Free Software Foundation.
      15                 :            : *
      16                 :            : * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            : * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            : * GNU Lesser General Public License version 3 for more details
      20                 :            : * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            : *
      22                 :            : * You should have received a copy of the GNU Lesser General Public License
      23                 :            : * version 3 along with OpenOffice.org.  If not, see
      24                 :            : * <http://www.openoffice.org/license.html>
      25                 :            : * for a copy of the LGPLv3 License.
      26                 :            : *
      27                 :            : ************************************************************************/
      28                 :            : 
      29                 :            : #include "sal/config.h"
      30                 :            : 
      31                 :            : #include "boost/noncopyable.hpp"
      32                 :            : #include "com/sun/star/beans/Optional.hpp"
      33                 :            : #include "com/sun/star/beans/PropertyVetoException.hpp"
      34                 :            : #include "com/sun/star/beans/UnknownPropertyException.hpp"
      35                 :            : #include "com/sun/star/beans/XPropertyChangeListener.hpp"
      36                 :            : #include "com/sun/star/beans/XPropertySet.hpp"
      37                 :            : #include "com/sun/star/beans/XPropertySetInfo.hpp"
      38                 :            : #include "com/sun/star/beans/XVetoableChangeListener.hpp"
      39                 :            : #include "com/sun/star/lang/IllegalArgumentException.hpp"
      40                 :            : #include "com/sun/star/lang/WrappedTargetException.hpp"
      41                 :            : #include "com/sun/star/lang/XMultiComponentFactory.hpp"
      42                 :            : #include "com/sun/star/lang/XServiceInfo.hpp"
      43                 :            : #include "com/sun/star/lang/WrappedTargetException.hpp"
      44                 :            : #include "com/sun/star/uno/Any.hxx"
      45                 :            : #include "com/sun/star/uno/Exception.hpp"
      46                 :            : #include "com/sun/star/uno/Reference.hxx"
      47                 :            : #include "com/sun/star/uno/RuntimeException.hpp"
      48                 :            : #include "com/sun/star/uno/Sequence.hxx"
      49                 :            : #include "com/sun/star/uno/XComponentContext.hpp"
      50                 :            : #include "com/sun/star/uno/XCurrentContext.hpp"
      51                 :            : #include "cppuhelper/factory.hxx"
      52                 :            : #include "cppuhelper/implbase2.hxx"
      53                 :            : #include "cppuhelper/implementationentry.hxx"
      54                 :            : #include "cppuhelper/weak.hxx"
      55                 :            : #include "osl/diagnose.h"
      56                 :            : #include "rtl/string.h"
      57                 :            : #include "rtl/textenc.h"
      58                 :            : #include "rtl/ustring.h"
      59                 :            : #include "rtl/ustring.hxx"
      60                 :            : #include "sal/types.h"
      61                 :            : #include "uno/current_context.hxx"
      62                 :            : #include "uno/lbnames.h"
      63                 :            : 
      64                 :            : namespace {
      65                 :            : 
      66                 :            : namespace css = com::sun::star;
      67                 :            : 
      68                 :        160 : rtl::OUString SAL_CALL getDefaultImplementationName() {
      69                 :            :     return rtl::OUString(
      70                 :            :         RTL_CONSTASCII_USTRINGPARAM(
      71                 :        160 :             "com.sun.star.comp.configuration.backend.DesktopBackend"));
      72                 :            : }
      73                 :            : 
      74                 :        160 : css::uno::Sequence< rtl::OUString > SAL_CALL getDefaultSupportedServiceNames() {
      75                 :            :     rtl::OUString name(
      76                 :            :         RTL_CONSTASCII_USTRINGPARAM(
      77         [ +  - ]:        160 :             "com.sun.star.configuration.backend.DesktopBackend"));
      78         [ +  - ]:        160 :     return css::uno::Sequence< rtl::OUString >(&name, 1);
      79                 :            : }
      80                 :            : 
      81                 :            : class Default:
      82                 :            :     public cppu::WeakImplHelper2<
      83                 :            :         css::lang::XServiceInfo, css::beans::XPropertySet >,
      84                 :            :     private boost::noncopyable
      85                 :            : {
      86                 :            : public:
      87                 :        160 :     Default() {}
      88                 :            : 
      89                 :            : private:
      90         [ #  # ]:          0 :     virtual ~Default() {}
      91                 :            : 
      92                 :          0 :     virtual rtl::OUString SAL_CALL getImplementationName()
      93                 :            :         throw (css::uno::RuntimeException)
      94                 :          0 :     { return getDefaultImplementationName(); }
      95                 :            : 
      96                 :          0 :     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
      97                 :            :         throw (css::uno::RuntimeException)
      98         [ #  # ]:          0 :     { return ServiceName == getSupportedServiceNames()[0]; }
      99                 :            : 
     100                 :            :     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
     101                 :          0 :     getSupportedServiceNames() throw (css::uno::RuntimeException)
     102                 :          0 :     { return getDefaultSupportedServiceNames(); }
     103                 :            : 
     104                 :            :     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
     105                 :          0 :     getPropertySetInfo() throw (css::uno::RuntimeException)
     106                 :          0 :     { return css::uno::Reference< css::beans::XPropertySetInfo >(); }
     107                 :            : 
     108                 :            :     virtual void SAL_CALL setPropertyValue(
     109                 :            :         rtl::OUString const &, css::uno::Any const &)
     110                 :            :         throw (
     111                 :            :             css::beans::UnknownPropertyException,
     112                 :            :             css::beans::PropertyVetoException,
     113                 :            :             css::lang::IllegalArgumentException,
     114                 :            :             css::lang::WrappedTargetException, css::uno::RuntimeException);
     115                 :            : 
     116                 :            :     virtual css::uno::Any SAL_CALL getPropertyValue(
     117                 :            :         rtl::OUString const & PropertyName)
     118                 :            :         throw (
     119                 :            :             css::beans::UnknownPropertyException,
     120                 :            :             css::lang::WrappedTargetException, css::uno::RuntimeException);
     121                 :            : 
     122                 :          0 :     virtual void SAL_CALL addPropertyChangeListener(
     123                 :            :         rtl::OUString const &,
     124                 :            :         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
     125                 :            :         throw (
     126                 :            :             css::beans::UnknownPropertyException,
     127                 :            :             css::lang::WrappedTargetException, css::uno::RuntimeException)
     128                 :          0 :     {}
     129                 :            : 
     130                 :          0 :     virtual void SAL_CALL removePropertyChangeListener(
     131                 :            :         rtl::OUString const &,
     132                 :            :         css::uno::Reference< css::beans::XPropertyChangeListener > const &)
     133                 :            :         throw (
     134                 :            :             css::beans::UnknownPropertyException,
     135                 :            :             css::lang::WrappedTargetException, css::uno::RuntimeException)
     136                 :          0 :     {}
     137                 :            : 
     138                 :          0 :     virtual void SAL_CALL addVetoableChangeListener(
     139                 :            :         rtl::OUString const &,
     140                 :            :         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
     141                 :            :         throw (
     142                 :            :             css::beans::UnknownPropertyException,
     143                 :            :             css::lang::WrappedTargetException, css::uno::RuntimeException)
     144                 :          0 :     {}
     145                 :            : 
     146                 :          0 :     virtual void SAL_CALL removeVetoableChangeListener(
     147                 :            :         rtl::OUString const &,
     148                 :            :         css::uno::Reference< css::beans::XVetoableChangeListener > const &)
     149                 :            :         throw (
     150                 :            :             css::beans::UnknownPropertyException,
     151                 :            :             css::lang::WrappedTargetException, css::uno::RuntimeException)
     152                 :          0 :     {}
     153                 :            : };
     154                 :            : 
     155                 :          0 : void Default::setPropertyValue(rtl::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)
     160                 :            : {
     161                 :            :     throw css::lang::IllegalArgumentException(
     162                 :            :         rtl::OUString(
     163                 :            :             RTL_CONSTASCII_USTRINGPARAM("setPropertyValue not supported")),
     164 [ #  # ][ #  # ]:          0 :         static_cast< cppu::OWeakObject * >(this), -1);
                 [ #  # ]
     165                 :            : }
     166                 :            : 
     167                 :        496 : css::uno::Any Default::getPropertyValue(rtl::OUString const & PropertyName)
     168                 :            :     throw (
     169                 :            :         css::beans::UnknownPropertyException, css::lang::WrappedTargetException,
     170                 :            :         css::uno::RuntimeException)
     171                 :            : {
     172 [ +  + ][ +  - ]:       2628 :     if ( PropertyName == "EnableATToolSupport" || PropertyName == "ExternalMailer" || PropertyName == "SourceViewFontHeight"
           [ +  -  +  -  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
           +  - ][ +  - ]
     173                 :        856 :       || PropertyName == "SourceViewFontName" || PropertyName == "WorkPathVariable" || PropertyName == "ooInetFTPProxyName"
     174                 :        500 :       || PropertyName == "ooInetFTPProxyPort" || PropertyName == "ooInetHTTPProxyName" || PropertyName == "ooInetHTTPProxyPort"
     175                 :        448 :       || PropertyName == "ooInetHTTPSProxyName" || PropertyName == "ooInetHTTPSProxyPort" || PropertyName == "ooInetNoProxy"
     176                 :        328 :       || PropertyName == "ooInetProxyType" || PropertyName == "givenname" || PropertyName == "sn" )
     177                 :            :     {
     178         [ +  - ]:        496 :         return css::uno::makeAny(css::beans::Optional< css::uno::Any >());
     179                 :            :     }
     180                 :            :     throw css::beans::UnknownPropertyException(
     181 [ #  # ][ #  # ]:          0 :         PropertyName, static_cast< cppu::OWeakObject * >(this));
     182                 :            : }
     183                 :            : 
     184                 :          0 : css::uno::Reference< css::uno::XInterface > createBackend(
     185                 :            :     css::uno::Reference< css::uno::XComponentContext > const & context,
     186                 :            :     rtl::OUString const & name)
     187                 :            : {
     188                 :            :     try {
     189                 :            :         return css::uno::Reference< css::lang::XMultiComponentFactory >(
     190 [ #  # ][ #  # ]:          0 :             context->getServiceManager(), css::uno::UNO_SET_THROW)->
         [ #  # ][ #  # ]
     191         [ #  # ]:          0 :             createInstanceWithContext(name, context);
     192      [ #  #  # ]:          0 :     } catch (css::uno::RuntimeException &) {
     193                 :            :         // Assuming these exceptions are real errors:
     194                 :          0 :         throw;
     195                 :          0 :     } catch (const css::uno::Exception & e) {
     196                 :            :         // Assuming these exceptions indicate that the service is not installed:
     197                 :            :         OSL_TRACE(
     198                 :            :             "createInstance(%s) failed with %s",
     199                 :            :             rtl::OUStringToOString(name, RTL_TEXTENCODING_UTF8).getStr(),
     200                 :            :             rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).getStr());
     201                 :          0 :         return css::uno::Reference< css::uno::XInterface >();
     202                 :            :     }
     203                 :            : }
     204                 :            : 
     205                 :        160 : css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
     206                 :            :     css::uno::Reference< css::uno::XComponentContext > const & context)
     207                 :            : {
     208                 :        160 :     rtl::OUString desktop;
     209                 :            :     css::uno::Reference< css::uno::XCurrentContext > current(
     210         [ +  - ]:        160 :         css::uno::getCurrentContext());
     211         [ +  - ]:        160 :     if (current.is()) {
     212         [ +  - ]:        160 :         current->getValueByName(
     213                 :            :             rtl::OUString(
     214                 :        160 :                 RTL_CONSTASCII_USTRINGPARAM("system.desktop-environment"))) >>=
     215 [ +  - ][ +  - ]:        160 :             desktop;
     216                 :            :     }
     217                 :            : 
     218                 :            :     // Fall back to the default if the specific backend is not available:
     219                 :        160 :     css::uno::Reference< css::uno::XInterface > backend;
     220         [ -  + ]:        160 :     if ( desktop == "GNOME" ) {
     221                 :            :         backend = createBackend(
     222                 :            :             context,
     223                 :            :             rtl::OUString(
     224                 :            :                 RTL_CONSTASCII_USTRINGPARAM(
     225 [ #  # ][ #  # ]:          0 :                     "com.sun.star.configuration.backend.GconfBackend")));
                 [ #  # ]
     226         [ -  + ]:        160 :     } else if ( desktop == "KDE" ) {
     227                 :            :         backend = createBackend(
     228                 :            :             context,
     229                 :            :             rtl::OUString(
     230                 :            :                 RTL_CONSTASCII_USTRINGPARAM(
     231 [ #  # ][ #  # ]:          0 :                     "com.sun.star.configuration.backend.KDEBackend")));
                 [ #  # ]
     232         [ -  + ]:        160 :     } else if ( desktop == "KDE4" ) {
     233                 :            :         backend = createBackend(
     234                 :            :             context,
     235                 :            :             rtl::OUString(
     236                 :            :                 RTL_CONSTASCII_USTRINGPARAM(
     237 [ #  # ][ #  # ]:          0 :                     "com.sun.star.configuration.backend.KDE4Backend")));
                 [ #  # ]
     238                 :            :     }
     239                 :        160 :     return backend.is()
     240 [ +  - ][ +  - ]:        160 :         ? backend : static_cast< cppu::OWeakObject * >(new Default);
                 [ -  + ]
     241                 :            : }
     242                 :            : 
     243                 :            : static cppu::ImplementationEntry const services[] = {
     244                 :            :     { &createInstance, &getDefaultImplementationName,
     245                 :            :       &getDefaultSupportedServiceNames, &cppu::createSingleComponentFactory, 0,
     246                 :            :       0 },
     247                 :            :     { 0, 0, 0, 0, 0, 0 }
     248                 :            : };
     249                 :            : 
     250                 :            : }
     251                 :            : 
     252                 :        160 : extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
     253                 :            :     char const * pImplName, void * pServiceManager, void * pRegistryKey)
     254                 :            : {
     255                 :            :     return cppu::component_getFactoryHelper(
     256                 :        160 :         pImplName, pServiceManager, pRegistryKey, services);
     257                 :            : }
     258                 :            : 
     259                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10