Fix errors, needed for a pull
This commit is contained in:
parent
2d2783ab04
commit
8cbe742d9f
@ -324,7 +324,6 @@ PodcastEpisodeList PodcastBackend::GetOldDownloadedEpisodes(
|
|||||||
|
|
||||||
PodcastEpisode PodcastBackend::GetOldestDownloadedListenedEpisode() {
|
PodcastEpisode PodcastBackend::GetOldestDownloadedListenedEpisode() {
|
||||||
PodcastEpisode ret;
|
PodcastEpisode ret;
|
||||||
PodcastEpisodeList list_;
|
|
||||||
|
|
||||||
QMutexLocker l(db_->Mutex());
|
QMutexLocker l(db_->Mutex());
|
||||||
QSqlDatabase db(db_->Connect());
|
QSqlDatabase db(db_->Connect());
|
||||||
|
@ -15,14 +15,14 @@
|
|||||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "podcastbackend.h"
|
|
||||||
#include "podcastdeleter.h"
|
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
#include "core/timeconstants.h"
|
#include "core/timeconstants.h"
|
||||||
#include "core/utilities.h"
|
#include "core/utilities.h"
|
||||||
#include "library/librarydirectorymodel.h"
|
#include "library/librarydirectorymodel.h"
|
||||||
#include "library/librarymodel.h"
|
#include "library/librarymodel.h"
|
||||||
|
#include "podcastbackend.h"
|
||||||
|
#include "podcastdeleter.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@ -43,6 +43,7 @@ PodcastDeleter::PodcastDeleter(Application* app, QObject* parent)
|
|||||||
auto_delete_timer_(new QTimer(this)) {
|
auto_delete_timer_(new QTimer(this)) {
|
||||||
|
|
||||||
ReloadSettings();
|
ReloadSettings();
|
||||||
|
auto_delete_timer_->setSingleShot(true);
|
||||||
AutoDelete();
|
AutoDelete();
|
||||||
connect(auto_delete_timer_, SIGNAL(timeout()), SLOT(AutoDelete()));
|
connect(auto_delete_timer_, SIGNAL(timeout()), SLOT(AutoDelete()));
|
||||||
connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()));
|
connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()));
|
||||||
@ -76,7 +77,7 @@ void PodcastDeleter::AutoDelete() {
|
|||||||
}
|
}
|
||||||
auto_delete_timer_->stop();
|
auto_delete_timer_->stop();
|
||||||
QDateTime max_date = QDateTime::currentDateTime();
|
QDateTime max_date = QDateTime::currentDateTime();
|
||||||
QDateTime time_out;
|
qint64 time_out;
|
||||||
PodcastEpisode oldest_episode;
|
PodcastEpisode oldest_episode;
|
||||||
QDateTime oldest_episode_time;
|
QDateTime oldest_episode_time;
|
||||||
max_date = max_date.addSecs(-delete_after_secs_);
|
max_date = max_date.addSecs(-delete_after_secs_);
|
||||||
@ -99,11 +100,11 @@ void PodcastDeleter::AutoDelete() {
|
|||||||
oldest_episode_time = oldest_episode.listened_date();
|
oldest_episode_time = oldest_episode.listened_date();
|
||||||
}
|
}
|
||||||
|
|
||||||
time_out = QDateTime::currentDateTime();
|
time_out = QDateTime::currentDateTime().toMSecsSinceEpoch();
|
||||||
time_out = time_out.addMSecs(-oldest_episode_time.toMSecsSinceEpoch());
|
time_out -= oldest_episode_time.toMSecsSinceEpoch();
|
||||||
time_out.setTime_t(delete_after_secs_ - time_out.toTime_t());
|
time_out = (delete_after_secs_ * kMsecPerSec) - time_out;
|
||||||
if (time_out.isValid()) {
|
if (time_out >= 0) {
|
||||||
auto_delete_timer_->setInterval(time_out.toMSecsSinceEpoch());
|
auto_delete_timer_->setInterval(time_out);
|
||||||
} else {
|
} else {
|
||||||
auto_delete_timer_->setInterval(kAutoDeleteCheckIntervalMsec);
|
auto_delete_timer_->setInterval(kAutoDeleteCheckIntervalMsec);
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "podcastbackend.h"
|
|
||||||
#include "podcastdownloader.h"
|
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
#include "core/network.h"
|
#include "core/network.h"
|
||||||
@ -27,6 +25,8 @@
|
|||||||
#include "core/utilities.h"
|
#include "core/utilities.h"
|
||||||
#include "library/librarydirectorymodel.h"
|
#include "library/librarydirectorymodel.h"
|
||||||
#include "library/librarymodel.h"
|
#include "library/librarymodel.h"
|
||||||
|
#include "podcastbackend.h"
|
||||||
|
#include "podcastdownloader.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@ -40,24 +40,18 @@ const char* PodcastDownloader::kSettingsGroup = "Podcasts";
|
|||||||
Task::Task(PodcastEpisode episode, QFile* file, PodcastBackend* backend)
|
Task::Task(PodcastEpisode episode, QFile* file, PodcastBackend* backend)
|
||||||
: file_(file),
|
: file_(file),
|
||||||
episode_(episode),
|
episode_(episode),
|
||||||
|
req_(QNetworkRequest(episode.url())),
|
||||||
backend_(backend),
|
backend_(backend),
|
||||||
network_(new NetworkAccessManager(this)) {
|
network_(new NetworkAccessManager(this)),
|
||||||
req_ = QNetworkRequest(episode_.url());
|
repl(new RedirectFollower(network_->get(req_))) {
|
||||||
repl = new RedirectFollower(network_->get(req_));
|
connect(repl.get(), SIGNAL(readyRead()), SLOT(reading()));
|
||||||
connect(repl, SIGNAL(readyRead()), SLOT(reading()));
|
connect(repl.get(), SIGNAL(finished()), SLOT(finishedInternal()));
|
||||||
connect(repl, SIGNAL(finished()), SLOT(finished_()));
|
connect(repl.get(), SIGNAL(downloadProgress(qint64, qint64)),
|
||||||
connect(repl, SIGNAL(downloadProgress(qint64, qint64)),
|
|
||||||
SLOT(downloadProgress_(qint64, qint64)));
|
SLOT(downloadProgress_(qint64, qint64)));
|
||||||
emit ProgressChanged(episode_, PodcastDownload::Downloading, 0);
|
emit ProgressChanged(episode_, PodcastDownload::Downloading, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::~Task() {
|
const PodcastEpisode Task::episode() {
|
||||||
delete repl;
|
|
||||||
delete file_;
|
|
||||||
delete network_;
|
|
||||||
}
|
|
||||||
|
|
||||||
PodcastEpisode Task::episode() {
|
|
||||||
return episode_;
|
return episode_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +65,7 @@ void Task::reading() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Task::finished_() {
|
void Task::finishedInternal() {
|
||||||
if (repl->error() != QNetworkReply::NoError) {
|
if (repl->error() != QNetworkReply::NoError) {
|
||||||
qLog(Warning) << "Error downloading episode:" << repl->errorString();
|
qLog(Warning) << "Error downloading episode:" << repl->errorString();
|
||||||
emit ProgressChanged(episode_, PodcastDownload::NotDownloading, 0);
|
emit ProgressChanged(episode_, PodcastDownload::NotDownloading, 0);
|
||||||
@ -177,9 +171,6 @@ QString PodcastDownloader::FilenameForEpisode(const QString& directory,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PodcastDownloader::DownloadEpisode(const PodcastEpisode& episode) {
|
void PodcastDownloader::DownloadEpisode(const PodcastEpisode& episode) {
|
||||||
QFile* file = nullptr;
|
|
||||||
Task* task = nullptr;
|
|
||||||
|
|
||||||
for ( Task* tas : list_tasks_ ) {
|
for ( Task* tas : list_tasks_ ) {
|
||||||
if (tas->episode().database_id() == episode.database_id()) {
|
if (tas->episode().database_id() == episode.database_id()) {
|
||||||
return;
|
return;
|
||||||
@ -189,7 +180,7 @@ void PodcastDownloader::DownloadEpisode(const PodcastEpisode& episode) {
|
|||||||
Podcast podcast =
|
Podcast podcast =
|
||||||
backend_->GetSubscriptionById(episode.podcast_database_id());
|
backend_->GetSubscriptionById(episode.podcast_database_id());
|
||||||
if (!podcast.is_valid()) {
|
if (!podcast.is_valid()) {
|
||||||
qLog(Warning) << "The podcast that contains episode" << task->episode().url()
|
qLog(Warning) << "The podcast that contains episode" << episode.url()
|
||||||
<< "doesn't exist any more";
|
<< "doesn't exist any more";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -199,13 +190,13 @@ void PodcastDownloader::DownloadEpisode(const PodcastEpisode& episode) {
|
|||||||
|
|
||||||
// Open the output file
|
// Open the output file
|
||||||
QDir().mkpath(directory);
|
QDir().mkpath(directory);
|
||||||
file = new QFile(filepath);
|
QFile* file = new QFile(filepath);
|
||||||
if (!file->open(QIODevice::WriteOnly)) {
|
if (!file->open(QIODevice::WriteOnly)) {
|
||||||
qLog(Warning) << "Could not open the file" << filepath << "for writing";
|
qLog(Warning) << "Could not open the file" << filepath << "for writing";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
task = new Task(episode, file, backend_);
|
Task* task = new Task(episode, file, backend_);
|
||||||
|
|
||||||
list_tasks_ << task;
|
list_tasks_ << task;
|
||||||
qLog(Info) << "Downloading" << task->episode().url() << "to" << filepath;
|
qLog(Info) << "Downloading" << task->episode().url() << "to" << filepath;
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "podcast.h"
|
#include "podcast.h"
|
||||||
#include "podcastepisode.h"
|
#include "podcastepisode.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@ -51,8 +52,7 @@ class Task : public QObject {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Task(PodcastEpisode episode, QFile* file, PodcastBackend* backend);
|
Task(PodcastEpisode episode, QFile* file, PodcastBackend* backend);
|
||||||
~Task();
|
const PodcastEpisode episode();
|
||||||
PodcastEpisode episode();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ProgressChanged(const PodcastEpisode& episode,
|
void ProgressChanged(const PodcastEpisode& episode,
|
||||||
@ -61,16 +61,16 @@ class Task : public QObject {
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void reading();
|
void reading();
|
||||||
void finished_();
|
void finishedInternal();
|
||||||
void downloadProgress_(qint64 received, qint64 total);
|
void downloadProgress_(qint64 received, qint64 total);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QFile* file_;
|
std::unique_ptr<QFile> file_;
|
||||||
PodcastEpisode episode_;
|
PodcastEpisode episode_;
|
||||||
QNetworkRequest req_;
|
QNetworkRequest req_;
|
||||||
PodcastBackend* backend_;
|
PodcastBackend* backend_;
|
||||||
NetworkAccessManager* network_;
|
std::unique_ptr<NetworkAccessManager> network_;
|
||||||
RedirectFollower* repl;
|
std::unique_ptr<RedirectFollower> repl;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PodcastDownloader : public QObject {
|
class PodcastDownloader : public QObject {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user