2021-05-14 16:46:54 +02:00
|
|
|
/**
|
|
|
|
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include "datamanager.h"
|
|
|
|
#include "entry.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "feed.h"
|
|
|
|
|
2021-07-14 20:21:55 +02:00
|
|
|
Error::Error(const Type type, const QString url, const QString id, const int code, const QString message, const QDateTime date, const QString title)
|
2021-05-14 16:46:54 +02:00
|
|
|
: QObject(nullptr)
|
|
|
|
{
|
|
|
|
this->type = type;
|
|
|
|
this->url = url;
|
|
|
|
this->id = id;
|
|
|
|
this->code = code;
|
|
|
|
this->message = message;
|
|
|
|
this->date = date;
|
2021-07-14 20:21:55 +02:00
|
|
|
this->m_title = title;
|
|
|
|
}
|
2021-05-14 16:46:54 +02:00
|
|
|
|
|
|
|
QString Error::title() const
|
|
|
|
{
|
2021-07-14 20:21:55 +02:00
|
|
|
QString title = m_title;
|
|
|
|
if (title.isEmpty()) {
|
|
|
|
if (!id.isEmpty()) {
|
|
|
|
if (DataManager::instance().getEntry(id))
|
|
|
|
title = DataManager::instance().getEntry(id)->title();
|
|
|
|
} else if (!url.isEmpty()) {
|
|
|
|
if (DataManager::instance().getFeed(url))
|
|
|
|
title = DataManager::instance().getFeed(url)->name();
|
|
|
|
}
|
2021-05-14 16:46:54 +02:00
|
|
|
}
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Error::description() const
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case Error::Type::FeedUpdate:
|
|
|
|
return i18n("Podcast Update Error");
|
|
|
|
case Error::Type::MediaDownload:
|
|
|
|
return i18n("Media Download Error");
|
|
|
|
case Error::Type::MeteredNotAllowed:
|
|
|
|
return i18n("Update Not Allowed on Metered Connection");
|
2021-07-04 14:53:42 +02:00
|
|
|
case Error::Type::InvalidMedia:
|
|
|
|
return i18n("Invalid Media File");
|
2021-07-21 09:14:06 +02:00
|
|
|
case Error::Type::DiscoverError:
|
|
|
|
return i18n("Nothing Found");
|
2021-07-04 18:35:09 +02:00
|
|
|
case Error::Type::StorageMoveError:
|
|
|
|
return i18n("Error moving storage path");
|
2021-10-29 17:00:52 +02:00
|
|
|
case Error::Type::SyncError:
|
|
|
|
return i18n("Error Syncing Feed and/or Episode Status");
|
2021-05-14 16:46:54 +02:00
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int Error::typeToDb(Error::Type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case Error::Type::FeedUpdate:
|
|
|
|
return 0;
|
|
|
|
case Error::Type::MediaDownload:
|
|
|
|
return 1;
|
|
|
|
case Error::Type::MeteredNotAllowed:
|
|
|
|
return 2;
|
2021-07-04 14:53:42 +02:00
|
|
|
case Error::Type::InvalidMedia:
|
|
|
|
return 3;
|
2021-07-21 09:14:06 +02:00
|
|
|
case Error::Type::DiscoverError:
|
|
|
|
return 4;
|
2021-07-04 18:35:09 +02:00
|
|
|
case Error::Type::StorageMoveError:
|
|
|
|
return 5;
|
2021-10-29 17:00:52 +02:00
|
|
|
case Error::Type::SyncError:
|
|
|
|
return 6;
|
2021-05-14 16:46:54 +02:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Error::Type Error::dbToType(int value)
|
|
|
|
{
|
|
|
|
switch (value) {
|
|
|
|
case 0:
|
|
|
|
return Error::Type::FeedUpdate;
|
|
|
|
case 1:
|
|
|
|
return Error::Type::MediaDownload;
|
|
|
|
case 2:
|
|
|
|
return Error::Type::MeteredNotAllowed;
|
2021-07-04 14:53:42 +02:00
|
|
|
case 3:
|
|
|
|
return Error::Type::InvalidMedia;
|
2021-07-21 09:14:06 +02:00
|
|
|
case 4:
|
|
|
|
return Error::Type::DiscoverError;
|
2021-07-04 18:35:09 +02:00
|
|
|
case 5:
|
|
|
|
return Error::Type::StorageMoveError;
|
2021-10-29 17:00:52 +02:00
|
|
|
case 6:
|
|
|
|
return Error::Type::SyncError;
|
2021-05-14 16:46:54 +02:00
|
|
|
default:
|
|
|
|
return Error::Type::Unknown;
|
|
|
|
}
|
|
|
|
}
|