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 #include <cppuhelper/implbase3.hxx> 29*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 30*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp> 34*cdf0e10cSrcweir #include <rtl/ref.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include "updatecheckconfiglistener.hxx" 37*cdf0e10cSrcweir #include "updateinfo.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir /* Interface to acess configuration data read-only */ 40*cdf0e10cSrcweir struct IByNameAccess 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir virtual ::com::sun::star::uno::Any getValue(const sal_Char * pName) = 0; 43*cdf0e10cSrcweir }; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir /* This helper class provides by name access to a sequence of named values */ 46*cdf0e10cSrcweir class NamedValueByNameAccess : public IByNameAccess 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& m_rValues; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir public: 51*cdf0e10cSrcweir NamedValueByNameAccess( 52*cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rValues) : 53*cdf0e10cSrcweir m_rValues(rValues) {} ; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir virtual ~NamedValueByNameAccess(); 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir virtual ::com::sun::star::uno::Any getValue(const sal_Char * pName); 58*cdf0e10cSrcweir }; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir /* This class encapsulates the configuration item actually used for storing the state 62*cdf0e10cSrcweir * the update check is actually in. 63*cdf0e10cSrcweir */ 64*cdf0e10cSrcweir class UpdateCheckROModel 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir public: 67*cdf0e10cSrcweir UpdateCheckROModel(IByNameAccess& aNameAccess) : m_aNameAccess(aNameAccess) {}; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir bool isAutoCheckEnabled() const; 70*cdf0e10cSrcweir bool isDownloadPaused() const; 71*cdf0e10cSrcweir rtl::OUString getLocalFileName() const; 72*cdf0e10cSrcweir sal_Int64 getDownloadSize() const; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir rtl::OUString getUpdateEntryVersion() const; 75*cdf0e10cSrcweir void getUpdateEntry(UpdateInfo& rInfo) const; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir private: 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir rtl::OUString getStringValue(const sal_Char *) const; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir IByNameAccess& m_aNameAccess; 82*cdf0e10cSrcweir }; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir /* This class implements the non published UNO service com.sun.star.setup.UpdateCheckConfig, 87*cdf0e10cSrcweir * which primary use is to be able to track changes done in the Toos -> Options page of this 88*cdf0e10cSrcweir * component, as this is not supported by the OOo configuration for extendable groups. 89*cdf0e10cSrcweir */ 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir class UpdateCheckConfig : public ::cppu::WeakImplHelper3< 92*cdf0e10cSrcweir ::com::sun::star::container::XNameReplace, 93*cdf0e10cSrcweir ::com::sun::star::util::XChangesBatch, 94*cdf0e10cSrcweir ::com::sun::star::lang::XServiceInfo > 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir UpdateCheckConfig( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xContainer, 97*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xAvailableUpdates, 98*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xIgnoredUpdates, 99*cdf0e10cSrcweir const ::rtl::Reference< UpdateCheckConfigListener >& rListener ); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir virtual ~UpdateCheckConfig(); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir public: 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< rtl::OUString > getServiceNames(); 106*cdf0e10cSrcweir static rtl::OUString getImplName(); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir static ::rtl::Reference< UpdateCheckConfig > get( 109*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext, 110*cdf0e10cSrcweir const ::rtl::Reference< UpdateCheckConfigListener >& rListener = ::rtl::Reference< UpdateCheckConfigListener >()); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir // Should really implement ROModel .. 113*cdf0e10cSrcweir bool isAutoCheckEnabled() const; 114*cdf0e10cSrcweir bool isAutoDownloadEnabled() const; 115*cdf0e10cSrcweir rtl::OUString getUpdateEntryVersion() const; 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir /* Updates the timestamp of last check, but does not commit the change 118*cdf0e10cSrcweir * as either clearUpdateFound() or setUpdateFound() are expected to get 119*cdf0e10cSrcweir * called next. 120*cdf0e10cSrcweir */ 121*cdf0e10cSrcweir void updateLastChecked(); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir /* Returns the date of the last successful check in seconds since 1970 */ 124*cdf0e10cSrcweir sal_Int64 getLastChecked() const; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir /* Returns configured check interval in seconds */ 127*cdf0e10cSrcweir sal_Int64 getCheckInterval() const; 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir /* Reset values of previously remembered update 130*cdf0e10cSrcweir */ 131*cdf0e10cSrcweir void clearUpdateFound(); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir /* Stores the specified data of an available update 134*cdf0e10cSrcweir */ 135*cdf0e10cSrcweir void storeUpdateFound(const UpdateInfo& rInfo, const rtl::OUString& aCurrentBuild); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir // Returns the local file name of a started download 138*cdf0e10cSrcweir rtl::OUString getLocalFileName() const; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir // Returns the local file name of a started download 141*cdf0e10cSrcweir rtl::OUString getDownloadDestination() const; 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir // stores the local file name of a just started download 144*cdf0e10cSrcweir void storeLocalFileName(const rtl::OUString& rFileName, sal_Int64 nFileSize); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // Removes the local file name of a download 147*cdf0e10cSrcweir void clearLocalFileName(); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir // Stores the bool value for manually paused downloads 150*cdf0e10cSrcweir void storeDownloadPaused(bool paused); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // Returns the directory that acts as the user's desktop 153*cdf0e10cSrcweir static rtl::OUString getDesktopDirectory(); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir // Returns a directory accessible for all users 156*cdf0e10cSrcweir static rtl::OUString getAllUsersDirectory(); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir // store and retrieve information about extensions 159*cdf0e10cSrcweir bool storeExtensionVersion( const rtl::OUString& rExtensionName, 160*cdf0e10cSrcweir const rtl::OUString& rVersion ); 161*cdf0e10cSrcweir bool checkExtensionVersion( const rtl::OUString& rExtensionName, 162*cdf0e10cSrcweir const rtl::OUString& rVersion ); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir // XElementAccess 165*cdf0e10cSrcweir virtual ::com::sun::star::uno::Type SAL_CALL getElementType( ) 166*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 167*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasElements( ) 168*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir // XNameAccess 171*cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) 172*cdf0e10cSrcweir throw (::com::sun::star::container::NoSuchElementException, 173*cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, 174*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException); 175*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) 176*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 177*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) 178*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir // XNameReplace 181*cdf0e10cSrcweir virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) 182*cdf0e10cSrcweir throw (::com::sun::star::lang::IllegalArgumentException, 183*cdf0e10cSrcweir ::com::sun::star::container::NoSuchElementException, 184*cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, 185*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // XChangesBatch 188*cdf0e10cSrcweir virtual void SAL_CALL commitChanges( ) 189*cdf0e10cSrcweir throw (::com::sun::star::lang::WrappedTargetException, 190*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException); 191*cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL hasPendingChanges( ) 192*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 193*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::util::ElementChange > SAL_CALL getPendingChanges( ) 194*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // XServiceInfo 197*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getImplementationName() 198*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 199*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & serviceName) 200*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 201*cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() 202*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir private: 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir static rtl::OUString getSubVersion( const rtl::OUString& rVersion, sal_Int32 *nIndex ); 207*cdf0e10cSrcweir static bool isVersionGreater( const rtl::OUString& rVersion1, const rtl::OUString& rVersion2 ); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xContainer; 210*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xAvailableUpdates; 211*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xIgnoredUpdates; 212*cdf0e10cSrcweir const ::rtl::Reference< UpdateCheckConfigListener > m_rListener; 213*cdf0e10cSrcweir }; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir //------------------------------------------------------------------------------ 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir template <typename T> 219*cdf0e10cSrcweir T getValue( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rNamedValues, const sal_Char * pszName ) 220*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir for( sal_Int32 n=0; n < rNamedValues.getLength(); n++ ) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir // Unfortunatly gcc-3.3 does not like Any.get<T>(); 225*cdf0e10cSrcweir if( rNamedValues[n].Name.equalsAscii( pszName ) ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir T value = T(); 228*cdf0e10cSrcweir if( ! (rNamedValues[n].Value >>= value) ) 229*cdf0e10cSrcweir throw ::com::sun::star::uno::RuntimeException( 230*cdf0e10cSrcweir ::rtl::OUString( 231*cdf0e10cSrcweir cppu_Any_extraction_failure_msg( 232*cdf0e10cSrcweir &rNamedValues[n].Value, 233*cdf0e10cSrcweir ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ), 234*cdf0e10cSrcweir SAL_NO_ACQUIRE ), 235*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() ); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir return value; 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir return T(); 242*cdf0e10cSrcweir } 243