mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-11 16:44:05 +02:00
Store download states across sessions.
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "TomahawkSettings.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
DownloadManager* DownloadManager::s_instance = 0;
|
DownloadManager* DownloadManager::s_instance = 0;
|
||||||
@@ -56,7 +57,47 @@ DownloadManager::~DownloadManager()
|
|||||||
jl << job;
|
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 <QUrl>
|
||||||
|
|
||||||
#include "DownloadJob.h"
|
#include "DownloadJob.h"
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
class DownloadManager : public QObject
|
class DLLEXPORT DownloadManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -42,6 +43,9 @@ public:
|
|||||||
bool containsJob( const downloadjob_ptr& job ) const;
|
bool containsJob( const downloadjob_ptr& job ) const;
|
||||||
downloadjob_ptr currentJob() const;
|
downloadjob_ptr currentJob() const;
|
||||||
|
|
||||||
|
void storeJobs( const QList<downloadjob_ptr>& jobs );
|
||||||
|
QString localFileForDownload( const QString& url ) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool addJob( const downloadjob_ptr& job );
|
bool addJob( const downloadjob_ptr& job );
|
||||||
bool removeJob( 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
|
bool
|
||||||
TomahawkSettings::httpEnabled() const
|
TomahawkSettings::httpEnabled() const
|
||||||
{
|
{
|
||||||
|
@@ -60,6 +60,9 @@ public:
|
|||||||
QString downloadsPath() const;
|
QString downloadsPath() const;
|
||||||
void setDownloadsPath( const QString& path );
|
void setDownloadsPath( const QString& path );
|
||||||
|
|
||||||
|
QVariantList downloadStates() const;
|
||||||
|
void setDownloadStates( const QVariantList& downloads );
|
||||||
|
|
||||||
uint infoSystemCacheVersion() const;
|
uint infoSystemCacheVersion() const;
|
||||||
void setInfoSystemCacheVersion( uint version );
|
void setInfoSystemCacheVersion( uint version );
|
||||||
uint genericCacheVersion() const;
|
uint genericCacheVersion() const;
|
||||||
|
Reference in New Issue
Block a user