Add static IsTypeSupported methods to playlist item classes
This commit is contained in:
parent
9455a3ef79
commit
ad882cc999
|
@ -31,8 +31,10 @@
|
||||||
#include "library/sqlrow.h"
|
#include "library/sqlrow.h"
|
||||||
#include "playlist/playlistbackend.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)
|
InternetPlaylistItem::InternetPlaylistItem(const QString& type)
|
||||||
: PlaylistItem(type), set_service_icon_(false) {}
|
: PlaylistItem("Internet"), set_service_icon_(false) {}
|
||||||
|
|
||||||
InternetPlaylistItem::InternetPlaylistItem(InternetService* service,
|
InternetPlaylistItem::InternetPlaylistItem(InternetService* service,
|
||||||
const Song& metadata)
|
const Song& metadata)
|
||||||
|
@ -43,6 +45,12 @@ InternetPlaylistItem::InternetPlaylistItem(InternetService* service,
|
||||||
InitMetadata();
|
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) {
|
bool InternetPlaylistItem::InitFromQuery(const SqlRow& query) {
|
||||||
// The song tables gets joined first, plus one each for the song ROWIDs
|
// The song tables gets joined first, plus one each for the song ROWIDs
|
||||||
const int row =
|
const int row =
|
||||||
|
|
|
@ -34,6 +34,8 @@ class InternetPlaylistItem : public PlaylistItem {
|
||||||
explicit InternetPlaylistItem(const QString& type);
|
explicit InternetPlaylistItem(const QString& type);
|
||||||
InternetPlaylistItem(InternetService* service, const Song& metadata);
|
InternetPlaylistItem(InternetService* service, const Song& metadata);
|
||||||
|
|
||||||
|
static bool IsTypeSupported(const QString& type);
|
||||||
|
|
||||||
Options options() const;
|
Options options() const;
|
||||||
|
|
||||||
QList<QAction*> actions();
|
QList<QAction*> actions();
|
||||||
|
|
|
@ -25,6 +25,10 @@ JamendoPlaylistItem::JamendoPlaylistItem(const QString& type)
|
||||||
JamendoPlaylistItem::JamendoPlaylistItem(const Song& song)
|
JamendoPlaylistItem::JamendoPlaylistItem(const Song& song)
|
||||||
: DbPlaylistItem("Jamendo", song) {}
|
: DbPlaylistItem("Jamendo", song) {}
|
||||||
|
|
||||||
|
bool JamendoPlaylistItem::IsTypeSupported(const QString& type) {
|
||||||
|
return type == "Jamendo";
|
||||||
|
}
|
||||||
|
|
||||||
bool JamendoPlaylistItem::InitFromQuery(const SqlRow& query) {
|
bool JamendoPlaylistItem::InitFromQuery(const SqlRow& query) {
|
||||||
// Rows from the songs tables come first
|
// Rows from the songs tables come first
|
||||||
song_.InitFromQuery(query, true, (Song::kColumns.count() + 1) * 2);
|
song_.InitFromQuery(query, true, (Song::kColumns.count() + 1) * 2);
|
||||||
|
|
|
@ -27,6 +27,8 @@ class JamendoPlaylistItem : public DbPlaylistItem {
|
||||||
explicit JamendoPlaylistItem(const QString& type);
|
explicit JamendoPlaylistItem(const QString& type);
|
||||||
explicit JamendoPlaylistItem(const Song& song);
|
explicit JamendoPlaylistItem(const Song& song);
|
||||||
|
|
||||||
|
static bool IsTypeSupported(const QString& type);
|
||||||
|
|
||||||
bool InitFromQuery(const SqlRow& query);
|
bool InitFromQuery(const SqlRow& query);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,10 @@ MagnatunePlaylistItem::MagnatunePlaylistItem(const QString& type)
|
||||||
MagnatunePlaylistItem::MagnatunePlaylistItem(const Song& song)
|
MagnatunePlaylistItem::MagnatunePlaylistItem(const Song& song)
|
||||||
: DbPlaylistItem("Magnatune", song) {}
|
: DbPlaylistItem("Magnatune", song) {}
|
||||||
|
|
||||||
|
bool MagnatunePlaylistItem::IsTypeSupported(const QString& type) {
|
||||||
|
return type == "Magnatune";
|
||||||
|
}
|
||||||
|
|
||||||
bool MagnatunePlaylistItem::InitFromQuery(const SqlRow& query) {
|
bool MagnatunePlaylistItem::InitFromQuery(const SqlRow& query) {
|
||||||
// Rows from the songs tables come first
|
// Rows from the songs tables come first
|
||||||
song_.InitFromQuery(query, true, Song::kColumns.count() + 1);
|
song_.InitFromQuery(query, true, Song::kColumns.count() + 1);
|
||||||
|
|
|
@ -27,6 +27,8 @@ class MagnatunePlaylistItem : public DbPlaylistItem {
|
||||||
explicit MagnatunePlaylistItem(const QString& type);
|
explicit MagnatunePlaylistItem(const QString& type);
|
||||||
explicit MagnatunePlaylistItem(const Song& song);
|
explicit MagnatunePlaylistItem(const Song& song);
|
||||||
|
|
||||||
|
static bool IsTypeSupported(const QString& type);
|
||||||
|
|
||||||
bool InitFromQuery(const SqlRow& query);
|
bool InitFromQuery(const SqlRow& query);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,10 @@ LibraryPlaylistItem::LibraryPlaylistItem(const QString& type)
|
||||||
LibraryPlaylistItem::LibraryPlaylistItem(const Song& song)
|
LibraryPlaylistItem::LibraryPlaylistItem(const Song& song)
|
||||||
: DbPlaylistItem("Library", song) {}
|
: DbPlaylistItem("Library", song) {}
|
||||||
|
|
||||||
|
bool LibraryPlaylistItem::IsTypeSupported(const QString& type) {
|
||||||
|
return type == "Library";
|
||||||
|
}
|
||||||
|
|
||||||
void LibraryPlaylistItem::Reload() {
|
void LibraryPlaylistItem::Reload() {
|
||||||
TagReaderClient::Instance()->ReadFileBlocking(song_.url().toLocalFile(),
|
TagReaderClient::Instance()->ReadFileBlocking(song_.url().toLocalFile(),
|
||||||
&song_);
|
&song_);
|
||||||
|
|
|
@ -26,6 +26,8 @@ class LibraryPlaylistItem : public DbPlaylistItem {
|
||||||
LibraryPlaylistItem(const QString& type);
|
LibraryPlaylistItem(const QString& type);
|
||||||
LibraryPlaylistItem(const Song& song);
|
LibraryPlaylistItem(const Song& song);
|
||||||
|
|
||||||
|
static bool IsTypeSupported(const QString& type);
|
||||||
|
|
||||||
bool InitFromQuery(const SqlRow& query);
|
bool InitFromQuery(const SqlRow& query);
|
||||||
void Reload();
|
void Reload();
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,16 @@
|
||||||
PlaylistItem::~PlaylistItem() {}
|
PlaylistItem::~PlaylistItem() {}
|
||||||
|
|
||||||
PlaylistItem* PlaylistItem::NewFromType(const QString& type) {
|
PlaylistItem* PlaylistItem::NewFromType(const QString& type) {
|
||||||
if (type == "Library") return new LibraryPlaylistItem(type);
|
if (LibraryPlaylistItem::IsTypeSupported(type))
|
||||||
if (type == "Magnatune") return new MagnatunePlaylistItem(type);
|
return new LibraryPlaylistItem(type);
|
||||||
if (type == "Jamendo") return new JamendoPlaylistItem(type);
|
if (MagnatunePlaylistItem::IsTypeSupported(type))
|
||||||
if (type == "Stream" || type == "File") return new SongPlaylistItem(type);
|
return new MagnatunePlaylistItem(type);
|
||||||
if (type == "Internet" || type == "Radio")
|
if (JamendoPlaylistItem::IsTypeSupported(type))
|
||||||
return new InternetPlaylistItem("Internet");
|
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;
|
qLog(Warning) << "Invalid PlaylistItem type:" << type;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -30,6 +30,12 @@ SongPlaylistItem::SongPlaylistItem(const QString& type) : PlaylistItem(type) {}
|
||||||
SongPlaylistItem::SongPlaylistItem(const Song& song)
|
SongPlaylistItem::SongPlaylistItem(const Song& song)
|
||||||
: PlaylistItem(song.is_stream() ? "Stream" : "File"), 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) {
|
bool SongPlaylistItem::InitFromQuery(const SqlRow& query) {
|
||||||
song_.InitFromQuery(query, false, (Song::kColumns.count() + 1) * 3);
|
song_.InitFromQuery(query, false, (Song::kColumns.count() + 1) * 3);
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ class SongPlaylistItem : public PlaylistItem {
|
||||||
SongPlaylistItem(const QString& type);
|
SongPlaylistItem(const QString& type);
|
||||||
SongPlaylistItem(const Song& song);
|
SongPlaylistItem(const Song& song);
|
||||||
|
|
||||||
|
static bool IsTypeSupported(const QString& type);
|
||||||
|
|
||||||
// Restores a stream- or file-related playlist item using query row.
|
// 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
|
// If it's a file related playlist item, this will restore it's CUE
|
||||||
// attributes (if any) but won't parse the CUE!
|
// attributes (if any) but won't parse the CUE!
|
||||||
|
|
Loading…
Reference in New Issue