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

Generated by: LCOV version 1.10