LCOV - code coverage report
Current view: top level - unotools/source/config - itemholder1.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 84 96 87.5 %
Date: 2014-11-03 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             : #include "itemholder1.hxx"
      21             : 
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <com/sun/star/lang/XComponent.hpp>
      24             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      25             : 
      26             : #include <unotools/misccfg.hxx>
      27             : #include <unotools/useroptions.hxx>
      28             : #include <unotools/cmdoptions.hxx>
      29             : #include <unotools/compatibility.hxx>
      30             : #include <unotools/defaultoptions.hxx>
      31             : #include <unotools/dynamicmenuoptions.hxx>
      32             : #include <unotools/eventcfg.hxx>
      33             : #include <unotools/extendedsecurityoptions.hxx>
      34             : #include <unotools/fltrcfg.hxx>
      35             : #include <unotools/fontoptions.hxx>
      36             : #include <unotools/historyoptions.hxx>
      37             : #include <unotools/lingucfg.hxx>
      38             : #include <unotools/localisationoptions.hxx>
      39             : #include <unotools/moduleoptions.hxx>
      40             : #include <unotools/pathoptions.hxx>
      41             : #include <unotools/printwarningoptions.hxx>
      42             : #include <unotools/optionsdlg.hxx>
      43             : #include <unotools/saveopt.hxx>
      44             : #include <unotools/searchopt.hxx>
      45             : #include <unotools/securityoptions.hxx>
      46             : #include <unotools/viewoptions.hxx>
      47             : #include <unotools/xmlaccelcfg.hxx>
      48             : #include <unotools/options.hxx>
      49             : #include <unotools/syslocaleoptions.hxx>
      50             : 
      51         375 : ItemHolder1::ItemHolder1()
      52         375 :     : ItemHolderMutexBase()
      53             : {
      54             :     try
      55             :     {
      56         375 :         css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
      57             :         css::uno::Reference< css::lang::XComponent > xCfg(
      58             :             css::configuration::theDefaultProvider::get( xContext ),
      59         750 :             css::uno::UNO_QUERY_THROW );
      60         750 :         xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this));
      61             :     }
      62             : #ifdef DBG_UTIL
      63             :     catch(const css::uno::Exception& rEx)
      64             :     {
      65             :         static bool bMessage = true;
      66             :         if(bMessage)
      67             :         {
      68             :             bMessage = false;
      69             :             OString sMsg("CreateInstance with arguments exception: ");
      70             :             sMsg += OString(rEx.Message.getStr(),
      71             :                         rEx.Message.getLength(),
      72             :                         RTL_TEXTENCODING_ASCII_US);
      73             :             OSL_FAIL(sMsg.getStr());
      74             :         }
      75             :     }
      76             : #else
      77           0 :     catch(css::uno::Exception&){}
      78             : #endif
      79         375 : }
      80             : 
      81        1113 : ItemHolder1::~ItemHolder1()
      82             : {
      83         371 :     impl_releaseAllItems();
      84         742 : }
      85             : 
      86        4442 : void ItemHolder1::holdConfigItem(EItem eItem)
      87             : {
      88        4442 :     static ItemHolder1* pHolder = new ItemHolder1();
      89        4442 :     pHolder->impl_addItem(eItem);
      90        4442 : }
      91             : 
      92         371 : void SAL_CALL ItemHolder1::disposing(const css::lang::EventObject&)
      93             :     throw(css::uno::RuntimeException, std::exception)
      94             : {
      95         371 :     css::uno::Reference< css::uno::XInterface > xSelfHold(static_cast< css::lang::XEventListener* >(this), css::uno::UNO_QUERY);
      96         371 :     impl_releaseAllItems();
      97         371 : }
      98             : 
      99        4442 : void ItemHolder1::impl_addItem(EItem eItem)
     100             : {
     101        4442 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     102             : 
     103        4442 :     TItems::const_iterator pIt;
     104      101823 :     for (  pIt  = m_lItems.begin();
     105       67882 :            pIt != m_lItems.end();
     106             :          ++pIt                    )
     107             :     {
     108       29499 :         const TItemInfo& rInfo = *pIt;
     109       29499 :         if (rInfo.eItem == eItem)
     110        4442 :             return;
     111             :     }
     112             : 
     113        4442 :     TItemInfo aNewItem;
     114        4442 :     aNewItem.eItem = eItem;
     115        4442 :     impl_newItem(aNewItem);
     116        4442 :     if (aNewItem.pItem)
     117        4024 :         m_lItems.push_back(aNewItem);
     118             : }
     119             : 
     120         742 : void ItemHolder1::impl_releaseAllItems()
     121             : {
     122         742 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     123             : 
     124         742 :     TItems::iterator pIt;
     125       14124 :     for (  pIt  = m_lItems.begin();
     126        9416 :            pIt != m_lItems.end();
     127             :          ++pIt                    )
     128             :     {
     129        3966 :         TItemInfo& rInfo = *pIt;
     130        3966 :         impl_deleteItem(rInfo);
     131             :     }
     132         742 :     m_lItems.clear();
     133         742 : }
     134             : 
     135        4442 : void ItemHolder1::impl_newItem(TItemInfo& rItem)
     136             : {
     137        4442 :     switch(rItem.eItem)
     138             :     {
     139             :         case E_CMDOPTIONS :
     140         309 :             rItem.pItem = new SvtCommandOptions();
     141         309 :             break;
     142             : 
     143             :         case E_COMPATIBILITY :
     144          86 :             rItem.pItem = new SvtCompatibilityOptions();
     145          86 :             break;
     146             : 
     147             :         case E_DEFAULTOPTIONS :
     148           0 :             rItem.pItem = new SvtDefaultOptions();
     149           0 :             break;
     150             : 
     151             :         case E_DYNAMICMENUOPTIONS :
     152          64 :             rItem.pItem = new SvtDynamicMenuOptions();
     153          64 :             break;
     154             : 
     155             :         case E_EVENTCFG :
     156             :             //rItem.pItem = new GlobalEventConfig();
     157         418 :             break;
     158             : 
     159             :         case E_EXTENDEDSECURITYOPTIONS :
     160           0 :             rItem.pItem = new SvtExtendedSecurityOptions();
     161           0 :             break;
     162             : 
     163             :         case E_FLTRCFG :
     164             : // no ref count            rItem.pItem = new SvtFilterOptions();
     165           0 :             break;
     166             : 
     167             :         case E_FONTOPTIONS :
     168          52 :             rItem.pItem = new SvtFontOptions();
     169          52 :             break;
     170             : 
     171             :         case E_HISTORYOPTIONS :
     172         303 :             rItem.pItem = new SvtHistoryOptions();
     173         303 :             break;
     174             : 
     175             :         case E_LINGUCFG :
     176         174 :             rItem.pItem = new SvtLinguConfig();
     177         174 :             break;
     178             : 
     179             :         case E_LOCALISATIONOPTIONS :
     180         303 :             rItem.pItem = new SvtLocalisationOptions();
     181         303 :             break;
     182             : 
     183             :         case E_MODULEOPTIONS :
     184         180 :             rItem.pItem = new SvtModuleOptions();
     185         180 :             break;
     186             : 
     187             :         case E_OPTIONSDLGOPTIONS :
     188           0 :             rItem.pItem = new SvtOptionsDialogOptions();
     189           0 :             break;
     190             : 
     191             :         case E_PATHOPTIONS :
     192         307 :             rItem.pItem = new SvtPathOptions();
     193         307 :             break;
     194             : 
     195             :         case E_PRINTWARNINGOPTIONS :
     196           0 :             rItem.pItem = new SvtPrintWarningOptions();
     197           0 :             break;
     198             : 
     199             :         case E_MISCCFG :
     200         182 :             rItem.pItem = new ::utl::MiscCfg();
     201         182 :             break;
     202             : 
     203             :         case E_SAVEOPTIONS :
     204         150 :             rItem.pItem = new SvtSaveOptions();
     205         150 :             break;
     206             : 
     207             :         case E_SEARCHOPT :
     208             : // no ref count            rItem.pItem = new SvtSearchOptions();
     209           0 :             break;
     210             : 
     211             :         case E_SECURITYOPTIONS :
     212         199 :             rItem.pItem = new SvtSecurityOptions();
     213         199 :             break;
     214             : 
     215             :         case E_VIEWOPTIONS_DIALOG :
     216         303 :             rItem.pItem = new SvtViewOptions(E_DIALOG, OUString());
     217         303 :             break;
     218             : 
     219             :         case E_VIEWOPTIONS_TABDIALOG :
     220         303 :             rItem.pItem = new SvtViewOptions(E_TABDIALOG, OUString());
     221         303 :             break;
     222             : 
     223             :         case E_VIEWOPTIONS_TABPAGE :
     224         303 :             rItem.pItem = new SvtViewOptions(E_TABPAGE, OUString());
     225         303 :             break;
     226             : 
     227             :         case E_VIEWOPTIONS_WINDOW :
     228         303 :             rItem.pItem = new SvtViewOptions(E_WINDOW, OUString());
     229         303 :             break;
     230             : 
     231             :         case E_USEROPTIONS :
     232         128 :             rItem.pItem = new SvtUserOptions();
     233         128 :             break;
     234             : 
     235             :         case E_SYSLOCALEOPTIONS :
     236         375 :             rItem.pItem = new SvtSysLocaleOptions();
     237         375 :             break;
     238             : 
     239             :         default:
     240             :             OSL_FAIL( "unknown item type" );
     241           0 :             break;
     242             :     }
     243        4442 : }
     244             : 
     245        3966 : void ItemHolder1::impl_deleteItem(TItemInfo& rItem)
     246             : {
     247        3966 :     if (rItem.pItem)
     248             :     {
     249        3966 :         delete rItem.pItem;
     250        3966 :         rItem.pItem = 0;
     251             :     }
     252        3966 : }
     253             : 
     254             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10