LCOV - code coverage report
Current view: top level - framework/source/accelerators - globalacceleratorconfiguration.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 22 36 61.1 %
Date: 2014-11-03 Functions: 8 11 72.7 %
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 <accelerators/acceleratorconfiguration.hxx>
      21             : #include <accelerators/presethandler.hxx>
      22             : #include <helper/mischelper.hxx>
      23             : 
      24             : #include <acceleratorconst.h>
      25             : 
      26             : #include <com/sun/star/util/XChangesNotifier.hpp>
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : 
      29             : #include <cppuhelper/supportsservice.hxx>
      30             : #include <rtl/ref.hxx>
      31             : #include <vcl/svapp.hxx>
      32             : #include <i18nlangtag/languagetag.hxx>
      33             : 
      34             : using namespace framework;
      35             : 
      36             : namespace {
      37             : 
      38             : /**
      39             :     implements a read/write access to the global
      40             :     accelerator configuration.
      41             :  */
      42             : typedef ::cppu::ImplInheritanceHelper1<
      43             :              XCUBasedAcceleratorConfiguration,
      44             :              css::lang::XServiceInfo > GlobalAcceleratorConfiguration_BASE;
      45             : class GlobalAcceleratorConfiguration : public GlobalAcceleratorConfiguration_BASE
      46             : {
      47             : public:
      48             : 
      49             :     /** initialize this instance and fill the internal cache.
      50             : 
      51             :         @param  xSMGR
      52             :                 reference to an uno service manager, which is used internally.
      53             :      */
      54             :     GlobalAcceleratorConfiguration(const css::uno::Reference< css::uno::XComponentContext >& xContext);
      55             : 
      56             :     /** TODO */
      57        6376 :     virtual ~GlobalAcceleratorConfiguration() {}
      58             : 
      59           0 :     virtual OUString SAL_CALL getImplementationName()
      60             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      61             :     {
      62           0 :         return OUString("com.sun.star.comp.framework.GlobalAcceleratorConfiguration");
      63             :     }
      64             : 
      65           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
      66             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      67             :     {
      68           0 :         return cppu::supportsService(this, ServiceName);
      69             :     }
      70             : 
      71           0 :     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
      72             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      73             :     {
      74           0 :         css::uno::Sequence< OUString > aSeq(1);
      75           0 :         aSeq[0] = OUString("com.sun.star.ui.GlobalAcceleratorConfiguration");
      76           0 :         return aSeq;
      77             :     }
      78             : 
      79             :     // XComponent
      80             :     virtual  void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      81             : 
      82             :     /// This has to be called after when the instance is acquire()'d.
      83             :     void fillCache();
      84             : 
      85             : private:
      86             : 
      87             :     /** helper to listen for configuration changes without ownership cycle problems */
      88             :     css::uno::Reference< css::util::XChangesListener > m_xCfgListener;
      89             : };
      90             : 
      91        3192 : GlobalAcceleratorConfiguration::GlobalAcceleratorConfiguration(const css::uno::Reference< css::uno::XComponentContext >& xContext)
      92        3192 :     : GlobalAcceleratorConfiguration_BASE(xContext)
      93             : {
      94        3192 : }
      95             : 
      96        3192 : void GlobalAcceleratorConfiguration::fillCache()
      97             : {
      98             :     /** read all data into the cache. */
      99             : 
     100             : #if 0
     101             :     // get current office locale ... but dont cache it.
     102             :     // Otherwise we must be listener on the configuration layer
     103             :     // which seems to superflous for this small implementation .-)
     104             :     // XXX: what is this good for? it was a comphelper::Locale but unused
     105             :     LanguageTag aLanguageTag(m_sLocale);
     106             : #endif
     107             : 
     108             :     // May be there exists no accelerator config? Handle it gracefully :-)
     109             :     try
     110             :     {
     111        3192 :         m_sGlobalOrModules = CFG_ENTRY_GLOBAL;
     112        3192 :         XCUBasedAcceleratorConfiguration::reload();
     113             : 
     114        3192 :         css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
     115        3192 :         m_xCfgListener = new WeakChangesListener(this);
     116        3192 :         xBroadcaster->addChangesListener(m_xCfgListener);
     117             :     }
     118           0 :     catch(const css::uno::RuntimeException&)
     119           0 :         { throw; }
     120           0 :     catch(const css::uno::Exception&)
     121             :         {}
     122        3192 : }
     123             : 
     124             : // XComponent.dispose(),  #i120029#, to release the cyclic reference
     125             : 
     126        3128 : void SAL_CALL GlobalAcceleratorConfiguration::dispose()
     127             :     throw(css::uno::RuntimeException, std::exception)
     128             : {
     129             :     try
     130             :     {
     131        3128 :         css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
     132        3128 :         if ( xBroadcaster.is() )
     133        3128 :             xBroadcaster->removeChangesListener(static_cast< css::util::XChangesListener* >(this));
     134             :     }
     135           0 :     catch(const css::uno::RuntimeException&)
     136           0 :     { throw; }
     137           0 :     catch(const css::uno::Exception&)
     138             :     {}
     139        3128 : }
     140             : 
     141             : }
     142             : 
     143             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     144        3192 : com_sun_star_comp_framework_GlobalAcceleratorConfiguration_get_implementation(
     145             :     css::uno::XComponentContext *context,
     146             :     css::uno::Sequence<css::uno::Any> const &)
     147             : {
     148        3192 :     GlobalAcceleratorConfiguration *inst = new GlobalAcceleratorConfiguration(context);
     149        3192 :     css::uno::XInterface *acquired_inst = cppu::acquire(inst);
     150             : 
     151        3192 :     inst->fillCache();
     152             : 
     153        3192 :     return acquired_inst;
     154         951 : }
     155             : 
     156             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10