1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 11:19:18 +01:00

Create the correct type of playlist item from query generators

This commit is contained in:
David Sansome 2010-11-27 19:23:52 +00:00
parent f11c494c44
commit 858a8650b8
3 changed files with 18 additions and 2 deletions

View File

@ -17,9 +17,12 @@
#include "playlistitem.h"
#include "songplaylistitem.h"
#include "library/library.h"
#include "library/libraryplaylistitem.h"
#include "radio/jamendoplaylistitem.h"
#include "radio/jamendoservice.h"
#include "radio/magnatuneplaylistitem.h"
#include "radio/magnatuneservice.h"
#include "radio/radioplaylistitem.h"
#include <QtConcurrentRun>
@ -47,6 +50,18 @@ PlaylistItem* PlaylistItem::NewFromType(const QString& type) {
return NULL;
}
PlaylistItem* PlaylistItem::NewFromSongsTable(const QString& table, const Song& song) {
if (table == Library::kSongsTable)
return new LibraryPlaylistItem(song);
if (table == MagnatuneService::kSongsTable)
return new MagnatunePlaylistItem(song);
if (table == JamendoService::kSongsTable)
return new JamendoPlaylistItem(song);
qWarning() << "Invalid PlaylistItem songs table:" << table;
return NULL;
}
void PlaylistItem::BindToQuery(QSqlQuery* query) const {
query->bindValue(1, type());
query->bindValue(2, DatabaseValue(Column_LibraryId));

View File

@ -34,6 +34,7 @@ class PlaylistItem : public boost::enable_shared_from_this<PlaylistItem> {
virtual ~PlaylistItem() {}
static PlaylistItem* NewFromType(const QString& type);
static PlaylistItem* NewFromSongsTable(const QString& table, const Song& song);
enum Option {
Default = 0x00,

View File

@ -17,7 +17,6 @@
#include "querygenerator.h"
#include "library/librarybackend.h"
#include "library/libraryplaylistitem.h"
#include <QtDebug>
@ -81,7 +80,8 @@ PlaylistItemList QueryGenerator::GenerateMore(int count) {
SongList songs = backend_->FindSongs(search_copy);
PlaylistItemList items;
foreach (const Song& song, songs) {
items << PlaylistItemPtr(new LibraryPlaylistItem(song));
items << PlaylistItemPtr(PlaylistItem::NewFromSongsTable(
backend_->songs_table(), song));
previous_ids_ << song.id();
if (previous_ids_.count() > kDynamicFuture + kDynamicHistory)