1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#include "playlistitem.h"
19
#include "songplaylistitem.h"
20
#include "library/library.h"
21
#include "library/libraryplaylistitem.h"
22
#include "radio/jamendoplaylistitem.h"
23
#include "radio/jamendoservice.h"
24
#include "radio/magnatuneplaylistitem.h"
25
#include "radio/magnatuneservice.h"
26
#include "radio/radioplaylistitem.h"
28
#include <QtConcurrentRun>
31
PlaylistItem::SpecialLoadResult::SpecialLoadResult(
32
Type type, const QUrl& original_url, const QUrl& media_url)
33
: type_(type), original_url_(original_url), media_url_(media_url)
37
PlaylistItem* PlaylistItem::NewFromType(const QString& type) {
38
if (type == "Library")
39
return new LibraryPlaylistItem(type);
40
if (type == "Magnatune")
41
return new MagnatunePlaylistItem(type);
42
if (type == "Jamendo")
43
return new JamendoPlaylistItem(type);
44
if (type == "Stream" || type == "File")
45
return new SongPlaylistItem(type);
47
return new RadioPlaylistItem(type);
49
qWarning() << "Invalid PlaylistItem type:" << type;
53
PlaylistItem* PlaylistItem::NewFromSongsTable(const QString& table, const Song& song) {
54
if (table == Library::kSongsTable)
55
return new LibraryPlaylistItem(song);
56
if (table == MagnatuneService::kSongsTable)
57
return new MagnatunePlaylistItem(song);
58
if (table == JamendoService::kSongsTable)
59
return new JamendoPlaylistItem(song);
61
qWarning() << "Invalid PlaylistItem songs table:" << table;
65
void PlaylistItem::BindToQuery(QSqlQuery* query) const {
66
query->bindValue(1, type());
67
query->bindValue(2, DatabaseValue(Column_LibraryId));
68
query->bindValue(3, DatabaseValue(Column_Url));
69
query->bindValue(4, DatabaseValue(Column_Title));
70
query->bindValue(5, DatabaseValue(Column_Artist));
71
query->bindValue(6, DatabaseValue(Column_Album));
72
query->bindValue(7, DatabaseValue(Column_Length));
73
query->bindValue(8, DatabaseValue(Column_RadioService));
76
void PlaylistItem::SetTemporaryMetadata(const Song& metadata) {
77
temp_metadata_ = metadata;
78
temp_metadata_.set_filetype(Song::Type_Stream);
81
void PlaylistItem::ClearTemporaryMetadata() {
82
temp_metadata_ = Song();
85
static void ReloadPlaylistItem(PlaylistItemPtr item) {
89
QFuture<void> PlaylistItem::BackgroundReload() {
90
return QtConcurrent::run(ReloadPlaylistItem, shared_from_this());