LCOV - code coverage report
Current view: top level - unotools/source/config - historyoptions.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 254 0.0 %
Date: 2014-04-14 Functions: 0 16 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #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           0 : SvtHistoryOptions_Impl::SvtHistoryOptions_Impl()
      98             : {
      99             :     try
     100             :     {
     101           0 :         m_xCfg = Reference< css::container::XNameAccess > (
     102             :             ::comphelper::ConfigurationHelper::openConfig(
     103             :             ::comphelper::getProcessComponentContext(),
     104             :             OUString(s_sHistories),
     105             :             ::comphelper::ConfigurationHelper::E_STANDARD),
     106           0 :             css::uno::UNO_QUERY );
     107             : 
     108           0 :         m_xCommonXCU = Reference< css::container::XNameAccess > (
     109             :             ::comphelper::ConfigurationHelper::openConfig(
     110             :             ::comphelper::getProcessComponentContext(),
     111             :             OUString(s_sCommonHistory),
     112             :             ::comphelper::ConfigurationHelper::E_STANDARD),
     113           0 :             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           0 : }
     123             : 
     124             : //  destructor
     125             : 
     126           0 : SvtHistoryOptions_Impl::~SvtHistoryOptions_Impl()
     127             : {
     128           0 : }
     129             : 
     130             : //  public method
     131             : //  Attention: We return the max. size of our internal lists - That is the capacity not the size!
     132             : 
     133           0 : sal_uInt32 SvtHistoryOptions_Impl::GetSize( EHistoryType eHistory )
     134             : {
     135           0 :     css::uno::Reference< css::beans::XPropertySet >  xListAccess(m_xCommonXCU, css::uno::UNO_QUERY);
     136             : 
     137           0 :     if (!xListAccess.is())
     138           0 :         return 0;
     139             : 
     140           0 :     sal_uInt32 nSize = 0;
     141             : 
     142             :     try
     143             :     {
     144           0 :         switch( eHistory )
     145             :         {
     146             :         case ePICKLIST:
     147           0 :             xListAccess->getPropertyValue(OUString(s_sPickListSize)) >>= nSize;
     148           0 :             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           0 :     return nSize;
     168             : }
     169             : 
     170           0 : void SvtHistoryOptions_Impl::impl_truncateList ( EHistoryType eHistory, sal_uInt32 nSize )
     171             : {
     172           0 :     css::uno::Reference< css::container::XNameAccess >    xList;
     173           0 :     css::uno::Reference< css::container::XNameContainer > xItemList;
     174           0 :     css::uno::Reference< css::container::XNameContainer > xOrderList;
     175           0 :     css::uno::Reference< css::beans::XPropertySet >       xSet;
     176             : 
     177             :     try
     178             :     {
     179           0 :         switch( eHistory )
     180             :         {
     181             :         case ePICKLIST:
     182           0 :             m_xCfg->getByName(OUString(s_sPickList)) >>= xList;
     183           0 :             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           0 :         if ( ! xList.is())
     200           0 :             return;
     201             : 
     202           0 :         xList->getByName(OUString(s_sOrderList)) >>= xOrderList;
     203           0 :         xList->getByName(OUString(s_sItemList))  >>= xItemList;
     204             : 
     205           0 :         const sal_uInt32 nLength = xOrderList->getElementNames().getLength();
     206           0 :         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           0 :     }
     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           0 : Sequence< Sequence< PropertyValue > > SvtHistoryOptions_Impl::GetList( EHistoryType eHistory )
     302             : {
     303           0 :     impl_truncateList (eHistory, GetSize (eHistory));
     304             : 
     305           0 :     Sequence< Sequence< PropertyValue > > seqReturn; // Set default return value.
     306           0 :     Sequence< PropertyValue >             seqProperties(5);
     307             : 
     308           0 :     css::uno::Reference< css::container::XNameAccess > xListAccess;
     309           0 :     css::uno::Reference< css::container::XNameAccess > xItemList;
     310           0 :     css::uno::Reference< css::container::XNameAccess > xOrderList;
     311           0 :     css::uno::Reference< css::beans::XPropertySet >    xSet;
     312             : 
     313           0 :     seqProperties[s_nOffsetURL       ].Name = HISTORY_PROPERTYNAME_URL;
     314           0 :     seqProperties[s_nOffsetFilter    ].Name = HISTORY_PROPERTYNAME_FILTER;
     315           0 :     seqProperties[s_nOffsetTitle     ].Name = HISTORY_PROPERTYNAME_TITLE;
     316           0 :     seqProperties[s_nOffsetPassword  ].Name = HISTORY_PROPERTYNAME_PASSWORD;
     317           0 :     seqProperties[s_nOffsetThumbnail ].Name = HISTORY_PROPERTYNAME_THUMBNAIL;
     318             : 
     319             :     try
     320             :     {
     321           0 :         switch( eHistory )
     322             :         {
     323             :         case ePICKLIST:
     324             :             {
     325           0 :                 m_xCfg->getByName(OUString(s_sPickList)) >>= xListAccess;
     326           0 :                 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           0 :         if (xListAccess.is())
     346             :         {
     347           0 :             xListAccess->getByName(OUString(s_sItemList))  >>= xItemList;
     348           0 :             xListAccess->getByName(OUString(s_sOrderList)) >>= xOrderList;
     349             : 
     350           0 :             const sal_Int32 nLength = xOrderList->getElementNames().getLength();
     351           0 :             Sequence< Sequence< PropertyValue > > aRet(nLength);
     352           0 :             sal_Int32 nCount = 0;
     353             : 
     354           0 :             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           0 :             aRet.realloc(nCount);
     387           0 :             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           0 :     return seqReturn;
     396             : }
     397             : 
     398             : //  public method
     399             : //  implements a deque in XML
     400             : 
     401           0 : 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           0 :     impl_truncateList (eHistory, GetSize (eHistory));
     406             : 
     407           0 :     css::uno::Reference< css::container::XNameAccess > xListAccess;
     408           0 :     sal_Int32             nMaxSize = 0;
     409             : 
     410           0 :     switch(eHistory)
     411             :     {
     412             :     case ePICKLIST:
     413             :         {
     414           0 :             m_xCfg->getByName(OUString(s_sPickList)) >>= xListAccess;
     415           0 :             nMaxSize = GetSize(ePICKLIST);
     416             :         }
     417           0 :         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           0 :     if (nMaxSize==0)
     435           0 :         return;
     436             : 
     437           0 :     css::uno::Reference< css::container::XNameContainer > xItemList;
     438           0 :     css::uno::Reference< css::container::XNameContainer > xOrderList;
     439           0 :     css::uno::Reference< css::beans::XPropertySet >       xSet;
     440             : 
     441             :     try
     442             :     {
     443           0 :         xListAccess->getByName(OUString(s_sItemList))  >>= xItemList;
     444           0 :         xListAccess->getByName(OUString(s_sOrderList)) >>= xOrderList;
     445           0 :         sal_Int32 nLength = xOrderList->getElementNames().getLength();
     446             : 
     447           0 :         OUString sHistoryItemRef(s_sHistoryItemRef);
     448             :         // The item to be appended already exists
     449           0 :         if (xItemList->hasByName(sURL))
     450             :         {
     451           0 :             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           0 :             for (sal_Int32 i=0; i<nLength; ++i)
     459             :             {
     460           0 :                 OUString sTmp;
     461           0 :                 xOrderList->getByName(OUString::number(i)) >>= xSet;
     462           0 :                 xSet->getPropertyValue(sHistoryItemRef) >>= sTmp;
     463             : 
     464           0 :                 if(sURL == sTmp)
     465             :                 {
     466           0 :                     OUString sFind;
     467           0 :                     xOrderList->getByName( OUString::number(i) ) >>= xSet;
     468           0 :                     xSet->getPropertyValue(sHistoryItemRef) >>= sFind;
     469           0 :                     for (sal_Int32 j=i-1; j>=0; --j)
     470             :                     {
     471           0 :                         css::uno::Reference< css::beans::XPropertySet > xPrevSet;
     472           0 :                         css::uno::Reference< css::beans::XPropertySet > xNextSet;
     473           0 :                         xOrderList->getByName( OUString::number(j+1) )   >>= xPrevSet;
     474           0 :                         xOrderList->getByName( OUString::number(j) )     >>= xNextSet;
     475             : 
     476           0 :                         OUString sTemp;
     477           0 :                         xNextSet->getPropertyValue(sHistoryItemRef) >>= sTemp;
     478           0 :                         xPrevSet->setPropertyValue(sHistoryItemRef, css::uno::makeAny(sTemp));
     479           0 :                     }
     480           0 :                     xOrderList->getByName( OUString::number(0) ) >>= xSet;
     481           0 :                     xSet->setPropertyValue(sHistoryItemRef, css::uno::makeAny(sFind));
     482           0 :                     break;
     483             :                 }
     484           0 :             }
     485             : 
     486           0 :             ::comphelper::ConfigurationHelper::flush(m_xCfg);
     487             :         }
     488             :         else // The item to be appended does not exist yet
     489             :         {
     490           0 :             css::uno::Reference< css::lang::XSingleServiceFactory > xFac;
     491           0 :             css::uno::Reference< css::uno::XInterface >             xInst;
     492           0 :             css::uno::Reference< css::beans::XPropertySet > xPrevSet;
     493           0 :             css::uno::Reference< css::beans::XPropertySet > xNextSet;
     494             : 
     495             :             // Append new item to OrderList.
     496           0 :             if ( nLength == nMaxSize )
     497             :             {
     498           0 :                 OUString sRemove;
     499           0 :                 xOrderList->getByName(OUString::number(nLength-1)) >>= xSet;
     500           0 :                 xSet->getPropertyValue(sHistoryItemRef) >>= sRemove;
     501             :                 try
     502             :                 {
     503           0 :                     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           0 :                 }
     518             :             }
     519           0 :             if ( nLength != nMaxSize )
     520             :             {
     521           0 :                 xFac = css::uno::Reference< css::lang::XSingleServiceFactory >(xOrderList, css::uno::UNO_QUERY);
     522           0 :                 xInst = xFac->createInstance();
     523           0 :                 OUString sPush = OUString::number(nLength++);
     524           0 :                 xOrderList->insertByName(sPush, css::uno::makeAny(xInst));
     525             :             }
     526           0 :             for (sal_Int32 j=nLength-1; j>0; --j)
     527             :             {
     528           0 :                 xOrderList->getByName( OUString::number(j) )   >>= xPrevSet;
     529           0 :                 xOrderList->getByName( OUString::number(j-1) ) >>= xNextSet;
     530           0 :                 OUString sTemp;
     531           0 :                 xNextSet->getPropertyValue(sHistoryItemRef) >>= sTemp;
     532           0 :                 xPrevSet->setPropertyValue(sHistoryItemRef, css::uno::makeAny(sTemp));
     533           0 :             }
     534           0 :             xOrderList->getByName( OUString::number(0) ) >>= xSet;
     535           0 :             xSet->setPropertyValue(sHistoryItemRef, css::uno::makeAny(sURL));
     536             : 
     537             :             // Append the item to ItemList.
     538           0 :             xFac = css::uno::Reference< css::lang::XSingleServiceFactory >(xItemList, css::uno::UNO_QUERY);
     539           0 :             xInst = xFac->createInstance();
     540           0 :             xItemList->insertByName(sURL, css::uno::makeAny(xInst));
     541           0 :             xSet = css::uno::Reference< css::beans::XPropertySet >(xInst, css::uno::UNO_QUERY);
     542           0 :             xSet->setPropertyValue(OUString(s_sFilter), css::uno::makeAny(sFilter));
     543           0 :             xSet->setPropertyValue(OUString(s_sTitle), css::uno::makeAny(sTitle));
     544           0 :             xSet->setPropertyValue(OUString(s_sPassword), css::uno::makeAny(sPassword));
     545           0 :             xSet->setPropertyValue(OUString(s_sThumbnail), css::uno::makeAny(sThumbnail));
     546             : 
     547           0 :             ::comphelper::ConfigurationHelper::flush(m_xCfg);
     548           0 :         }
     549             :     }
     550           0 :     catch(const css::uno::Exception& ex)
     551             :     {
     552             :         SAL_WARN("unotools.config", "Caught unexpected: " << ex.Message);
     553           0 :     }
     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           0 : SvtHistoryOptions::SvtHistoryOptions()
     566             : {
     567             :     // Global access, must be guarded (multithreading!).
     568           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     569             :     // Increase our refcount ...
     570           0 :     ++m_nRefCount;
     571             :     // ... and initialize our data container only if it not already exist!
     572           0 :     if( m_pDataContainer == NULL )
     573             :     {
     574           0 :         m_pDataContainer = new SvtHistoryOptions_Impl;
     575             : 
     576           0 :         ItemHolder1::holdConfigItem(E_HISTORYOPTIONS);
     577           0 :     }
     578           0 : }
     579             : 
     580             : // destructor
     581             : 
     582           0 : SvtHistoryOptions::~SvtHistoryOptions()
     583             : {
     584             :     // Global access, must be guarded (multithreading!)
     585           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     586             :     // Decrease our refcount.
     587           0 :     --m_nRefCount;
     588             :     // If last instance was deleted ...
     589             :     // we must destroy our static data container!
     590           0 :     if( m_nRefCount <= 0 )
     591             :     {
     592           0 :         delete m_pDataContainer;
     593           0 :         m_pDataContainer = NULL;
     594           0 :     }
     595           0 : }
     596             : 
     597             : // public method
     598             : 
     599           0 : sal_uInt32 SvtHistoryOptions::GetSize( EHistoryType eHistory ) const
     600             : {
     601           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     602           0 :     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           0 : Sequence< Sequence< PropertyValue > > SvtHistoryOptions::GetList( EHistoryType eHistory ) const
     616             : {
     617           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     618           0 :     return m_pDataContainer->GetList( eHistory );
     619             : }
     620             : 
     621             : // public method
     622             : 
     623           0 : void SvtHistoryOptions::AppendItem(EHistoryType eHistory,
     624             :         const OUString& sURL, const OUString& sFilter, const OUString& sTitle,
     625             :         const OUString& sPassword, const OUString& sThumbnail)
     626             : {
     627           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     628           0 :     m_pDataContainer->AppendItem(eHistory, sURL, sFilter, sTitle, sPassword, sThumbnail);
     629           0 : }
     630             : 
     631             : namespace
     632             : {
     633             :     class theHistoryOptionsMutex : public rtl::Static<osl::Mutex, theHistoryOptionsMutex>{};
     634             : }
     635             : 
     636             : // private method
     637             : 
     638           0 : Mutex& SvtHistoryOptions::GetOwnStaticMutex()
     639             : {
     640           0 :     return theHistoryOptionsMutex::get();
     641             : }
     642             : 
     643             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10