LCOV - code coverage report
Current view: top level - unotools/source/config - historyoptions.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 147 261 56.3 %
Date: 2014-11-03 Functions: 13 18 72.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <osl/file.hxx>
      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 "itemholder1.hxx"
      32             : 
      33             : #include <com/sun/star/beans/XPropertySet.hpp>
      34             : #include <com/sun/star/container/XNameAccess.hpp>
      35             : #include <com/sun/star/container/XNameContainer.hpp>
      36             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      37             : #include <comphelper/configurationhelper.hxx>
      38             : #include <comphelper/processfactory.hxx>
      39             : 
      40             : using namespace ::std;
      41             : using namespace ::utl;
      42             : using namespace ::osl;
      43             : using namespace ::com::sun::star;
      44             : using namespace ::com::sun::star::uno;
      45             : using namespace ::com::sun::star::beans;
      46             : 
      47             : namespace {
      48             :     static const ::sal_Int32 s_nOffsetURL               = 0;
      49             :     static const ::sal_Int32 s_nOffsetFilter            = 1;
      50             :     static const ::sal_Int32 s_nOffsetTitle             = 2;
      51             :     static const ::sal_Int32 s_nOffsetPassword          = 3;
      52             :     static const ::sal_Int32 s_nOffsetThumbnail         = 4;
      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_sHelpBookmarksSize[] = "HelpBookmarkSize";
      58             :     const char s_sPickList[] = "PickList";
      59             :     const char s_sHelpBookmarks[] = "HelpBookmarks";
      60             :     const char s_sItemList[] = "ItemList";
      61             :     const char s_sOrderList[] = "OrderList";
      62             :     const char s_sHistoryItemRef[] = "HistoryItemRef";
      63             :     const char s_sFilter[] = "Filter";
      64             :     const char s_sTitle[] = "Title";
      65             :     const char s_sPassword[] = "Password";
      66             :     const char s_sThumbnail[] = "Thumbnail";
      67             : 
      68             :     class theHistoryOptionsMutex : public rtl::Static<osl::Mutex, theHistoryOptionsMutex>{};
      69             : }
      70             : 
      71             : /// Internal implementation of the SvtHistoryOptions.
      72             : class SvtHistoryOptions_Impl
      73             : {
      74             : public:
      75             :     SvtHistoryOptions_Impl();
      76             :     ~SvtHistoryOptions_Impl();
      77             : 
      78             :     /// Returns the maximum size of the internal lists, ie. the capacity not the size.
      79             :     sal_uInt32 GetCapacity(EHistoryType eHistory);
      80             : 
      81             :     /// Clear the specified history list.
      82             :     void Clear(EHistoryType eHistory);
      83             : 
      84             :     /// Get a sequence list from the items.
      85             :     Sequence< Sequence<PropertyValue> > GetList(EHistoryType eHistory);
      86             : 
      87             :     void AppendItem(EHistoryType eHistory,
      88             :         const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
      89             :         const OUString& sPassword, const OUString& sThumbnail);
      90             : 
      91             :     void DeleteItem(EHistoryType eHistory, const OUString& sURL);
      92             : 
      93             : private:
      94             :     /// Return the appropriate list of recent documents (based on eHistory).
      95             :     uno::Reference<container::XNameAccess> GetListAccess(EHistoryType eHistory) const;
      96             : 
      97             :     void impl_truncateList(EHistoryType eHistory, sal_uInt32 nSize);
      98             : 
      99             : private:
     100             :     uno::Reference<container::XNameAccess> m_xCfg;
     101             :     uno::Reference<container::XNameAccess> m_xCommonXCU;
     102             : };
     103             : 
     104         303 : SvtHistoryOptions_Impl::SvtHistoryOptions_Impl()
     105             : {
     106             :     try
     107             :     {
     108         606 :         m_xCfg = Reference<container::XNameAccess> (
     109             :             ::comphelper::ConfigurationHelper::openConfig(
     110             :             ::comphelper::getProcessComponentContext(),
     111             :             s_sHistories,
     112             :             ::comphelper::ConfigurationHelper::E_STANDARD),
     113         303 :             uno::UNO_QUERY);
     114             : 
     115         606 :         m_xCommonXCU = Reference<container::XNameAccess> (
     116             :             ::comphelper::ConfigurationHelper::openConfig(
     117             :             ::comphelper::getProcessComponentContext(),
     118             :             s_sCommonHistory,
     119             :             ::comphelper::ConfigurationHelper::E_STANDARD),
     120         303 :             uno::UNO_QUERY);
     121             :     }
     122           0 :     catch(const uno::Exception& ex)
     123             :     {
     124           0 :         m_xCfg.clear();
     125           0 :         m_xCommonXCU.clear();
     126             : 
     127             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     128             :     }
     129         303 : }
     130             : 
     131         299 : SvtHistoryOptions_Impl::~SvtHistoryOptions_Impl()
     132             : {
     133         299 : }
     134             : 
     135       10645 : sal_uInt32 SvtHistoryOptions_Impl::GetCapacity(EHistoryType eHistory)
     136             : {
     137       10645 :     uno::Reference<beans::XPropertySet> xListAccess(m_xCommonXCU, uno::UNO_QUERY);
     138             : 
     139       10645 :     if (!xListAccess.is())
     140           0 :         return 0;
     141             : 
     142       10645 :     sal_uInt32 nSize = 0;
     143             : 
     144             :     try
     145             :     {
     146       10645 :         switch (eHistory)
     147             :         {
     148             :         case ePICKLIST:
     149       10645 :             xListAccess->getPropertyValue(s_sPickListSize) >>= nSize;
     150       10645 :             break;
     151             : 
     152             :         case eHELPBOOKMARKS:
     153           0 :             xListAccess->getPropertyValue(s_sHelpBookmarksSize) >>= nSize;
     154           0 :             break;
     155             : 
     156             :         default:
     157           0 :             break;
     158             :         }
     159             :     }
     160           0 :     catch (const uno::Exception& ex)
     161             :     {
     162             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     163             :     }
     164             : 
     165       10645 :     return nSize;
     166             : }
     167             : 
     168       10344 : uno::Reference<container::XNameAccess> SvtHistoryOptions_Impl::GetListAccess(EHistoryType eHistory) const
     169             : {
     170       10344 :     uno::Reference<container::XNameAccess> xListAccess;
     171             : 
     172             :     try
     173             :     {
     174       10344 :         switch (eHistory)
     175             :         {
     176             :         case ePICKLIST:
     177       10344 :             m_xCfg->getByName(s_sPickList) >>= xListAccess;
     178       10344 :             break;
     179             : 
     180             :         case eHELPBOOKMARKS:
     181           0 :             m_xCfg->getByName(s_sHelpBookmarks) >>= xListAccess;
     182           0 :             break;
     183             : 
     184             :         default:
     185           0 :             break;
     186             :         }
     187             :     }
     188           0 :     catch (const uno::Exception& ex)
     189             :     {
     190             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     191             :     }
     192             : 
     193       10344 :     return xListAccess;
     194             : }
     195             : 
     196        5172 : void SvtHistoryOptions_Impl::impl_truncateList(EHistoryType eHistory, sal_uInt32 nSize)
     197             : {
     198        5172 :     uno::Reference<container::XNameAccess> xList(GetListAccess(eHistory));
     199        5172 :     if (!xList.is())
     200        5172 :         return;
     201             : 
     202       10344 :     uno::Reference<container::XNameContainer> xItemList;
     203       10344 :     uno::Reference<container::XNameContainer> xOrderList;
     204       10344 :     uno::Reference<beans::XPropertySet>       xSet;
     205             : 
     206             :     try
     207             :     {
     208        5172 :         xList->getByName(s_sOrderList) >>= xOrderList;
     209        5172 :         xList->getByName(s_sItemList)  >>= xItemList;
     210             : 
     211        5172 :         const sal_uInt32 nLength = xOrderList->getElementNames().getLength();
     212        5172 :         if (nSize < nLength)
     213             :         {
     214           0 :             for (sal_uInt32 i=nLength-1; i>=nSize; --i)
     215             :             {
     216           0 :                 OUString sTmp;
     217           0 :                 const OUString sRemove = OUString::number(i);
     218           0 :                 xOrderList->getByName(sRemove) >>= xSet;
     219           0 :                 xSet->getPropertyValue(s_sHistoryItemRef) >>= sTmp;
     220           0 :                 xItemList->removeByName(sTmp);
     221           0 :                 xOrderList->removeByName(sRemove);
     222           0 :             }
     223             : 
     224           0 :             ::comphelper::ConfigurationHelper::flush(m_xCfg);
     225             :         }
     226             :     }
     227           0 :     catch(const uno::Exception& ex)
     228             :     {
     229             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     230        5172 :     }
     231             : }
     232             : 
     233           0 : void SvtHistoryOptions_Impl::Clear( EHistoryType eHistory )
     234             : {
     235           0 :     uno::Reference<container::XNameAccess> xListAccess(GetListAccess(eHistory));
     236           0 :     if (!xListAccess.is())
     237           0 :         return;
     238             : 
     239           0 :     uno::Reference<container::XNameContainer> xNode;
     240             : 
     241             :     try
     242             :     {
     243             :         // clear ItemList
     244           0 :         xListAccess->getByName(s_sItemList) >>= xNode;
     245           0 :         Sequence<OUString> aStrings(xNode->getElementNames());
     246             : 
     247           0 :         const sal_Int32 nLength = aStrings.getLength();
     248           0 :         for (sal_Int32 i = 0; i < nLength; ++i)
     249           0 :             xNode->removeByName(aStrings[i]);
     250             : 
     251             :         // clear OrderList
     252           0 :         xListAccess->getByName(s_sOrderList) >>= xNode;
     253           0 :         aStrings = xNode->getElementNames();
     254             : 
     255           0 :         for (sal_Int32 j = 0; j < nLength; ++j)
     256           0 :             xNode->removeByName(aStrings[j]);
     257             : 
     258           0 :         ::comphelper::ConfigurationHelper::flush(m_xCfg);
     259             :     }
     260           0 :     catch(const uno::Exception& ex)
     261             :     {
     262             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     263           0 :     }
     264             : }
     265             : 
     266           0 : static bool lcl_fileOpenable(const OUString &rURL)
     267             : {
     268           0 :     osl::File aRecentFile(rURL);
     269           0 :     if(!aRecentFile.open(osl_File_OpenFlag_Read))
     270             :     {
     271           0 :         aRecentFile.close();
     272           0 :         return true;
     273             :     }
     274             :     else
     275           0 :         return false;
     276             : }
     277             : 
     278           2 : Sequence< Sequence<PropertyValue> > SvtHistoryOptions_Impl::GetList(EHistoryType eHistory)
     279             : {
     280           2 :     uno::Reference<container::XNameAccess> xListAccess(GetListAccess(eHistory));
     281           2 :     if (!xListAccess.is())
     282           0 :         return Sequence< Sequence<PropertyValue> >();
     283             : 
     284           2 :     impl_truncateList(eHistory, GetCapacity(eHistory));
     285             : 
     286           4 :     Sequence<PropertyValue> seqProperties(5);
     287           2 :     seqProperties[s_nOffsetURL       ].Name = HISTORY_PROPERTYNAME_URL;
     288           2 :     seqProperties[s_nOffsetFilter    ].Name = HISTORY_PROPERTYNAME_FILTER;
     289           2 :     seqProperties[s_nOffsetTitle     ].Name = HISTORY_PROPERTYNAME_TITLE;
     290           2 :     seqProperties[s_nOffsetPassword  ].Name = HISTORY_PROPERTYNAME_PASSWORD;
     291           2 :     seqProperties[s_nOffsetThumbnail ].Name = HISTORY_PROPERTYNAME_THUMBNAIL;
     292             : 
     293           4 :     uno::Reference<container::XNameAccess> xItemList;
     294           4 :     uno::Reference<container::XNameAccess> xOrderList;
     295             :     try
     296             :     {
     297           2 :         xListAccess->getByName(s_sItemList)  >>= xItemList;
     298           2 :         xListAccess->getByName(s_sOrderList) >>= xOrderList;
     299             :     }
     300           0 :     catch(const uno::Exception& ex)
     301             :     {
     302             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     303             :     }
     304             : 
     305           2 :     const sal_Int32 nLength = xOrderList->getElementNames().getLength();
     306           4 :     Sequence< Sequence<PropertyValue> > aRet(nLength);
     307           2 :     sal_Int32 nCount = 0;
     308             : 
     309           2 :     for (sal_Int32 nItem = 0; nItem < nLength; ++nItem)
     310             :     {
     311             :         try
     312             :         {
     313           0 :             OUString sUrl;
     314           0 :             uno::Reference<beans::XPropertySet> xSet;
     315           0 :             xOrderList->getByName(OUString::number(nItem)) >>= xSet;
     316           0 :             xSet->getPropertyValue(s_sHistoryItemRef) >>= sUrl;
     317             : 
     318           0 :             if (!sUrl.startsWith("file://") || lcl_fileOpenable(sUrl))
     319             :             {
     320           0 :                 xItemList->getByName(sUrl) >>= xSet;
     321           0 :                 seqProperties[s_nOffsetURL  ].Value <<= sUrl;
     322             : 
     323           0 :                 xSet->getPropertyValue(s_sFilter)   >>= seqProperties[s_nOffsetFilter   ].Value;
     324           0 :                 xSet->getPropertyValue(s_sTitle)    >>= seqProperties[s_nOffsetTitle    ].Value;
     325           0 :                 xSet->getPropertyValue(s_sPassword) >>= seqProperties[s_nOffsetPassword ].Value;
     326           0 :                 xSet->getPropertyValue(s_sThumbnail)>>= seqProperties[s_nOffsetThumbnail].Value;
     327           0 :                 aRet[nCount++] = seqProperties;
     328           0 :             }
     329             :         }
     330           0 :         catch(const uno::Exception& ex)
     331             :         {
     332             :             // <https://bugs.libreoffice.org/show_bug.cgi?id=46074>
     333             :             // "FILEOPEN: No Recent Documents..." discusses a problem
     334             :             // with corrupted /org.openoffice.Office/Histories/Histories
     335             :             // configuration items; to work around that problem, simply
     336             :             // ignore such corrupted individual items here, so that at
     337             :             // least newly added items are successfully reported back
     338             :             // from this function:
     339             :             SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     340             :         }
     341             :     }
     342             :     assert(nCount <= nLength);
     343           2 :     aRet.realloc(nCount);
     344           4 :     return aRet;
     345             : }
     346             : 
     347        5170 : void SvtHistoryOptions_Impl::AppendItem(EHistoryType eHistory,
     348             :         const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
     349             :         const OUString& sPassword, const OUString& sThumbnail)
     350             : {
     351        5170 :     uno::Reference<container::XNameAccess> xListAccess(GetListAccess(eHistory));
     352        5170 :     if (!xListAccess.is())
     353           0 :         return;
     354             : 
     355        5170 :     impl_truncateList(eHistory, GetCapacity(eHistory));
     356             : 
     357        5170 :     sal_Int32 nMaxSize = GetCapacity(eHistory);
     358        5170 :     if (nMaxSize == 0)
     359           0 :         return;
     360             : 
     361       10340 :     uno::Reference<container::XNameContainer> xItemList;
     362       10340 :     uno::Reference<container::XNameContainer> xOrderList;
     363       10340 :     uno::Reference<beans::XPropertySet>       xSet;
     364             : 
     365             :     try
     366             :     {
     367        5170 :         xListAccess->getByName(s_sItemList)  >>= xItemList;
     368        5170 :         xListAccess->getByName(s_sOrderList) >>= xOrderList;
     369        5170 :         sal_Int32 nLength = xOrderList->getElementNames().getLength();
     370             : 
     371             :         // The item to be appended already exists
     372        5170 :         if (xItemList->hasByName(sURL))
     373             :         {
     374        2114 :             if (!sThumbnail.isEmpty())
     375             :             {
     376             :                 // update the thumbnail
     377           0 :                 xItemList->getByName(sURL) >>= xSet;
     378           0 :                 xSet->setPropertyValue(s_sThumbnail, uno::makeAny(sThumbnail));
     379             :             }
     380             : 
     381        2174 :             for (sal_Int32 i=0; i<nLength; ++i)
     382             :             {
     383        2174 :                 OUString aItem;
     384        2174 :                 xOrderList->getByName(OUString::number(i)) >>= xSet;
     385        2174 :                 xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
     386             : 
     387        2174 :                 if (aItem == sURL)
     388             :                 {
     389        2174 :                     for (sal_Int32 j = i - 1; j >= 0; --j)
     390             :                     {
     391          60 :                         uno::Reference<beans::XPropertySet> xPrevSet;
     392         120 :                         uno::Reference<beans::XPropertySet> xNextSet;
     393          60 :                         xOrderList->getByName(OUString::number(j+1)) >>= xPrevSet;
     394          60 :                         xOrderList->getByName(OUString::number(j))   >>= xNextSet;
     395             : 
     396         120 :                         OUString sTemp;
     397          60 :                         xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
     398          60 :                         xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::makeAny(sTemp));
     399          60 :                     }
     400        2114 :                     xOrderList->getByName(OUString::number(0)) >>= xSet;
     401        2114 :                     xSet->setPropertyValue(s_sHistoryItemRef, uno::makeAny(aItem));
     402        2114 :                     break;
     403             :                 }
     404          60 :             }
     405             : 
     406        2114 :             ::comphelper::ConfigurationHelper::flush(m_xCfg);
     407             :         }
     408             :         else // The item to be appended does not exist yet
     409             :         {
     410        3056 :             uno::Reference<lang::XSingleServiceFactory> xFac;
     411        6112 :             uno::Reference<uno::XInterface>             xInst;
     412        6112 :             uno::Reference<beans::XPropertySet> xPrevSet;
     413        6112 :             uno::Reference<beans::XPropertySet> xNextSet;
     414             : 
     415             :             // Append new item to OrderList.
     416        3056 :             if ( nLength == nMaxSize )
     417             :             {
     418        2084 :                 OUString sRemove;
     419        2084 :                 xOrderList->getByName(OUString::number(nLength-1)) >>= xSet;
     420        2084 :                 xSet->getPropertyValue(s_sHistoryItemRef) >>= sRemove;
     421             :                 try
     422             :                 {
     423        2084 :                     xItemList->removeByName(sRemove);
     424             :                 }
     425           0 :                 catch (container::NoSuchElementException &)
     426             :                 {
     427             :                     // <https://bugs.libreoffice.org/show_bug.cgi?id=46074>
     428             :                     // "FILEOPEN: No Recent Documents..." discusses a problem
     429             :                     // with corrupted /org.openoffice.Office/Histories/Histories
     430             :                     // configuration items; to work around that problem, simply
     431             :                     // ignore such corrupted individual items here, so that at
     432             :                     // least newly added items are successfully added:
     433           0 :                     if (!sRemove.isEmpty())
     434             :                     {
     435           0 :                         throw;
     436             :                     }
     437        2084 :                 }
     438             :             }
     439        3056 :             if (nLength != nMaxSize)
     440             :             {
     441         972 :                 xFac = uno::Reference<lang::XSingleServiceFactory>(xOrderList, uno::UNO_QUERY);
     442         972 :                 xInst = xFac->createInstance();
     443         972 :                 OUString sPush = OUString::number(nLength++);
     444         972 :                 xOrderList->insertByName(sPush, uno::makeAny(xInst));
     445             :             }
     446       63194 :             for (sal_Int32 j=nLength-1; j>0; --j)
     447             :             {
     448       60138 :                 xOrderList->getByName( OUString::number(j) )   >>= xPrevSet;
     449       60138 :                 xOrderList->getByName( OUString::number(j-1) ) >>= xNextSet;
     450       60138 :                 OUString sTemp;
     451       60138 :                 xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
     452       60138 :                 xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::makeAny(sTemp));
     453       60138 :             }
     454        3056 :             xOrderList->getByName( OUString::number(0) ) >>= xSet;
     455        3056 :             xSet->setPropertyValue(s_sHistoryItemRef, uno::makeAny(sURL));
     456             : 
     457             :             // Append the item to ItemList.
     458        3056 :             xFac = uno::Reference<lang::XSingleServiceFactory>(xItemList, uno::UNO_QUERY);
     459        3056 :             xInst = xFac->createInstance();
     460        3056 :             xItemList->insertByName(sURL, uno::makeAny(xInst));
     461             : 
     462        3056 :             xSet = uno::Reference<beans::XPropertySet>(xInst, uno::UNO_QUERY);
     463        3056 :             xSet->setPropertyValue(s_sFilter, uno::makeAny(sFilter));
     464        3056 :             xSet->setPropertyValue(s_sTitle, uno::makeAny(sTitle));
     465        3056 :             xSet->setPropertyValue(s_sPassword, uno::makeAny(sPassword));
     466        3056 :             xSet->setPropertyValue(s_sThumbnail, uno::makeAny(sThumbnail));
     467             : 
     468        6112 :             ::comphelper::ConfigurationHelper::flush(m_xCfg);
     469             :         }
     470             :     }
     471           0 :     catch(const uno::Exception& ex)
     472             :     {
     473             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     474        5170 :     }
     475             : }
     476             : 
     477           0 : void SvtHistoryOptions_Impl::DeleteItem(EHistoryType eHistory, const OUString& sURL)
     478             : {
     479           0 :     uno::Reference<container::XNameAccess> xListAccess(GetListAccess(eHistory));
     480           0 :     if (!xListAccess.is())
     481           0 :         return;
     482             : 
     483           0 :     uno::Reference<container::XNameContainer> xItemList;
     484           0 :     uno::Reference<container::XNameContainer> xOrderList;
     485           0 :     uno::Reference<beans::XPropertySet>       xSet;
     486             : 
     487             :     try
     488             :     {
     489           0 :         xListAccess->getByName(s_sItemList)  >>= xItemList;
     490           0 :         xListAccess->getByName(s_sOrderList) >>= xOrderList;
     491           0 :         sal_Int32 nLength = xOrderList->getElementNames().getLength();
     492             : 
     493             :         // if it does not exist, nothing to do
     494           0 :         if (!xItemList->hasByName(sURL))
     495           0 :             return;
     496             : 
     497             :         // it's the last one, just clear the lists
     498           0 :         if (nLength == 1)
     499             :         {
     500           0 :             Clear(eHistory);
     501           0 :             return;
     502             :         }
     503             : 
     504             :         // find it in the OrderList
     505           0 :         sal_Int32 nFromWhere = 0;
     506           0 :         for (; nFromWhere < nLength - 1; ++nFromWhere)
     507             :         {
     508           0 :             OUString aItem;
     509           0 :             xOrderList->getByName(OUString::number(nFromWhere)) >>= xSet;
     510           0 :             xSet->getPropertyValue(s_sHistoryItemRef) >>= aItem;
     511             : 
     512           0 :             if (aItem == sURL)
     513           0 :                 break;
     514           0 :         }
     515             : 
     516             :         // and shift the rest of the items in OrderList accordingly
     517           0 :         for (sal_Int32 i = nFromWhere; i < nLength - 1; ++i)
     518             :         {
     519           0 :             uno::Reference<beans::XPropertySet> xPrevSet;
     520           0 :             uno::Reference<beans::XPropertySet> xNextSet;
     521           0 :             xOrderList->getByName(OUString::number(i))     >>= xPrevSet;
     522           0 :             xOrderList->getByName(OUString::number(i + 1)) >>= xNextSet;
     523             : 
     524           0 :             OUString sTemp;
     525           0 :             xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
     526           0 :             xPrevSet->setPropertyValue(s_sHistoryItemRef, uno::makeAny(sTemp));
     527           0 :         }
     528           0 :         xOrderList->removeByName(OUString::number(nLength - 1));
     529             : 
     530             :         // and finally remove it from the ItemList
     531           0 :         xItemList->removeByName(sURL);
     532             : 
     533           0 :         ::comphelper::ConfigurationHelper::flush(m_xCfg);
     534             :     }
     535           0 :     catch (const uno::Exception& ex)
     536             :     {
     537             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     538           0 :     }
     539             : }
     540             : 
     541             : // initialize static member
     542             : // DON'T DO IT IN YOUR HEADER!
     543             : // see definition for further information
     544             : 
     545             : SvtHistoryOptions_Impl*  SvtHistoryOptions::m_pDataContainer = NULL;
     546             : sal_Int32     SvtHistoryOptions::m_nRefCount  = 0;
     547             : 
     548             : // constructor
     549             : 
     550        5778 : SvtHistoryOptions::SvtHistoryOptions()
     551             : {
     552        5778 :     MutexGuard aGuard(theHistoryOptionsMutex::get());
     553             : 
     554             :     // Increase our refcount ...
     555        5778 :     ++m_nRefCount;
     556             :     // ... and initialize our data container only if it not already exist!
     557        5778 :     if( m_pDataContainer == NULL )
     558             :     {
     559         303 :         m_pDataContainer = new SvtHistoryOptions_Impl;
     560             : 
     561         303 :         ItemHolder1::holdConfigItem(E_HISTORYOPTIONS);
     562        5778 :     }
     563        5778 : }
     564             : 
     565             : // destructor
     566             : 
     567       11847 : SvtHistoryOptions::~SvtHistoryOptions()
     568             : {
     569        5774 :     MutexGuard aGuard(theHistoryOptionsMutex::get());
     570             : 
     571             :     // Decrease our refcount.
     572        5774 :     --m_nRefCount;
     573             :     // If last instance was deleted ...
     574             :     // we must destroy our static data container!
     575        5774 :     if( m_nRefCount <= 0 )
     576             :     {
     577         299 :         delete m_pDataContainer;
     578         299 :         m_pDataContainer = NULL;
     579        5774 :     }
     580        6073 : }
     581             : 
     582         303 : sal_uInt32 SvtHistoryOptions::GetSize( EHistoryType eHistory ) const
     583             : {
     584         303 :     MutexGuard aGuard(theHistoryOptionsMutex::get());
     585             : 
     586         303 :     return m_pDataContainer->GetCapacity(eHistory);
     587             : }
     588             : 
     589           0 : void SvtHistoryOptions::Clear( EHistoryType eHistory )
     590             : {
     591           0 :     MutexGuard aGuard(theHistoryOptionsMutex::get());
     592             : 
     593           0 :     m_pDataContainer->Clear( eHistory );
     594           0 : }
     595             : 
     596           2 : Sequence< Sequence< PropertyValue > > SvtHistoryOptions::GetList( EHistoryType eHistory ) const
     597             : {
     598           2 :     MutexGuard aGuard(theHistoryOptionsMutex::get());
     599             : 
     600           2 :     return m_pDataContainer->GetList( eHistory );
     601             : }
     602             : 
     603        5170 : void SvtHistoryOptions::AppendItem(EHistoryType eHistory,
     604             :         const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
     605             :         const OUString& sPassword, const OUString& sThumbnail)
     606             : {
     607        5170 :     MutexGuard aGuard(theHistoryOptionsMutex::get());
     608             : 
     609        5170 :     m_pDataContainer->AppendItem(eHistory, sURL, sFilter, sTitle, sPassword, sThumbnail);
     610        5170 : }
     611             : 
     612           0 : void SvtHistoryOptions::DeleteItem(EHistoryType eHistory, const OUString& sURL)
     613             : {
     614           0 :     MutexGuard aGuard(theHistoryOptionsMutex::get());
     615             : 
     616           0 :     m_pDataContainer->DeleteItem(eHistory, sURL);
     617           0 : }
     618             : 
     619             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10