Refactor conversion from enum to int and vice versa

This commit is contained in:
Bart De Vries 2024-04-22 16:49:46 +02:00
parent f58fd20201
commit b7b7f18922
No known key found for this signature in database
GPG Key ID: 7285665DA6E2D42B
4 changed files with 8 additions and 72 deletions

View File

@ -120,34 +120,12 @@ void Enclosure::updateFromDb()
int Enclosure::statusToDb(Enclosure::Status status) int Enclosure::statusToDb(Enclosure::Status status)
{ {
switch (status) { return static_cast<int>(status);
case Enclosure::Status::Downloadable:
return 0;
case Enclosure::Status::Downloading:
return 1;
case Enclosure::Status::PartiallyDownloaded:
return 2;
case Enclosure::Status::Downloaded:
return 3;
default:
return -1;
}
} }
Enclosure::Status Enclosure::dbToStatus(int value) Enclosure::Status Enclosure::dbToStatus(int value)
{ {
switch (value) { return Enclosure::Status(value);
case 0:
return Enclosure::Status::Downloadable;
case 1:
return Enclosure::Status::Downloading;
case 2:
return Enclosure::Status::PartiallyDownloaded;
case 3:
return Enclosure::Status::Downloaded;
default:
return Enclosure::Status::Error;
}
} }
void Enclosure::download() void Enclosure::download()

View File

@ -45,11 +45,11 @@ public:
Enclosure(Entry *entry); Enclosure(Entry *entry);
enum Status { enum Status {
Downloadable, Error = -1,
Downloadable = 0,
Downloading, Downloading,
PartiallyDownloaded, PartiallyDownloaded,
Downloaded, Downloaded,
Error,
}; };
Q_ENUM(Status) Q_ENUM(Status)

View File

@ -69,52 +69,10 @@ QString Error::description() const
int Error::typeToDb(Error::Type type) int Error::typeToDb(Error::Type type)
{ {
switch (type) { return static_cast<int>(type);
case Error::Type::FeedUpdate:
return 0;
case Error::Type::MediaDownload:
return 1;
case Error::Type::MeteredNotAllowed:
return 2;
case Error::Type::InvalidMedia:
return 3;
case Error::Type::DiscoverError:
return 4;
case Error::Type::StorageMoveError:
return 5;
case Error::Type::SyncError:
return 6;
case Error::Type::MeteredStreamingNotAllowed:
return 7;
case Error::Type::NoNetwork:
return 8;
default:
return -1;
}
} }
Error::Type Error::dbToType(int value) Error::Type Error::dbToType(int value)
{ {
switch (value) { return Error::Type(value);
case 0:
return Error::Type::FeedUpdate;
case 1:
return Error::Type::MediaDownload;
case 2:
return Error::Type::MeteredNotAllowed;
case 3:
return Error::Type::InvalidMedia;
case 4:
return Error::Type::DiscoverError;
case 5:
return Error::Type::StorageMoveError;
case 6:
return Error::Type::SyncError;
case 7:
return Error::Type::MeteredStreamingNotAllowed;
case 8:
return Error::Type::NoNetwork;
default:
return Error::Type::Unknown;
}
} }

View File

@ -16,8 +16,8 @@ class Error : public QObject
public: public:
enum Type { enum Type {
Unknown, Unknown = -1,
FeedUpdate, FeedUpdate = 0,
MediaDownload, MediaDownload,
MeteredNotAllowed, MeteredNotAllowed,
InvalidMedia, InvalidMedia,