From b9b82d783feb7b06c153cdf45c4add37b172a1c1 Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Wed, 14 Jul 2021 22:27:52 +0200 Subject: [PATCH] Also add title argument to Error elsewhere --- src/audiomanager.cpp | 2 +- src/audiomanager.h | 2 +- src/database.cpp | 14 ++++++++++++++ src/database.h | 1 + src/enclosure.cpp | 10 ++++++++-- src/enclosure.h | 2 +- src/errorlogmodel.cpp | 26 ++++++++++++++++---------- src/errorlogmodel.h | 3 ++- src/fetcher.cpp | 4 ++-- src/fetcher.h | 2 +- 10 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/audiomanager.cpp b/src/audiomanager.cpp index fb361ad9..41ec5cf8 100644 --- a/src/audiomanager.cpp +++ b/src/audiomanager.cpp @@ -429,7 +429,7 @@ void AudioManager::mediaStatusChanged() next(); if (badEntry && badEntry->enclosure()) { badEntry->enclosure()->deleteFile(); - Q_EMIT logError(Error::Type::InvalidMedia, badEntry->feed()->url(), badEntry->id(), QMediaPlayer::InvalidMedia, i18n("Invalid Media")); + Q_EMIT logError(Error::Type::InvalidMedia, badEntry->feed()->url(), badEntry->id(), QMediaPlayer::InvalidMedia, i18n("Invalid Media"), QString()); } } } diff --git a/src/audiomanager.h b/src/audiomanager.h index 46f67f96..d0ad9d35 100644 --- a/src/audiomanager.h +++ b/src/audiomanager.h @@ -132,7 +132,7 @@ Q_SIGNALS: void canGoNextChanged(); - void logError(Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString); + void logError(Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString, const QString &title); public Q_SLOTS: diff --git a/src/database.cpp b/src/database.cpp index a3623aa6..0b586271 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -45,6 +45,8 @@ bool Database::migrate() TRUE_OR_RETURN(migrateTo2()); if (dbversion < 3) TRUE_OR_RETURN(migrateTo3()); + if (dbversion < 4) + TRUE_OR_RETURN(migrateTo4()); return true; } @@ -96,6 +98,18 @@ bool Database::migrateTo3() return true; } +bool Database::migrateTo4() +{ + qDebug() << "Migrating database to version 4"; + TRUE_OR_RETURN(execute(QStringLiteral("BEGIN TRANSACTION;"))); + TRUE_OR_RETURN(execute(QStringLiteral("DROP TABLE Errors;"))); + TRUE_OR_RETURN( + execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Errors (type INTEGER, url TEXT, id TEXT, code INTEGER, message TEXT, date INTEGER, title TEXT);"))); + TRUE_OR_RETURN(execute(QStringLiteral("PRAGMA user_version = 4;"))); + TRUE_OR_RETURN(execute(QStringLiteral("COMMIT;"))); + return true; +} + bool Database::execute(const QString &query) { QSqlQuery q; diff --git a/src/database.h b/src/database.h index 511ff66e..b5fd3985 100644 --- a/src/database.h +++ b/src/database.h @@ -30,5 +30,6 @@ private: bool migrateTo1(); bool migrateTo2(); bool migrateTo3(); + bool migrateTo4(); void cleanup(); }; diff --git a/src/enclosure.cpp b/src/enclosure.cpp index a2c1c43e..5a3530f9 100644 --- a/src/enclosure.cpp +++ b/src/enclosure.cpp @@ -91,7 +91,8 @@ void Enclosure::download() m_entry->feed()->url(), m_entry->id(), 0, - i18n("Podcast downloads not allowed due to user setting")); + i18n("Podcast downloads not allowed due to user setting"), + QString()); return; } @@ -120,7 +121,12 @@ void Enclosure::download() if (downloadJob->error() != QNetworkReply::OperationCanceledError) { m_entry->feed()->setErrorId(downloadJob->error()); m_entry->feed()->setErrorString(downloadJob->errorString()); - Q_EMIT downloadError(Error::Type::MediaDownload, m_entry->feed()->url(), m_entry->id(), downloadJob->error(), downloadJob->errorString()); + Q_EMIT downloadError(Error::Type::MediaDownload, + m_entry->feed()->url(), + m_entry->id(), + downloadJob->error(), + downloadJob->errorString(), + QString()); } } disconnect(this, &Enclosure::cancelDownload, this, nullptr); diff --git a/src/enclosure.h b/src/enclosure.h index 48902225..17393ba3 100644 --- a/src/enclosure.h +++ b/src/enclosure.h @@ -81,7 +81,7 @@ Q_SIGNALS: void durationChanged(); void sizeChanged(); void sizeOnDiskChanged(); - void downloadError(const Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString); + void downloadError(const Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString, const QString &title); private: void processDownloadedFile(); diff --git a/src/errorlogmodel.cpp b/src/errorlogmodel.cpp index fa2f2a7c..7eb6fd5f 100644 --- a/src/errorlogmodel.cpp +++ b/src/errorlogmodel.cpp @@ -27,7 +27,8 @@ ErrorLogModel::ErrorLogModel() query.value(QStringLiteral("code")).toInt(), query.value(QStringLiteral("message")).toString(), - QDateTime::fromSecsSinceEpoch(query.value(QStringLiteral("date")).toInt())); + QDateTime::fromSecsSinceEpoch(query.value(QStringLiteral("date")).toInt()), + query.value(QStringLiteral("title")).toString()); m_errors += error; } } @@ -53,25 +54,30 @@ int ErrorLogModel::rowCount(const QModelIndex &parent) const return m_errors.count(); } -void ErrorLogModel::monitorErrorMessages(const Error::Type type, const QString &url, const QString &id, const int errorCode, const QString &errorString) +void ErrorLogModel::monitorErrorMessages(const Error::Type type, + const QString &url, + const QString &id, + const int errorCode, + const QString &errorString, + const QString &title) { qDebug() << "Error happened:" << type << url << id << errorCode << errorString; - QString title; - Error *error = new Error(type, url, id, errorCode, errorString, QDateTime::currentDateTime()); + Error *error = new Error(type, url, id, errorCode, errorString, QDateTime::currentDateTime(), title); beginInsertRows(QModelIndex(), 0, 0); m_errors.prepend(error); endInsertRows(); // Also add error to database QSqlQuery query; - query.prepare(QStringLiteral("INSERT INTO Errors VALUES (:type, :url, :id, :code, :message, :date);")); - query.bindValue(QStringLiteral(":type"), Error::typeToDb(error->type)); - query.bindValue(QStringLiteral(":url"), error->url); - query.bindValue(QStringLiteral(":id"), error->id); - query.bindValue(QStringLiteral(":code"), error->code); - query.bindValue(QStringLiteral(":message"), error->message); + query.prepare(QStringLiteral("INSERT INTO Errors VALUES (:type, :url, :id, :code, :message, :date, :title);")); + query.bindValue(QStringLiteral(":type"), Error::typeToDb(type)); + query.bindValue(QStringLiteral(":url"), url); + query.bindValue(QStringLiteral(":id"), id); + query.bindValue(QStringLiteral(":code"), errorCode); + query.bindValue(QStringLiteral(":message"), errorString); query.bindValue(QStringLiteral(":date"), error->date.toSecsSinceEpoch()); + query.bindValue(QStringLiteral(":title"), title); Database::instance().execute(query); // Send signal to display inline error message diff --git a/src/errorlogmodel.h b/src/errorlogmodel.h index 5d6bf6fc..b1f8cbe4 100644 --- a/src/errorlogmodel.h +++ b/src/errorlogmodel.h @@ -32,7 +32,8 @@ public: Q_INVOKABLE void clearAll(); public: - void monitorErrorMessages(const Error::Type type, const QString &url, const QString &id, const int errorCode, const QString &errorString); + void + monitorErrorMessages(const Error::Type type, const QString &url, const QString &id, const int errorCode, const QString &errorString, const QString &title); Q_SIGNALS: void newErrorLogged(Error *error); diff --git a/src/fetcher.cpp b/src/fetcher.cpp index 31b132b2..730732a4 100644 --- a/src/fetcher.cpp +++ b/src/fetcher.cpp @@ -90,7 +90,7 @@ void Fetcher::fetchAll() void Fetcher::retrieveFeed(const QString &url) { if (isMeteredConnection() && !SettingsManager::self()->allowMeteredFeedUpdates()) { - Q_EMIT error(Error::Type::MeteredNotAllowed, url, QString(), 0, i18n("Podcast updates not allowed due to user setting")); + Q_EMIT error(Error::Type::MeteredNotAllowed, url, QString(), 0, i18n("Podcast updates not allowed due to user setting"), QString()); m_updateProgress++; Q_EMIT updateProgressChanged(m_updateProgress); return; @@ -107,7 +107,7 @@ void Fetcher::retrieveFeed(const QString &url) if (reply->error()) { qWarning() << "Error fetching feed"; qWarning() << reply->errorString(); - Q_EMIT error(Error::Type::FeedUpdate, url, QString(), reply->error(), reply->errorString()); + Q_EMIT error(Error::Type::FeedUpdate, url, QString(), reply->error(), reply->errorString(), QString()); } else { QByteArray data = reply->readAll(); Syndication::DocumentSource *document = new Syndication::DocumentSource(data, url); diff --git a/src/fetcher.h b/src/fetcher.h index 27d04c7c..6e60a3e6 100644 --- a/src/fetcher.h +++ b/src/fetcher.h @@ -61,7 +61,7 @@ Q_SIGNALS: const QString &description, const QDateTime &lastUpdated); void feedUpdateFinished(const QString &url); - void error(Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString); + void error(Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString, const QString &title); void entryAdded(const QString &feedurl, const QString &id); void downloadFinished(QString url) const;