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

Generated by: LCOV version 1.10