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

Generated by: LCOV version 1.10