2014-03-07 18:58:50 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2013, Vlad Maltsev <shedwardx@gmail.com>
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VKMUSICCACHE_H
|
|
|
|
#define VKMUSICCACHE_H
|
|
|
|
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
class VkService;
|
|
|
|
class Application;
|
|
|
|
|
|
|
|
class VkMusicCache : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-08-03 14:40:06 +02:00
|
|
|
public:
|
2014-03-07 18:58:50 +01:00
|
|
|
explicit VkMusicCache(Application* app, VkService* service);
|
|
|
|
~VkMusicCache() {}
|
|
|
|
// Return file path if file in cache otherwise
|
|
|
|
// return internet url and add song to caching queue
|
|
|
|
QUrl Get(const QUrl& url);
|
2014-08-03 14:10:09 +02:00
|
|
|
void AddToCache(const QUrl& url, const QUrl& media_url, bool force = false);
|
2014-03-07 18:58:50 +01:00
|
|
|
void BreakCurrentCaching();
|
|
|
|
bool InCache(const QUrl& url);
|
|
|
|
|
2014-08-03 14:40:06 +02:00
|
|
|
private slots:
|
2014-03-07 18:58:50 +01:00
|
|
|
void AddToQueue(const QString& filename, const QUrl& download_url);
|
|
|
|
void DownloadNext();
|
|
|
|
void DownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
|
|
|
void DownloadReadyToRead();
|
|
|
|
void Downloaded();
|
|
|
|
|
2014-08-03 14:40:06 +02:00
|
|
|
private:
|
2014-03-07 18:58:50 +01:00
|
|
|
struct DownloadItem {
|
|
|
|
QString filename;
|
|
|
|
QUrl url;
|
|
|
|
|
2014-08-03 14:40:06 +02:00
|
|
|
bool operator==(const DownloadItem& rhv) {
|
2014-03-07 18:58:50 +01:00
|
|
|
return filename == rhv.filename;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
QString CachedFilename(const QUrl& url);
|
|
|
|
|
|
|
|
Application* app_;
|
|
|
|
VkService* service_;
|
|
|
|
QList<DownloadItem> queue_;
|
2014-08-03 14:10:09 +02:00
|
|
|
// Contain index of current song in queue, need for removing if song was
|
|
|
|
// skipped. It's zero if song downloading now, and less that zero
|
|
|
|
// if current song not caching or cached.
|
|
|
|
int current_song_index;
|
2014-03-07 18:58:50 +01:00
|
|
|
DownloadItem current_download;
|
|
|
|
bool is_downloading;
|
|
|
|
bool is_aborted;
|
|
|
|
int task_id;
|
|
|
|
QFile* file_;
|
|
|
|
QNetworkAccessManager* network_manager_;
|
|
|
|
QNetworkReply* reply_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VKMUSICCACHE_H
|