diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a4a65c53..c96d97ea9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,31 +53,32 @@ include( CheckTagLibFileName ) check_taglib_filename( COMPLEX_TAGLIB_FILENAME ) # optional -macro_optional_find_package(Jreen) -IF( ENABLE_JREEN AND NOT LIBJREEN_FOUND ) +IF( ENABLE_JREEN ) + macro_optional_find_package(Jreen) + IF( LIBJREEN_FOUND ) + macro_log_feature(JREEN_FOUND "Jreen" "Qt XMPP library" "http://gitorious.org/jreen" FALSE "" "Jreen is needed for the alternative/new Jabber SIP plugin. Built automatically inside Tomahawk, if not installed systemwide and ENABLE_JREEN is true") + ELSE( LIBJREEN_FOUND ) ADD_SUBDIRECTORY( thirdparty/jreen ) SET( LIBJREEN_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/thirdparty/jreen/include ) IF( UNIX AND NOT APPLE ) SET( LIBJREEN_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/thirdparty/jreen/libjreen.so ) ENDIF( UNIX AND NOT APPLE ) IF( WIN32 ) - SET( LIBJREEN_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/thirdparty/jreen/libjreen.dll ) + SET( LIBJREEN_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/thirdparty/jreen/libjreen.dll ) ENDIF( WIN32 ) SET( LIBJREEN_FOUND true ) MESSAGE(STATUS "Internal libjreen: ${LIBJREEN_INCLUDE_DIR}, ${LIBJREEN_LIBRARY}") -ENDIF( ENABLE_JREEN AND NOT LIBJREEN_FOUND ) + ENDIF( LIBJREEN_FOUND ) +ELSE( LIBJREEN_FOUND ) + macro_optional_find_package(Gloox 1.0) + macro_log_feature(GLOOX_FOUND "Gloox" "A portable high-level Jabber/XMPP library for C++" "http://camaya.net/gloox" FALSE "" "Gloox is needed for the Jabber SIP plugin and the XMPP-Bot") + +ENDIF( ENABLE_JREEN ) IF( WIN32 ) find_library(QTSPARKLE_LIBRARIES qtsparkle) ENDIF( WIN32 ) -macro_log_feature(JREEN_FOUND "Jreen" "Qt XMPP library" "http://gitorious.org/jreen" FALSE "" "Jreen is needed for the alternative/new Jabber SIP plugin. Built automatically inside Tomahawk, if not installed systemwide and ENABLE_JREEN is true") - -macro_optional_find_package(Gloox 1.0) -IF( ENABLE_JREEN ) - set( GLOOX_FOUND false ) -ENDIF( ENABLE_JREEN) -macro_log_feature(GLOOX_FOUND "Gloox" "A portable high-level Jabber/XMPP library for C++" "http://camaya.net/gloox" FALSE "" "Gloox is needed for the Jabber SIP plugin and the XMPP-Bot") #show dep log macro_display_feature_log() MESSAGE("WARNING!") diff --git a/include/tomahawk/infosystem.h b/include/tomahawk/infosystem.h index 1409dabf9..e36af20d3 100644 --- a/include/tomahawk/infosystem.h +++ b/include/tomahawk/infosystem.h @@ -112,7 +112,7 @@ public: virtual void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData ) = 0; signals: - void getCachedInfo( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData ); + void getCachedInfo( Tomahawk::InfoSystem::InfoCacheCriteria criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData ); void updateCache( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output ); void info( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData ); void finished( QString, Tomahawk::InfoSystem::InfoType ); diff --git a/src/infosystem/infoplugins/lastfmplugin.cpp b/src/infosystem/infoplugins/lastfmplugin.cpp index 652d87414..fcff625bf 100644 --- a/src/infosystem/infoplugins/lastfmplugin.cpp +++ b/src/infosystem/infoplugins/lastfmplugin.cpp @@ -178,7 +178,7 @@ LastFmPlugin::fetchCoverArt( const QString &caller, const InfoType type, const Q criteria["artist"] = hash["artist"].toString(); criteria["album"] = hash["album"].toString(); - emit getCachedInfo( criteria, caller, type, data, customData ); + emit getCachedInfo( criteria, 2419200000, caller, type, data, customData ); } void diff --git a/src/infosystem/infosystemcache.cpp b/src/infosystem/infosystemcache.cpp index 7d73c6ade..9ecdc7435 100644 --- a/src/infosystem/infosystemcache.cpp +++ b/src/infosystem/infosystemcache.cpp @@ -53,10 +53,10 @@ InfoSystemCache::~InfoSystemCache() qDebug() << Q_FUNC_INFO; qDebug() << "Saving infosystemcache to disk"; QString cacheBaseDir = QDesktopServices::storageLocation( QDesktopServices::CacheLocation ); - for( int i = 0; i <= InfoNoInfo; i++ ) + for ( int i = 0; i <= InfoNoInfo; i++ ) { InfoType type = (InfoType)(i); - if( m_dirtySet.contains( type ) && m_dataCache.contains( type ) ) + if ( m_dirtySet.contains( type ) && m_dataCache.contains( type ) ) { QString cacheDir = cacheBaseDir + "/InfoSystemCache/" + QString::number( i ); saveCache( type, cacheDir ); @@ -66,29 +66,57 @@ InfoSystemCache::~InfoSystemCache() void -InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData ) +InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData ) { qDebug() << Q_FUNC_INFO; - if( !m_dataCache.contains( type ) || !m_dataCache[type].contains( criteria ) ) + if ( !m_dataCache.contains( type ) || !m_dataCache[type].contains( criteria ) ) { emit notInCache( criteria, caller, type, input, customData ); return; } + QHash< InfoCacheCriteria, QDateTime > typemaxtimecache = m_maxTimeCache[type]; + + if ( typemaxtimecache[criteria].toMSecsSinceEpoch() < QDateTime::currentMSecsSinceEpoch() ) + { + QHash< InfoCacheCriteria, QVariant > typedatacache = m_dataCache[type]; + QHash< InfoCacheCriteria, QDateTime > typeinserttimecache = m_insertTimeCache[type]; + typemaxtimecache.remove( criteria ); + m_maxTimeCache[type] = typemaxtimecache; + typedatacache.remove( criteria ); + m_dataCache[type] = typedatacache; + typeinserttimecache.remove( criteria ); + m_insertTimeCache[type] = typeinserttimecache; + m_dirtySet.insert( type ); + emit notInCache( criteria, caller, type, input, customData ); + return; + } + + if ( newMaxAge > 0 ) + { + QHash< InfoCacheCriteria, QDateTime > typemaxtimecache = m_maxTimeCache[type]; + typemaxtimecache[criteria] = QDateTime::fromMSecsSinceEpoch( QDateTime::currentMSecsSinceEpoch() + newMaxAge ); + m_maxTimeCache[type] = typemaxtimecache; + m_dirtySet.insert( type ); + } + emit info( caller, type, input, m_dataCache[type][criteria], customData ); } void -InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output ) +InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, qint64 maxAge, Tomahawk::InfoSystem::InfoType type, QVariant output ) { qDebug() << Q_FUNC_INFO; QHash< InfoCacheCriteria, QVariant > typedatacache = m_dataCache[type]; - QHash< InfoCacheCriteria, QDateTime > typetimecache = m_timeCache[type]; + QHash< InfoCacheCriteria, QDateTime > typeinserttimecache = m_insertTimeCache[type]; + QHash< InfoCacheCriteria, QDateTime > typemaxtimecache = m_maxTimeCache[type]; typedatacache[criteria] = output; - typetimecache[criteria] = QDateTime::currentDateTimeUtc(); + typeinserttimecache[criteria] = QDateTime::currentDateTimeUtc(); + typemaxtimecache[criteria] = QDateTime::fromMSecsSinceEpoch( QDateTime::currentMSecsSinceEpoch() + maxAge ); m_dataCache[type] = typedatacache; - m_timeCache[type] = typetimecache; + m_insertTimeCache[type] = typeinserttimecache; + m_maxTimeCache[type] = typemaxtimecache; m_dirtySet.insert( type ); } @@ -99,26 +127,31 @@ InfoSystemCache::loadCache( InfoType type, const QString &cacheFile ) qDebug() << Q_FUNC_INFO; QSettings cachedSettings( cacheFile, QSettings::IniFormat ); - foreach( QString group, cachedSettings.childGroups() ) + foreach ( QString group, cachedSettings.childGroups() ) { - QHash< InfoCacheCriteria, QVariant > dataHash = m_dataCache[type]; - QHash< InfoCacheCriteria, QDateTime > dateHash = m_timeCache[type]; - InfoCacheCriteria criteria; cachedSettings.beginGroup( group ); + if ( cachedSettings.value( "maxtime" ).toDateTime().toMSecsSinceEpoch() < QDateTime::currentMSecsSinceEpoch() ) + continue; + QHash< InfoCacheCriteria, QVariant > dataHash = m_dataCache[type]; + QHash< InfoCacheCriteria, QDateTime > insertDateHash = m_insertTimeCache[type]; + QHash< InfoCacheCriteria, QDateTime > maxDateHash = m_maxTimeCache[type]; + InfoCacheCriteria criteria; int numCriteria = cachedSettings.beginReadArray( "criteria" ); - for( int i = 0; i < numCriteria; i++ ) + for ( int i = 0; i < numCriteria; i++ ) { cachedSettings.setArrayIndex( i ); QStringList criteriaValues = cachedSettings.value( QString::number( i ) ).toStringList(); - for( int j = 0; j < criteriaValues.length(); j += 2 ) + for ( int j = 0; j < criteriaValues.length(); j += 2 ) criteria[criteriaValues.at( j )] = criteriaValues.at( j + 1 ); } cachedSettings.endArray(); dataHash[criteria] = cachedSettings.value( "data" ); - dateHash[criteria] = cachedSettings.value( "time" ).toDateTime(); + insertDateHash[criteria] = cachedSettings.value( "inserttime" ).toDateTime(); + maxDateHash[criteria] = cachedSettings.value( "maxtime" ).toDateTime(); cachedSettings.endGroup(); m_dataCache[type] = dataHash; - m_timeCache[type] = dateHash; + m_insertTimeCache[type] = insertDateHash; + m_maxTimeCache[type] = maxDateHash; } } @@ -156,7 +189,8 @@ InfoSystemCache::saveCache( InfoType type, const QString &cacheDir ) } cachedSettings.endArray(); cachedSettings.setValue( "data", m_dataCache[type][criteria] ); - cachedSettings.setValue( "time", m_timeCache[type][criteria] ); + cachedSettings.setValue( "inserttime", m_insertTimeCache[type][criteria] ); + cachedSettings.setValue( "maxtime", m_maxTimeCache[type][criteria] ); cachedSettings.endGroup(); ++criteriaNumber; } diff --git a/src/infosystem/infosystemcache.h b/src/infosystem/infosystemcache.h index ca347f7bc..0ccad6d19 100644 --- a/src/infosystem/infosystemcache.h +++ b/src/infosystem/infosystemcache.h @@ -45,15 +45,16 @@ signals: void info( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData ); public slots: - void getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData ); - void updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output ); + void getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData ); + void updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, qint64 maxAge, Tomahawk::InfoSystem::InfoType type, QVariant output ); private: void loadCache( InfoType type, const QString &cacheFile ); void saveCache( InfoType type, const QString &cacheDir ); QHash< InfoType, QHash< InfoCacheCriteria, QVariant > > m_dataCache; - QHash< InfoType, QHash< InfoCacheCriteria, QDateTime > > m_timeCache; + QHash< InfoType, QHash< InfoCacheCriteria, QDateTime > > m_insertTimeCache; + QHash< InfoType, QHash< InfoCacheCriteria, QDateTime > > m_maxTimeCache; QSet< InfoType > m_dirtySet; };