mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
Actually start writing cached info to disk
This commit is contained in:
@@ -36,7 +36,7 @@ namespace InfoSystem {
|
|||||||
class InfoSystemCache;
|
class InfoSystemCache;
|
||||||
|
|
||||||
enum InfoType {
|
enum InfoType {
|
||||||
InfoTrackID,
|
InfoTrackID = 0,
|
||||||
InfoTrackArtist,
|
InfoTrackArtist,
|
||||||
InfoTrackAlbum,
|
InfoTrackAlbum,
|
||||||
InfoTrackGenre,
|
InfoTrackGenre,
|
||||||
|
@@ -17,29 +17,128 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
#include "infosystemcache.h"
|
#include "infosystemcache.h"
|
||||||
|
|
||||||
void
|
|
||||||
Tomahawk::InfoSystem::InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData )
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace InfoSystem
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
InfoSystemCache::InfoSystemCache( QObject* parent )
|
||||||
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
if( !m_memCache.contains( type ) || !m_memCache[type].contains( criteria ) )
|
QString cacheBaseDir = QDesktopServices::storageLocation( QDesktopServices::CacheLocation );
|
||||||
|
for( int i = 0; i <= InfoNoInfo; i++ )
|
||||||
|
{
|
||||||
|
InfoType type = (InfoType)(i);
|
||||||
|
if( m_dirtySet.contains( type ) && m_dataCache.contains( type ) )
|
||||||
|
{
|
||||||
|
QString cacheDir = cacheBaseDir + QString::number( i );
|
||||||
|
QDir dir( cacheDir );
|
||||||
|
if( dir.exists() && QFile::exists( QString( cacheDir + '/' + QString::number( i ) ) ) )
|
||||||
|
loadCache( type, QString( cacheDir + '/' + QString::number( i ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
InfoSystemCache::~InfoSystemCache()
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
qDebug() << "Saving infosystemcache to disk";
|
||||||
|
QString cacheBaseDir = QDesktopServices::storageLocation( QDesktopServices::CacheLocation );
|
||||||
|
for( int i = 0; i <= InfoNoInfo; i++ )
|
||||||
|
{
|
||||||
|
InfoType type = (InfoType)(i);
|
||||||
|
if( m_dirtySet.contains( type ) && m_dataCache.contains( type ) )
|
||||||
|
{
|
||||||
|
QString cacheDir = cacheBaseDir + QString::number( i );
|
||||||
|
saveCache( type, cacheDir );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, 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 ) )
|
||||||
{
|
{
|
||||||
emit notInCache( criteria, caller, type, input, customData );
|
emit notInCache( criteria, caller, type, input, customData );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit info( caller, type, input, m_memCache[type][criteria], customData );
|
emit info( caller, type, input, m_dataCache[type][criteria], customData );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Tomahawk::InfoSystem::InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output )
|
InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
QHash< InfoCacheCriteria, QVariant > typecache;
|
QHash< InfoCacheCriteria, QVariant > typedatacache;
|
||||||
if( m_memCache.contains( type ) )
|
QHash< InfoCacheCriteria, QDateTime > typetimecache;
|
||||||
typecache = m_memCache[type];
|
typedatacache[criteria] = output;
|
||||||
typecache[criteria] = output;
|
typetimecache[criteria] = QDateTime::currentDateTimeUtc();
|
||||||
m_memCache[type] = typecache;
|
m_dataCache[type] = typedatacache;
|
||||||
|
m_timeCache[type] = typetimecache;
|
||||||
|
m_dirtySet.insert( type );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InfoSystemCache::loadCache( InfoType type, const QString &cacheDir )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
InfoSystemCache::saveCache( InfoType type, const QString &cacheDir )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
QDir dir( cacheDir );
|
||||||
|
if( !dir.exists( cacheDir ) )
|
||||||
|
{
|
||||||
|
qDebug() << "Creating cache directory " << cacheDir;
|
||||||
|
if( !dir.mkpath( cacheDir ) )
|
||||||
|
{
|
||||||
|
qDebug() << "Failed to create cache dir! Bailing...";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QSettings cacheFile( QString( cacheDir + '/' + QString::number( (int)type ) ), QSettings::IniFormat );
|
||||||
|
|
||||||
|
foreach( InfoCacheCriteria criteria, m_dataCache[type].keys() )
|
||||||
|
{
|
||||||
|
cacheFile.beginGroup( "type_" + QString::number( type ) );
|
||||||
|
cacheFile.beginWriteArray( "criteria" );
|
||||||
|
QStringList keys = criteria.keys();
|
||||||
|
for( int i = 0; i < criteria.size(); i++ )
|
||||||
|
{
|
||||||
|
cacheFile.setArrayIndex( i );
|
||||||
|
cacheFile.setValue( keys.at( i ), criteria[keys.at( i )] );
|
||||||
|
}
|
||||||
|
cacheFile.endArray();
|
||||||
|
cacheFile.setValue( "data", m_dataCache[type][criteria] );
|
||||||
|
cacheFile.setValue( "time", m_timeCache[type][criteria] );
|
||||||
|
cacheFile.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_dirtySet.remove( type );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} //namespace InfoSystem
|
||||||
|
|
||||||
|
} //namespace Tomahawk
|
@@ -19,6 +19,7 @@
|
|||||||
#ifndef TOMAHAWK_INFOSYSTEMCACHE_H
|
#ifndef TOMAHAWK_INFOSYSTEMCACHE_H
|
||||||
#define TOMAHAWK_INFOSYSTEMCACHE_H
|
#define TOMAHAWK_INFOSYSTEMCACHE_H
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
@@ -35,16 +36,9 @@ class InfoSystemCache : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InfoSystemCache( QObject *parent = 0 )
|
InfoSystemCache( QObject *parent = 0 );
|
||||||
: QObject( parent )
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~InfoSystemCache()
|
virtual ~InfoSystemCache();
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
}
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void notInCache( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
|
void notInCache( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
|
||||||
@@ -55,7 +49,12 @@ public slots:
|
|||||||
void updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output );
|
void updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash< InfoType, QHash< InfoCacheCriteria, QVariant > > m_memCache;
|
void loadCache( InfoType type, const QString &cache );
|
||||||
|
void saveCache( InfoType type, const QString &cache );
|
||||||
|
|
||||||
|
QHash< InfoType, QHash< InfoCacheCriteria, QVariant > > m_dataCache;
|
||||||
|
QHash< InfoType, QHash< InfoCacheCriteria, QDateTime > > m_timeCache;
|
||||||
|
QSet< InfoType > m_dirtySet;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace InfoSystem
|
} //namespace InfoSystem
|
||||||
|
@@ -299,7 +299,7 @@ TomahawkApp::~TomahawkApp()
|
|||||||
delete m_mainwindow;
|
delete m_mainwindow;
|
||||||
delete m_audioEngine;
|
delete m_audioEngine;
|
||||||
#endif
|
#endif
|
||||||
|
delete m_infoSystem;
|
||||||
delete m_database;
|
delete m_database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user