1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-18 06:48:23 +01:00

Keep download states in memory for faster access.

This commit is contained in:
Christian Muehlhaeuser 2015-03-25 07:28:40 +01:00
parent 837505b1b1
commit 488100b67d
2 changed files with 12 additions and 10 deletions

View File

@ -43,6 +43,12 @@ DownloadManager::DownloadManager()
{
tLog() << Q_FUNC_INFO << "Initializing DownloadManager.";
QVariantList downloads = TomahawkSettings::instance()->downloadStates();
foreach ( const QVariant& download, downloads )
{
m_downloadStates << download.toMap();
}
QTimer::singleShot( 0, this, SLOT( resumeJobs() ) );
}
@ -51,12 +57,6 @@ DownloadManager::~DownloadManager()
{
tLog() << Q_FUNC_INFO << "Shutting down DownloadManager.";
QList< downloadjob_ptr > jl;
foreach ( const downloadjob_ptr& job, jobs() )
{
jl << job;
}
storeJobs( jobs( DownloadJob::Finished ) );
}
@ -64,15 +64,13 @@ DownloadManager::~DownloadManager()
QString
DownloadManager::localFileForDownload( const QString& url ) const
{
QVariantList downloads = TomahawkSettings::instance()->downloadStates();
foreach ( const QVariant& download, downloads )
foreach ( const QVariantMap& map, m_downloadStates )
{
QVariantMap map = download.toMap();
tDebug() << "Found known download:" << map["url"] << map["localfile"];
tDebug() << "Looking for download:" << url;
if ( map[ "url" ].toString() == url )
{
QString localFile = map[ "localfile"].toString();
QString localFile = map[ "localfile" ].toString();
QFileInfo fi( localFile );
if ( fi.exists() )
return localFile;
@ -89,11 +87,14 @@ DownloadManager::storeJobs( const QList<downloadjob_ptr>& jobs )
QVariantList downloads = TomahawkSettings::instance()->downloadStates();
foreach ( const downloadjob_ptr& job, jobs )
{
if ( job->state() != DownloadJob::Finished )
continue;
tDebug() << "Storing job:" << job->format().url << job->localFile();
QVariantMap map;
map[ "url" ] = job->format().url;
map[ "localfile" ] = job->localFile();
m_downloadStates << map;
downloads << map;
}

View File

@ -67,6 +67,7 @@ private slots:
private:
QList< downloadjob_ptr > m_jobs;
bool m_globalState;
QList<QVariantMap> m_downloadStates;
static DownloadManager* s_instance;
};