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

Generated by: LCOV version 1.10