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

Generated by: LCOV version 1.10