2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#include "playlistitem.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
|
|
|
|
#include <QSqlQuery>
|
|
|
|
#include <QtConcurrentRun>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
2011-04-22 18:50:29 +02:00
|
|
|
#include "core/logging.h"
|
2011-04-27 00:06:58 +02:00
|
|
|
#include "core/song.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "internet/core/internetplaylistitem.h"
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/jamendo/jamendoplaylistitem.h"
|
|
|
|
#include "internet/jamendo/jamendoservice.h"
|
|
|
|
#include "internet/magnatune/magnatuneplaylistitem.h"
|
|
|
|
#include "internet/magnatune/magnatuneservice.h"
|
2010-11-27 20:23:52 +01:00
|
|
|
#include "library/library.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "library/libraryplaylistitem.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "songplaylistitem.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
PlaylistItem::~PlaylistItem() {}
|
2012-05-27 17:46:16 +02:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
PlaylistItem* PlaylistItem::NewFromType(const QString& type) {
|
2020-06-21 06:21:12 +02:00
|
|
|
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);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2011-04-22 18:50:29 +02:00
|
|
|
qLog(Warning) << "Invalid PlaylistItem type:" << type;
|
2014-02-06 16:49:49 +01:00
|
|
|
return nullptr;
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
2010-04-14 23:03:00 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
PlaylistItem* PlaylistItem::NewFromSongsTable(const QString& table,
|
|
|
|
const Song& song) {
|
|
|
|
if (table == Library::kSongsTable) return new LibraryPlaylistItem(song);
|
2010-11-27 20:23:52 +01:00
|
|
|
if (table == MagnatuneService::kSongsTable)
|
|
|
|
return new MagnatunePlaylistItem(song);
|
|
|
|
if (table == JamendoService::kSongsTable)
|
|
|
|
return new JamendoPlaylistItem(song);
|
|
|
|
|
2011-04-22 18:50:29 +02:00
|
|
|
qLog(Warning) << "Invalid PlaylistItem songs table:" << table;
|
2014-02-06 16:49:49 +01:00
|
|
|
return nullptr;
|
2010-11-27 20:23:52 +01:00
|
|
|
}
|
|
|
|
|
2010-04-14 23:03:00 +02:00
|
|
|
void PlaylistItem::BindToQuery(QSqlQuery* query) const {
|
2011-04-27 00:06:58 +02:00
|
|
|
query->bindValue(":type", type());
|
|
|
|
query->bindValue(":library_id", DatabaseValue(Column_LibraryId));
|
2011-07-15 15:27:50 +02:00
|
|
|
query->bindValue(":radio_service", DatabaseValue(Column_InternetService));
|
2011-04-27 00:06:58 +02:00
|
|
|
|
|
|
|
DatabaseSongMetadata().BindToQuery(query);
|
2010-04-14 23:03:00 +02:00
|
|
|
}
|
|
|
|
|
2010-07-10 21:45:29 +02:00
|
|
|
void PlaylistItem::SetTemporaryMetadata(const Song& metadata) {
|
|
|
|
temp_metadata_ = metadata;
|
|
|
|
temp_metadata_.set_filetype(Song::Type_Stream);
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void PlaylistItem::ClearTemporaryMetadata() { temp_metadata_ = Song(); }
|
2010-07-10 21:45:29 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
static void ReloadPlaylistItem(PlaylistItemPtr item) { item->Reload(); }
|
2010-08-08 14:36:07 +02:00
|
|
|
|
|
|
|
QFuture<void> PlaylistItem::BackgroundReload() {
|
|
|
|
return QtConcurrent::run(ReloadPlaylistItem, shared_from_this());
|
|
|
|
}
|
2011-03-13 12:43:44 +01:00
|
|
|
|
|
|
|
void PlaylistItem::SetBackgroundColor(short priority, const QColor& color) {
|
|
|
|
background_colors_[priority] = color;
|
|
|
|
}
|
2011-03-19 11:22:55 +01:00
|
|
|
bool PlaylistItem::HasBackgroundColor(short priority) const {
|
|
|
|
return background_colors_.contains(priority);
|
|
|
|
}
|
2011-03-13 12:43:44 +01:00
|
|
|
void PlaylistItem::RemoveBackgroundColor(short priority) {
|
|
|
|
background_colors_.remove(priority);
|
|
|
|
}
|
|
|
|
QColor PlaylistItem::GetCurrentBackgroundColor() const {
|
|
|
|
return background_colors_.isEmpty()
|
2014-02-07 16:34:20 +01:00
|
|
|
? QColor()
|
|
|
|
: background_colors_[background_colors_.keys().last()];
|
2011-03-13 12:43:44 +01:00
|
|
|
}
|
|
|
|
bool PlaylistItem::HasCurrentBackgroundColor() const {
|
|
|
|
return !background_colors_.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistItem::SetForegroundColor(short priority, const QColor& color) {
|
|
|
|
foreground_colors_[priority] = color;
|
|
|
|
}
|
2011-03-19 11:22:55 +01:00
|
|
|
bool PlaylistItem::HasForegroundColor(short priority) const {
|
|
|
|
return foreground_colors_.contains(priority);
|
|
|
|
}
|
2011-03-13 12:43:44 +01:00
|
|
|
void PlaylistItem::RemoveForegroundColor(short priority) {
|
|
|
|
foreground_colors_.remove(priority);
|
|
|
|
}
|
|
|
|
QColor PlaylistItem::GetCurrentForegroundColor() const {
|
|
|
|
return foreground_colors_.isEmpty()
|
2014-02-07 16:34:20 +01:00
|
|
|
? QColor()
|
|
|
|
: foreground_colors_[foreground_colors_.keys().last()];
|
2011-03-13 12:43:44 +01:00
|
|
|
}
|
|
|
|
bool PlaylistItem::HasCurrentForegroundColor() const {
|
|
|
|
return !foreground_colors_.isEmpty();
|
|
|
|
}
|
2014-02-10 14:29:07 +01:00
|
|
|
void PlaylistItem::SetShouldSkip(bool val) { should_skip_ = val; }
|
|
|
|
bool PlaylistItem::GetShouldSkip() const { return should_skip_; }
|