LCOV - code coverage report
Current view: top level - libreoffice/framework/source/xml - acceleratorconfigurationwriter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 53 0.0 %
Date: 2012-12-27 Functions: 0 5 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 <xml/acceleratorconfigurationwriter.hxx>
      21             : 
      22             : #include <acceleratorconst.h>
      23             : #include <threadhelp/readguard.hxx>
      24             : 
      25             : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
      26             : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      27             : #include <com/sun/star/awt/KeyModifier.hpp>
      28             : 
      29             : #include <vcl/svapp.hxx>
      30             : #include <rtl/ustrbuf.hxx>
      31             : 
      32             : #include <comphelper/attributelist.hxx>
      33             : 
      34             : 
      35             : namespace framework{
      36             : 
      37             : 
      38             : //-----------------------------------------------
      39           0 : AcceleratorConfigurationWriter::AcceleratorConfigurationWriter(const AcceleratorCache&                                       rContainer,
      40             :                                                                const css::uno::Reference< css::xml::sax::XDocumentHandler >& xConfig   )
      41           0 :     : ThreadHelpBase(&Application::GetSolarMutex())
      42             :     , m_xConfig     (xConfig                      )
      43           0 :     , m_rContainer  (rContainer                   )
      44             : {
      45           0 : }
      46             : 
      47             : //-----------------------------------------------
      48           0 : AcceleratorConfigurationWriter::~AcceleratorConfigurationWriter()
      49             : {
      50           0 : }
      51             : 
      52             : //-----------------------------------------------
      53           0 : void AcceleratorConfigurationWriter::flush()
      54             : {
      55             :     // SAFE -> ----------------------------------
      56           0 :     ReadGuard aReadLock(m_aLock);
      57             : 
      58           0 :     css::uno::Reference< css::xml::sax::XDocumentHandler >         xCFG        = m_xConfig;
      59           0 :     css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > xExtendedCFG(m_xConfig, css::uno::UNO_QUERY_THROW);
      60             : 
      61           0 :     aReadLock.unlock();
      62             :     // <- SAFE ----------------------------------
      63             : 
      64             :     // prepare attribute list
      65           0 :     ::comphelper::AttributeList* pAttribs = new ::comphelper::AttributeList;
      66           0 :     css::uno::Reference< css::xml::sax::XAttributeList > xAttribs(static_cast< css::xml::sax::XAttributeList* >(pAttribs), css::uno::UNO_QUERY);
      67             : 
      68           0 :     pAttribs->AddAttribute(AL_XMLNS_ACCEL, ATTRIBUTE_TYPE_CDATA, NS_XMLNS_ACCEL);
      69           0 :     pAttribs->AddAttribute(AL_XMLNS_XLINK, ATTRIBUTE_TYPE_CDATA, NS_XMLNS_XLINK);
      70             : 
      71             :     // generate xml
      72           0 :     xCFG->startDocument();
      73             : 
      74           0 :     xExtendedCFG->unknown(DOCTYPE_ACCELERATORS);
      75           0 :     xCFG->ignorableWhitespace(::rtl::OUString());
      76             : 
      77           0 :     xCFG->startElement(AL_ELEMENT_ACCELERATORLIST, xAttribs);
      78           0 :     xCFG->ignorableWhitespace(::rtl::OUString());
      79             : 
      80             :     // TODO think about threadsafe using of cache
      81           0 :     AcceleratorCache::TKeyList                 lKeys = m_rContainer.getAllKeys();
      82           0 :     AcceleratorCache::TKeyList::const_iterator pKey  ;
      83           0 :     for (  pKey  = lKeys.begin();
      84           0 :            pKey != lKeys.end()  ;
      85             :          ++pKey                 )
      86             :     {
      87           0 :         const css::awt::KeyEvent& rKey     = *pKey;
      88           0 :         const ::rtl::OUString&    rCommand = m_rContainer.getCommandByKey(rKey);
      89           0 :         impl_ts_writeKeyCommandPair(rKey, rCommand, xCFG);
      90           0 :     }
      91             : 
      92             :     /* TODO write key-command list
      93             :     std::vector< SfxAcceleratorConfigItem>::const_iterator p;
      94             :     for ( p = m_aWriteAcceleratorList.begin(); p != m_aWriteAcceleratorList.end(); p++ )
      95             :         WriteAcceleratorItem( *p );
      96             :     */
      97             : 
      98           0 :     xCFG->ignorableWhitespace(::rtl::OUString());
      99           0 :     xCFG->endElement(AL_ELEMENT_ACCELERATORLIST);
     100           0 :     xCFG->ignorableWhitespace(::rtl::OUString());
     101           0 :     xCFG->endDocument();
     102           0 : }
     103             : 
     104             : //-----------------------------------------------
     105           0 : void AcceleratorConfigurationWriter::impl_ts_writeKeyCommandPair(const css::awt::KeyEvent&                                     aKey    ,
     106             :                                                                  const ::rtl::OUString&                                        sCommand,
     107             :                                                                  const css::uno::Reference< css::xml::sax::XDocumentHandler >& xConfig )
     108             : {
     109           0 :     ::comphelper::AttributeList* pAttribs = new ::comphelper::AttributeList;
     110           0 :     css::uno::Reference< css::xml::sax::XAttributeList > xAttribs (static_cast< css::xml::sax::XAttributeList* >(pAttribs) , css::uno::UNO_QUERY_THROW);
     111             : 
     112           0 :     ::rtl::OUString sKey = m_rKeyMapping->mapCodeToIdentifier(aKey.KeyCode);
     113             :     // TODO check if key is empty!
     114             : 
     115           0 :     pAttribs->AddAttribute(AL_ATTRIBUTE_KEYCODE, ATTRIBUTE_TYPE_CDATA, sKey    );
     116           0 :     pAttribs->AddAttribute(AL_ATTRIBUTE_URL    , ATTRIBUTE_TYPE_CDATA, sCommand);
     117             : 
     118           0 :     if ((aKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT)
     119           0 :         pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_SHIFT, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString("true"));
     120             : 
     121           0 :     if ((aKey.Modifiers & css::awt::KeyModifier::MOD1) == css::awt::KeyModifier::MOD1)
     122           0 :         pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_MOD1, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString("true"));
     123             : 
     124           0 :     if ((aKey.Modifiers & css::awt::KeyModifier::MOD2) == css::awt::KeyModifier::MOD2)
     125           0 :         pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_MOD2, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString("true"));
     126             : 
     127           0 :     if ((aKey.Modifiers & css::awt::KeyModifier::MOD3) == css::awt::KeyModifier::MOD3)
     128           0 :         pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_MOD3, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString("true"));
     129             : 
     130           0 :     xConfig->ignorableWhitespace(::rtl::OUString());
     131           0 :     xConfig->startElement(AL_ELEMENT_ITEM, xAttribs);
     132           0 :     xConfig->ignorableWhitespace(::rtl::OUString());
     133           0 :     xConfig->endElement(AL_ELEMENT_ITEM);
     134           0 :     xConfig->ignorableWhitespace(::rtl::OUString());
     135           0 : }
     136             : 
     137             : } // namespace framework
     138             : 
     139             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10