LCOV - code coverage report
Current view: top level - framework/source/accelerators - globalacceleratorconfiguration.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 27 35 77.1 %
Date: 2015-06-13 12:38:46 Functions: 8 9 88.9 %
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        2590 :     virtual ~GlobalAcceleratorConfiguration() {}
      58             : 
      59           1 :     virtual OUString SAL_CALL getImplementationName()
      60             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      61             :     {
      62           1 :         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           1 :     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
      72             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      73             :     {
      74           1 :         css::uno::Sequence< OUString > aSeq(1);
      75           1 :         aSeq[0] = "com.sun.star.ui.GlobalAcceleratorConfiguration";
      76           1 :         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        1297 : GlobalAcceleratorConfiguration::GlobalAcceleratorConfiguration(const css::uno::Reference< css::uno::XComponentContext >& xContext)
      92        1297 :     : GlobalAcceleratorConfiguration_BASE(xContext)
      93             : {
      94        1297 : }
      95             : 
      96        1297 : 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        1297 :         m_sGlobalOrModules = CFG_ENTRY_GLOBAL;
     112        1297 :         XCUBasedAcceleratorConfiguration::reload();
     113             : 
     114        1297 :         css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
     115        1297 :         m_xCfgListener = new WeakChangesListener(this);
     116        1297 :         xBroadcaster->addChangesListener(m_xCfgListener);
     117             :     }
     118           0 :     catch(const css::uno::RuntimeException&)
     119           0 :         { throw; }
     120           0 :     catch(const css::uno::Exception&)
     121             :         {}
     122        1297 : }
     123             : 
     124             : // XComponent.dispose(),  #i120029#, to release the cyclic reference
     125             : 
     126        1242 : void SAL_CALL GlobalAcceleratorConfiguration::dispose()
     127             :     throw(css::uno::RuntimeException, std::exception)
     128             : {
     129             :     try
     130             :     {
     131        1242 :         css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
     132        1242 :         if ( xBroadcaster.is() )
     133        1242 :             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        1242 : }
     140             : 
     141             : }
     142             : 
     143             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     144        1297 : com_sun_star_comp_framework_GlobalAcceleratorConfiguration_get_implementation(
     145             :     css::uno::XComponentContext *context,
     146             :     css::uno::Sequence<css::uno::Any> const &)
     147             : {
     148        1297 :     GlobalAcceleratorConfiguration *inst = new GlobalAcceleratorConfiguration(context);
     149        1297 :     css::uno::XInterface *acquired_inst = cppu::acquire(inst);
     150             : 
     151        1297 :     inst->fillCache();
     152             : 
     153        1297 :     return acquired_inst;
     154             : }
     155             : 
     156             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11