LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/unotools/source/config - historyoptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 137 241 56.8 %
Date: 2013-07-09 Functions: 11 15 73.3 %
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 <unotools/historyoptions.hxx>
      22             : #include <unotools/configmgr.hxx>
      23             : #include <unotools/configitem.hxx>
      24             : #include <com/sun/star/uno/Any.hxx>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : 
      27             : #include <cassert>
      28             : #include <deque>
      29             : #include <algorithm>
      30             : 
      31             : #include <rtl/logfile.hxx>
      32             : #include "itemholder1.hxx"
      33             : 
      34             : #include <com/sun/star/beans/XPropertySet.hpp>
      35             : #include <com/sun/star/container/XNameAccess.hpp>
      36             : #include <com/sun/star/container/XNameContainer.hpp>
      37             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      38             : #include <comphelper/configurationhelper.hxx>
      39             : #include <comphelper/processfactory.hxx>
      40             : 
      41             : using namespace ::std     ;
      42             : using namespace ::utl     ;
      43             : using namespace ::rtl     ;
      44             : using namespace ::osl     ;
      45             : using namespace ::com::sun::star::uno ;
      46             : using namespace ::com::sun::star::beans ;
      47             : 
      48             : namespace {
      49             :     static const ::sal_Int32 s_nOffsetURL               = 0;
      50             :     static const ::sal_Int32 s_nOffsetFilter            = 1;
      51             :     static const ::sal_Int32 s_nOffsetTitle             = 2;
      52             :     static const ::sal_Int32 s_nOffsetPassword          = 3;
      53             : 
      54             :     const char s_sCommonHistory[] = "org.openoffice.Office.Common/History";
      55             :     const char s_sHistories[] = "org.openoffice.Office.Histories/Histories";
      56             :     const char s_sPickListSize[] = "PickListSize";
      57             :     const char s_sURLHistorySize[] = "Size";
      58             :     const char s_sHelpBookmarksSize[] = "HelpBookmarkSize";
      59             :     const char s_sPickList[] = "PickList";
      60             :     const char s_sURLHistory[] = "URLHistory";
      61             :     const char s_sHelpBookmarks[] = "HelpBookmarks";
      62             :     const char s_sItemList[] = "ItemList";
      63             :     const char s_sOrderList[] = "OrderList";
      64             :     const char s_sHistoryItemRef[] = "HistoryItemRef";
      65             :     const char s_sFilter[] = "Filter";
      66             :     const char s_sTitle[] = "Title";
      67             :     const char s_sPassword[] = "Password";
      68             : }
      69             : 
      70             : struct IMPL_THistoryItem
      71             : {
      72             :     IMPL_THistoryItem()
      73             :     {
      74             :     }
      75             : 
      76             :     IMPL_THistoryItem( const OUString& sNewURL   ,
      77             :         const OUString& sNewFilter  ,
      78             :         const OUString& sNewTitle  ,
      79             :         const OUString& sNewPassword )
      80             :     {
      81             :         sURL  = sNewURL  ;
      82             :         sFilter  = sNewFilter ;
      83             :         sTitle  = sNewTitle  ;
      84             :         sPassword = sNewPassword ;
      85             :     }
      86             : 
      87             :     sal_Bool operator==( const OUString& sSearchedURL ) const
      88             :     {
      89             :         return( sURL == sSearchedURL );
      90             :     }
      91             : 
      92             :     OUString sURL  ;
      93             :     OUString sFilter  ;
      94             :     OUString sTitle  ;
      95             :     OUString sPassword ;
      96             : };
      97             : 
      98             : //*****************************************************************************************************************
      99             : //  class SvtHistoryOptions_Impl
     100             : //  redesigned
     101             : //*****************************************************************************************************************
     102             : class SvtHistoryOptions_Impl
     103             : {
     104             : public:
     105             :     SvtHistoryOptions_Impl();
     106             :     ~SvtHistoryOptions_Impl();
     107             : 
     108             :     sal_uInt32 GetSize( EHistoryType eHistory );
     109             :     void Clear( EHistoryType eHistory );
     110             :     Sequence< Sequence< PropertyValue > > GetList( EHistoryType eHistory );
     111             :     void                                  AppendItem(       EHistoryType eHistory ,
     112             :         const OUString&    sURL     ,
     113             :         const OUString&    sFilter  ,
     114             :         const OUString&    sTitle   ,
     115             :         const OUString&    sPassword );
     116             : 
     117             : private:
     118             :     void impl_truncateList (EHistoryType eHistory, sal_uInt32 nSize);
     119             : 
     120             : private:
     121             :     css::uno::Reference< css::container::XNameAccess > m_xCfg;
     122             :     css::uno::Reference< css::container::XNameAccess > m_xCommonXCU;
     123             : };
     124             : 
     125             : //*****************************************************************************************************************
     126             : //  constructor
     127             : //*****************************************************************************************************************
     128         133 : SvtHistoryOptions_Impl::SvtHistoryOptions_Impl()
     129             : {
     130             :     try
     131             :     {
     132         266 :         m_xCfg = Reference< css::container::XNameAccess > (
     133             :             ::comphelper::ConfigurationHelper::openConfig(
     134             :             ::comphelper::getProcessComponentContext(),
     135             :             OUString(s_sHistories),
     136             :             ::comphelper::ConfigurationHelper::E_STANDARD),
     137         133 :             css::uno::UNO_QUERY );
     138             : 
     139         266 :         m_xCommonXCU = Reference< css::container::XNameAccess > (
     140             :             ::comphelper::ConfigurationHelper::openConfig(
     141             :             ::comphelper::getProcessComponentContext(),
     142             :             OUString(s_sCommonHistory),
     143             :             ::comphelper::ConfigurationHelper::E_STANDARD),
     144         133 :             css::uno::UNO_QUERY );
     145             :     }
     146           0 :     catch(const css::uno::Exception& ex)
     147             :     {
     148           0 :         m_xCfg.clear();
     149           0 :         m_xCommonXCU.clear();
     150             : 
     151             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     152             :     }
     153         133 : }
     154             : 
     155             : //*****************************************************************************************************************
     156             : //  destructor
     157             : //*****************************************************************************************************************
     158         132 : SvtHistoryOptions_Impl::~SvtHistoryOptions_Impl()
     159             : {
     160         132 : }
     161             : 
     162             : //*****************************************************************************************************************
     163             : //  public method
     164             : //  Attention: We return the max. size of our internal lists - That is the capacity not the size!
     165             : //*****************************************************************************************************************
     166        1361 : sal_uInt32 SvtHistoryOptions_Impl::GetSize( EHistoryType eHistory )
     167             : {
     168        1361 :     css::uno::Reference< css::beans::XPropertySet >  xListAccess(m_xCommonXCU, css::uno::UNO_QUERY);
     169             : 
     170        1361 :     if (!xListAccess.is())
     171           0 :         return 0;
     172             : 
     173        1361 :     sal_uInt32 nSize = 0  ;
     174             : 
     175             :     try
     176             :     {
     177        1361 :         switch( eHistory )
     178             :         {
     179             :         case ePICKLIST:
     180        1279 :             xListAccess->getPropertyValue(OUString(s_sPickListSize)) >>= nSize;
     181        1279 :             break;
     182             : 
     183             :         case eHISTORY:
     184          82 :             xListAccess->getPropertyValue(OUString(s_sURLHistorySize)) >>= nSize;
     185          82 :             break;
     186             : 
     187             :         case eHELPBOOKMARKS:
     188           0 :             xListAccess->getPropertyValue(OUString(s_sHelpBookmarksSize)) >>= nSize;
     189           0 :             break;
     190             : 
     191             :         default:
     192           0 :             break;
     193             :         }
     194             :     }
     195           0 :     catch(const css::uno::Exception& ex)
     196             :     {
     197             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     198             :     }
     199             : 
     200        1361 :     return nSize;
     201             : }
     202             : 
     203             : //*****************************************************************************************************************
     204         614 : void SvtHistoryOptions_Impl::impl_truncateList ( EHistoryType eHistory, sal_uInt32 nSize )
     205             : {
     206         614 :     css::uno::Reference< css::container::XNameAccess >    xList;
     207        1228 :     css::uno::Reference< css::container::XNameContainer > xItemList;
     208        1228 :     css::uno::Reference< css::container::XNameContainer > xOrderList;
     209        1228 :     css::uno::Reference< css::beans::XPropertySet >       xSet;
     210             : 
     211             :     try
     212             :     {
     213         614 :         switch( eHistory )
     214             :         {
     215             :         case ePICKLIST:
     216         573 :             m_xCfg->getByName(OUString(s_sPickList)) >>= xList;
     217         573 :             break;
     218             : 
     219             :         case eHISTORY:
     220          41 :             m_xCfg->getByName(OUString(s_sURLHistory)) >>= xList;
     221          41 :             break;
     222             : 
     223             :         case eHELPBOOKMARKS:
     224           0 :             m_xCfg->getByName(OUString(s_sHelpBookmarks)) >>= xList;
     225           0 :             break;
     226             : 
     227             :         default:
     228           0 :             break;
     229             :         }
     230             : 
     231             :         // If too much items in current list ...
     232             :         // truncate the oldest items BEFORE you set the new one.
     233         614 :         if ( ! xList.is())
     234         614 :             return;
     235             : 
     236         614 :         xList->getByName(OUString(s_sOrderList)) >>= xOrderList;
     237         614 :         xList->getByName(OUString(s_sItemList))  >>= xItemList;
     238             : 
     239         614 :         const sal_uInt32 nLength = xOrderList->getElementNames().getLength();
     240         614 :         if (nSize < nLength)
     241             :         {
     242           0 :             for (sal_uInt32 i=nLength-1; i>=nSize; --i)
     243             :             {
     244           0 :                 OUString sTmp;
     245           0 :                 const OUString sRemove = OUString::valueOf((sal_Int32)i);
     246           0 :                 xOrderList->getByName(sRemove) >>= xSet;
     247           0 :                 xSet->getPropertyValue(OUString(s_sHistoryItemRef)) >>= sTmp;
     248           0 :                 xItemList->removeByName(sTmp);
     249           0 :                 xOrderList->removeByName(sRemove);
     250           0 :             }
     251             : 
     252           0 :             ::comphelper::ConfigurationHelper::flush(m_xCfg);
     253             :         }
     254             :     }
     255           0 :     catch(const css::uno::Exception& ex)
     256             :     {
     257             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     258         614 :     }
     259             : }
     260             : 
     261             : //*****************************************************************************************************************
     262             : //  public method
     263             : //  Clear specified history list
     264             : //*****************************************************************************************************************
     265           0 : void SvtHistoryOptions_Impl::Clear( EHistoryType eHistory )
     266             : {
     267           0 :     css::uno::Reference< css::container::XNameAccess >    xListAccess;
     268           0 :     css::uno::Reference< css::container::XNameContainer > xNode;
     269           0 :     Sequence< OUString >                           lOrders;
     270             : 
     271             :     try
     272             :     {
     273           0 :         switch( eHistory )
     274             :         {
     275             :         case ePICKLIST:
     276             :             {
     277           0 :                 m_xCfg->getByName(OUString(s_sPickList)) >>= xListAccess;
     278           0 :                 break;
     279             :             }
     280             : 
     281             :         case eHISTORY:
     282             :             {
     283           0 :                 m_xCfg->getByName(OUString(s_sURLHistory)) >>= xListAccess;
     284           0 :                 break;
     285             :             }
     286             : 
     287             :         case eHELPBOOKMARKS:
     288             :             {
     289           0 :                 m_xCfg->getByName(OUString(s_sHelpBookmarks)) >>= xListAccess;
     290           0 :                 break;
     291             :             }
     292             : 
     293             :         default:
     294           0 :             break;
     295             :         }
     296             : 
     297           0 :         if (xListAccess.is())
     298             :         {
     299             :             // clear ItemList
     300           0 :             xListAccess->getByName(OUString(s_sItemList))  >>= xNode  ;
     301           0 :             lOrders = xNode->getElementNames();
     302           0 :             const sal_Int32 nLength = lOrders.getLength();
     303           0 :             for(sal_Int32 i=0; i<nLength; ++i)
     304           0 :                 xNode->removeByName(lOrders[i]);
     305             : 
     306             :             // clear OrderList
     307           0 :             xListAccess->getByName(OUString(s_sOrderList)) >>= xNode ;
     308           0 :             lOrders = xNode->getElementNames();
     309           0 :             for(sal_Int32 j=0; j<nLength; ++j)
     310           0 :                 xNode->removeByName(lOrders[j]);
     311             : 
     312           0 :             ::comphelper::ConfigurationHelper::flush(m_xCfg);
     313             :         }
     314             :     }
     315           0 :     catch(const css::uno::Exception& ex)
     316             :     {
     317             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     318           0 :     }
     319           0 : }
     320             : 
     321             : //*****************************************************************************************************************
     322             : //  public method
     323             : //  get a sequence list from the items
     324             : //*****************************************************************************************************************
     325           0 : Sequence< Sequence< PropertyValue > > SvtHistoryOptions_Impl::GetList( EHistoryType eHistory )
     326             : {
     327           0 :     impl_truncateList (eHistory, GetSize (eHistory));
     328             : 
     329           0 :     Sequence< Sequence< PropertyValue > > seqReturn; // Set default return value.
     330           0 :     Sequence< PropertyValue >             seqProperties( 4 );
     331           0 :     Sequence< OUString >           lOrders;
     332             : 
     333           0 :     css::uno::Reference< css::container::XNameAccess > xListAccess;
     334           0 :     css::uno::Reference< css::container::XNameAccess > xItemList;
     335           0 :     css::uno::Reference< css::container::XNameAccess > xOrderList;
     336           0 :     css::uno::Reference< css::beans::XPropertySet >    xSet;
     337             : 
     338           0 :     seqProperties[s_nOffsetURL       ].Name = HISTORY_PROPERTYNAME_URL;
     339           0 :     seqProperties[s_nOffsetFilter    ].Name = HISTORY_PROPERTYNAME_FILTER;
     340           0 :     seqProperties[s_nOffsetTitle     ].Name = HISTORY_PROPERTYNAME_TITLE;
     341           0 :     seqProperties[s_nOffsetPassword  ].Name = HISTORY_PROPERTYNAME_PASSWORD;
     342             : 
     343             :     try
     344             :     {
     345           0 :         switch( eHistory )
     346             :         {
     347             :         case ePICKLIST:
     348             :             {
     349           0 :                 m_xCfg->getByName(OUString(s_sPickList)) >>= xListAccess;
     350           0 :                 break;
     351             :             }
     352             : 
     353             :         case eHISTORY:
     354             :             {
     355           0 :                 m_xCfg->getByName(OUString(s_sURLHistory)) >>= xListAccess;
     356           0 :                 break;
     357             :             }
     358             : 
     359             :         case eHELPBOOKMARKS:
     360             :             {
     361           0 :                 m_xCfg->getByName(OUString(s_sHelpBookmarks)) >>= xListAccess;
     362           0 :                 break;
     363             :             }
     364             : 
     365             :         default:
     366           0 :             break;
     367             :         }
     368             : 
     369           0 :         if (xListAccess.is())
     370             :         {
     371           0 :             xListAccess->getByName(OUString(s_sItemList))  >>= xItemList;
     372           0 :             xListAccess->getByName(OUString(s_sOrderList)) >>= xOrderList;
     373             : 
     374           0 :             const sal_Int32 nLength = xOrderList->getElementNames().getLength();
     375           0 :             Sequence< Sequence< PropertyValue > > aRet(nLength);
     376           0 :             sal_Int32 nCount = 0;
     377             : 
     378           0 :             for(sal_Int32 nItem=0; nItem<nLength; ++nItem)
     379             :             {
     380             :                 try
     381             :                 {
     382           0 :                     OUString sUrl;
     383           0 :                     xOrderList->getByName(OUString::valueOf(nItem)) >>= xSet;
     384           0 :                     xSet->getPropertyValue(OUString(s_sHistoryItemRef)) >>= sUrl;
     385             : 
     386           0 :                     xItemList->getByName(sUrl) >>= xSet;
     387           0 :                     seqProperties[s_nOffsetURL  ].Value <<= sUrl;
     388           0 :                     xSet->getPropertyValue(OUString(s_sFilter))   >>= seqProperties[s_nOffsetFilter   ].Value;
     389           0 :                     xSet->getPropertyValue(OUString(s_sTitle))    >>= seqProperties[s_nOffsetTitle    ].Value;
     390           0 :                     xSet->getPropertyValue(OUString(s_sPassword)) >>= seqProperties[s_nOffsetPassword ].Value;
     391           0 :                     aRet[nCount++] = seqProperties;
     392             :                 }
     393           0 :                 catch(const css::uno::Exception& ex)
     394             :                 {
     395             :                     // <https://bugs.freedesktop.org/show_bug.cgi?id=46074>
     396             :                     // "FILEOPEN: No Recent Documents..." discusses a problem
     397             :                     // with corrupted /org.openoffice.Office/Histories/Histories
     398             :                     // configuration items; to work around that problem, simply
     399             :                     // ignore such corrupted individual items here, so that at
     400             :                     // least newly added items are successfully reported back
     401             :                     // from this function:
     402             :                     SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     403             :                 }
     404             :             }
     405             :             assert(nCount <= nLength);
     406           0 :             aRet.realloc(nCount);
     407           0 :             seqReturn = aRet;
     408             :         }
     409             :     }
     410           0 :     catch(const css::uno::Exception& ex)
     411             :     {
     412             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     413             :     }
     414             : 
     415           0 :     return seqReturn;
     416             : }
     417             : 
     418             : //*****************************************************************************************************************
     419             : //  public method
     420             : //  implements a deque in XML
     421             : //*****************************************************************************************************************
     422         614 : void SvtHistoryOptions_Impl::AppendItem(       EHistoryType eHistory ,
     423             :                                         const OUString& sURL        ,
     424             :                                         const OUString& sFilter     ,
     425             :                                         const OUString& sTitle      ,
     426             :                                         const OUString& sPassword   )
     427             : {
     428         614 :     impl_truncateList (eHistory, GetSize (eHistory));
     429             : 
     430         614 :     css::uno::Reference< css::container::XNameAccess > xListAccess;
     431         614 :     sal_Int32             nMaxSize = 0;
     432             : 
     433         614 :     switch(eHistory)
     434             :     {
     435             :     case ePICKLIST:
     436             :         {
     437         573 :             m_xCfg->getByName(OUString(s_sPickList)) >>= xListAccess;
     438         573 :             nMaxSize = GetSize(ePICKLIST);
     439             :         }
     440         573 :         break;
     441             :     case eHISTORY:
     442             :         {
     443          41 :             m_xCfg->getByName(OUString(s_sURLHistory)) >>= xListAccess;
     444          41 :             nMaxSize = GetSize(eHISTORY);
     445             :         }
     446          41 :         break;
     447             :     case eHELPBOOKMARKS:
     448             :         {
     449           0 :             m_xCfg->getByName(OUString(s_sHelpBookmarks)) >>= xListAccess;
     450           0 :             nMaxSize = GetSize(eHELPBOOKMARKS);
     451             :         }
     452           0 :         break;
     453             :     default:
     454           0 :         break;
     455             :     }
     456             : 
     457         614 :     if (nMaxSize==0)
     458         614 :         return;
     459             : 
     460         614 :     css::uno::Reference< css::container::XNameContainer > xItemList;
     461        1228 :     css::uno::Reference< css::container::XNameContainer > xOrderList;
     462        1228 :     css::uno::Reference< css::beans::XPropertySet >       xSet;
     463             : 
     464             :     try
     465             :     {
     466         614 :         xListAccess->getByName(OUString(s_sItemList))  >>= xItemList;
     467         614 :         xListAccess->getByName(OUString(s_sOrderList)) >>= xOrderList;
     468         614 :         sal_Int32 nLength = xOrderList->getElementNames().getLength();
     469             : 
     470         614 :         OUString sHistoryItemRef(s_sHistoryItemRef);
     471             :         // The item to be appended is already existing!
     472         614 :         if (xItemList->hasByName(sURL))
     473             :         {
     474         140 :             for (sal_Int32 i=0; i<nLength; ++i)
     475             :             {
     476         140 :                 OUString sTmp;
     477         140 :                 xOrderList->getByName(OUString::valueOf(i)) >>= xSet;
     478         140 :                 xSet->getPropertyValue(sHistoryItemRef) >>= sTmp;
     479             : 
     480         140 :                 if(sURL == sTmp)
     481             :                 {
     482         131 :                     OUString sFind;
     483         131 :                     xOrderList->getByName( OUString::valueOf(i) ) >>= xSet;
     484         131 :                     xSet->getPropertyValue(sHistoryItemRef) >>= sFind;
     485         140 :                     for (sal_Int32 j=i-1; j>=0; --j)
     486             :                     {
     487           9 :                         css::uno::Reference< css::beans::XPropertySet > xPrevSet;
     488          18 :                         css::uno::Reference< css::beans::XPropertySet > xNextSet;
     489           9 :                         xOrderList->getByName( OUString::valueOf(j+1) )   >>= xPrevSet;
     490           9 :                         xOrderList->getByName( OUString::valueOf(j) )     >>= xNextSet;
     491             : 
     492          18 :                         OUString sTemp;
     493           9 :                         xNextSet->getPropertyValue(sHistoryItemRef) >>= sTemp;
     494           9 :                         xPrevSet->setPropertyValue(sHistoryItemRef, css::uno::makeAny(sTemp));
     495           9 :                     }
     496         131 :                     xOrderList->getByName( OUString::valueOf((sal_Int32)0) ) >>= xSet;
     497         131 :                     xSet->setPropertyValue(sHistoryItemRef, css::uno::makeAny(sFind));
     498             : 
     499         131 :                     ::comphelper::ConfigurationHelper::flush(m_xCfg);
     500         131 :                     break;
     501             :                 }
     502           9 :             }
     503             :         }
     504             : 
     505             :         // The item to be appended is not existing!
     506             :         else
     507             :         {
     508         483 :             css::uno::Reference< css::lang::XSingleServiceFactory > xFac;
     509         966 :             css::uno::Reference< css::uno::XInterface >             xInst;
     510         966 :             css::uno::Reference< css::beans::XPropertySet > xPrevSet;
     511         966 :             css::uno::Reference< css::beans::XPropertySet > xNextSet;
     512             : 
     513             :             // Append new item to OrderList.
     514         483 :             if ( nLength == nMaxSize )
     515             :             {
     516         327 :                 OUString sRemove;
     517         327 :                 xOrderList->getByName(OUString::valueOf(nLength-1)) >>= xSet;
     518         327 :                 xSet->getPropertyValue(sHistoryItemRef) >>= sRemove;
     519             :                 try
     520             :                 {
     521         327 :                     xItemList->removeByName(sRemove);
     522             :                 }
     523           0 :                 catch (css::container::NoSuchElementException &)
     524             :                 {
     525             :                     // <https://bugs.freedesktop.org/show_bug.cgi?id=46074>
     526             :                     // "FILEOPEN: No Recent Documents..." discusses a problem
     527             :                     // with corrupted /org.openoffice.Office/Histories/Histories
     528             :                     // configuration items; to work around that problem, simply
     529             :                     // ignore such corrupted individual items here, so that at
     530             :                     // least newly added items are successfully added:
     531           0 :                     if (!sRemove.isEmpty())
     532             :                     {
     533           0 :                         throw;
     534             :                     }
     535         327 :                 }
     536             :             }
     537         483 :             if ( nLength != nMaxSize )
     538             :             {
     539         156 :                 xFac = css::uno::Reference< css::lang::XSingleServiceFactory >(xOrderList, css::uno::UNO_QUERY);
     540         156 :                 xInst = xFac->createInstance();
     541         156 :                 OUString sPush = OUString::valueOf(nLength++);
     542         156 :                 xOrderList->insertByName(sPush, css::uno::makeAny(xInst));
     543             :             }
     544        4185 :             for (sal_Int32 j=nLength-1; j>0; --j)
     545             :             {
     546        3702 :                 xOrderList->getByName( OUString::valueOf(j) )   >>= xPrevSet;
     547        3702 :                 xOrderList->getByName( OUString::valueOf(j-1) ) >>= xNextSet;
     548        3702 :                 OUString sTemp;
     549        3702 :                 xNextSet->getPropertyValue(sHistoryItemRef) >>= sTemp;
     550        3702 :                 xPrevSet->setPropertyValue(sHistoryItemRef, css::uno::makeAny(sTemp));
     551        3702 :             }
     552         483 :             xOrderList->getByName( OUString::valueOf((sal_Int32)0) ) >>= xSet;
     553         483 :             xSet->setPropertyValue(sHistoryItemRef, css::uno::makeAny(sURL));
     554             : 
     555             :             // Append the item to ItemList.
     556         483 :             xFac = css::uno::Reference< css::lang::XSingleServiceFactory >(xItemList, css::uno::UNO_QUERY);
     557         483 :             xInst = xFac->createInstance();
     558         483 :             xItemList->insertByName(sURL, css::uno::makeAny(xInst));
     559         483 :             xSet = css::uno::Reference< css::beans::XPropertySet >(xInst, css::uno::UNO_QUERY);
     560         483 :             xSet->setPropertyValue(OUString(s_sFilter), css::uno::makeAny(sFilter));
     561         483 :             xSet->setPropertyValue(OUString(s_sTitle), css::uno::makeAny(sTitle));
     562         483 :             xSet->setPropertyValue(OUString(s_sPassword), css::uno::makeAny(sPassword));
     563             : 
     564         966 :             ::comphelper::ConfigurationHelper::flush(m_xCfg);
     565         614 :         }
     566             :     }
     567           0 :     catch(const css::uno::Exception& ex)
     568             :     {
     569             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     570         614 :     }
     571             : }
     572             : 
     573             : //*****************************************************************************************************************
     574             : // initialize static member
     575             : // DON'T DO IT IN YOUR HEADER!
     576             : // see definition for further information
     577             : //*****************************************************************************************************************
     578             : SvtHistoryOptions_Impl*  SvtHistoryOptions::m_pDataContainer = NULL ;
     579             : sal_Int32     SvtHistoryOptions::m_nRefCount  = 0  ;
     580             : 
     581             : //*****************************************************************************************************************
     582             : // constructor
     583             : //*****************************************************************************************************************
     584         880 : SvtHistoryOptions::SvtHistoryOptions()
     585             : {
     586             :     // Global access, must be guarded (multithreading!).
     587         880 :     MutexGuard aGuard( GetOwnStaticMutex() );
     588             :     // Increase ouer refcount ...
     589         880 :     ++m_nRefCount;
     590             :     // ... and initialize ouer data container only if it not already exist!
     591         880 :     if( m_pDataContainer == NULL )
     592             :     {
     593             :         RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtHistoryOptions_Impl::ctor()");
     594         133 :         m_pDataContainer = new SvtHistoryOptions_Impl;
     595             : 
     596         133 :         ItemHolder1::holdConfigItem(E_HISTORYOPTIONS);
     597         880 :     }
     598         880 : }
     599             : 
     600             : //*****************************************************************************************************************
     601             : // destructor
     602             : //*****************************************************************************************************************
     603        1890 : SvtHistoryOptions::~SvtHistoryOptions()
     604             : {
     605             :     // Global access, must be guarded (multithreading!)
     606         879 :     MutexGuard aGuard( GetOwnStaticMutex() );
     607             :     // Decrease ouer refcount.
     608         879 :     --m_nRefCount;
     609             :     // If last instance was deleted ...
     610             :     // we must destroy ouer static data container!
     611         879 :     if( m_nRefCount <= 0 )
     612             :     {
     613         132 :         delete m_pDataContainer;
     614         132 :         m_pDataContainer = NULL;
     615         879 :     }
     616        1011 : }
     617             : 
     618             : //*****************************************************************************************************************
     619             : // public method
     620             : //*****************************************************************************************************************
     621         133 : sal_uInt32 SvtHistoryOptions::GetSize( EHistoryType eHistory ) const
     622             : {
     623         133 :     MutexGuard aGuard( GetOwnStaticMutex() );
     624         133 :     return m_pDataContainer->GetSize( eHistory );
     625             : }
     626             : 
     627             : //*****************************************************************************************************************
     628             : // public method
     629             : //*****************************************************************************************************************
     630           0 : void SvtHistoryOptions::Clear( EHistoryType eHistory )
     631             : {
     632           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     633           0 :     m_pDataContainer->Clear( eHistory );
     634           0 : }
     635             : 
     636             : //*****************************************************************************************************************
     637             : // public method
     638             : //*****************************************************************************************************************
     639           0 : Sequence< Sequence< PropertyValue > > SvtHistoryOptions::GetList( EHistoryType eHistory ) const
     640             : {
     641           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     642           0 :     return m_pDataContainer->GetList( eHistory );
     643             : }
     644             : 
     645             : //*****************************************************************************************************************
     646             : // public method
     647             : //*****************************************************************************************************************
     648         614 : void SvtHistoryOptions::AppendItem(   EHistoryType eHistory ,
     649             :                                    const OUString&  sURL  ,
     650             :                                    const OUString&  sFilter  ,
     651             :                                    const OUString&  sTitle  ,
     652             :                                    const OUString&  sPassword )
     653             : {
     654         614 :     MutexGuard aGuard( GetOwnStaticMutex() );
     655         614 :     m_pDataContainer->AppendItem( eHistory, sURL, sFilter, sTitle, sPassword );
     656         614 : }
     657             : 
     658             : namespace
     659             : {
     660             :     class theHistoryOptionsMutex : public rtl::Static<osl::Mutex, theHistoryOptionsMutex>{};
     661             : }
     662             : 
     663             : //*****************************************************************************************************************
     664             : // private method
     665             : //*****************************************************************************************************************
     666        2506 : Mutex& SvtHistoryOptions::GetOwnStaticMutex()
     667             : {
     668        2506 :     return theHistoryOptionsMutex::get();
     669             : }
     670             : 
     671             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10