LCOV - code coverage report
Current view: top level - libreoffice/desktop/source/app - configinit.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 43 0.0 %
Date: 2012-12-27 Functions: 0 15 0.0 %
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 "configinit.hxx"
      21             : 
      22             : #include "desktop.hrc"
      23             : #include "app.hxx"
      24             : #include <comphelper/processfactory.hxx>
      25             : #include <uno/current_context.hxx>
      26             : #include <cppuhelper/implbase1.hxx>
      27             : #include <rtl/ustrbuf.hxx>
      28             : #include <osl/diagnose.h>
      29             : #include <stdio.h>
      30             : #include <com/sun/star/task/InteractionHandler.hpp>
      31             : 
      32             : // ----------------------------------------------------------------------------
      33             : 
      34             : namespace uno           = ::com::sun::star::uno;
      35             : namespace lang          = ::com::sun::star::lang;
      36             : using rtl::OUString;
      37             : using uno::UNO_QUERY;
      38             : 
      39             : // ----------------------------------------------------------------------------
      40             : 
      41             : // must be aligned with configmgr/source/misc/configinteractionhandler
      42             : static char const CONFIG_ERROR_HANDLER[] = "configuration.interaction-handler";
      43             : // ----------------------------------------------------------------------------
      44             : 
      45             : #define OUSTRING( constascii ) OUString( RTL_CONSTASCII_USTRINGPARAM( constascii ) )
      46             : 
      47             : #define k_ERRORHANDLER OUSTRING( CONFIGURATION_ERROR_HANDLER )
      48             : 
      49             : // ----------------------------------------------------------------------------
      50             : // ConfigurationErrorHandler
      51             : // ----------------------------------------------------------------------------
      52             : 
      53             : namespace
      54             : {
      55             :     typedef uno::Reference< uno::XCurrentContext > CurrentContext;
      56           0 :     class SimpleCurrentContext : public cppu::WeakImplHelper1< uno::XCurrentContext >
      57             :     {
      58             :         CurrentContext m_xChainedContext;
      59             :     public:
      60             :         explicit
      61           0 :         SimpleCurrentContext(const CurrentContext & xChainedContext)
      62           0 :         : m_xChainedContext(xChainedContext)
      63           0 :         {}
      64             : 
      65           0 :         void install()      { uno::setCurrentContext(this); }
      66           0 :         void deinstall()    { uno::setCurrentContext(m_xChainedContext); }
      67             : 
      68           0 :         uno::Any getChainedValueByName( OUString const & aName) const
      69             :         {
      70           0 :             return m_xChainedContext.is()
      71           0 :                             ? m_xChainedContext->getValueByName(aName)
      72           0 :                             : uno::Any();
      73             :         }
      74             : 
      75             :         // XCurrentContext
      76             :         virtual uno::Any SAL_CALL
      77             :             getValueByName( OUString const & aName)
      78             :                 throw (uno::RuntimeException);
      79             :     };
      80             : 
      81             :     uno::Any SAL_CALL
      82           0 :         SimpleCurrentContext::getValueByName( OUString const & aName)
      83             :             throw (uno::RuntimeException)
      84             :     {
      85           0 :         return getChainedValueByName(aName);
      86             :     }
      87             : 
      88             : }
      89             : 
      90             : // ----------------------------------------------------------------------------
      91             : class ConfigurationErrorHandler::Context : public SimpleCurrentContext
      92             : {
      93             : public:
      94           0 :     Context()
      95           0 :     : SimpleCurrentContext( uno::getCurrentContext() )
      96             :     {
      97           0 :     }
      98             : 
      99           0 :     ~Context()
     100           0 :     {
     101           0 :     }
     102             : 
     103             :     // XCurrentContext
     104             :     virtual uno::Any SAL_CALL
     105             :         getValueByName( OUString const & aName)
     106             :             throw (uno::RuntimeException);
     107             : 
     108             : private:
     109             :     InteractionHandler  m_xHandler;
     110             : };
     111             : 
     112             : //------------------------------------------------------------------------------
     113           0 : uno::Any SAL_CALL ConfigurationErrorHandler::Context::getValueByName( OUString const & aName)
     114             :         throw (uno::RuntimeException)
     115             : {
     116           0 :     if ( aName == CONFIG_ERROR_HANDLER )
     117             :     {
     118           0 :         if ( !m_xHandler.is() )
     119           0 :             m_xHandler = ConfigurationErrorHandler::getDefaultInteractionHandler();
     120           0 :         return uno::Any( m_xHandler );
     121             :     }
     122           0 :     return SimpleCurrentContext::getValueByName( aName );
     123             : }
     124             : 
     125             : //------------------------------------------------------------------------------
     126           0 : ConfigurationErrorHandler::~ConfigurationErrorHandler()
     127             : {
     128           0 :     deactivate();
     129           0 : }
     130             : 
     131             : //------------------------------------------------------------------------------
     132             : /// installs the handler into the current context
     133           0 : void ConfigurationErrorHandler::activate()
     134             : {
     135           0 :     if (!m_pContext)
     136             :     {
     137           0 :         m_pContext = new Context;
     138           0 :         m_pContext->acquire();
     139             :     }
     140           0 :     m_pContext->install();
     141           0 : }
     142             : 
     143             : //------------------------------------------------------------------------------
     144             : /// deinstalls the handler from the current context, restoring the previous context
     145           0 : void ConfigurationErrorHandler::deactivate()
     146             : {
     147           0 :     if (m_pContext)
     148             :     {
     149           0 :         m_pContext->deinstall();
     150           0 :         m_pContext->release();
     151           0 :         m_pContext = 0;
     152             :     }
     153           0 : }
     154             : //------------------------------------------------------------------------------
     155             : 
     156           0 : ConfigurationErrorHandler::InteractionHandler ConfigurationErrorHandler::getDefaultInteractionHandler()
     157             : {
     158           0 :     uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     159           0 :     InteractionHandler xHandler( com::sun::star::task::InteractionHandler::createWithParent(xContext, 0), UNO_QUERY );
     160           0 :     return xHandler;
     161             : }
     162             : //------------------------------------------------------------------------------
     163             : 
     164             : 
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10