Hello Andreas,
Now the config item of historyoption has implemented a deque.There are
the following feature set:
1)updating already existing items.
2)adding new items to non-full list.
3)adding new items to full list by removing item with lowest prio.
4)increasing prio of existing and reopened items.
5)the capacity of the list can be set via SetSize().
I have tested it with the testing stuff(have been sent in 06.19's
email).And it works expected.
Could you help me review it? If there is any incorrect or
inappropriate,please give me some advice.
Regards,
Yan Wu
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: historyoptions.cxx,v $
*
* $Revision: 1.19.6.3 $
*
* last change: $Author: as $ $Date: 2007/06/15 06:00:34 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svtools.hxx"
#ifndef GCC
#endif
//_________________________________________________________________________________________________________________
// includes
//_________________________________________________________________________________________________________________
#include <svtools/historyoptions.hxx>
#include "configitems/historyoptions_const.hxx"
#ifndef _UTL_CONFIGMGR_HXX_
#include <unotools/configmgr.hxx>
#endif
#ifndef _UTL_CONFIGITEM_HXX_
#include <unotools/configitem.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _COM_SUN_STAR_UNO_ANY_HXX_
#include <com/sun/star/uno/Any.hxx>
#endif
#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
#include <com/sun/star/uno/Sequence.hxx>
#endif
#ifndef __SGI_STL_DEQUE
#include <deque>
#endif
#ifndef __SGI_STL_ALGORITHM
#include <algorithm>
#endif
#include <rtl/logfile.hxx>
#include "itemholder1.hxx"
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
#include <com/sun/star/container/XNameContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#endif
#ifndef _COMPHELPER_CONFIGURATIONHELPER_HXX_
#include <comphelper/configurationhelper.hxx>
#endif
#ifndef _UNOTOOLS_PROCESSFACTORY_HXX_
#include <unotools/processfactory.hxx>
#endif
#ifndef _SVT_LOGHELPER_HXX
#include "loghelper.hxx"
#endif
//_________________________________________________________________________________________________________________
// namespaces
//_________________________________________________________________________________________________________________
using namespace ::std ;
using namespace ::utl ;
using namespace ::rtl ;
using namespace ::osl ;
using namespace ::com::sun::star::uno ;
using namespace ::com::sun::star::beans ;
namespace css = ::com::sun::star;
//_________________________________________________________________________________________________________________
// const
//_________________________________________________________________________________________________________________
namespace {
static const ::sal_Int32 s_nOffsetURL = 0;
static const ::sal_Int32 s_nOffsetFilter = 1;
static const ::sal_Int32 s_nOffsetTitle = 2;
static const ::sal_Int32 s_nOffsetPassword = 3;
}
//_________________________________________________________________________________________________________________
// private declarations!
//_________________________________________________________________________________________________________________
struct IMPL_THistoryItem
{
IMPL_THistoryItem()
{
}
IMPL_THistoryItem( const OUString& sNewURL ,
const OUString& sNewFilter ,
const OUString& sNewTitle ,
const OUString& sNewPassword )
{
sURL = sNewURL ;
sFilter = sNewFilter ;
sTitle = sNewTitle ;
sPassword = sNewPassword ;
}
sal_Bool operator==( const OUString& sSearchedURL )
{
return( sURL == sSearchedURL );
}
OUString sURL ;
OUString sFilter ;
OUString sTitle ;
OUString sPassword ;
};
//*****************************************************************************************************************
// class SvtHistoryOptions_Impl
// redesigned
//*****************************************************************************************************************
class SvtHistoryOptions_Impl
{
public:
SvtHistoryOptions_Impl();
~SvtHistoryOptions_Impl();
sal_uInt32 GetSize( EHistoryType eHistory );
void SetSize( EHistoryType eHistory, sal_uInt32 nSize );
void Clear( EHistoryType eHistory );
Sequence< Sequence< PropertyValue > > GetList( EHistoryType eHistory );
void AppendItem( EHistoryType
eHistory ,
const OUString& sURL ,
const OUString& sFilter ,
const OUString& sTitle ,
const OUString& sPassword );
private:
css::uno::Reference< css::container::XNameAccess > m_xCfg;
css::uno::Reference< css::container::XNameAccess > m_xCommonXCU;
};
//*****************************************************************************************************************
// constructor
//*****************************************************************************************************************
SvtHistoryOptions_Impl::SvtHistoryOptions_Impl()
{
try
{
m_xCfg = Reference< css::container::XNameAccess > (
::comphelper::ConfigurationHelper::openConfig(
utl::getProcessServiceFactory(),
s_sHistories,
::comphelper::ConfigurationHelper::E_STANDARD),
css::uno::UNO_QUERY );
m_xCommonXCU = Reference< css::container::XNameAccess > (
::comphelper::ConfigurationHelper::openConfig(
utl::getProcessServiceFactory(),
s_sCommonHistory,
::comphelper::ConfigurationHelper::E_STANDARD),
css::uno::UNO_QUERY );
}
catch(const css::uno::Exception& ex)
{
m_xCfg.clear();
m_xCommonXCU.clear();
LogHelper::logIt(ex);
}
}
//*****************************************************************************************************************
// destructor
//*****************************************************************************************************************
SvtHistoryOptions_Impl::~SvtHistoryOptions_Impl()
{
}
//*****************************************************************************************************************
// public method
// Attention: We return the max. size of our internal lists - That is the
capacity not the size!
//*****************************************************************************************************************
sal_uInt32 SvtHistoryOptions_Impl::GetSize( EHistoryType eHistory )
{
sal_uInt32 nSize = 0 ;
css::uno::Reference< css::beans::XPropertySet >
xListAccess(m_xCommonXCU, css::uno::UNO_QUERY);
try
{
switch( eHistory )
{
case ePICKLIST:
xListAccess->getPropertyValue(s_sPickListSize) >>=
nSize;
break;
case eHISTORY:
xListAccess->getPropertyValue(s_sURLHistorySize) >>=
nSize;
break;
case eHELPBOOKMARKS:
xListAccess->getPropertyValue(s_sHelpBookmarksSize) >>=
nSize;
break;
default:
break;
}
}
catch(const css::uno::Exception& ex)
{
LogHelper::logIt(ex);
}
return nSize;
}
//*****************************************************************************************************************
// public method
// Attention: We return the max. size of our internal lists - That is the
capacity not the size!
//*****************************************************************************************************************
void SvtHistoryOptions_Impl::SetSize( EHistoryType eHistory, sal_uInt32 nSize )
{
css::uno::Reference< css::container::XNameAccess > xList;
css::uno::Reference< css::container::XNameContainer > xItemList;
css::uno::Reference< css::container::XNameContainer > xOrderList;
css::uno::Reference< css::beans::XPropertySet > xSet;
css::uno::Reference< css::beans::XPropertySet > xListSet;
css::uno::Reference< css::beans::XPropertySet >
xListAccess(m_xCommonXCU, css::uno::UNO_QUERY);
try
{
switch( eHistory )
{
case ePICKLIST:
if(xListAccess.is() && nSize!=GetSize(ePICKLIST))
{
xListAccess->setPropertyValue(s_sPickListSize,
css::uno::makeAny(nSize));
::comphelper::ConfigurationHelper::flush(m_xCommonXCU);
// If too much items in current list ...
// truncate the oldest items BEFORE you set the
new one.
m_xCfg->getByName(s_sPickList) >>= xList;
xList->getByName(s_sOrderList) >>= xOrderList;
Sequence< ::rtl::OUString > lOrders =
xOrderList->getElementNames();
const sal_uInt32 nLength = lOrders.getLength();
if (nSize < nLength)
{
sal_Int32 nOrderIterator;
xListSet = css::uno::Reference<
css::beans::XPropertySet >(xList, css::uno::UNO_QUERY);
xListSet->getPropertyValue(s_sFirstItem) >>= nOrderIterator;
const sal_Int32 nOldItemCount = nLength
- nSize;
xList->getByName(s_sItemList) >>=
xItemList;
for (sal_Int32 i=0; i<nOldItemCount;
++i)
{
::rtl::OUString sTmp;
const ::rtl::OUString sRemove =
::rtl::OUString::valueOf(i+nOrderIterator);
xOrderList->getByName(sRemove)
>>= xSet;
xSet->getPropertyValue(s_sHistoryItemRef) >>= sTmp;
xItemList->removeByName(sTmp);
xOrderList->removeByName(sRemove);
}
// increasing the value of FirstItem
xListSet->setPropertyValue(s_sFirstItem,
css::uno::makeAny(nOldItemCount+nOrderIterator));
::comphelper::ConfigurationHelper::flush(m_xCfg);
}
}
break;
case eHISTORY:
if(xListAccess.is() && nSize!=GetSize(eHISTORY))
{
xListAccess->setPropertyValue(s_sURLHistorySize, css::uno::makeAny(nSize));
::comphelper::ConfigurationHelper::flush(m_xCommonXCU);
// If too much items in current list ...
// truncate the oldest items BEFORE you set the
new one.
m_xCfg->getByName(s_sURLHistory) >>= xList;
xList->getByName(s_sOrderList) >>= xOrderList;
Sequence< ::rtl::OUString > lOrders =
xOrderList->getElementNames();
const sal_uInt32 nLength = lOrders.getLength();
if (nSize < nLength)
{
sal_Int32 nOrderIterator;
xListSet = css::uno::Reference<
css::beans::XPropertySet >(xList, css::uno::UNO_QUERY);
xListSet->getPropertyValue(s_sFirstItem) >>= nOrderIterator;
const sal_Int32 nOldItemCount = nLength
- nSize;
xList->getByName(s_sItemList) >>=
xItemList;
for (sal_Int32 i=0; i<nOldItemCount;
++i)
{
::rtl::OUString sTmp;
const ::rtl::OUString sRemove =
::rtl::OUString::valueOf(i+nOrderIterator);
xOrderList->getByName(sRemove)
>>= xSet;
xSet->getPropertyValue(s_sHistoryItemRef) >>= sTmp;
xItemList->removeByName(sTmp);
xOrderList->removeByName(sRemove);
}
// increasing the value of FirstItem
xListSet->setPropertyValue(s_sFirstItem,
css::uno::makeAny(nOldItemCount+nOrderIterator));
::comphelper::ConfigurationHelper::flush(m_xCfg);
}
}
break;
case eHELPBOOKMARKS:
if(xListAccess.is() && nSize!=GetSize(eHELPBOOKMARKS))
{
xListAccess->setPropertyValue(s_sHelpBookmarksSize, css::uno::makeAny(nSize));
::comphelper::ConfigurationHelper::flush(m_xCommonXCU);
// If too much items in current list ...
// truncate the oldest items BEFORE you set the
new one.
m_xCfg->getByName(s_sHelpBookmarks) >>= xList;
xList->getByName(s_sOrderList) >>= xOrderList;
Sequence< ::rtl::OUString > lOrders =
xOrderList->getElementNames();
const sal_uInt32 nLength = lOrders.getLength();
if (nSize < nLength)
{
sal_Int32 nOrderIterator;
xListSet = css::uno::Reference<
css::beans::XPropertySet >(xList, css::uno::UNO_QUERY);
xListSet->getPropertyValue(s_sFirstItem) >>= nOrderIterator;
const sal_Int32 nOldItemCount = nLength
- nSize;
xList->getByName(s_sItemList) >>=
xItemList;
for (sal_Int32 i=0; i<nOldItemCount;
++i)
{
::rtl::OUString sTmp;
const ::rtl::OUString sRemove =
::rtl::OUString::valueOf(i+nOrderIterator);
xOrderList->getByName(sRemove)
>>= xSet;
xSet->getPropertyValue(s_sHistoryItemRef) >>= sTmp;
xItemList->removeByName(sTmp);
xOrderList->removeByName(sRemove);
}
// increasing the value of FirstItem
xListSet->setPropertyValue(s_sFirstItem,
css::uno::makeAny(nOldItemCount+nOrderIterator));
::comphelper::ConfigurationHelper::flush(m_xCfg);
}
}
break;
default:
break;
}
}
catch(const css::uno::Exception& ex)
{
LogHelper::logIt(ex);
}
}
//*****************************************************************************************************************
// public method
// Clear specified history list
//*****************************************************************************************************************
void SvtHistoryOptions_Impl::Clear( EHistoryType eHistory )
{
css::uno::Reference< css::container::XNameAccess > xListAccess;
css::uno::Reference< css::container::XNameContainer > xNode;
css::uno::Reference< css::beans::XPropertySet > xFirstItem;
Sequence< ::rtl::OUString > lOrders;
try
{
switch( eHistory )
{
case ePICKLIST:
{
m_xCfg->getByName(s_sPickList) >>= xListAccess;
// clear ItemList
xListAccess->getByName(s_sItemList) >>= xNode
;
lOrders = xNode->getElementNames();
sal_Int32 nItemLength = lOrders.getLength();
for(sal_Int32 i=0; i<nItemLength; ++i)
xNode->removeByName(lOrders[i]);
// clear OrderList
xListAccess->getByName(s_sOrderList) >>= xNode
;
lOrders = xNode->getElementNames();
sal_Int32 nOrderLength = lOrders.getLength();
for(sal_Int32 j=0; j<nOrderLength; ++j)
xNode->removeByName(lOrders[j]);
// set FirstItem = 0
xFirstItem = css::uno::Reference<
css::beans::XPropertySet >(xListAccess, css::uno::UNO_QUERY);
xFirstItem->setPropertyValue( s_sFirstItem,
css::uno::makeAny((sal_Int32)0) );
::comphelper::ConfigurationHelper::flush(m_xCfg);
}
break;
case eHISTORY:
{
m_xCfg->getByName(s_sURLHistory) >>=
xListAccess;
// clear ItemList
xListAccess->getByName(s_sItemList) >>= xNode
;
lOrders = xNode->getElementNames();
sal_Int32 nItemLength = lOrders.getLength();
for(sal_Int32 i=0; i<nItemLength; ++i)
xNode->removeByName(lOrders[i]);
// clear OrderList
xListAccess->getByName(s_sOrderList) >>= xNode
;
lOrders = xNode->getElementNames();
sal_Int32 nOrderLength = lOrders.getLength();
for(sal_Int32 j=0; j<nOrderLength; ++j)
xNode->removeByName(lOrders[j]);
// set FirstItem = 0
xFirstItem = css::uno::Reference<
css::beans::XPropertySet >(xListAccess, css::uno::UNO_QUERY);
xFirstItem->setPropertyValue( s_sFirstItem,
css::uno::makeAny((sal_Int32)0) );
::comphelper::ConfigurationHelper::flush(m_xCfg);
}
break;
case eHELPBOOKMARKS:
{
m_xCfg->getByName(s_sHelpBookmarks) >>=
xListAccess;
// clear ItemList
xListAccess->getByName(s_sItemList) >>= xNode
;
lOrders = xNode->getElementNames();
sal_Int32 nItemLength = lOrders.getLength();
for(sal_Int32 i=0; i<nItemLength; ++i)
xNode->removeByName(lOrders[i]);
// clear OrderList
xListAccess->getByName(s_sOrderList) >>= xNode
;
lOrders = xNode->getElementNames();
sal_Int32 nOrderLength = lOrders.getLength();
for(sal_Int32 j=0; j<nOrderLength; ++j)
xNode->removeByName(lOrders[j]);
// set FirstItem = 0
xFirstItem = css::uno::Reference<
css::beans::XPropertySet >(xListAccess, css::uno::UNO_QUERY);
xFirstItem->setPropertyValue( s_sFirstItem,
css::uno::makeAny((sal_Int32)0) );
::comphelper::ConfigurationHelper::flush(m_xCfg);
}
break;
default:
break;
}
}
catch(const css::uno::Exception& ex)
{
LogHelper::logIt(ex);
}
}
//*****************************************************************************************************************
// public method
// get a sequence list from the items
//*****************************************************************************************************************
Sequence< Sequence< PropertyValue > > SvtHistoryOptions_Impl::GetList(
EHistoryType eHistory )
{
Sequence< Sequence< PropertyValue > > seqReturn; // Set default return
value.
Sequence< PropertyValue > seqProperties( 4 );
Sequence< ::rtl::OUString > lOrders;
css::uno::Reference< css::container::XNameAccess > xListAccess;
css::uno::Reference< css::container::XNameAccess > xItemList;
css::uno::Reference< css::container::XNameAccess > xOrderList;
css::uno::Reference< css::beans::XPropertySet > xSet;
seqProperties[s_nOffsetURL ].Name = HISTORY_PROPERTYNAME_URL;
seqProperties[s_nOffsetFilter ].Name = HISTORY_PROPERTYNAME_FILTER;
seqProperties[s_nOffsetTitle ].Name = HISTORY_PROPERTYNAME_TITLE;
seqProperties[s_nOffsetPassword ].Name = HISTORY_PROPERTYNAME_PASSWORD;
try
{
switch( eHistory )
{
case ePICKLIST:
{
m_xCfg->getByName(s_sPickList) >>= xListAccess;
xListAccess->getByName(s_sItemList) >>=
xItemList;
xListAccess->getByName(s_sOrderList) >>=
xOrderList;
sal_Int32 nOrderIterator;
xSet = css::uno::Reference<
css::beans::XPropertySet >(xListAccess, css::uno::UNO_QUERY);
xSet->getPropertyValue(s_sFirstItem) >>=
nOrderIterator;
lOrders = xOrderList->getElementNames();
const sal_Int32 nLength = lOrders.getLength();
Sequence< Sequence< PropertyValue > >
aRet(nLength);
for(sal_Int32 nItem=0; nItem<nLength; ++nItem)
{
::rtl::OUString sUrl;
const ::rtl::OUString sItem =
::rtl::OUString::valueOf(nItem+nOrderIterator);
xOrderList->getByName(/*lOrders[nItem]*/sItem) >>= xSet;
xSet->getPropertyValue(s_sHistoryItemRef) >>= sUrl;
xItemList->getByName(sUrl) >>= xSet;
seqProperties[s_nOffsetURL ].Value
<<= sUrl;
xSet->getPropertyValue(s_sFilter) >>=
seqProperties[s_nOffsetFilter ].Value;
xSet->getPropertyValue(s_sTitle) >>=
seqProperties[s_nOffsetTitle ].Value;
xSet->getPropertyValue(s_sPassword) >>=
seqProperties[s_nOffsetPassword ].Value;
const sal_Int32 nPos = nLength - nItem
- 1;
aRet[nPos] = seqProperties;
}
seqReturn = aRet;
}
break;
case eHISTORY:
{
m_xCfg->getByName(s_sURLHistory) >>=
xListAccess;
xListAccess->getByName(s_sItemList) >>=
xItemList;
xListAccess->getByName(s_sOrderList) >>=
xOrderList;
sal_Int32 nOrderIterator;
xSet = css::uno::Reference<
css::beans::XPropertySet >(xListAccess, css::uno::UNO_QUERY);
xSet->getPropertyValue(s_sFirstItem) >>=
nOrderIterator;
lOrders = xOrderList->getElementNames();
const sal_Int32 nLength = lOrders.getLength();
Sequence< Sequence< PropertyValue > >
aRet(nLength);
for(sal_Int32 nItem=0; nItem<nLength; ++nItem)
{
rtl::OUString sUrl;
const ::rtl::OUString sItem =
::rtl::OUString::valueOf(nItem+nOrderIterator);
xOrderList->getByName(/*lOrders[nItem]*/sItem) >>= xSet;
xSet->getPropertyValue(s_sHistoryItemRef) >>= sUrl;
xItemList->getByName(sUrl) >>= xSet;
seqProperties[s_nOffsetURL ].Value
<<= sUrl;
xSet->getPropertyValue(s_sFilter) >>=
seqProperties[s_nOffsetFilter ].Value;
xSet->getPropertyValue(s_sTitle) >>=
seqProperties[s_nOffsetTitle ].Value;
xSet->getPropertyValue(s_sPassword) >>=
seqProperties[s_nOffsetPassword ].Value;
const sal_Int32 nPos = nLength - nItem
- 1;
aRet[nPos] = seqProperties;
}
seqReturn = aRet;
}
break;
case eHELPBOOKMARKS:
{
m_xCfg->getByName(s_sHelpBookmarks) >>=
xListAccess;
xListAccess->getByName(s_sItemList) >>=
xItemList;
xListAccess->getByName(s_sOrderList) >>=
xOrderList;
sal_Int32 nOrderIterator;
xSet = css::uno::Reference<
css::beans::XPropertySet >(xListAccess, css::uno::UNO_QUERY);
xSet->getPropertyValue(s_sFirstItem) >>=
nOrderIterator;
lOrders = xOrderList->getElementNames();
const sal_Int32 nLength = lOrders.getLength();
Sequence< Sequence< PropertyValue > >
aRet(nLength);
for(sal_Int32 nItem=0; nItem<nLength; ++nItem)
{
rtl::OUString sUrl;
const ::rtl::OUString sItem =
::rtl::OUString::valueOf(nItem+nOrderIterator);
xOrderList->getByName(/*lOrders[nItem]*/sItem) >>= xSet;
xSet->getPropertyValue(s_sHistoryItemRef) >>= sUrl;
xItemList->getByName(sUrl) >>= xSet;
seqProperties[s_nOffsetURL ].Value
<<= sUrl;
xSet->getPropertyValue(s_sFilter) >>=
seqProperties[s_nOffsetFilter ].Value;
xSet->getPropertyValue(s_sTitle) >>=
seqProperties[s_nOffsetTitle ].Value;
xSet->getPropertyValue(s_sPassword) >>=
seqProperties[s_nOffsetPassword ].Value;
const sal_Int32 nPos = nLength - nItem
- 1;
aRet[nPos] = seqProperties;
}
seqReturn = aRet;
}
break;
default:
break;
}
}
catch(const css::uno::Exception& ex)
{
LogHelper::logIt(ex);
}
return seqReturn;
}
//*****************************************************************************************************************
// public method
// implements a deque in XML
//*****************************************************************************************************************
void SvtHistoryOptions_Impl::AppendItem( EHistoryType eHistory ,
const OUString& sURL ,
const OUString& sFilter ,
const OUString& sTitle ,
const OUString& sPassword )
{
css::uno::Reference< css::container::XNameAccess > xListAccess;
sal_Int32 nMaxSize = 0;
switch(eHistory)
{
case ePICKLIST:
{
m_xCfg->getByName(s_sPickList) >>= xListAccess;
nMaxSize = GetSize(ePICKLIST);
}
break;
case eHISTORY:
{
m_xCfg->getByName(s_sURLHistory) >>= xListAccess;
nMaxSize = GetSize(eHISTORY);
}
break;
case eHELPBOOKMARKS:
{
m_xCfg->getByName(s_sHelpBookmarks) >>= xListAccess;
nMaxSize = GetSize(eHELPBOOKMARKS);
}
break;
default:
break;
}
if (nMaxSize==0)
return;
css::uno::Reference< css::container::XNameContainer > xItemList;
css::uno::Reference< css::container::XNameContainer > xOrderList;
css::uno::Reference< css::beans::XPropertySet > xSet;
try
{
xListAccess->getByName(s_sItemList) >>= xItemList;
xListAccess->getByName(s_sOrderList) >>= xOrderList;
Sequence< ::rtl::OUString > lOrders =
xOrderList->getElementNames();
const nLength = lOrders.getLength();
sal_Int32 nOrderIterator;
xSet = css::uno::Reference< css::beans::XPropertySet
>(xListAccess, css::uno::UNO_QUERY);
xSet->getPropertyValue(s_sFirstItem) >>= nOrderIterator;
// The item to be appended is already existing!
if (xItemList->hasByName(sURL))
{
for (sal_Int32 i=0; i<nLength; ++i)
{
::rtl::OUString sTmp;
xOrderList->getByName(::rtl::OUString::valueOf(i+nOrderIterator)) >>= xSet;
xSet->getPropertyValue(s_sHistoryItemRef) >>=
sTmp;
if(sURL == sTmp)
{
const sal_Int32 nFind = i +
nOrderIterator;
const sal_Int32 nTop = nLength +
nOrderIterator -1;
// increasing prio of existing items
::rtl::OUString sFind;
xOrderList->getByName(
::rtl::OUString::valueOf(nFind) ) >>= xSet;
xSet->getPropertyValue(s_sHistoryItemRef) >>= sFind;
for (sal_Int32 j=nFind; j<nTop; ++j)
{
css::uno::Reference<
css::beans::XPropertySet > xPrevSet;
css::uno::Reference<
css::beans::XPropertySet > xNextSet;
xOrderList->getByName(
::rtl::OUString::valueOf(j) ) >>= xPrevSet; //we cannt use lOrders[j]!
xOrderList->getByName(
::rtl::OUString::valueOf(j+1) ) >>= xNextSet; //we cannt use lOrders[j+1]!
::rtl::OUString sTemp;
xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
xPrevSet->setPropertyValue(s_sHistoryItemRef, css::uno::makeAny(sTemp));
}
xOrderList->getByName(
::rtl::OUString::valueOf(nTop) ) >>= xSet;
xSet->setPropertyValue(s_sHistoryItemRef, css::uno::makeAny(sFind));
::comphelper::ConfigurationHelper::flush(m_xCfg);
break;
}
}
}
// The item to be appended is not existing!
else
{
css::uno::Reference< css::lang::XSingleServiceFactory >
xFac;
css::uno::Reference< css::uno::XInterface >
xInst;
// If current list full ... delete the oldest item.
if ( nLength == nMaxSize )
{
::rtl::OUString sRemove;
::rtl::OUString sFirstOrder =
::rtl::OUString::valueOf(nOrderIterator);
xOrderList->getByName(sFirstOrder) >>= xSet;
xSet->getPropertyValue(s_sHistoryItemRef) >>=
sRemove;
xItemList->removeByName(sRemove);
// increasing prio of reopened items
for (sal_Int32 j=0; j<nLength-1; ++j)
{
css::uno::Reference<
css::beans::XPropertySet > xPrevSet;
css::uno::Reference<
css::beans::XPropertySet > xNextSet;
xOrderList->getByName(
::rtl::OUString::valueOf(j+nOrderIterator) ) >>= xPrevSet; //we cannt use
lOrders[j]!
xOrderList->getByName(
::rtl::OUString::valueOf(j+nOrderIterator+1) ) >>= xNextSet; //we cannt use
lOrders[j+1]!
::rtl::OUString sTemp;
xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp;
xPrevSet->setPropertyValue(s_sHistoryItemRef, css::uno::makeAny(sTemp));
}
::rtl::OUString sReplace =
::rtl::OUString::valueOf(nLength+nOrderIterator-1);
xOrderList->getByName(sReplace) >>= xSet;
xSet->setPropertyValue(s_sHistoryItemRef,
css::uno::makeAny(sURL));
}
// Append new item to OrderList.
else
{
xFac = css::uno::Reference<
css::lang::XSingleServiceFactory >(xOrderList, css::uno::UNO_QUERY);
xInst = xFac->createInstance();
::rtl::OUString sPush =
::rtl::OUString::valueOf(nLength+nOrderIterator);
xOrderList->insertByName(sPush,
css::uno::makeAny(xInst));
xSet = css::uno::Reference<
css::beans::XPropertySet >(xInst, css::uno::UNO_QUERY);
xSet->setPropertyValue(s_sHistoryItemRef,
css::uno::makeAny(sURL));
}
// Append the item to ItemList.
xFac = css::uno::Reference<
css::lang::XSingleServiceFactory >(xItemList, css::uno::UNO_QUERY);
xInst = xFac->createInstance();
xItemList->insertByName(sURL,
css::uno::makeAny(xInst));
xSet = css::uno::Reference< css::beans::XPropertySet
>(xInst, css::uno::UNO_QUERY);
xSet->setPropertyValue(s_sFilter,
css::uno::makeAny(sFilter));
xSet->setPropertyValue(s_sTitle,
css::uno::makeAny(sTitle));
xSet->setPropertyValue(s_sPassword,
css::uno::makeAny(sPassword));
::comphelper::ConfigurationHelper::flush(m_xCfg);
}
}
catch(const css::uno::Exception& ex)
{
LogHelper::logIt(ex);
}
}
//*****************************************************************************************************************
// initialize static member
// DON'T DO IT IN YOUR HEADER!
// see definition for further informations
//*****************************************************************************************************************
SvtHistoryOptions_Impl* SvtHistoryOptions::m_pDataContainer = NULL ;
sal_Int32 SvtHistoryOptions::m_nRefCount = 0 ;
//*****************************************************************************************************************
// constructor
//*****************************************************************************************************************
SvtHistoryOptions::SvtHistoryOptions()
{
// Global access, must be guarded (multithreading!).
MutexGuard aGuard( GetOwnStaticMutex() );
// Increase ouer refcount ...
++m_nRefCount;
// ... and initialize ouer data container only if it not already exist!
if( m_pDataContainer == NULL )
{
RTL_LOGFILE_CONTEXT(aLog, "svtools ( ??? )
::SvtHistoryOptions_Impl::ctor()");
m_pDataContainer = new SvtHistoryOptions_Impl;
ItemHolder1::holdConfigItem(E_HISTORYOPTIONS);
}
}
//*****************************************************************************************************************
// destructor
//*****************************************************************************************************************
SvtHistoryOptions::~SvtHistoryOptions()
{
// Global access, must be guarded (multithreading!)
MutexGuard aGuard( GetOwnStaticMutex() );
// Decrease ouer refcount.
--m_nRefCount;
// If last instance was deleted ...
// we must destroy ouer static data container!
if( m_nRefCount <= 0 )
{
delete m_pDataContainer;
m_pDataContainer = NULL;
}
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
sal_uInt32 SvtHistoryOptions::GetSize( EHistoryType eHistory ) const
{
MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->GetSize( eHistory );
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
void SvtHistoryOptions::SetSize( EHistoryType eHistory, sal_uInt32 nSize )
{
MutexGuard aGuard( GetOwnStaticMutex() );
m_pDataContainer->SetSize( eHistory, nSize );
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
void SvtHistoryOptions::Clear( EHistoryType eHistory )
{
MutexGuard aGuard( GetOwnStaticMutex() );
m_pDataContainer->Clear( eHistory );
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
Sequence< Sequence< PropertyValue > > SvtHistoryOptions::GetList( EHistoryType
eHistory ) const
{
MutexGuard aGuard( GetOwnStaticMutex() );
return m_pDataContainer->GetList( eHistory );
}
//*****************************************************************************************************************
// public method
//*****************************************************************************************************************
void SvtHistoryOptions::AppendItem( EHistoryType eHistory ,
const
OUString& sURL ,
const
OUString& sFilter ,
const
OUString& sTitle ,
const
OUString& sPassword )
{
MutexGuard aGuard( GetOwnStaticMutex() );
m_pDataContainer->AppendItem( eHistory, sURL, sFilter, sTitle,
sPassword );
}
//*****************************************************************************************************************
// private method
//*****************************************************************************************************************
Mutex& SvtHistoryOptions::GetOwnStaticMutex()
{
// Initialize static mutex only for one time!
static Mutex* pMutex = NULL;
// If these method first called (Mutex not already exist!) ...
if( pMutex == NULL )
{
// ... we must create a new one. Protect follow code with the
global mutex -
// It must be - we create a static variable!
MutexGuard aGuard( Mutex::getGlobalMutex() );
// We must check our pointer again - because it can be that
another instance of ouer class will be fastr then these!
if( pMutex == NULL )
{
// Create the new mutex and set it for return on static
variable.
static Mutex aMutex;
pMutex = &aMutex;
}
}
// Return new created or already existing mutex object.
return *pMutex;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]