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