File indexing completed on 2024-05-12 16:21:29
0001 /** 0002 * SPDX-FileCopyrightText: 2021-2022 Bart De Vries <bart@mogwai.be> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include <KLocalizedString> 0008 #include <QDateTime> 0009 #include <QObject> 0010 #include <QString> 0011 0012 #include "datamanager.h" 0013 #include "entry.h" 0014 #include "error.h" 0015 #include "feed.h" 0016 0017 Error::Error(const Type type, const QString url, const QString id, const int code, const QString message, const QDateTime date, const QString title) 0018 : QObject(nullptr) 0019 { 0020 this->type = type; 0021 this->url = url; 0022 this->id = id; 0023 this->code = code; 0024 this->message = message; 0025 this->date = date; 0026 this->m_title = title; 0027 } 0028 0029 QString Error::title() const 0030 { 0031 QString title = m_title; 0032 if (title.isEmpty()) { 0033 if (!id.isEmpty()) { 0034 if (DataManager::instance().getEntry(id)) 0035 title = DataManager::instance().getEntry(id)->title(); 0036 } else if (!url.isEmpty()) { 0037 if (DataManager::instance().getFeed(url)) 0038 title = DataManager::instance().getFeed(url)->name(); 0039 } 0040 } 0041 return title; 0042 } 0043 0044 QString Error::description() const 0045 { 0046 switch (type) { 0047 case Error::Type::FeedUpdate: 0048 return i18n("Podcast update error"); 0049 case Error::Type::MediaDownload: 0050 return i18n("Media download error"); 0051 case Error::Type::MeteredNotAllowed: 0052 return i18n("Update not allowed on metered connection"); 0053 case Error::Type::InvalidMedia: 0054 return i18n("Invalid media file"); 0055 case Error::Type::DiscoverError: 0056 return i18n("Nothing found"); 0057 case Error::Type::StorageMoveError: 0058 return i18n("Error moving storage path"); 0059 case Error::Type::SyncError: 0060 return i18n("Error syncing feed and/or episode status"); 0061 case Error::Type::MeteredStreamingNotAllowed: 0062 return i18n("Connection or streaming not allowed on metered connection"); 0063 default: 0064 return QString(); 0065 } 0066 } 0067 0068 int Error::typeToDb(Error::Type type) 0069 { 0070 switch (type) { 0071 case Error::Type::FeedUpdate: 0072 return 0; 0073 case Error::Type::MediaDownload: 0074 return 1; 0075 case Error::Type::MeteredNotAllowed: 0076 return 2; 0077 case Error::Type::InvalidMedia: 0078 return 3; 0079 case Error::Type::DiscoverError: 0080 return 4; 0081 case Error::Type::StorageMoveError: 0082 return 5; 0083 case Error::Type::SyncError: 0084 return 6; 0085 case Error::Type::MeteredStreamingNotAllowed: 0086 return 7; 0087 default: 0088 return -1; 0089 } 0090 } 0091 0092 Error::Type Error::dbToType(int value) 0093 { 0094 switch (value) { 0095 case 0: 0096 return Error::Type::FeedUpdate; 0097 case 1: 0098 return Error::Type::MediaDownload; 0099 case 2: 0100 return Error::Type::MeteredNotAllowed; 0101 case 3: 0102 return Error::Type::InvalidMedia; 0103 case 4: 0104 return Error::Type::DiscoverError; 0105 case 5: 0106 return Error::Type::StorageMoveError; 0107 case 6: 0108 return Error::Type::SyncError; 0109 case 7: 0110 return Error::Type::MeteredStreamingNotAllowed; 0111 default: 0112 return Error::Type::Unknown; 0113 } 0114 }