Clementine-audio-player-Mac.../src/internet/podcasts/podcastdownloader.h

125 lines
3.3 KiB
C
Raw Normal View History

2012-03-10 16:32:36 +01:00
/* This file is part of Clementine.
Copyright 2012, David Sansome <me@davidsansome.com>
Copyright 2014, John Maguire <john.maguire@gmail.com>
2014-11-02 19:50:39 +01:00
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
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.
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.
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/>.
*/
2014-12-18 23:54:21 +01:00
#ifndef INTERNET_PODCASTS_PODCASTDOWNLOADER_H_
#define INTERNET_PODCASTS_PODCASTDOWNLOADER_H_
2012-03-10 16:32:36 +01:00
#include <QFile>
2012-03-10 16:32:36 +01:00
#include <QList>
#include <QObject>
#include <QQueue>
#include <QRegExp>
#include <QSet>
2020-09-18 16:15:19 +02:00
#include <memory>
#include "core/network.h"
#include "podcast.h"
#include "podcastepisode.h"
2012-03-10 16:32:36 +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;
class PodcastBackend;
2012-03-10 16:32:36 +01:00
class QNetworkAccessManager;
namespace PodcastDownload {
2020-09-18 16:15:19 +02:00
enum State { NotDownloading, Queued, Downloading, Finished };
}
class Task : public QObject {
Q_OBJECT
public:
Task(PodcastEpisode episode, QFile* file, PodcastBackend* backend);
PodcastEpisode episode() const;
signals:
void ProgressChanged(const PodcastEpisode& episode,
PodcastDownload::State state, int percent);
2014-12-13 20:05:45 +01:00
void finished(Task* task);
public slots:
void finishedPublic();
private slots:
void reading();
void downloadProgressInternal(qint64 received, qint64 total);
2014-12-10 21:57:09 +01:00
void finishedInternal();
private:
2014-12-10 21:57:09 +01:00
std::unique_ptr<QFile> file_;
PodcastEpisode episode_;
QNetworkRequest req_;
PodcastBackend* backend_;
2014-12-10 21:57:09 +01:00
std::unique_ptr<NetworkAccessManager> network_;
std::unique_ptr<RedirectFollower> repl;
};
2012-03-10 16:32:36 +01:00
class PodcastDownloader : public QObject {
Q_OBJECT
public:
2014-11-02 21:37:15 +01:00
explicit PodcastDownloader(Application* app, QObject* parent = nullptr);
2012-03-10 16:32:36 +01:00
static const char* kSettingsGroup;
PodcastEpisodeList EpisodesDownloading(const PodcastEpisodeList& episodes);
2012-03-10 16:32:36 +01:00
QString DefaultDownloadDir() const;
public slots:
2012-03-10 16:32:36 +01:00
// Adds the episode to the download queue
void DownloadEpisode(const PodcastEpisode& episode);
void cancelDownload(const PodcastEpisodeList& episodes);
2014-02-07 20:34:34 +01:00
signals:
void ProgressChanged(const PodcastEpisode& episode,
PodcastDownload::State state, int percent);
2012-03-10 16:32:36 +01:00
private slots:
2012-03-10 16:32:36 +01:00
void ReloadSettings();
void SubscriptionAdded(const Podcast& podcast);
void EpisodesAdded(const PodcastEpisodeList& episodes);
2012-03-10 16:32:36 +01:00
2014-12-13 20:05:45 +01:00
void ReplyFinished(Task* task);
2012-03-10 16:32:36 +01:00
private:
QString FilenameForEpisode(const QString& directory,
const PodcastEpisode& episode) const;
2012-03-10 16:32:36 +01:00
QString SanitiseFilenameComponent(const QString& text) const;
private:
2012-03-10 16:32:36 +01:00
Application* app_;
PodcastBackend* backend_;
2012-03-10 16:32:36 +01:00
QNetworkAccessManager* network_;
QRegExp disallowed_filename_characters_;
bool auto_download_;
2012-03-10 16:32:36 +01:00
QString download_dir_;
QList<Task*> list_tasks_;
2012-03-10 16:32:36 +01:00
};
2014-12-18 23:54:21 +01:00
#endif // INTERNET_PODCASTS_PODCASTDOWNLOADER_H_