mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-20 07:52:30 +02:00
Store download states across sessions.
This commit is contained in:
parent
de90512371
commit
797000a0bb
@ -20,6 +20,7 @@
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include "TomahawkSettings.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
DownloadManager* DownloadManager::s_instance = 0;
|
||||
@ -56,7 +57,47 @@ DownloadManager::~DownloadManager()
|
||||
jl << job;
|
||||
}
|
||||
|
||||
// TomahawkSettings::instance()->storeJobs( jl );
|
||||
storeJobs( jobs( DownloadJob::Finished ) );
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
DownloadManager::localFileForDownload( const QString& url ) const
|
||||
{
|
||||
QVariantList downloads = TomahawkSettings::instance()->downloadStates();
|
||||
foreach ( const QVariant& download, downloads )
|
||||
{
|
||||
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();
|
||||
QFileInfo fi( localFile );
|
||||
if ( fi.exists() )
|
||||
return localFile;
|
||||
}
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DownloadManager::storeJobs( const QList<downloadjob_ptr>& jobs )
|
||||
{
|
||||
QVariantList downloads = TomahawkSettings::instance()->downloadStates();
|
||||
foreach ( const downloadjob_ptr& job, jobs )
|
||||
{
|
||||
tDebug() << "Storing job:" << job->format().url << job->localFile();
|
||||
QVariantMap map;
|
||||
map[ "url" ] = job->format().url;
|
||||
map[ "localfile" ] = job->localFile();
|
||||
|
||||
downloads << map;
|
||||
}
|
||||
|
||||
TomahawkSettings::instance()->setDownloadStates( downloads );
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,8 +24,9 @@
|
||||
#include <QUrl>
|
||||
|
||||
#include "DownloadJob.h"
|
||||
#include "DllMacro.h"
|
||||
|
||||
class DownloadManager : public QObject
|
||||
class DLLEXPORT DownloadManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -42,6 +43,9 @@ public:
|
||||
bool containsJob( const downloadjob_ptr& job ) const;
|
||||
downloadjob_ptr currentJob() const;
|
||||
|
||||
void storeJobs( const QList<downloadjob_ptr>& jobs );
|
||||
QString localFileForDownload( const QString& url ) const;
|
||||
|
||||
public slots:
|
||||
bool addJob( const downloadjob_ptr& job );
|
||||
bool removeJob( const downloadjob_ptr& job );
|
||||
|
@ -817,6 +817,20 @@ TomahawkSettings::setDownloadsPath( const QString& path )
|
||||
}
|
||||
|
||||
|
||||
QVariantList
|
||||
TomahawkSettings::downloadStates() const
|
||||
{
|
||||
return value( "downloadmanager/states", QVariantList() ).toList();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkSettings::setDownloadStates( const QVariantList& downloads )
|
||||
{
|
||||
setValue( "downloadmanager/states", downloads );
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TomahawkSettings::httpEnabled() const
|
||||
{
|
||||
|
@ -60,6 +60,9 @@ public:
|
||||
QString downloadsPath() const;
|
||||
void setDownloadsPath( const QString& path );
|
||||
|
||||
QVariantList downloadStates() const;
|
||||
void setDownloadStates( const QVariantList& downloads );
|
||||
|
||||
uint infoSystemCacheVersion() const;
|
||||
void setInfoSystemCacheVersion( uint version );
|
||||
uint genericCacheVersion() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user