LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/config - itemholder2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 56 66 84.8 %
Date: 2012-12-17 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 <svtools/accessibilityoptions.hxx>
      28             : #include <svtools/apearcfg.hxx>
      29             : #include <svtools/menuoptions.hxx>
      30             : #include <svtools/colorcfg.hxx>
      31             : #include <svtools/fontsubstconfig.hxx>
      32             : #include <svtools/helpopt.hxx>
      33             : #include <svtools/printoptions.hxx>
      34             : #include <unotools/options.hxx>
      35             : #include <svtools/miscopt.hxx>
      36             : 
      37             : 
      38             : #include <tools/debug.hxx>
      39             : 
      40             : namespace svtools {
      41             : //-----------------------------------------------
      42          72 : ItemHolder2::ItemHolder2()
      43          72 :     : ItemHolderMutexBase()
      44             : {
      45             :     try
      46             :     {
      47          72 :         css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
      48             :         css::uno::Reference< css::lang::XComponent > xCfg(
      49             :             css::configuration::theDefaultProvider::get( xContext ),
      50          72 :             css::uno::UNO_QUERY_THROW );
      51          72 :         xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
      52             :     }
      53           0 :     catch(const css::uno::RuntimeException&)
      54             :     {
      55           0 :         throw;
      56             :     }
      57             : #ifdef DBG_UTIL
      58             :     catch(const css::uno::Exception& rEx)
      59             :     {
      60             :         static sal_Bool bMessage = sal_True;
      61             :         if(bMessage)
      62             :         {
      63             :             bMessage = sal_False;
      64             :             ::rtl::OString sMsg("CreateInstance with arguments exception: ");
      65             :             sMsg += ::rtl::OString(rEx.Message.getStr(),
      66             :                         rEx.Message.getLength(),
      67             :                         RTL_TEXTENCODING_ASCII_US);
      68             :             OSL_FAIL(sMsg.getStr());
      69             :         }
      70             :     }
      71             : #else
      72           0 :     catch(css::uno::Exception&){}
      73             : #endif
      74          72 : }
      75             : 
      76             : //-----------------------------------------------
      77         216 : ItemHolder2::~ItemHolder2()
      78             : {
      79          72 :     impl_releaseAllItems();
      80         144 : }
      81             : 
      82             : //-----------------------------------------------
      83         256 : void ItemHolder2::holdConfigItem(EItem eItem)
      84             : {
      85         256 :     static ItemHolder2* pHolder = new ItemHolder2();
      86         256 :     pHolder->impl_addItem(eItem);
      87         256 : }
      88             : 
      89             : //-----------------------------------------------
      90          72 : void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&)
      91             :     throw(css::uno::RuntimeException)
      92             : {
      93          72 :     impl_releaseAllItems();
      94          72 : }
      95             : 
      96             : //-----------------------------------------------
      97         256 : void ItemHolder2::impl_addItem(EItem eItem)
      98             : {
      99         256 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     100             : 
     101         256 :     TItems::const_iterator pIt;
     102        1836 :     for (  pIt  = m_lItems.begin();
     103        1224 :            pIt != m_lItems.end()  ;
     104             :          ++pIt                    )
     105             :     {
     106         356 :         const TItemInfo& rInfo = *pIt;
     107         356 :         if (rInfo.eItem == eItem)
     108         256 :             return;
     109             :     }
     110             : 
     111         256 :     TItemInfo aNewItem;
     112         256 :     aNewItem.eItem = eItem;
     113         256 :     impl_newItem(aNewItem);
     114         256 :     if (aNewItem.pItem)
     115         256 :         m_lItems.push_back(aNewItem);
     116             : }
     117             : 
     118             : //-----------------------------------------------
     119         144 : void ItemHolder2::impl_releaseAllItems()
     120             : {
     121         144 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     122             : 
     123         144 :     TItems::iterator pIt;
     124        1200 :     for (  pIt  = m_lItems.begin();
     125         800 :            pIt != m_lItems.end()  ;
     126             :          ++pIt                    )
     127             :     {
     128         256 :         TItemInfo& rInfo = *pIt;
     129         256 :         impl_deleteItem(rInfo);
     130             :     }
     131         144 :     m_lItems.clear();
     132         144 : }
     133             : 
     134             : //-----------------------------------------------
     135         256 : void ItemHolder2::impl_newItem(TItemInfo& rItem)
     136             : {
     137         256 :     switch(rItem.eItem)
     138             :     {
     139             :         case E_ACCESSIBILITYOPTIONS :
     140          64 :             rItem.pItem = new SvtAccessibilityOptions();
     141          64 :             break;
     142             : 
     143             :         case E_APEARCFG :
     144             : // no ref count            rItem.pItem = new SvtTabAppearanceCfg();
     145           0 :             break;
     146             : 
     147             :         case E_COLORCFG :
     148          60 :             rItem.pItem = new ::svtools::ColorConfig();
     149          60 :             break;
     150             : 
     151             :         case E_FONTSUBSTCONFIG :
     152             : // no ref count            rItem.pItem = new SvtFontSubstConfig();
     153           0 :             break;
     154             : 
     155             :         case E_HELPOPTIONS :
     156          72 :             rItem.pItem = new SvtHelpOptions();
     157          72 :             break;
     158             : 
     159             :         case E_MENUOPTIONS :
     160           8 :             rItem.pItem = new SvtMenuOptions();
     161           8 :             break;
     162             : 
     163             :         case E_PRINTOPTIONS :
     164           0 :             rItem.pItem = new SvtPrinterOptions();
     165           0 :             break;
     166             : 
     167             :         case E_PRINTFILEOPTIONS :
     168           0 :             rItem.pItem = new SvtPrintFileOptions();
     169           0 :             break;
     170             : 
     171             :         case E_MISCOPTIONS :
     172          52 :             rItem.pItem = new SvtMiscOptions();
     173          52 :             break;
     174             : 
     175             :         default:
     176             :             OSL_ASSERT(false);
     177           0 :             break;
     178             :     }
     179         256 : }
     180             : 
     181             : //-----------------------------------------------
     182         256 : void ItemHolder2::impl_deleteItem(TItemInfo& rItem)
     183             : {
     184         256 :     if (rItem.pItem)
     185             :     {
     186         256 :         delete rItem.pItem;
     187         256 :         rItem.pItem = 0;
     188             :     }
     189         256 : }
     190             : 
     191             : } // namespace svtools
     192             : 
     193             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10