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

Generated by: LCOV version 1.11