LCOV - code coverage report
Current view: top level - svl/source/config - itemholder2.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 55 0.0 %
Date: 2014-04-14 Functions: 0 9 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             : 
      21             : #include "itemholder2.hxx"
      22             : 
      23             : #include <comphelper/processfactory.hxx>
      24             : #include <com/sun/star/lang/XComponent.hpp>
      25             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      26             : 
      27             : #include <svl/cjkoptions.hxx>
      28             : #include <svl/ctloptions.hxx>
      29             : #include <svl/languageoptions.hxx>
      30             : #include <unotools/options.hxx>
      31             : 
      32             : #include <tools/debug.hxx>
      33             : 
      34           0 : ItemHolder2::ItemHolder2()
      35           0 :     : ItemHolderMutexBase()
      36             : {
      37             :     try
      38             :     {
      39           0 :         css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
      40           0 :         css::uno::Reference< css::lang::XComponent > xCfg( css::configuration::theDefaultProvider::get(xContext), css::uno::UNO_QUERY_THROW );
      41           0 :         xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
      42             :     }
      43           0 :     catch(const css::uno::RuntimeException&)
      44             :     {
      45           0 :         throw;
      46             :     }
      47             : #ifdef DBG_UTIL
      48             :     catch(const css::uno::Exception& rEx)
      49             :     {
      50             :         static bool bMessage = true;
      51             :         if(bMessage)
      52             :         {
      53             :             bMessage = false;
      54             :             OString sMsg("CreateInstance with arguments exception: ");
      55             :             sMsg += OString(rEx.Message.getStr(),
      56             :                         rEx.Message.getLength(),
      57             :                         RTL_TEXTENCODING_ASCII_US);
      58             :             OSL_FAIL(sMsg.getStr());
      59             :         }
      60             :     }
      61             : #else
      62           0 :     catch(css::uno::Exception&){}
      63             : #endif
      64           0 : }
      65             : 
      66           0 : ItemHolder2::~ItemHolder2()
      67             : {
      68           0 :     impl_releaseAllItems();
      69           0 : }
      70             : 
      71           0 : void ItemHolder2::holdConfigItem(EItem eItem)
      72             : {
      73           0 :     static ItemHolder2* pHolder = new ItemHolder2();
      74           0 :     pHolder->impl_addItem(eItem);
      75           0 : }
      76             : 
      77           0 : void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
      78             :     throw(css::uno::RuntimeException, std::exception)
      79             : {
      80           0 :     impl_releaseAllItems();
      81           0 : }
      82             : 
      83           0 : void ItemHolder2::impl_addItem(EItem eItem)
      84             : {
      85           0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      86             : 
      87           0 :     TItems::const_iterator pIt;
      88           0 :     for (  pIt  = m_lItems.begin();
      89           0 :            pIt != m_lItems.end()  ;
      90             :          ++pIt                    )
      91             :     {
      92           0 :         const TItemInfo& rInfo = *pIt;
      93           0 :         if (rInfo.eItem == eItem)
      94           0 :             return;
      95             :     }
      96             : 
      97           0 :     TItemInfo aNewItem;
      98           0 :     aNewItem.eItem = eItem;
      99           0 :     impl_newItem(aNewItem);
     100           0 :     if (aNewItem.pItem)
     101           0 :         m_lItems.push_back(aNewItem);
     102             : }
     103             : 
     104           0 : void ItemHolder2::impl_releaseAllItems()
     105             : {
     106           0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     107             : 
     108           0 :     TItems::iterator pIt;
     109           0 :     for (  pIt  = m_lItems.begin();
     110           0 :            pIt != m_lItems.end()  ;
     111             :          ++pIt                    )
     112             :     {
     113           0 :         TItemInfo& rInfo = *pIt;
     114           0 :         impl_deleteItem(rInfo);
     115             :     }
     116           0 :     m_lItems.clear();
     117           0 : }
     118             : 
     119           0 : void ItemHolder2::impl_newItem(TItemInfo& rItem)
     120             : {
     121           0 :     switch(rItem.eItem)
     122             :     {
     123             :         case E_CJKOPTIONS :
     124           0 :             rItem.pItem = new SvtCJKOptions();
     125           0 :             break;
     126             : 
     127             :         case E_CTLOPTIONS :
     128           0 :             rItem.pItem = new SvtCTLOptions();
     129           0 :             break;
     130             : 
     131             :         case E_LANGUAGEOPTIONS :
     132             : // capsulate CTL and CJL options !            rItem.pItem = new SvtLanguageOptions();
     133           0 :             break;
     134             : 
     135             :         default:
     136             :             OSL_ASSERT(false);
     137           0 :             break;
     138             :     }
     139           0 : }
     140             : 
     141           0 : void ItemHolder2::impl_deleteItem(TItemInfo& rItem)
     142             : {
     143           0 :     if (rItem.pItem)
     144             :     {
     145           0 :         delete rItem.pItem;
     146           0 :         rItem.pItem = 0;
     147             :     }
     148           0 : }
     149             : 
     150             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10