Bump for 3.6-28
[LibreOffice.git] / extensions / source / update / check / updatecheckconfig.cxx
blob52efd91eca08dd35dfcbf1ec7d1c70b6a2a95685
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include "updatecheckconfig.hxx"
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/beans/XPropertyState.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/configuration/theDefaultProvider.hpp>
36 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
37 #include <osl/security.hxx>
38 #include <osl/time.h>
39 #include <osl/file.hxx>
40 #include <sal/macros.h>
42 #ifdef WNT
43 #ifdef _MSC_VER
44 #pragma warning(push,1) // disable warnings within system headers
45 #pragma warning(disable: 4917)
46 #endif
47 #include <shlobj.h>
48 #ifdef _MSC_VER
49 #pragma warning(pop)
50 #endif
51 #endif
53 namespace container = com::sun::star::container ;
54 namespace beans = com::sun::star::beans ;
55 namespace lang = com::sun::star::lang ;
56 namespace util = com::sun::star::util ;
57 namespace uno = com::sun::star::uno ;
59 #define UNISTRING(s) rtl::OUString(s)
61 #define LAST_CHECK "LastCheck"
62 #define VERSION_FOUND "UpdateVersionFound"
63 #define UPDATE_VERSION "UpdateVersion"
64 #define UPDATE_BUILDID "UpdateBuildId"
65 #define UPDATE_DESCRIPTION "UpdateDescription"
66 #define DOWNLOAD_URL "DownloadURL"
67 #define IS_DIRECT_DOWNLOAD "IsDirectDownload"
68 #define OLD_VERSION "UpdateFoundFor"
69 #define AUTOCHECK_ENABLED "AutoCheckEnabled"
70 #define AUTODOWNLOAD_ENABLED "AutoDownloadEnabled"
71 #define CHECK_INTERVAL "CheckInterval"
72 #define LOCAL_FILE "LocalFile"
73 #define DOWNLOAD_SIZE "DownloadSize"
74 #define DOWNLOAD_PAUSED "DownloadPaused"
75 #define DOWNLOAD_DESTINATION "DownloadDestination"
76 #define RELEASE_NOTE "ReleaseNote"
77 #define EXTENSION_PREFIX "Extension_"
79 #define PROPERTY_VERSION UNISTRING("Version")
81 static const sal_Char * const aUpdateEntryProperties[] = {
82 UPDATE_VERSION,
83 UPDATE_BUILDID,
84 UPDATE_DESCRIPTION,
85 DOWNLOAD_URL,
86 IS_DIRECT_DOWNLOAD,
87 RELEASE_NOTE"1",
88 RELEASE_NOTE"2",
89 RELEASE_NOTE"3",
90 RELEASE_NOTE"4",
91 RELEASE_NOTE"5",
92 OLD_VERSION
95 static const sal_uInt32 nUpdateEntryProperties = SAL_N_ELEMENTS(aUpdateEntryProperties);
97 //------------------------------------------------------------------------------
99 NamedValueByNameAccess::~NamedValueByNameAccess()
103 //------------------------------------------------------------------------------
105 ::com::sun::star::uno::Any
106 NamedValueByNameAccess::getValue(const sal_Char * pName)
108 const sal_Int32 nLen = m_rValues.getLength();
109 for( sal_Int32 n=0; n < nLen; ++n )
111 if( m_rValues[n].Name.equalsAscii( pName ) )
112 return m_rValues[n].Value;
114 return ::com::sun::star::uno::Any();
118 //------------------------------------------------------------------------------
120 bool
121 UpdateCheckROModel::isAutoCheckEnabled() const
123 return sal_True == m_aNameAccess.getValue(AUTOCHECK_ENABLED).get< sal_Bool >();
126 //------------------------------------------------------------------------------
128 bool
129 UpdateCheckROModel::isDownloadPaused() const
131 return sal_True == m_aNameAccess.getValue(DOWNLOAD_PAUSED).get< sal_Bool >();
134 //------------------------------------------------------------------------------
136 rtl::OUString
137 UpdateCheckROModel::getStringValue(const sal_Char * pStr) const
139 uno::Any aAny( m_aNameAccess.getValue(pStr) );
140 rtl::OUString aRet;
142 aAny >>= aRet;
144 return aRet;
147 //------------------------------------------------------------------------------
149 rtl::OUString UpdateCheckROModel::getLocalFileName() const
151 return getStringValue(LOCAL_FILE);
154 //------------------------------------------------------------------------------
156 sal_Int64 UpdateCheckROModel::getDownloadSize() const
158 uno::Any aAny( m_aNameAccess.getValue(DOWNLOAD_SIZE) );
159 sal_Int64 nRet = -1;
161 aAny >>= nRet;
162 return nRet;
165 //------------------------------------------------------------------------------
167 rtl::OUString
168 UpdateCheckROModel::getUpdateEntryVersion() const
170 return getStringValue(OLD_VERSION);
173 //------------------------------------------------------------------------------
175 void
176 UpdateCheckROModel::getUpdateEntry(UpdateInfo& rInfo) const
178 rInfo.BuildId = getStringValue(UPDATE_BUILDID);
179 rInfo.Version = getStringValue(UPDATE_VERSION);
180 rInfo.Description = getStringValue(UPDATE_DESCRIPTION);
182 sal_Bool isDirectDownload = sal_False;
183 m_aNameAccess.getValue(IS_DIRECT_DOWNLOAD) >>= isDirectDownload;
185 rInfo.Sources.push_back( DownloadSource( isDirectDownload, getStringValue(DOWNLOAD_URL) ) );
187 rtl::OString aStr(RELEASE_NOTE);
188 for(sal_Int32 n=1; n < 6; ++n )
190 rtl::OUString aUStr = getStringValue(
191 (aStr + rtl::OString::valueOf(n)).getStr());
192 if( !aUStr.isEmpty() )
193 rInfo.ReleaseNotes.push_back(ReleaseNote((sal_Int8) n, aUStr));
198 //------------------------------------------------------------------------------
200 rtl::OUString UpdateCheckConfig::getDesktopDirectory()
202 rtl::OUString aRet;
204 #ifdef WNT
205 WCHAR szPath[MAX_PATH];
207 if( ! FAILED( SHGetSpecialFolderPathW( NULL, szPath, CSIDL_DESKTOPDIRECTORY, true ) ) )
209 aRet = rtl::OUString( reinterpret_cast< sal_Unicode * >(szPath) );
210 osl::FileBase::getFileURLFromSystemPath( aRet, aRet );
212 #else
213 // This should become a desktop specific setting in some system backend ..
214 rtl::OUString aHomeDir;
215 osl::Security().getHomeDir( aHomeDir );
216 aRet = aHomeDir + rtl::OUString("/Desktop");
218 // Set path to home directory when there is no /Desktop directory
219 osl::Directory aDocumentsDir( aRet );
220 if( osl::FileBase::E_None != aDocumentsDir.open() )
221 aRet = aHomeDir;
222 #endif
224 return aRet;
227 //------------------------------------------------------------------------------
229 rtl::OUString UpdateCheckConfig::getAllUsersDirectory()
231 rtl::OUString aRet;
233 #ifdef WNT
234 WCHAR szPath[MAX_PATH];
236 if( ! FAILED( SHGetSpecialFolderPathW( NULL, szPath, CSIDL_COMMON_DOCUMENTS, true ) ) )
238 aRet = rtl::OUString( reinterpret_cast< sal_Unicode * >(szPath) );
239 osl::FileBase::getFileURLFromSystemPath( aRet, aRet );
241 #else
242 osl::FileBase::getTempDirURL(aRet);
243 #endif
245 return aRet;
248 //------------------------------------------------------------------------------
249 UpdateCheckConfig::UpdateCheckConfig( const uno::Reference<container::XNameContainer>& xContainer,
250 const uno::Reference<container::XNameContainer>& xAvailableUpdates,
251 const uno::Reference<container::XNameContainer>& xIgnoredUpdates,
252 const ::rtl::Reference< UpdateCheckConfigListener >& rListener ) :
253 m_xContainer( xContainer ),
254 m_xAvailableUpdates( xAvailableUpdates ),
255 m_xIgnoredUpdates( xIgnoredUpdates ),
256 m_rListener( rListener )
259 //------------------------------------------------------------------------------
260 UpdateCheckConfig::~UpdateCheckConfig()
263 //------------------------------------------------------------------------------
265 ::rtl::Reference< UpdateCheckConfig >
266 UpdateCheckConfig::get(
267 const uno::Reference<uno::XComponentContext>& xContext,
268 const ::rtl::Reference< UpdateCheckConfigListener >& rListener)
270 uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
271 com::sun::star::configuration::theDefaultProvider::get( xContext ) );
273 beans::PropertyValue aProperty;
274 aProperty.Name = UNISTRING( "nodepath" );
275 aProperty.Value = uno::makeAny( UNISTRING("org.openoffice.Office.Jobs/Jobs/UpdateCheck/Arguments") );
277 uno::Sequence< uno::Any > aArgumentList( 1 );
278 aArgumentList[0] = uno::makeAny( aProperty );
280 uno::Reference< container::XNameContainer > xContainer(
281 xConfigProvider->createInstanceWithArguments(
282 UNISTRING("com.sun.star.configuration.ConfigurationUpdateAccess"), aArgumentList ),
283 uno::UNO_QUERY_THROW );
285 aProperty.Value = uno::makeAny( UNISTRING("/org.openoffice.Office.ExtensionManager/ExtensionUpdateData/IgnoredUpdates") );
286 aArgumentList[0] = uno::makeAny( aProperty );
287 uno::Reference< container::XNameContainer > xIgnoredExt( xConfigProvider->createInstanceWithArguments( UNISTRING("com.sun.star.configuration.ConfigurationUpdateAccess"), aArgumentList ), uno::UNO_QUERY_THROW );
289 aProperty.Value = uno::makeAny( UNISTRING("/org.openoffice.Office.ExtensionManager/ExtensionUpdateData/AvailableUpdates") );
290 aArgumentList[0] = uno::makeAny( aProperty );
291 uno::Reference< container::XNameContainer > xUpdateAvail( xConfigProvider->createInstanceWithArguments( UNISTRING("com.sun.star.configuration.ConfigurationUpdateAccess"), aArgumentList ), uno::UNO_QUERY_THROW );
293 return new UpdateCheckConfig( xContainer, xUpdateAvail, xIgnoredExt, rListener );
296 //------------------------------------------------------------------------------
298 bool
299 UpdateCheckConfig::isAutoCheckEnabled() const
301 sal_Bool nValue = sal_False;
302 const_cast < UpdateCheckConfig *> (this)->getByName( UNISTRING( AUTOCHECK_ENABLED ) ) >>= nValue;
303 return nValue;
306 //------------------------------------------------------------------------------
308 bool
309 UpdateCheckConfig::isAutoDownloadEnabled() const
311 sal_Bool nValue = sal_False;
312 const_cast < UpdateCheckConfig *> (this)->getByName( UNISTRING( AUTODOWNLOAD_ENABLED ) ) >>= nValue;
313 return nValue;
316 //------------------------------------------------------------------------------
318 rtl::OUString
319 UpdateCheckConfig::getUpdateEntryVersion() const
321 rtl::OUString aValue;
323 // getByName is defined as non const in XNameAccess
324 const_cast < UpdateCheckConfig *> (this)->getByName( UNISTRING( OLD_VERSION ) ) >>= aValue;
326 return aValue;
329 //------------------------------------------------------------------------------
331 sal_Int64
332 UpdateCheckConfig::getLastChecked() const
334 sal_Int64 nValue = 0;
336 // getByName is defined as non const in XNameAccess
337 const_cast < UpdateCheckConfig *> (this)->getByName( UNISTRING( LAST_CHECK ) ) >>= nValue;
339 return nValue;
342 //------------------------------------------------------------------------------
344 sal_Int64
345 UpdateCheckConfig::getCheckInterval() const
347 sal_Int64 nValue = 0;
349 // getByName is defined as non const in XNameAccess
350 const_cast < UpdateCheckConfig *> (this)->getByName( UNISTRING( CHECK_INTERVAL ) ) >>= nValue;
352 return nValue;
355 //------------------------------------------------------------------------------
357 rtl::OUString
358 UpdateCheckConfig::getLocalFileName() const
360 rtl::OUString aName = UNISTRING(LOCAL_FILE);
361 rtl::OUString aRet;
363 if( m_xContainer->hasByName(aName) )
364 m_xContainer->getByName(aName) >>= aRet;
366 return aRet;
369 //------------------------------------------------------------------------------
371 rtl::OUString
372 UpdateCheckConfig::getDownloadDestination() const
374 rtl::OUString aName = UNISTRING(DOWNLOAD_DESTINATION);
375 rtl::OUString aRet;
377 const_cast <UpdateCheckConfig *> (this)->getByName(aName) >>= aRet;
379 return aRet;
382 //------------------------------------------------------------------------------
384 void
385 UpdateCheckConfig::storeLocalFileName(const rtl::OUString& rLocalFileName, sal_Int64 nFileSize)
387 const sal_uInt8 nItems = 2;
388 const rtl::OUString aNameList[nItems] = { UNISTRING(LOCAL_FILE), UNISTRING(DOWNLOAD_SIZE) };
389 const uno::Any aValueList[nItems] = { uno::makeAny(rLocalFileName), uno::makeAny(nFileSize) };
391 for( sal_uInt8 i=0; i < nItems; ++i )
393 if( m_xContainer->hasByName(aNameList[i]) )
394 m_xContainer->replaceByName(aNameList[i], aValueList[i]);
395 else
396 m_xContainer->insertByName(aNameList[i], aValueList[i]);
399 commitChanges();
402 //------------------------------------------------------------------------------
404 void
405 UpdateCheckConfig::clearLocalFileName()
407 const sal_uInt8 nItems = 2;
408 const rtl::OUString aNameList[nItems] = { UNISTRING(LOCAL_FILE), UNISTRING(DOWNLOAD_SIZE) };
410 for( sal_uInt8 i=0; i < nItems; ++i )
412 if( m_xContainer->hasByName(aNameList[i]) )
413 m_xContainer->removeByName(aNameList[i]);
416 commitChanges();
419 //------------------------------------------------------------------------------
421 void
422 UpdateCheckConfig::storeDownloadPaused(bool paused)
424 replaceByName(UNISTRING(DOWNLOAD_PAUSED) , uno::makeAny(paused));
425 commitChanges();
428 //------------------------------------------------------------------------------
430 void
431 UpdateCheckConfig::updateLastChecked()
433 TimeValue systime;
434 osl_getSystemTime(&systime);
436 sal_Int64 lastCheck = systime.Seconds;
438 replaceByName(UNISTRING(LAST_CHECK), uno::makeAny(lastCheck));
441 //------------------------------------------------------------------------------
443 void
444 UpdateCheckConfig::storeUpdateFound( const UpdateInfo& rInfo, const rtl::OUString& aCurrentBuild)
447 bool autoDownloadEnabled = isAutoDownloadEnabled();
449 uno::Any aValues[nUpdateEntryProperties] =
451 uno::makeAny(rInfo.Version),
452 uno::makeAny(rInfo.BuildId),
453 uno::makeAny(rInfo.Description),
454 uno::makeAny(rInfo.Sources[0].URL),
455 uno::makeAny(rInfo.Sources[0].IsDirect ? sal_True : sal_False),
456 uno::makeAny(getReleaseNote(rInfo, 1, autoDownloadEnabled) ),
457 uno::makeAny(getReleaseNote(rInfo, 2, autoDownloadEnabled) ),
458 uno::makeAny(getReleaseNote(rInfo, 3, autoDownloadEnabled) ),
459 uno::makeAny(getReleaseNote(rInfo, 4, autoDownloadEnabled) ),
460 uno::makeAny(getReleaseNote(rInfo, 5, autoDownloadEnabled) ),
461 uno::makeAny(aCurrentBuild)
464 rtl::OUString aName;
465 for( sal_uInt32 n=0; n < nUpdateEntryProperties; ++n )
467 aName = rtl::OUString::createFromAscii(aUpdateEntryProperties[n]);
469 if( m_xContainer->hasByName(aName) )
470 m_xContainer->replaceByName(aName, aValues[n]);
471 else
472 m_xContainer->insertByName(aName,aValues[n]);
475 commitChanges();
478 //------------------------------------------------------------------------------
480 void
481 UpdateCheckConfig::clearUpdateFound()
483 rtl::OUString aName;
485 for( sal_uInt32 n=0; n < nUpdateEntryProperties; ++n )
487 aName = rtl::OUString::createFromAscii(aUpdateEntryProperties[n]);
489 try {
490 if( m_xContainer->hasByName(aName) )
491 m_xContainer->removeByName(aName);
492 } catch(const lang::WrappedTargetException& ) {
493 // Can not remove value, probably in share layer
494 OSL_ASSERT(false);
495 m_xContainer->replaceByName(aName, uno::makeAny(rtl::OUString()));
499 /* As we have removed UpdateVersionFound from the shared configuration
500 * existing entries in the user layer do not have a oor operation and
501 * thus are completly ignored (which also means they can not be removed).
504 commitChanges();
507 //------------------------------------------------------------------------------
509 uno::Sequence< rtl::OUString >
510 UpdateCheckConfig::getServiceNames()
512 uno::Sequence< rtl::OUString > aServiceList(1);
513 aServiceList[0] = UNISTRING( "com.sun.star.setup.UpdateCheckConfig");
514 return aServiceList;
517 //------------------------------------------------------------------------------
519 rtl::OUString
520 UpdateCheckConfig::getImplName()
522 return UNISTRING( "vnd.sun.UpdateCheckConfig");
525 //------------------------------------------------------------------------------
527 uno::Type SAL_CALL
528 UpdateCheckConfig::getElementType() throw (uno::RuntimeException)
530 return m_xContainer->getElementType();
533 //------------------------------------------------------------------------------
535 sal_Bool SAL_CALL
536 UpdateCheckConfig::hasElements() throw (uno::RuntimeException)
538 return m_xContainer->hasElements();
541 //------------------------------------------------------------------------------
543 uno::Any SAL_CALL
544 UpdateCheckConfig::getByName( const ::rtl::OUString& aName )
545 throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
547 uno::Any aValue = m_xContainer->getByName( aName );
549 // Provide dynamic default value
550 if( aName.equalsAscii(DOWNLOAD_DESTINATION) )
552 rtl::OUString aStr;
553 aValue >>= aStr;
555 if( aStr.isEmpty() )
556 aValue = uno::makeAny(getDesktopDirectory());
559 return aValue;
562 //------------------------------------------------------------------------------
564 uno::Sequence< ::rtl::OUString > SAL_CALL
565 UpdateCheckConfig::getElementNames( ) throw (uno::RuntimeException)
567 return m_xContainer->getElementNames();
570 //------------------------------------------------------------------------------
572 sal_Bool SAL_CALL
573 UpdateCheckConfig::hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
575 return m_xContainer->hasByName( aName );
578 //------------------------------------------------------------------------------
580 void SAL_CALL
581 UpdateCheckConfig::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement )
582 throw (lang::IllegalArgumentException, container::NoSuchElementException,
583 lang::WrappedTargetException, uno::RuntimeException)
585 return m_xContainer->replaceByName( aName, aElement );
588 //------------------------------------------------------------------------------
589 // XChangesBatch
591 void SAL_CALL
592 UpdateCheckConfig::commitChanges()
593 throw (lang::WrappedTargetException, uno::RuntimeException)
595 uno::Reference< util::XChangesBatch > xChangesBatch(m_xContainer, uno::UNO_QUERY);
596 if( xChangesBatch.is() && xChangesBatch->hasPendingChanges() )
598 util::ChangesSet aChangesSet = xChangesBatch->getPendingChanges();
599 xChangesBatch->commitChanges();
601 if( m_rListener.is() )
603 const sal_Int32 nChanges = aChangesSet.getLength();
604 rtl::OUString aString;
606 for( sal_Int32 i=0; i<nChanges; ++i )
608 aChangesSet[i].Accessor >>= aString;
610 // FIXME: use non IgnoreAsciiCase version as soon as it becomes available
611 if( aString.endsWithIgnoreAsciiCaseAsciiL(AUTOCHECK_ENABLED "']", sizeof(AUTOCHECK_ENABLED)+1) )
613 sal_Bool bEnabled = sal_False;
614 aChangesSet[i].Element >>= bEnabled;
615 m_rListener->autoCheckStatusChanged(sal_True == bEnabled);
617 // FIXME: use non IgnoreAsciiCase version as soon as it becomes available
618 else if( aString.endsWithIgnoreAsciiCaseAsciiL(CHECK_INTERVAL "']", sizeof(CHECK_INTERVAL)+1) )
620 m_rListener->autoCheckIntervalChanged();
626 xChangesBatch = uno::Reference< util::XChangesBatch > ( m_xAvailableUpdates, uno::UNO_QUERY );
627 if( xChangesBatch.is() && xChangesBatch->hasPendingChanges() )
629 util::ChangesSet aChangesSet = xChangesBatch->getPendingChanges();
630 xChangesBatch->commitChanges();
632 xChangesBatch = uno::Reference< util::XChangesBatch > ( m_xIgnoredUpdates, uno::UNO_QUERY );
633 if( xChangesBatch.is() && xChangesBatch->hasPendingChanges() )
635 util::ChangesSet aChangesSet = xChangesBatch->getPendingChanges();
636 xChangesBatch->commitChanges();
640 //------------------------------------------------------------------------------
642 sal_Bool SAL_CALL
643 UpdateCheckConfig::hasPendingChanges( ) throw (uno::RuntimeException)
645 uno::Reference< util::XChangesBatch > xChangesBatch(m_xContainer, uno::UNO_QUERY);
646 if( xChangesBatch.is() )
647 return xChangesBatch->hasPendingChanges();
649 return sal_False;
652 //------------------------------------------------------------------------------
654 uno::Sequence< util::ElementChange > SAL_CALL
655 UpdateCheckConfig::getPendingChanges( ) throw (uno::RuntimeException)
657 uno::Reference< util::XChangesBatch > xChangesBatch(m_xContainer, uno::UNO_QUERY);
658 if( xChangesBatch.is() )
659 return xChangesBatch->getPendingChanges();
661 return uno::Sequence< util::ElementChange >();
664 //------------------------------------------------------------------------------
665 bool UpdateCheckConfig::storeExtensionVersion( const rtl::OUString& rExtensionName,
666 const rtl::OUString& rVersion )
668 bool bNotify = true;
670 if ( m_xAvailableUpdates->hasByName( rExtensionName ) )
671 uno::Reference< beans::XPropertySet >( m_xAvailableUpdates->getByName( rExtensionName ), uno::UNO_QUERY_THROW )->setPropertyValue( PROPERTY_VERSION, uno::Any( rVersion ) );
672 else
674 uno::Reference< beans::XPropertySet > elem( uno::Reference< lang::XSingleServiceFactory >( m_xAvailableUpdates, uno::UNO_QUERY_THROW )->createInstance(), uno::UNO_QUERY_THROW );
675 elem->setPropertyValue( PROPERTY_VERSION, uno::Any( rVersion ) );
676 m_xAvailableUpdates->insertByName( rExtensionName, uno::Any( elem ) );
679 if ( m_xIgnoredUpdates->hasByName( rExtensionName ) )
681 ::rtl::OUString aIgnoredVersion;
682 uno::Any aValue( uno::Reference< beans::XPropertySet >( m_xIgnoredUpdates->getByName( rExtensionName ), uno::UNO_QUERY_THROW )->getPropertyValue( PROPERTY_VERSION ) );
683 aValue >>= aIgnoredVersion;
684 if ( aIgnoredVersion.isEmpty() ) // no version means ignore all updates
685 bNotify = false;
686 else if ( aIgnoredVersion == rVersion ) // the user wanted to ignore this update
687 bNotify = false;
690 commitChanges();
692 return bNotify;
695 //------------------------------------------------------------------------------
696 bool UpdateCheckConfig::checkExtensionVersion( const rtl::OUString& rExtensionName,
697 const rtl::OUString& rVersion )
699 if ( m_xAvailableUpdates->hasByName( rExtensionName ) )
701 ::rtl::OUString aStoredVersion;
702 uno::Any aValue( uno::Reference< beans::XPropertySet >( m_xAvailableUpdates->getByName( rExtensionName ), uno::UNO_QUERY_THROW )->getPropertyValue( PROPERTY_VERSION ) );
703 aValue >>= aStoredVersion;
705 if ( m_xIgnoredUpdates->hasByName( rExtensionName ) )
707 ::rtl::OUString aIgnoredVersion;
708 uno::Any aValue2( uno::Reference< beans::XPropertySet >( m_xIgnoredUpdates->getByName( rExtensionName ), uno::UNO_QUERY_THROW )->getPropertyValue( PROPERTY_VERSION ) );
709 aValue2 >>= aIgnoredVersion;
710 if ( aIgnoredVersion.isEmpty() ) // no version means ignore all updates
711 return false;
712 else if ( aIgnoredVersion == aStoredVersion ) // the user wanted to ignore this update
713 return false;
714 // TODO: else delete ignored entry?
716 if ( isVersionGreater( rVersion, aStoredVersion ) )
717 return true;
718 else
720 m_xAvailableUpdates->removeByName( rExtensionName );
721 commitChanges();
725 return false;
728 //------------------------------------------------------------------------------
729 rtl::OUString UpdateCheckConfig::getSubVersion( const rtl::OUString& rVersion,
730 sal_Int32 *nIndex )
732 while ( *nIndex < rVersion.getLength() && rVersion[*nIndex] == '0')
734 ++*nIndex;
737 return rVersion.getToken( 0, '.', *nIndex );
740 //------------------------------------------------------------------------------
741 // checks if the second version string is greater than the first one
743 bool UpdateCheckConfig::isVersionGreater( const rtl::OUString& rVersion1,
744 const rtl::OUString& rVersion2 )
746 for ( sal_Int32 i1 = 0, i2 = 0; i1 >= 0 || i2 >= 0; )
748 ::rtl::OUString sSub1( getSubVersion( rVersion1, &i1 ) );
749 ::rtl::OUString sSub2( getSubVersion( rVersion2, &i2 ) );
751 if ( sSub1.getLength() < sSub2.getLength() ) {
752 return true;
753 } else if ( sSub1.getLength() > sSub2.getLength() ) {
754 return false;
755 } else if ( sSub1 < sSub2 ) {
756 return true;
757 } else if ( sSub1 > sSub2 ) {
758 return false;
761 return false;
764 //------------------------------------------------------------------------------
765 //------------------------------------------------------------------------------
766 //------------------------------------------------------------------------------
768 rtl::OUString SAL_CALL
769 UpdateCheckConfig::getImplementationName() throw (uno::RuntimeException)
771 return getImplName();
774 //------------------------------------------------------------------------------
776 sal_Bool SAL_CALL
777 UpdateCheckConfig::supportsService(rtl::OUString const & serviceName)
778 throw (uno::RuntimeException)
780 uno::Sequence< rtl::OUString > aServiceNameList = getServiceNames();
782 for( sal_Int32 n=0; n < aServiceNameList.getLength(); n++ )
783 if( aServiceNameList[n].equals(serviceName) )
784 return sal_True;
786 return sal_False;
789 //------------------------------------------------------------------------------
791 uno::Sequence< rtl::OUString > SAL_CALL
792 UpdateCheckConfig::getSupportedServiceNames() throw (uno::RuntimeException)
794 return getServiceNames();
798 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */