1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-02-01 20:06:53 +01:00

Fix errors, needed for a pull

This commit is contained in:
Krzysztof Sobiecki 2014-12-10 21:57:09 +01:00
parent 2d2783ab04
commit 8cbe742d9f
4 changed files with 28 additions and 37 deletions

View File

@ -324,7 +324,6 @@ PodcastEpisodeList PodcastBackend::GetOldDownloadedEpisodes(
PodcastEpisode PodcastBackend::GetOldestDownloadedListenedEpisode() {
PodcastEpisode ret;
PodcastEpisodeList list_;
QMutexLocker l(db_->Mutex());
QSqlDatabase db(db_->Connect());

View File

@ -15,14 +15,14 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "podcastbackend.h"
#include "podcastdeleter.h"
#include "core/application.h"
#include "core/logging.h"
#include "core/timeconstants.h"
#include "core/utilities.h"
#include "library/librarydirectorymodel.h"
#include "library/librarymodel.h"
#include "podcastbackend.h"
#include "podcastdeleter.h"
#include <QDateTime>
#include <QDir>
@ -43,6 +43,7 @@ PodcastDeleter::PodcastDeleter(Application* app, QObject* parent)
auto_delete_timer_(new QTimer(this)) {
ReloadSettings();
auto_delete_timer_->setSingleShot(true);
AutoDelete();
connect(auto_delete_timer_, SIGNAL(timeout()), SLOT(AutoDelete()));
connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()));
@ -76,7 +77,7 @@ void PodcastDeleter::AutoDelete() {
}
auto_delete_timer_->stop();
QDateTime max_date = QDateTime::currentDateTime();
QDateTime time_out;
qint64 time_out;
PodcastEpisode oldest_episode;
QDateTime oldest_episode_time;
max_date = max_date.addSecs(-delete_after_secs_);
@ -99,11 +100,11 @@ void PodcastDeleter::AutoDelete() {
oldest_episode_time = oldest_episode.listened_date();
}
time_out = QDateTime::currentDateTime();
time_out = time_out.addMSecs(-oldest_episode_time.toMSecsSinceEpoch());
time_out.setTime_t(delete_after_secs_ - time_out.toTime_t());
if (time_out.isValid()) {
auto_delete_timer_->setInterval(time_out.toMSecsSinceEpoch());
time_out = QDateTime::currentDateTime().toMSecsSinceEpoch();
time_out -= oldest_episode_time.toMSecsSinceEpoch();
time_out = (delete_after_secs_ * kMsecPerSec) - time_out;
if (time_out >= 0) {
auto_delete_timer_->setInterval(time_out);
} else {
auto_delete_timer_->setInterval(kAutoDeleteCheckIntervalMsec);
}

View File

@ -17,8 +17,6 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "podcastbackend.h"
#include "podcastdownloader.h"
#include "core/application.h"
#include "core/logging.h"
#include "core/network.h"
@ -27,6 +25,8 @@
#include "core/utilities.h"
#include "library/librarydirectorymodel.h"
#include "library/librarymodel.h"
#include "podcastbackend.h"
#include "podcastdownloader.h"
#include <QDateTime>
#include <QDir>
@ -40,24 +40,18 @@ const char* PodcastDownloader::kSettingsGroup = "Podcasts";
Task::Task(PodcastEpisode episode, QFile* file, PodcastBackend* backend)
: file_(file),
episode_(episode),
req_(QNetworkRequest(episode.url())),
backend_(backend),
network_(new NetworkAccessManager(this)) {
req_ = QNetworkRequest(episode_.url());
repl = new RedirectFollower(network_->get(req_));
connect(repl, SIGNAL(readyRead()), SLOT(reading()));
connect(repl, SIGNAL(finished()), SLOT(finished_()));
connect(repl, SIGNAL(downloadProgress(qint64, qint64)),
network_(new NetworkAccessManager(this)),
repl(new RedirectFollower(network_->get(req_))) {
connect(repl.get(), SIGNAL(readyRead()), SLOT(reading()));
connect(repl.get(), SIGNAL(finished()), SLOT(finishedInternal()));
connect(repl.get(), SIGNAL(downloadProgress(qint64, qint64)),
SLOT(downloadProgress_(qint64, qint64)));
emit ProgressChanged(episode_, PodcastDownload::Downloading, 0);
}
Task::~Task() {
delete repl;
delete file_;
delete network_;
}
PodcastEpisode Task::episode() {
const PodcastEpisode Task::episode() {
return episode_;
}
@ -71,7 +65,7 @@ void Task::reading() {
}
}
void Task::finished_() {
void Task::finishedInternal() {
if (repl->error() != QNetworkReply::NoError) {
qLog(Warning) << "Error downloading episode:" << repl->errorString();
emit ProgressChanged(episode_, PodcastDownload::NotDownloading, 0);
@ -177,9 +171,6 @@ QString PodcastDownloader::FilenameForEpisode(const QString& directory,
}
void PodcastDownloader::DownloadEpisode(const PodcastEpisode& episode) {
QFile* file = nullptr;
Task* task = nullptr;
for ( Task* tas : list_tasks_ ) {
if (tas->episode().database_id() == episode.database_id()) {
return;
@ -189,7 +180,7 @@ void PodcastDownloader::DownloadEpisode(const PodcastEpisode& episode) {
Podcast podcast =
backend_->GetSubscriptionById(episode.podcast_database_id());
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";
return;
}
@ -199,13 +190,13 @@ void PodcastDownloader::DownloadEpisode(const PodcastEpisode& episode) {
// Open the output file
QDir().mkpath(directory);
file = new QFile(filepath);
QFile* file = new QFile(filepath);
if (!file->open(QIODevice::WriteOnly)) {
qLog(Warning) << "Could not open the file" << filepath << "for writing";
return;
}
task = new Task(episode, file, backend_);
Task* task = new Task(episode, file, backend_);
list_tasks_ << task;
qLog(Info) << "Downloading" << task->episode().url() << "to" << filepath;

View File

@ -24,6 +24,7 @@
#include "podcast.h"
#include "podcastepisode.h"
#include <memory>
#include <QFile>
#include <QList>
#include <QObject>
@ -51,8 +52,7 @@ class Task : public QObject {
public:
Task(PodcastEpisode episode, QFile* file, PodcastBackend* backend);
~Task();
PodcastEpisode episode();
const PodcastEpisode episode();
signals:
void ProgressChanged(const PodcastEpisode& episode,
@ -61,16 +61,16 @@ class Task : public QObject {
private slots:
void reading();
void finished_();
void finishedInternal();
void downloadProgress_(qint64 received, qint64 total);
private:
QFile* file_;
std::unique_ptr<QFile> file_;
PodcastEpisode episode_;
QNetworkRequest req_;
PodcastBackend* backend_;
NetworkAccessManager* network_;
RedirectFollower* repl;
std::unique_ptr<NetworkAccessManager> network_;
std::unique_ptr<RedirectFollower> repl;
};
class PodcastDownloader : public QObject {