Also add title argument to Error elsewhere

This commit is contained in:
Bart De Vries 2021-07-14 22:27:52 +02:00
parent a5b021cffd
commit b9b82d783f
10 changed files with 47 additions and 19 deletions

View File

@ -429,7 +429,7 @@ void AudioManager::mediaStatusChanged()
next(); next();
if (badEntry && badEntry->enclosure()) { if (badEntry && badEntry->enclosure()) {
badEntry->enclosure()->deleteFile(); 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());
} }
} }
} }

View File

@ -132,7 +132,7 @@ Q_SIGNALS:
void canGoNextChanged(); 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: public Q_SLOTS:

View File

@ -45,6 +45,8 @@ bool Database::migrate()
TRUE_OR_RETURN(migrateTo2()); TRUE_OR_RETURN(migrateTo2());
if (dbversion < 3) if (dbversion < 3)
TRUE_OR_RETURN(migrateTo3()); TRUE_OR_RETURN(migrateTo3());
if (dbversion < 4)
TRUE_OR_RETURN(migrateTo4());
return true; return true;
} }
@ -96,6 +98,18 @@ bool Database::migrateTo3()
return true; 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) bool Database::execute(const QString &query)
{ {
QSqlQuery q; QSqlQuery q;

View File

@ -30,5 +30,6 @@ private:
bool migrateTo1(); bool migrateTo1();
bool migrateTo2(); bool migrateTo2();
bool migrateTo3(); bool migrateTo3();
bool migrateTo4();
void cleanup(); void cleanup();
}; };

View File

@ -91,7 +91,8 @@ void Enclosure::download()
m_entry->feed()->url(), m_entry->feed()->url(),
m_entry->id(), m_entry->id(),
0, 0,
i18n("Podcast downloads not allowed due to user setting")); i18n("Podcast downloads not allowed due to user setting"),
QString());
return; return;
} }
@ -120,7 +121,12 @@ void Enclosure::download()
if (downloadJob->error() != QNetworkReply::OperationCanceledError) { if (downloadJob->error() != QNetworkReply::OperationCanceledError) {
m_entry->feed()->setErrorId(downloadJob->error()); m_entry->feed()->setErrorId(downloadJob->error());
m_entry->feed()->setErrorString(downloadJob->errorString()); 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); disconnect(this, &Enclosure::cancelDownload, this, nullptr);

View File

@ -81,7 +81,7 @@ Q_SIGNALS:
void durationChanged(); void durationChanged();
void sizeChanged(); void sizeChanged();
void sizeOnDiskChanged(); 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: private:
void processDownloadedFile(); void processDownloadedFile();

View File

@ -27,7 +27,8 @@ ErrorLogModel::ErrorLogModel()
query.value(QStringLiteral("code")).toInt(), query.value(QStringLiteral("code")).toInt(),
query.value(QStringLiteral("message")).toString(), 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; m_errors += error;
} }
} }
@ -53,25 +54,30 @@ int ErrorLogModel::rowCount(const QModelIndex &parent) const
return m_errors.count(); 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; 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); beginInsertRows(QModelIndex(), 0, 0);
m_errors.prepend(error); m_errors.prepend(error);
endInsertRows(); endInsertRows();
// Also add error to database // Also add error to database
QSqlQuery query; QSqlQuery query;
query.prepare(QStringLiteral("INSERT INTO Errors VALUES (:type, :url, :id, :code, :message, :date);")); query.prepare(QStringLiteral("INSERT INTO Errors VALUES (:type, :url, :id, :code, :message, :date, :title);"));
query.bindValue(QStringLiteral(":type"), Error::typeToDb(error->type)); query.bindValue(QStringLiteral(":type"), Error::typeToDb(type));
query.bindValue(QStringLiteral(":url"), error->url); query.bindValue(QStringLiteral(":url"), url);
query.bindValue(QStringLiteral(":id"), error->id); query.bindValue(QStringLiteral(":id"), id);
query.bindValue(QStringLiteral(":code"), error->code); query.bindValue(QStringLiteral(":code"), errorCode);
query.bindValue(QStringLiteral(":message"), error->message); query.bindValue(QStringLiteral(":message"), errorString);
query.bindValue(QStringLiteral(":date"), error->date.toSecsSinceEpoch()); query.bindValue(QStringLiteral(":date"), error->date.toSecsSinceEpoch());
query.bindValue(QStringLiteral(":title"), title);
Database::instance().execute(query); Database::instance().execute(query);
// Send signal to display inline error message // Send signal to display inline error message

View File

@ -32,7 +32,8 @@ public:
Q_INVOKABLE void clearAll(); Q_INVOKABLE void clearAll();
public: 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: Q_SIGNALS:
void newErrorLogged(Error *error); void newErrorLogged(Error *error);

View File

@ -90,7 +90,7 @@ void Fetcher::fetchAll()
void Fetcher::retrieveFeed(const QString &url) void Fetcher::retrieveFeed(const QString &url)
{ {
if (isMeteredConnection() && !SettingsManager::self()->allowMeteredFeedUpdates()) { 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++; m_updateProgress++;
Q_EMIT updateProgressChanged(m_updateProgress); Q_EMIT updateProgressChanged(m_updateProgress);
return; return;
@ -107,7 +107,7 @@ void Fetcher::retrieveFeed(const QString &url)
if (reply->error()) { if (reply->error()) {
qWarning() << "Error fetching feed"; qWarning() << "Error fetching feed";
qWarning() << reply->errorString(); 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 { } else {
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
Syndication::DocumentSource *document = new Syndication::DocumentSource(data, url); Syndication::DocumentSource *document = new Syndication::DocumentSource(data, url);

View File

@ -61,7 +61,7 @@ Q_SIGNALS:
const QString &description, const QString &description,
const QDateTime &lastUpdated); const QDateTime &lastUpdated);
void feedUpdateFinished(const QString &url); 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 entryAdded(const QString &feedurl, const QString &id);
void downloadFinished(QString url) const; void downloadFinished(QString url) const;