LCOV - code coverage report
Current view: top level - framework/source/accelerators - moduleacceleratorconfiguration.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 35 47 74.5 %
Date: 2015-06-13 12:38:46 Functions: 7 9 77.8 %
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/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      29             : #include <com/sun/star/embed/ElementModes.hpp>
      30             : 
      31             : #include <cppuhelper/supportsservice.hxx>
      32             : #include <comphelper/sequenceashashmap.hxx>
      33             : #include <vcl/svapp.hxx>
      34             : 
      35             : #include <com/sun/star/util/XChangesNotifier.hpp>
      36             : 
      37             : #include <cppuhelper/implbase1.hxx>
      38             : #include <rtl/ref.hxx>
      39             : 
      40             : using namespace framework;
      41             : 
      42             : namespace {
      43             : 
      44             : /**
      45             :     implements a read/write access to a module
      46             :     dependent accelerator configuration.
      47             :  */
      48             : typedef ::cppu::ImplInheritanceHelper1<
      49             :             XCUBasedAcceleratorConfiguration,
      50             :             css::lang::XServiceInfo > ModuleAcceleratorConfiguration_BASE;
      51             : 
      52             : class ModuleAcceleratorConfiguration : public ModuleAcceleratorConfiguration_BASE
      53             : {
      54             : private:
      55             :     /** identify the application module, where this accelerator
      56             :         configuration cache should work on. */
      57             :     OUString m_sModule;
      58             :     OUString m_sLocale;
      59             : 
      60             : public:
      61             : 
      62             :     /** initialize this instance and fill the internal cache.
      63             : 
      64             :         @param  xSMGR
      65             :                 reference to an uno service manager, which is used internally.
      66             :      */
      67             :     ModuleAcceleratorConfiguration(
      68             :             const css::uno::Reference< css::uno::XComponentContext >& xContext,
      69             :             const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& lArguments);
      70             : 
      71             :     /** TODO */
      72             :     virtual ~ModuleAcceleratorConfiguration();
      73             : 
      74           0 :     virtual OUString SAL_CALL getImplementationName()
      75             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      76             :     {
      77           0 :         return OUString("com.sun.star.comp.framework.ModuleAcceleratorConfiguration");
      78             :     }
      79             : 
      80           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
      81             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      82             :     {
      83           0 :         return cppu::supportsService(this, ServiceName);
      84             :     }
      85             : 
      86           1 :     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
      87             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      88             :     {
      89           1 :         css::uno::Sequence< OUString > aSeq(1);
      90           1 :         aSeq[0] = "com.sun.star.ui.ModuleAcceleratorConfiguration";
      91           1 :         return aSeq;
      92             :     }
      93             : 
      94             :     // XComponent
      95             :     virtual  void SAL_CALL dispose() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      96             : 
      97             :     /// This has to be called after when the instance is acquire()'d.
      98             :     void SAL_CALL fillCache();
      99             : 
     100             : private:
     101             :     /** helper to listen for configuration changes without ownership cycle problems */
     102             :     css::uno::Reference< css::util::XChangesListener > m_xCfgListener;
     103             : };
     104             : 
     105          67 : ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration(
     106             :         const css::uno::Reference< css::uno::XComponentContext >& xContext,
     107             :         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& lArguments)
     108          67 :     : ModuleAcceleratorConfiguration_BASE(xContext)
     109             : {
     110          67 :     SolarMutexGuard g;
     111             : 
     112         134 :     OUString sModule;
     113          67 :     if (lArguments.getLength() == 1 && (lArguments[0] >>= sModule))
     114             :     {
     115          67 :         m_sModule = sModule;
     116             :     } else
     117             :     {
     118           0 :         ::comphelper::SequenceAsHashMap lArgs(lArguments);
     119           0 :         m_sModule = lArgs.getUnpackedValueOrDefault("ModuleIdentifier", OUString());
     120           0 :         m_sLocale = lArgs.getUnpackedValueOrDefault("Locale", OUString("x-default"));
     121             :     }
     122             : 
     123          67 :     if (m_sModule.isEmpty())
     124             :         throw css::uno::RuntimeException(
     125             :                 OUString("The module dependent accelerator configuration service was initialized with an empty module identifier!"),
     126          67 :                 static_cast< ::cppu::OWeakObject* >(this));
     127          67 : }
     128             : 
     129         128 : ModuleAcceleratorConfiguration::~ModuleAcceleratorConfiguration()
     130             : {
     131         128 : }
     132             : 
     133          67 : void ModuleAcceleratorConfiguration::fillCache()
     134             : {
     135             :     {
     136          67 :         SolarMutexGuard g;
     137          67 :         m_sModuleCFG = m_sModule;
     138             :     }
     139             : 
     140             : #if 0
     141             :     // get current office locale ... but dont cache it.
     142             :     // Otherwise we must be listener on the configuration layer
     143             :     // which seems to superflous for this small implementation .-)
     144             :     // XXX: what is this good for? it was a comphelper::Locale but unused
     145             :     LanguageTag aLanguageTag(m_sLocale);
     146             : #endif
     147             : 
     148             :     // May be the current app module does not have any
     149             :     // accelerator config? Handle it gracefully :-)
     150             :     try
     151             :     {
     152          67 :         m_sGlobalOrModules = CFG_ENTRY_MODULES;
     153          67 :         XCUBasedAcceleratorConfiguration::reload();
     154             : 
     155          59 :         css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
     156          59 :         m_xCfgListener = new WeakChangesListener(this);
     157          59 :         xBroadcaster->addChangesListener(m_xCfgListener);
     158             :     }
     159           0 :     catch(const css::uno::RuntimeException&)
     160           0 :         { throw; }
     161           8 :     catch(const css::uno::Exception&)
     162             :         {}
     163          67 : }
     164             : 
     165             : // XComponent.dispose(),  #i120029#, to release the cyclic reference
     166             : 
     167          66 : void SAL_CALL ModuleAcceleratorConfiguration::dispose()
     168             :     throw(css::uno::RuntimeException, std::exception)
     169             : {
     170             :     try
     171             :     {
     172          66 :         css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
     173          66 :         if ( xBroadcaster.is() )
     174          66 :             xBroadcaster->removeChangesListener(static_cast< css::util::XChangesListener* >(this));
     175             :     }
     176           0 :     catch(const css::uno::RuntimeException&)
     177           0 :     { throw; }
     178           0 :     catch(const css::uno::Exception&)
     179             :     {}
     180          66 : }
     181             : 
     182             : }
     183             : 
     184             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     185          67 : com_sun_star_comp_framework_ModuleAcceleratorConfiguration_get_implementation(
     186             :     css::uno::XComponentContext *context,
     187             :     css::uno::Sequence<css::uno::Any> const &arguments)
     188             : {
     189          67 :     ModuleAcceleratorConfiguration *inst = new ModuleAcceleratorConfiguration(context, arguments);
     190          67 :     css::uno::XInterface *acquired_inst = cppu::acquire(inst);
     191             : 
     192          67 :     inst->fillCache();
     193             : 
     194          67 :     return acquired_inst;
     195             : }
     196             : 
     197             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11