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
|
|
|
#ifndef PLAYLISTITEM_H
|
|
|
|
#define PLAYLISTITEM_H
|
|
|
|
|
2011-03-13 12:43:44 +01:00
|
|
|
#include <QMap>
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <QStandardItem>
|
|
|
|
#include <QUrl>
|
|
|
|
|
2010-08-08 14:36:07 +02:00
|
|
|
#include <boost/enable_shared_from_this.hpp>
|
2010-04-15 00:05:41 +02:00
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
2010-07-10 21:45:29 +02:00
|
|
|
#include "core/song.h"
|
2010-04-14 23:03:00 +02:00
|
|
|
|
2010-08-03 20:57:17 +02:00
|
|
|
class SqlRow;
|
2009-12-26 23:15:57 +01:00
|
|
|
|
2010-08-08 14:36:07 +02:00
|
|
|
class PlaylistItem : public boost::enable_shared_from_this<PlaylistItem> {
|
2009-12-24 20:16:07 +01:00
|
|
|
public:
|
2011-03-13 12:43:44 +01:00
|
|
|
PlaylistItem(const QString& type)
|
2011-03-13 14:02:48 +01:00
|
|
|
: type_(type) {}
|
2009-12-24 20:16:07 +01:00
|
|
|
virtual ~PlaylistItem() {}
|
|
|
|
|
|
|
|
static PlaylistItem* NewFromType(const QString& type);
|
2010-11-27 20:23:52 +01:00
|
|
|
static PlaylistItem* NewFromSongsTable(const QString& table, const Song& song);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-29 17:12:08 +01:00
|
|
|
enum Option {
|
|
|
|
Default = 0x00,
|
|
|
|
|
2010-05-18 22:43:10 +02:00
|
|
|
// The URL returned by Url() isn't the actual URL of the music - the
|
|
|
|
// item needs to do something special before it can get an actual URL.
|
|
|
|
// Causes StartLoading() to get called when the user wants to play.
|
2009-12-29 17:12:08 +01:00
|
|
|
SpecialPlayBehaviour = 0x01,
|
2010-05-18 22:43:10 +02:00
|
|
|
|
|
|
|
// This item might be able to provide another track after one finishes, for
|
|
|
|
// example in a radio stream. Causes LoadNext() to get called when the
|
|
|
|
// next URL is required.
|
2009-12-29 17:12:08 +01:00
|
|
|
ContainsMultipleTracks = 0x02,
|
2010-05-18 22:43:10 +02:00
|
|
|
|
|
|
|
// Disables the "pause" action.
|
2009-12-29 17:12:08 +01:00
|
|
|
PauseDisabled = 0x04,
|
2010-05-18 22:43:10 +02:00
|
|
|
|
|
|
|
// Enables the last.fm "ban" action.
|
2009-12-29 17:12:08 +01:00
|
|
|
LastFMControls = 0x08,
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(Options, Option);
|
|
|
|
|
2010-05-18 22:43:10 +02:00
|
|
|
// Returned by StartLoading() and LoadNext(), indicates what the player
|
|
|
|
// should do when it wants to load a playlist item that is marked
|
|
|
|
// SpecialPlayBehaviour or ContainsMultipleTracks.
|
|
|
|
struct SpecialLoadResult {
|
|
|
|
enum Type {
|
|
|
|
// There wasn't a track available, and the player should move on to the
|
|
|
|
// next playlist item.
|
|
|
|
NoMoreTracks,
|
|
|
|
|
|
|
|
// There might be another track available, something will call the
|
|
|
|
// player's HandleSpecialLoad() slot later with the same original_url.
|
|
|
|
WillLoadAsynchronously,
|
|
|
|
|
|
|
|
// There was a track available. Its url is in media_url.
|
|
|
|
TrackAvailable,
|
|
|
|
};
|
|
|
|
|
|
|
|
SpecialLoadResult(Type type = NoMoreTracks,
|
|
|
|
const QUrl& original_url = QUrl(),
|
|
|
|
const QUrl& media_url = QUrl());
|
|
|
|
|
|
|
|
Type type_;
|
|
|
|
|
|
|
|
// The url that the playlist items has in Url().
|
|
|
|
// Might be something unplayable like lastfm://...
|
|
|
|
QUrl original_url_;
|
|
|
|
|
|
|
|
// The actual url to something that gstreamer can play.
|
|
|
|
QUrl media_url_;
|
|
|
|
};
|
|
|
|
|
2010-04-14 23:03:00 +02:00
|
|
|
virtual QString type() const { return type_; }
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-29 17:12:08 +01:00
|
|
|
virtual Options options() const { return Default; }
|
|
|
|
|
2010-08-03 20:57:17 +02:00
|
|
|
virtual bool InitFromQuery(const SqlRow& query) = 0;
|
2010-04-14 23:03:00 +02:00
|
|
|
void BindToQuery(QSqlQuery* query) const;
|
2010-01-16 17:12:47 +01:00
|
|
|
virtual void Reload() {}
|
2010-08-08 14:36:07 +02:00
|
|
|
QFuture<void> BackgroundReload();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-29 20:22:02 +01:00
|
|
|
virtual Song Metadata() const = 0;
|
2010-03-24 21:58:17 +01:00
|
|
|
virtual QUrl Url() const = 0;
|
2009-12-26 23:15:57 +01:00
|
|
|
|
2010-05-18 22:43:10 +02:00
|
|
|
// Called by the Player if SpecialPlayBehaviour is set - gives the playlist
|
|
|
|
// item a chance to do something clever to get a playable track.
|
|
|
|
virtual SpecialLoadResult StartLoading() { return SpecialLoadResult(); }
|
|
|
|
|
|
|
|
// Called by the player if ContainsMultipleTracks is set - gives the playlist
|
|
|
|
// item a chance to get another track to play.
|
|
|
|
virtual SpecialLoadResult LoadNext() { return SpecialLoadResult(); }
|
2009-12-26 23:59:11 +01:00
|
|
|
|
2010-07-10 21:45:29 +02:00
|
|
|
void SetTemporaryMetadata(const Song& metadata);
|
|
|
|
void ClearTemporaryMetadata();
|
|
|
|
bool HasTemporaryMetadata() const { return temp_metadata_.is_valid(); }
|
2010-04-14 23:03:00 +02:00
|
|
|
|
2011-03-13 12:43:44 +01:00
|
|
|
// Background colors.
|
|
|
|
void SetBackgroundColor(short priority, const QColor& color);
|
2011-03-19 11:22:55 +01:00
|
|
|
bool HasBackgroundColor(short priority) const;
|
2011-03-13 12:43:44 +01:00
|
|
|
void RemoveBackgroundColor(short priority);
|
|
|
|
QColor GetCurrentBackgroundColor() const;
|
|
|
|
bool HasCurrentBackgroundColor() const;
|
|
|
|
|
|
|
|
// Foreground colors.
|
|
|
|
void SetForegroundColor(short priority, const QColor& color);
|
2011-03-19 11:22:55 +01:00
|
|
|
bool HasForegroundColor(short priority) const;
|
2011-03-13 12:43:44 +01:00
|
|
|
void RemoveForegroundColor(short priority);
|
|
|
|
QColor GetCurrentForegroundColor() const;
|
|
|
|
bool HasCurrentForegroundColor() const;
|
2010-11-20 19:49:54 +01:00
|
|
|
|
2010-10-17 23:56:19 +02:00
|
|
|
// Convenience function to find out whether this item is from the local
|
|
|
|
// library, as opposed to a device, a file on disk, or a stream.
|
2011-03-20 17:07:24 +01:00
|
|
|
// Remember that even if this returns true, the library item might be
|
|
|
|
// invalid so you might want to check that it's id is not equal to -1
|
|
|
|
// before actually using it.
|
2010-10-17 23:56:19 +02:00
|
|
|
virtual bool IsLocalLibraryItem() const { return false; }
|
|
|
|
|
2010-04-14 23:03:00 +02:00
|
|
|
protected:
|
|
|
|
enum DatabaseColumn {
|
|
|
|
Column_LibraryId,
|
|
|
|
Column_Url,
|
|
|
|
Column_Title,
|
|
|
|
Column_Artist,
|
|
|
|
Column_Album,
|
|
|
|
Column_Length,
|
|
|
|
Column_RadioService,
|
2011-01-19 16:36:40 +01:00
|
|
|
Column_Beginning,
|
|
|
|
Column_CuePath,
|
2010-04-14 23:03:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual QVariant DatabaseValue(DatabaseColumn) const {
|
|
|
|
return QVariant(QVariant::String); }
|
|
|
|
|
|
|
|
QString type_;
|
2010-07-10 21:45:29 +02:00
|
|
|
|
|
|
|
Song temp_metadata_;
|
2011-03-13 12:43:44 +01:00
|
|
|
|
|
|
|
QMap<short, QColor> background_colors_;
|
|
|
|
QMap<short, QColor> foreground_colors_;
|
2009-12-24 20:16:07 +01:00
|
|
|
};
|
2010-10-16 17:22:14 +02:00
|
|
|
typedef boost::shared_ptr<PlaylistItem> PlaylistItemPtr;
|
|
|
|
typedef QList<PlaylistItemPtr> PlaylistItemList;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-29 17:12:08 +01:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::Options);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#endif // PLAYLISTITEM_H
|