Add error overlay for Invalid Media

This implements a TODO mentioned in the sources.
This commit is contained in:
Bart De Vries 2021-07-04 14:53:42 +02:00
parent 1b3df48ce8
commit d2cee8a066
5 changed files with 19 additions and 3 deletions

View File

@ -13,8 +13,11 @@
#include <QtMath> #include <QtMath>
#include <algorithm> #include <algorithm>
#include <KLocalizedString>
#include "audiologging.h" #include "audiologging.h"
#include "datamanager.h" #include "datamanager.h"
#include "feed.h"
#include "powermanagementinterface.h" #include "powermanagementinterface.h"
#include "settingsmanager.h" #include "settingsmanager.h"
@ -417,9 +420,10 @@ void AudioManager::mediaStatusChanged()
DataManager::instance().setLastPlayingEntry(QStringLiteral("none")); DataManager::instance().setLastPlayingEntry(QStringLiteral("none"));
stop(); stop();
next(); next();
if (badEntry && badEntry->enclosure()) if (badEntry && badEntry->enclosure()) {
badEntry->enclosure()->deleteFile(); badEntry->enclosure()->deleteFile();
// TODO: show error overlay? Q_EMIT logError(Error::Type::InvalidMedia, badEntry->feed()->url(), badEntry->id(), QMediaPlayer::InvalidMedia, i18n("Invalid Media"));
}
} }
} }

View File

@ -17,6 +17,7 @@
#include <memory> #include <memory>
#include "entry.h" #include "entry.h"
#include "error.h"
class AudioManagerPrivate; class AudioManagerPrivate;
@ -131,6 +132,8 @@ Q_SIGNALS:
void canGoNextChanged(); void canGoNextChanged();
void logError(Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString);
public Q_SLOTS: public Q_SLOTS:
void setEntry(Entry *entry); void setEntry(Entry *entry);

View File

@ -47,6 +47,8 @@ QString Error::description() const
return i18n("Media Download Error"); return i18n("Media Download Error");
case Error::Type::MeteredNotAllowed: case Error::Type::MeteredNotAllowed:
return i18n("Update Not Allowed on Metered Connection"); return i18n("Update Not Allowed on Metered Connection");
case Error::Type::InvalidMedia:
return i18n("Invalid Media File");
default: default:
return QString(); return QString();
} }
@ -61,6 +63,8 @@ int Error::typeToDb(Error::Type type)
return 1; return 1;
case Error::Type::MeteredNotAllowed: case Error::Type::MeteredNotAllowed:
return 2; return 2;
case Error::Type::InvalidMedia:
return 3;
default: default:
return -1; return -1;
} }
@ -75,6 +79,8 @@ Error::Type Error::dbToType(int value)
return Error::Type::MediaDownload; return Error::Type::MediaDownload;
case 2: case 2:
return Error::Type::MeteredNotAllowed; return Error::Type::MeteredNotAllowed;
case 3:
return Error::Type::InvalidMedia;
default: default:
return Error::Type::Unknown; return Error::Type::Unknown;
} }

View File

@ -20,6 +20,7 @@ public:
FeedUpdate, FeedUpdate,
MediaDownload, MediaDownload,
MeteredNotAllowed, MeteredNotAllowed,
InvalidMedia,
}; };
Q_ENUM(Type) Q_ENUM(Type)

View File

@ -8,6 +8,7 @@
#include <QSqlQuery> #include <QSqlQuery>
#include "audiomanager.h"
#include "database.h" #include "database.h"
#include "datamanager.h" #include "datamanager.h"
#include "fetcher.h" #include "fetcher.h"
@ -16,6 +17,7 @@ ErrorLogModel::ErrorLogModel()
: QAbstractListModel(nullptr) : QAbstractListModel(nullptr)
{ {
connect(&Fetcher::instance(), &Fetcher::error, this, &ErrorLogModel::monitorErrorMessages); connect(&Fetcher::instance(), &Fetcher::error, this, &ErrorLogModel::monitorErrorMessages);
connect(&AudioManager::instance(), &AudioManager::logError, this, &ErrorLogModel::monitorErrorMessages);
QSqlQuery query; QSqlQuery query;
query.prepare(QStringLiteral("SELECT * FROM Errors ORDER BY date DESC;")); query.prepare(QStringLiteral("SELECT * FROM Errors ORDER BY date DESC;"));