Add static IsTypeSupported methods to playlist item classes

This commit is contained in:
Jim Broadus 2020-06-20 21:21:12 -07:00 committed by John Maguire
parent 9455a3ef79
commit ad882cc999
11 changed files with 47 additions and 7 deletions

View File

@ -31,8 +31,10 @@
#include "library/sqlrow.h"
#include "playlist/playlistbackend.h"
// Note that the "Radio" type is legacy and only supported for database
// backwards compatibility, so this uses "Internet" for all types.
InternetPlaylistItem::InternetPlaylistItem(const QString& type)
: PlaylistItem(type), set_service_icon_(false) {}
: PlaylistItem("Internet"), set_service_icon_(false) {}
InternetPlaylistItem::InternetPlaylistItem(InternetService* service,
const Song& metadata)
@ -43,6 +45,12 @@ InternetPlaylistItem::InternetPlaylistItem(InternetService* service,
InitMetadata();
}
bool InternetPlaylistItem::IsTypeSupported(const QString& type) {
if (type == "Radio") return true;
if (type == "Internet") return true;
return false;
}
bool InternetPlaylistItem::InitFromQuery(const SqlRow& query) {
// The song tables gets joined first, plus one each for the song ROWIDs
const int row =

View File

@ -34,6 +34,8 @@ class InternetPlaylistItem : public PlaylistItem {
explicit InternetPlaylistItem(const QString& type);
InternetPlaylistItem(InternetService* service, const Song& metadata);
static bool IsTypeSupported(const QString& type);
Options options() const;
QList<QAction*> actions();

View File

@ -25,6 +25,10 @@ JamendoPlaylistItem::JamendoPlaylistItem(const QString& type)
JamendoPlaylistItem::JamendoPlaylistItem(const Song& song)
: DbPlaylistItem("Jamendo", song) {}
bool JamendoPlaylistItem::IsTypeSupported(const QString& type) {
return type == "Jamendo";
}
bool JamendoPlaylistItem::InitFromQuery(const SqlRow& query) {
// Rows from the songs tables come first
song_.InitFromQuery(query, true, (Song::kColumns.count() + 1) * 2);

View File

@ -27,6 +27,8 @@ class JamendoPlaylistItem : public DbPlaylistItem {
explicit JamendoPlaylistItem(const QString& type);
explicit JamendoPlaylistItem(const Song& song);
static bool IsTypeSupported(const QString& type);
bool InitFromQuery(const SqlRow& query);
};

View File

@ -26,6 +26,10 @@ MagnatunePlaylistItem::MagnatunePlaylistItem(const QString& type)
MagnatunePlaylistItem::MagnatunePlaylistItem(const Song& song)
: DbPlaylistItem("Magnatune", song) {}
bool MagnatunePlaylistItem::IsTypeSupported(const QString& type) {
return type == "Magnatune";
}
bool MagnatunePlaylistItem::InitFromQuery(const SqlRow& query) {
// Rows from the songs tables come first
song_.InitFromQuery(query, true, Song::kColumns.count() + 1);

View File

@ -27,6 +27,8 @@ class MagnatunePlaylistItem : public DbPlaylistItem {
explicit MagnatunePlaylistItem(const QString& type);
explicit MagnatunePlaylistItem(const Song& song);
static bool IsTypeSupported(const QString& type);
bool InitFromQuery(const SqlRow& query);
};

View File

@ -26,6 +26,10 @@ LibraryPlaylistItem::LibraryPlaylistItem(const QString& type)
LibraryPlaylistItem::LibraryPlaylistItem(const Song& song)
: DbPlaylistItem("Library", song) {}
bool LibraryPlaylistItem::IsTypeSupported(const QString& type) {
return type == "Library";
}
void LibraryPlaylistItem::Reload() {
TagReaderClient::Instance()->ReadFileBlocking(song_.url().toLocalFile(),
&song_);

View File

@ -26,6 +26,8 @@ class LibraryPlaylistItem : public DbPlaylistItem {
LibraryPlaylistItem(const QString& type);
LibraryPlaylistItem(const Song& song);
static bool IsTypeSupported(const QString& type);
bool InitFromQuery(const SqlRow& query);
void Reload();

View File

@ -34,12 +34,16 @@
PlaylistItem::~PlaylistItem() {}
PlaylistItem* PlaylistItem::NewFromType(const QString& type) {
if (type == "Library") return new LibraryPlaylistItem(type);
if (type == "Magnatune") return new MagnatunePlaylistItem(type);
if (type == "Jamendo") return new JamendoPlaylistItem(type);
if (type == "Stream" || type == "File") return new SongPlaylistItem(type);
if (type == "Internet" || type == "Radio")
return new InternetPlaylistItem("Internet");
if (LibraryPlaylistItem::IsTypeSupported(type))
return new LibraryPlaylistItem(type);
if (MagnatunePlaylistItem::IsTypeSupported(type))
return new MagnatunePlaylistItem(type);
if (JamendoPlaylistItem::IsTypeSupported(type))
return new JamendoPlaylistItem(type);
if (SongPlaylistItem::IsTypeSupported(type))
return new SongPlaylistItem(type);
if (InternetPlaylistItem::IsTypeSupported(type))
return new InternetPlaylistItem(type);
qLog(Warning) << "Invalid PlaylistItem type:" << type;
return nullptr;

View File

@ -30,6 +30,12 @@ SongPlaylistItem::SongPlaylistItem(const QString& type) : PlaylistItem(type) {}
SongPlaylistItem::SongPlaylistItem(const Song& song)
: PlaylistItem(song.is_stream() ? "Stream" : "File"), song_(song) {}
bool SongPlaylistItem::IsTypeSupported(const QString& type) {
if (type == "Stream") return true;
if (type == "File") return true;
return false;
}
bool SongPlaylistItem::InitFromQuery(const SqlRow& query) {
song_.InitFromQuery(query, false, (Song::kColumns.count() + 1) * 3);

View File

@ -26,6 +26,8 @@ class SongPlaylistItem : public PlaylistItem {
SongPlaylistItem(const QString& type);
SongPlaylistItem(const Song& song);
static bool IsTypeSupported(const QString& type);
// Restores a stream- or file-related playlist item using query row.
// If it's a file related playlist item, this will restore it's CUE
// attributes (if any) but won't parse the CUE!