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

Generated by: LCOV version 1.11