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 <algorithm>
#include <KLocalizedString>
#include "audiologging.h"
#include "datamanager.h"
#include "feed.h"
#include "powermanagementinterface.h"
#include "settingsmanager.h"
@ -417,9 +420,10 @@ void AudioManager::mediaStatusChanged()
DataManager::instance().setLastPlayingEntry(QStringLiteral("none"));
stop();
next();
if (badEntry && badEntry->enclosure())
if (badEntry && badEntry->enclosure()) {
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 "entry.h"
#include "error.h"
class AudioManagerPrivate;
@ -131,6 +132,8 @@ Q_SIGNALS:
void canGoNextChanged();
void logError(Error::Type type, const QString &url, const QString &id, const int errorId, const QString &errorString);
public Q_SLOTS:
void setEntry(Entry *entry);

View File

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

View File

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

View File

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