1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_unotools.hxx" 30*cdf0e10cSrcweir #ifndef GCC 31*cdf0e10cSrcweir #endif 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir // includes 35*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <unotools/historyoptions.hxx> 38*cdf0e10cSrcweir #include <unotools/historyoptions_const.hxx> 39*cdf0e10cSrcweir #include <unotools/configmgr.hxx> 40*cdf0e10cSrcweir #include <unotools/configitem.hxx> 41*cdf0e10cSrcweir #include <tools/debug.hxx> 42*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 43*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir #ifndef __SGI_STL_DEQUE 46*cdf0e10cSrcweir #include <deque> 47*cdf0e10cSrcweir #endif 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #ifndef __SGI_STL_ALGORITHM 50*cdf0e10cSrcweir #include <algorithm> 51*cdf0e10cSrcweir #endif 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir #include <rtl/logfile.hxx> 54*cdf0e10cSrcweir #include "itemholder1.hxx" 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ 57*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 58*cdf0e10cSrcweir #endif 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ 61*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 62*cdf0e10cSrcweir #endif 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_ 65*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 66*cdf0e10cSrcweir #endif 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ 69*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 70*cdf0e10cSrcweir #endif 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir #ifndef _COMPHELPER_CONFIGURATIONHELPER_HXX_ 73*cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx> 74*cdf0e10cSrcweir #endif 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX_ 77*cdf0e10cSrcweir #include <unotools/processfactory.hxx> 78*cdf0e10cSrcweir #endif 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir #ifndef _SVT_LOGHELPER_HXX 81*cdf0e10cSrcweir #include <unotools/loghelper.hxx> 82*cdf0e10cSrcweir #endif 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 85*cdf0e10cSrcweir // namespaces 86*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir using namespace ::std ; 89*cdf0e10cSrcweir using namespace ::utl ; 90*cdf0e10cSrcweir using namespace ::rtl ; 91*cdf0e10cSrcweir using namespace ::osl ; 92*cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 93*cdf0e10cSrcweir using namespace ::com::sun::star::beans ; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir namespace css = ::com::sun::star; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 98*cdf0e10cSrcweir // const 99*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir namespace { 102*cdf0e10cSrcweir static const ::sal_Int32 s_nOffsetURL = 0; 103*cdf0e10cSrcweir static const ::sal_Int32 s_nOffsetFilter = 1; 104*cdf0e10cSrcweir static const ::sal_Int32 s_nOffsetTitle = 2; 105*cdf0e10cSrcweir static const ::sal_Int32 s_nOffsetPassword = 3; 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 109*cdf0e10cSrcweir // private declarations! 110*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir struct IMPL_THistoryItem 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir IMPL_THistoryItem() 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir IMPL_THistoryItem( const OUString& sNewURL , 119*cdf0e10cSrcweir const OUString& sNewFilter , 120*cdf0e10cSrcweir const OUString& sNewTitle , 121*cdf0e10cSrcweir const OUString& sNewPassword ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir sURL = sNewURL ; 124*cdf0e10cSrcweir sFilter = sNewFilter ; 125*cdf0e10cSrcweir sTitle = sNewTitle ; 126*cdf0e10cSrcweir sPassword = sNewPassword ; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir sal_Bool operator==( const OUString& sSearchedURL ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir return( sURL == sSearchedURL ); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir OUString sURL ; 135*cdf0e10cSrcweir OUString sFilter ; 136*cdf0e10cSrcweir OUString sTitle ; 137*cdf0e10cSrcweir OUString sPassword ; 138*cdf0e10cSrcweir }; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir //***************************************************************************************************************** 141*cdf0e10cSrcweir // class SvtHistoryOptions_Impl 142*cdf0e10cSrcweir // redesigned 143*cdf0e10cSrcweir //***************************************************************************************************************** 144*cdf0e10cSrcweir class SvtHistoryOptions_Impl 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir public: 147*cdf0e10cSrcweir SvtHistoryOptions_Impl(); 148*cdf0e10cSrcweir ~SvtHistoryOptions_Impl(); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir sal_uInt32 GetSize( EHistoryType eHistory ); 151*cdf0e10cSrcweir void SetSize( EHistoryType eHistory, sal_uInt32 nSize ); 152*cdf0e10cSrcweir void Clear( EHistoryType eHistory ); 153*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > GetList( EHistoryType eHistory ); 154*cdf0e10cSrcweir void AppendItem( EHistoryType eHistory , 155*cdf0e10cSrcweir const OUString& sURL , 156*cdf0e10cSrcweir const OUString& sFilter , 157*cdf0e10cSrcweir const OUString& sTitle , 158*cdf0e10cSrcweir const OUString& sPassword ); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir private: 161*cdf0e10cSrcweir void impl_truncateList (EHistoryType eHistory, sal_uInt32 nSize); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir private: 164*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > m_xCfg; 165*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > m_xCommonXCU; 166*cdf0e10cSrcweir }; 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir //***************************************************************************************************************** 169*cdf0e10cSrcweir // constructor 170*cdf0e10cSrcweir //***************************************************************************************************************** 171*cdf0e10cSrcweir SvtHistoryOptions_Impl::SvtHistoryOptions_Impl() 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir try 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir m_xCfg = Reference< css::container::XNameAccess > ( 176*cdf0e10cSrcweir ::comphelper::ConfigurationHelper::openConfig( 177*cdf0e10cSrcweir utl::getProcessServiceFactory(), 178*cdf0e10cSrcweir s_sHistories, 179*cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_STANDARD), 180*cdf0e10cSrcweir css::uno::UNO_QUERY ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir m_xCommonXCU = Reference< css::container::XNameAccess > ( 183*cdf0e10cSrcweir ::comphelper::ConfigurationHelper::openConfig( 184*cdf0e10cSrcweir utl::getProcessServiceFactory(), 185*cdf0e10cSrcweir s_sCommonHistory, 186*cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_STANDARD), 187*cdf0e10cSrcweir css::uno::UNO_QUERY ); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir catch(const css::uno::Exception& ex) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir m_xCfg.clear(); 192*cdf0e10cSrcweir m_xCommonXCU.clear(); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir LogHelper::logIt(ex); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir //***************************************************************************************************************** 199*cdf0e10cSrcweir // destructor 200*cdf0e10cSrcweir //***************************************************************************************************************** 201*cdf0e10cSrcweir SvtHistoryOptions_Impl::~SvtHistoryOptions_Impl() 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir //***************************************************************************************************************** 206*cdf0e10cSrcweir // public method 207*cdf0e10cSrcweir // Attention: We return the max. size of our internal lists - That is the capacity not the size! 208*cdf0e10cSrcweir //***************************************************************************************************************** 209*cdf0e10cSrcweir sal_uInt32 SvtHistoryOptions_Impl::GetSize( EHistoryType eHistory ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir sal_uInt32 nSize = 0 ; 212*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xListAccess(m_xCommonXCU, css::uno::UNO_QUERY); 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir try 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir switch( eHistory ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir case ePICKLIST: 219*cdf0e10cSrcweir xListAccess->getPropertyValue(s_sPickListSize) >>= nSize; 220*cdf0e10cSrcweir break; 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir case eHISTORY: 223*cdf0e10cSrcweir xListAccess->getPropertyValue(s_sURLHistorySize) >>= nSize; 224*cdf0e10cSrcweir break; 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir case eHELPBOOKMARKS: 227*cdf0e10cSrcweir xListAccess->getPropertyValue(s_sHelpBookmarksSize) >>= nSize; 228*cdf0e10cSrcweir break; 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir default: 231*cdf0e10cSrcweir break; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir catch(const css::uno::Exception& ex) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir LogHelper::logIt(ex); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir return nSize; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir //***************************************************************************************************************** 243*cdf0e10cSrcweir // public method 244*cdf0e10cSrcweir // Attention: We return the max. size of our internal lists - That is the capacity not the size! 245*cdf0e10cSrcweir //***************************************************************************************************************** 246*cdf0e10cSrcweir void SvtHistoryOptions_Impl::SetSize( EHistoryType eHistory, sal_uInt32 nSize ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xListAccess(m_xCommonXCU, css::uno::UNO_QUERY); 249*cdf0e10cSrcweir if (! xListAccess.is ()) 250*cdf0e10cSrcweir return; 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir try 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir switch( eHistory ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir case ePICKLIST: 257*cdf0e10cSrcweir if(nSize!=GetSize(ePICKLIST)) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir xListAccess->setPropertyValue(s_sPickListSize, css::uno::makeAny(nSize)); 260*cdf0e10cSrcweir ::comphelper::ConfigurationHelper::flush(m_xCommonXCU); 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir break; 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir case eHISTORY: 265*cdf0e10cSrcweir if(nSize!=GetSize(eHISTORY)) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir xListAccess->setPropertyValue(s_sURLHistorySize, css::uno::makeAny(nSize)); 268*cdf0e10cSrcweir ::comphelper::ConfigurationHelper::flush(m_xCommonXCU); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir break; 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir case eHELPBOOKMARKS: 273*cdf0e10cSrcweir if(nSize!=GetSize(eHELPBOOKMARKS)) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir xListAccess->setPropertyValue(s_sHelpBookmarksSize, css::uno::makeAny(nSize)); 276*cdf0e10cSrcweir ::comphelper::ConfigurationHelper::flush(m_xCommonXCU); 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir break; 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir default: 281*cdf0e10cSrcweir break; 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir impl_truncateList (eHistory, nSize); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir catch(const css::uno::Exception& ex) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir LogHelper::logIt(ex); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir //***************************************************************************************************************** 293*cdf0e10cSrcweir void SvtHistoryOptions_Impl::impl_truncateList ( EHistoryType eHistory, sal_uInt32 nSize ) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xList; 296*cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xItemList; 297*cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xOrderList; 298*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xSet; 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir try 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir switch( eHistory ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir case ePICKLIST: 305*cdf0e10cSrcweir m_xCfg->getByName(s_sPickList) >>= xList; 306*cdf0e10cSrcweir break; 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir case eHISTORY: 309*cdf0e10cSrcweir m_xCfg->getByName(s_sURLHistory) >>= xList; 310*cdf0e10cSrcweir break; 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir case eHELPBOOKMARKS: 313*cdf0e10cSrcweir m_xCfg->getByName(s_sHelpBookmarks) >>= xList; 314*cdf0e10cSrcweir break; 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir default: 317*cdf0e10cSrcweir break; 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir // If too much items in current list ... 321*cdf0e10cSrcweir // truncate the oldest items BEFORE you set the new one. 322*cdf0e10cSrcweir if ( ! xList.is()) 323*cdf0e10cSrcweir return; 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir xList->getByName(s_sOrderList) >>= xOrderList; 326*cdf0e10cSrcweir xList->getByName(s_sItemList) >>= xItemList; 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir const sal_uInt32 nLength = xOrderList->getElementNames().getLength(); 329*cdf0e10cSrcweir if (nSize < nLength) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir for (sal_uInt32 i=nLength-1; i>=nSize; --i) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir ::rtl::OUString sTmp; 334*cdf0e10cSrcweir const ::rtl::OUString sRemove = ::rtl::OUString::valueOf((sal_Int32)i); 335*cdf0e10cSrcweir xOrderList->getByName(sRemove) >>= xSet; 336*cdf0e10cSrcweir xSet->getPropertyValue(s_sHistoryItemRef) >>= sTmp; 337*cdf0e10cSrcweir xItemList->removeByName(sTmp); 338*cdf0e10cSrcweir xOrderList->removeByName(sRemove); 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir ::comphelper::ConfigurationHelper::flush(m_xCfg); 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir catch(const css::uno::Exception& ex) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir LogHelper::logIt(ex); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir //***************************************************************************************************************** 351*cdf0e10cSrcweir // public method 352*cdf0e10cSrcweir // Clear specified history list 353*cdf0e10cSrcweir //***************************************************************************************************************** 354*cdf0e10cSrcweir void SvtHistoryOptions_Impl::Clear( EHistoryType eHistory ) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xListAccess; 357*cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xNode; 358*cdf0e10cSrcweir Sequence< ::rtl::OUString > lOrders; 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir try 361*cdf0e10cSrcweir { 362*cdf0e10cSrcweir switch( eHistory ) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir case ePICKLIST: 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir m_xCfg->getByName(s_sPickList) >>= xListAccess; 367*cdf0e10cSrcweir break; 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir case eHISTORY: 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir m_xCfg->getByName(s_sURLHistory) >>= xListAccess; 373*cdf0e10cSrcweir break; 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir case eHELPBOOKMARKS: 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir m_xCfg->getByName(s_sHelpBookmarks) >>= xListAccess; 379*cdf0e10cSrcweir break; 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir default: 383*cdf0e10cSrcweir break; 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir if (xListAccess.is()) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir // clear ItemList 389*cdf0e10cSrcweir xListAccess->getByName(s_sItemList) >>= xNode ; 390*cdf0e10cSrcweir lOrders = xNode->getElementNames(); 391*cdf0e10cSrcweir const sal_Int32 nLength = lOrders.getLength(); 392*cdf0e10cSrcweir for(sal_Int32 i=0; i<nLength; ++i) 393*cdf0e10cSrcweir xNode->removeByName(lOrders[i]); 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir // clear OrderList 396*cdf0e10cSrcweir xListAccess->getByName(s_sOrderList) >>= xNode ; 397*cdf0e10cSrcweir lOrders = xNode->getElementNames(); 398*cdf0e10cSrcweir for(sal_Int32 j=0; j<nLength; ++j) 399*cdf0e10cSrcweir xNode->removeByName(lOrders[j]); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir ::comphelper::ConfigurationHelper::flush(m_xCfg); 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir catch(const css::uno::Exception& ex) 405*cdf0e10cSrcweir { 406*cdf0e10cSrcweir LogHelper::logIt(ex); 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir //***************************************************************************************************************** 411*cdf0e10cSrcweir // public method 412*cdf0e10cSrcweir // get a sequence list from the items 413*cdf0e10cSrcweir //***************************************************************************************************************** 414*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > SvtHistoryOptions_Impl::GetList( EHistoryType eHistory ) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir impl_truncateList (eHistory, GetSize (eHistory)); 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > seqReturn; // Set default return value. 419*cdf0e10cSrcweir Sequence< PropertyValue > seqProperties( 4 ); 420*cdf0e10cSrcweir Sequence< ::rtl::OUString > lOrders; 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xListAccess; 423*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xItemList; 424*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xOrderList; 425*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xSet; 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir seqProperties[s_nOffsetURL ].Name = HISTORY_PROPERTYNAME_URL; 428*cdf0e10cSrcweir seqProperties[s_nOffsetFilter ].Name = HISTORY_PROPERTYNAME_FILTER; 429*cdf0e10cSrcweir seqProperties[s_nOffsetTitle ].Name = HISTORY_PROPERTYNAME_TITLE; 430*cdf0e10cSrcweir seqProperties[s_nOffsetPassword ].Name = HISTORY_PROPERTYNAME_PASSWORD; 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir try 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir switch( eHistory ) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir case ePICKLIST: 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir m_xCfg->getByName(s_sPickList) >>= xListAccess; 439*cdf0e10cSrcweir break; 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir case eHISTORY: 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir m_xCfg->getByName(s_sURLHistory) >>= xListAccess; 445*cdf0e10cSrcweir break; 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir case eHELPBOOKMARKS: 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir m_xCfg->getByName(s_sHelpBookmarks) >>= xListAccess; 451*cdf0e10cSrcweir break; 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir default: 455*cdf0e10cSrcweir break; 456*cdf0e10cSrcweir } 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir if (xListAccess.is()) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir xListAccess->getByName(s_sItemList) >>= xItemList; 461*cdf0e10cSrcweir xListAccess->getByName(s_sOrderList) >>= xOrderList; 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir const sal_Int32 nLength = xOrderList->getElementNames().getLength(); 464*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > aRet(nLength); 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir for(sal_Int32 nItem=0; nItem<nLength; ++nItem) 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir ::rtl::OUString sUrl; 469*cdf0e10cSrcweir xOrderList->getByName(::rtl::OUString::valueOf(nItem)) >>= xSet; 470*cdf0e10cSrcweir xSet->getPropertyValue(s_sHistoryItemRef) >>= sUrl; 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir xItemList->getByName(sUrl) >>= xSet; 473*cdf0e10cSrcweir seqProperties[s_nOffsetURL ].Value <<= sUrl; 474*cdf0e10cSrcweir xSet->getPropertyValue(s_sFilter) >>= seqProperties[s_nOffsetFilter ].Value; 475*cdf0e10cSrcweir xSet->getPropertyValue(s_sTitle) >>= seqProperties[s_nOffsetTitle ].Value; 476*cdf0e10cSrcweir xSet->getPropertyValue(s_sPassword) >>= seqProperties[s_nOffsetPassword ].Value; 477*cdf0e10cSrcweir aRet[nItem] = seqProperties; 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir seqReturn = aRet; 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir catch(const css::uno::Exception& ex) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir LogHelper::logIt(ex); 485*cdf0e10cSrcweir } 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir return seqReturn; 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir //***************************************************************************************************************** 491*cdf0e10cSrcweir // public method 492*cdf0e10cSrcweir // implements a deque in XML 493*cdf0e10cSrcweir //***************************************************************************************************************** 494*cdf0e10cSrcweir void SvtHistoryOptions_Impl::AppendItem( EHistoryType eHistory , 495*cdf0e10cSrcweir const OUString& sURL , 496*cdf0e10cSrcweir const OUString& sFilter , 497*cdf0e10cSrcweir const OUString& sTitle , 498*cdf0e10cSrcweir const OUString& sPassword ) 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir impl_truncateList (eHistory, GetSize (eHistory)); 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xListAccess; 503*cdf0e10cSrcweir sal_Int32 nMaxSize = 0; 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir switch(eHistory) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir case ePICKLIST: 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir m_xCfg->getByName(s_sPickList) >>= xListAccess; 510*cdf0e10cSrcweir nMaxSize = GetSize(ePICKLIST); 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir break; 513*cdf0e10cSrcweir case eHISTORY: 514*cdf0e10cSrcweir { 515*cdf0e10cSrcweir m_xCfg->getByName(s_sURLHistory) >>= xListAccess; 516*cdf0e10cSrcweir nMaxSize = GetSize(eHISTORY); 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir break; 519*cdf0e10cSrcweir case eHELPBOOKMARKS: 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir m_xCfg->getByName(s_sHelpBookmarks) >>= xListAccess; 522*cdf0e10cSrcweir nMaxSize = GetSize(eHELPBOOKMARKS); 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir break; 525*cdf0e10cSrcweir default: 526*cdf0e10cSrcweir break; 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir if (nMaxSize==0) 530*cdf0e10cSrcweir return; 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xItemList; 533*cdf0e10cSrcweir css::uno::Reference< css::container::XNameContainer > xOrderList; 534*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xSet; 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir try 537*cdf0e10cSrcweir { 538*cdf0e10cSrcweir xListAccess->getByName(s_sItemList) >>= xItemList; 539*cdf0e10cSrcweir xListAccess->getByName(s_sOrderList) >>= xOrderList; 540*cdf0e10cSrcweir sal_Int32 nLength = xOrderList->getElementNames().getLength(); 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir // The item to be appended is already existing! 543*cdf0e10cSrcweir if (xItemList->hasByName(sURL)) 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir for (sal_Int32 i=0; i<nLength; ++i) 546*cdf0e10cSrcweir { 547*cdf0e10cSrcweir ::rtl::OUString sTmp; 548*cdf0e10cSrcweir xOrderList->getByName(::rtl::OUString::valueOf(i)) >>= xSet; 549*cdf0e10cSrcweir xSet->getPropertyValue(s_sHistoryItemRef) >>= sTmp; 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir if(sURL == sTmp) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir ::rtl::OUString sFind; 554*cdf0e10cSrcweir xOrderList->getByName( ::rtl::OUString::valueOf(i) ) >>= xSet; 555*cdf0e10cSrcweir xSet->getPropertyValue(s_sHistoryItemRef) >>= sFind; 556*cdf0e10cSrcweir for (sal_Int32 j=i-1; j>=0; --j) 557*cdf0e10cSrcweir { 558*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xPrevSet; 559*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xNextSet; 560*cdf0e10cSrcweir xOrderList->getByName( ::rtl::OUString::valueOf(j+1) ) >>= xPrevSet; 561*cdf0e10cSrcweir xOrderList->getByName( ::rtl::OUString::valueOf(j) ) >>= xNextSet; 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir ::rtl::OUString sTemp; 564*cdf0e10cSrcweir xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp; 565*cdf0e10cSrcweir xPrevSet->setPropertyValue(s_sHistoryItemRef, css::uno::makeAny(sTemp)); 566*cdf0e10cSrcweir } 567*cdf0e10cSrcweir xOrderList->getByName( ::rtl::OUString::valueOf((sal_Int32)0) ) >>= xSet; 568*cdf0e10cSrcweir xSet->setPropertyValue(s_sHistoryItemRef, css::uno::makeAny(sFind)); 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir ::comphelper::ConfigurationHelper::flush(m_xCfg); 571*cdf0e10cSrcweir break; 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir // The item to be appended is not existing! 577*cdf0e10cSrcweir else 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > xFac; 580*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xInst; 581*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xPrevSet; 582*cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xNextSet; 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir // Append new item to OrderList. 585*cdf0e10cSrcweir if ( nLength == nMaxSize ) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir ::rtl::OUString sRemove; 588*cdf0e10cSrcweir xOrderList->getByName(::rtl::OUString::valueOf(nLength-1)) >>= xSet; 589*cdf0e10cSrcweir xSet->getPropertyValue(s_sHistoryItemRef) >>= sRemove; 590*cdf0e10cSrcweir xItemList->removeByName(sRemove); 591*cdf0e10cSrcweir } 592*cdf0e10cSrcweir if ( nLength != nMaxSize ) 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir xFac = css::uno::Reference< css::lang::XSingleServiceFactory >(xOrderList, css::uno::UNO_QUERY); 595*cdf0e10cSrcweir xInst = xFac->createInstance(); 596*cdf0e10cSrcweir ::rtl::OUString sPush = ::rtl::OUString::valueOf(nLength++); 597*cdf0e10cSrcweir xOrderList->insertByName(sPush, css::uno::makeAny(xInst)); 598*cdf0e10cSrcweir } 599*cdf0e10cSrcweir for (sal_Int32 j=nLength-1; j>0; --j) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir xOrderList->getByName( ::rtl::OUString::valueOf(j) ) >>= xPrevSet; 602*cdf0e10cSrcweir xOrderList->getByName( ::rtl::OUString::valueOf(j-1) ) >>= xNextSet; 603*cdf0e10cSrcweir ::rtl::OUString sTemp; 604*cdf0e10cSrcweir xNextSet->getPropertyValue(s_sHistoryItemRef) >>= sTemp; 605*cdf0e10cSrcweir xPrevSet->setPropertyValue(s_sHistoryItemRef, css::uno::makeAny(sTemp)); 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir xOrderList->getByName( ::rtl::OUString::valueOf((sal_Int32)0) ) >>= xSet; 608*cdf0e10cSrcweir xSet->setPropertyValue(s_sHistoryItemRef, css::uno::makeAny(sURL)); 609*cdf0e10cSrcweir 610*cdf0e10cSrcweir // Append the item to ItemList. 611*cdf0e10cSrcweir xFac = css::uno::Reference< css::lang::XSingleServiceFactory >(xItemList, css::uno::UNO_QUERY); 612*cdf0e10cSrcweir xInst = xFac->createInstance(); 613*cdf0e10cSrcweir xItemList->insertByName(sURL, css::uno::makeAny(xInst)); 614*cdf0e10cSrcweir xSet = css::uno::Reference< css::beans::XPropertySet >(xInst, css::uno::UNO_QUERY); 615*cdf0e10cSrcweir xSet->setPropertyValue(s_sFilter, css::uno::makeAny(sFilter)); 616*cdf0e10cSrcweir xSet->setPropertyValue(s_sTitle, css::uno::makeAny(sTitle)); 617*cdf0e10cSrcweir xSet->setPropertyValue(s_sPassword, css::uno::makeAny(sPassword)); 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir ::comphelper::ConfigurationHelper::flush(m_xCfg); 620*cdf0e10cSrcweir } 621*cdf0e10cSrcweir } 622*cdf0e10cSrcweir catch(const css::uno::Exception& ex) 623*cdf0e10cSrcweir { 624*cdf0e10cSrcweir LogHelper::logIt(ex); 625*cdf0e10cSrcweir } 626*cdf0e10cSrcweir } 627*cdf0e10cSrcweir 628*cdf0e10cSrcweir //***************************************************************************************************************** 629*cdf0e10cSrcweir // initialize static member 630*cdf0e10cSrcweir // DON'T DO IT IN YOUR HEADER! 631*cdf0e10cSrcweir // see definition for further informations 632*cdf0e10cSrcweir //***************************************************************************************************************** 633*cdf0e10cSrcweir SvtHistoryOptions_Impl* SvtHistoryOptions::m_pDataContainer = NULL ; 634*cdf0e10cSrcweir sal_Int32 SvtHistoryOptions::m_nRefCount = 0 ; 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir //***************************************************************************************************************** 637*cdf0e10cSrcweir // constructor 638*cdf0e10cSrcweir //***************************************************************************************************************** 639*cdf0e10cSrcweir SvtHistoryOptions::SvtHistoryOptions() 640*cdf0e10cSrcweir { 641*cdf0e10cSrcweir // Global access, must be guarded (multithreading!). 642*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 643*cdf0e10cSrcweir // Increase ouer refcount ... 644*cdf0e10cSrcweir ++m_nRefCount; 645*cdf0e10cSrcweir // ... and initialize ouer data container only if it not already exist! 646*cdf0e10cSrcweir if( m_pDataContainer == NULL ) 647*cdf0e10cSrcweir { 648*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtHistoryOptions_Impl::ctor()"); 649*cdf0e10cSrcweir m_pDataContainer = new SvtHistoryOptions_Impl; 650*cdf0e10cSrcweir 651*cdf0e10cSrcweir ItemHolder1::holdConfigItem(E_HISTORYOPTIONS); 652*cdf0e10cSrcweir } 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir //***************************************************************************************************************** 656*cdf0e10cSrcweir // destructor 657*cdf0e10cSrcweir //***************************************************************************************************************** 658*cdf0e10cSrcweir SvtHistoryOptions::~SvtHistoryOptions() 659*cdf0e10cSrcweir { 660*cdf0e10cSrcweir // Global access, must be guarded (multithreading!) 661*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 662*cdf0e10cSrcweir // Decrease ouer refcount. 663*cdf0e10cSrcweir --m_nRefCount; 664*cdf0e10cSrcweir // If last instance was deleted ... 665*cdf0e10cSrcweir // we must destroy ouer static data container! 666*cdf0e10cSrcweir if( m_nRefCount <= 0 ) 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir delete m_pDataContainer; 669*cdf0e10cSrcweir m_pDataContainer = NULL; 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir } 672*cdf0e10cSrcweir 673*cdf0e10cSrcweir //***************************************************************************************************************** 674*cdf0e10cSrcweir // public method 675*cdf0e10cSrcweir //***************************************************************************************************************** 676*cdf0e10cSrcweir sal_uInt32 SvtHistoryOptions::GetSize( EHistoryType eHistory ) const 677*cdf0e10cSrcweir { 678*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 679*cdf0e10cSrcweir return m_pDataContainer->GetSize( eHistory ); 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir //***************************************************************************************************************** 683*cdf0e10cSrcweir // public method 684*cdf0e10cSrcweir //***************************************************************************************************************** 685*cdf0e10cSrcweir void SvtHistoryOptions::SetSize( EHistoryType eHistory, sal_uInt32 nSize ) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 688*cdf0e10cSrcweir m_pDataContainer->SetSize( eHistory, nSize ); 689*cdf0e10cSrcweir } 690*cdf0e10cSrcweir 691*cdf0e10cSrcweir //***************************************************************************************************************** 692*cdf0e10cSrcweir // public method 693*cdf0e10cSrcweir //***************************************************************************************************************** 694*cdf0e10cSrcweir void SvtHistoryOptions::Clear( EHistoryType eHistory ) 695*cdf0e10cSrcweir { 696*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 697*cdf0e10cSrcweir m_pDataContainer->Clear( eHistory ); 698*cdf0e10cSrcweir } 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir //***************************************************************************************************************** 701*cdf0e10cSrcweir // public method 702*cdf0e10cSrcweir //***************************************************************************************************************** 703*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > SvtHistoryOptions::GetList( EHistoryType eHistory ) const 704*cdf0e10cSrcweir { 705*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 706*cdf0e10cSrcweir return m_pDataContainer->GetList( eHistory ); 707*cdf0e10cSrcweir } 708*cdf0e10cSrcweir 709*cdf0e10cSrcweir //***************************************************************************************************************** 710*cdf0e10cSrcweir // public method 711*cdf0e10cSrcweir //***************************************************************************************************************** 712*cdf0e10cSrcweir void SvtHistoryOptions::AppendItem( EHistoryType eHistory , 713*cdf0e10cSrcweir const OUString& sURL , 714*cdf0e10cSrcweir const OUString& sFilter , 715*cdf0e10cSrcweir const OUString& sTitle , 716*cdf0e10cSrcweir const OUString& sPassword ) 717*cdf0e10cSrcweir { 718*cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() ); 719*cdf0e10cSrcweir m_pDataContainer->AppendItem( eHistory, sURL, sFilter, sTitle, sPassword ); 720*cdf0e10cSrcweir } 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir //***************************************************************************************************************** 723*cdf0e10cSrcweir // private method 724*cdf0e10cSrcweir //***************************************************************************************************************** 725*cdf0e10cSrcweir Mutex& SvtHistoryOptions::GetOwnStaticMutex() 726*cdf0e10cSrcweir { 727*cdf0e10cSrcweir // Initialize static mutex only for one time! 728*cdf0e10cSrcweir static Mutex* pMutex = NULL; 729*cdf0e10cSrcweir // If these method first called (Mutex not already exist!) ... 730*cdf0e10cSrcweir if( pMutex == NULL ) 731*cdf0e10cSrcweir { 732*cdf0e10cSrcweir // ... we must create a new one. Protect follow code with the global mutex - 733*cdf0e10cSrcweir // It must be - we create a static variable! 734*cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() ); 735*cdf0e10cSrcweir // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these! 736*cdf0e10cSrcweir if( pMutex == NULL ) 737*cdf0e10cSrcweir { 738*cdf0e10cSrcweir // Create the new mutex and set it for return on static variable. 739*cdf0e10cSrcweir static Mutex aMutex; 740*cdf0e10cSrcweir pMutex = &aMutex; 741*cdf0e10cSrcweir } 742*cdf0e10cSrcweir } 743*cdf0e10cSrcweir // Return new created or already existing mutex object. 744*cdf0e10cSrcweir return *pMutex; 745*cdf0e10cSrcweir } 746