2012-03-10 16:32:36 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2012, David Sansome <me@davidsansome.com>
|
2014-01-23 17:06:43 +01:00
|
|
|
|
2012-03-10 16:32:36 +01:00
|
|
|
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.
|
2014-01-23 17:06:43 +01:00
|
|
|
|
2012-03-10 16:32:36 +01:00
|
|
|
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.
|
2014-01-23 17:06:43 +01:00
|
|
|
|
2012-03-10 16:32:36 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PODCASTDOWNLOADER_H
|
|
|
|
#define PODCASTDOWNLOADER_H
|
|
|
|
|
|
|
|
#include "podcast.h"
|
|
|
|
#include "podcastepisode.h"
|
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QQueue>
|
|
|
|
#include <QRegExp>
|
2012-03-10 23:26:53 +01:00
|
|
|
#include <QSet>
|
2012-03-10 16:32:36 +01:00
|
|
|
|
2014-01-23 17:06:43 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#include <time.h>
|
|
|
|
#else
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
2012-03-10 16:32:36 +01:00
|
|
|
class Application;
|
2012-03-10 22:05:57 +01:00
|
|
|
class PodcastBackend;
|
2012-03-10 16:32:36 +01:00
|
|
|
|
|
|
|
class QNetworkAccessManager;
|
|
|
|
|
|
|
|
class PodcastDownloader : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
PodcastDownloader(Application* app, QObject* parent = 0);
|
|
|
|
|
|
|
|
enum State {
|
2012-03-10 22:05:57 +01:00
|
|
|
NotDownloading,
|
2012-03-10 16:32:36 +01:00
|
|
|
Queued,
|
|
|
|
Downloading,
|
|
|
|
Finished
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* kSettingsGroup;
|
2012-03-12 20:35:47 +01:00
|
|
|
static const int kAutoDeleteCheckIntervalMsec;
|
2012-03-10 16:32:36 +01:00
|
|
|
|
|
|
|
QString DefaultDownloadDir() const;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
// Adds the episode to the download queue
|
|
|
|
void DownloadEpisode(const PodcastEpisode& episode);
|
2012-03-11 16:36:35 +01:00
|
|
|
|
|
|
|
// Deletes downloaded data for this episode
|
|
|
|
void DeleteEpisode(const PodcastEpisode& episode);
|
2012-03-10 16:32:36 +01:00
|
|
|
|
|
|
|
signals:
|
2012-03-10 22:05:57 +01:00
|
|
|
void ProgressChanged(const PodcastEpisode& episode,
|
|
|
|
PodcastDownloader::State state, int percent);
|
2012-03-10 16:32:36 +01:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void ReloadSettings();
|
|
|
|
|
|
|
|
void SubscriptionAdded(const Podcast& podcast);
|
|
|
|
void EpisodesAdded(const QList<PodcastEpisode>& episodes);
|
|
|
|
|
|
|
|
void ReplyReadyRead();
|
|
|
|
void ReplyFinished();
|
|
|
|
void ReplyDownloadProgress(qint64 received, qint64 total);
|
|
|
|
|
2012-03-12 20:35:47 +01:00
|
|
|
void AutoDelete();
|
|
|
|
|
2012-03-10 16:32:36 +01:00
|
|
|
private:
|
|
|
|
struct Task;
|
|
|
|
|
|
|
|
void StartDownloading(Task* task);
|
|
|
|
void NextTask();
|
2012-03-10 23:26:53 +01:00
|
|
|
void FinishAndDelete(Task* task);
|
2012-03-10 16:32:36 +01:00
|
|
|
|
2012-06-14 18:07:21 +02:00
|
|
|
QString FilenameForEpisode(const QString& directory,
|
|
|
|
const PodcastEpisode& episode) const;
|
2012-03-10 16:32:36 +01:00
|
|
|
QString SanitiseFilenameComponent(const QString& text) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Application* app_;
|
2012-03-10 22:05:57 +01:00
|
|
|
PodcastBackend* backend_;
|
2012-03-10 16:32:36 +01:00
|
|
|
QNetworkAccessManager* network_;
|
|
|
|
|
|
|
|
QRegExp disallowed_filename_characters_;
|
|
|
|
|
2012-03-10 23:26:53 +01:00
|
|
|
bool auto_download_;
|
2012-03-10 16:32:36 +01:00
|
|
|
QString download_dir_;
|
2012-03-12 20:35:47 +01:00
|
|
|
int delete_after_secs_;
|
2012-03-10 16:32:36 +01:00
|
|
|
|
|
|
|
Task* current_task_;
|
|
|
|
QQueue<Task*> queued_tasks_;
|
2012-03-10 23:26:53 +01:00
|
|
|
QSet<int> downloading_episode_ids_;
|
2012-03-10 16:32:36 +01:00
|
|
|
|
|
|
|
time_t last_progress_signal_;
|
2012-03-12 20:35:47 +01:00
|
|
|
|
|
|
|
QTimer* auto_delete_timer_;
|
2012-03-10 16:32:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PODCASTDOWNLOADER_H
|