Clementine-audio-player-Mac.../src/playlist/playlistitem.h

120 lines
3.6 KiB
C
Raw Normal View History

/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
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
#include <QMap>
#include <QMetaType>
2009-12-24 20:16:07 +01:00
#include <QStandardItem>
#include <QUrl>
#include <boost/enable_shared_from_this.hpp>
#include "core/song.h"
class QAction;
class SqlRow;
2009-12-26 23:15:57 +01:00
class PlaylistItem : public boost::enable_shared_from_this<PlaylistItem> {
2009-12-24 20:16:07 +01:00
public:
PlaylistItem(const QString& type)
: type_(type) {}
2012-05-27 17:46:16 +02:00
virtual ~PlaylistItem();
2009-12-24 20:16:07 +01:00
static PlaylistItem* NewFromType(const QString& type);
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,
// Disables the "pause" action.
PauseDisabled = 0x01,
// Enables the last.fm "ban" action.
LastFMControls = 0x02,
2011-11-28 19:19:11 +01:00
// Disables the seek slider.
SeekDisabled = 0x04,
2009-12-29 17:12:08 +01:00
};
Q_DECLARE_FLAGS(Options, Option);
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; }
virtual QList<QAction*> actions() { return QList<QAction*>(); }
virtual bool InitFromQuery(const SqlRow& query) = 0;
void BindToQuery(QSqlQuery* query) const;
2010-01-16 17:12:47 +01:00
virtual void Reload() {}
QFuture<void> BackgroundReload();
2009-12-24 20:16:07 +01:00
2009-12-29 20:22:02 +01:00
virtual Song Metadata() const = 0;
virtual QUrl Url() const = 0;
2009-12-26 23:15:57 +01:00
void SetTemporaryMetadata(const Song& metadata);
void ClearTemporaryMetadata();
bool HasTemporaryMetadata() const { return temp_metadata_.is_valid(); }
// Background colors.
void SetBackgroundColor(short priority, const QColor& color);
bool HasBackgroundColor(short priority) const;
void RemoveBackgroundColor(short priority);
QColor GetCurrentBackgroundColor() const;
bool HasCurrentBackgroundColor() const;
// Foreground colors.
void SetForegroundColor(short priority, const QColor& color);
bool HasForegroundColor(short priority) const;
void RemoveForegroundColor(short priority);
QColor GetCurrentForegroundColor() const;
bool HasCurrentForegroundColor() const;
// 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.
// Remember that even if this returns true, the library item might be
// invalid so you might want to check that its id is not equal to -1
// before actually using it.
virtual bool IsLocalLibraryItem() const { return false; }
protected:
enum DatabaseColumn {
Column_LibraryId,
Column_InternetService,
};
virtual QVariant DatabaseValue(DatabaseColumn) const {
return QVariant(QVariant::String); }
virtual Song DatabaseSongMetadata() const { return Song(); }
QString type_;
Song temp_metadata_;
QMap<short, QColor> background_colors_;
QMap<short, QColor> foreground_colors_;
2009-12-24 20:16:07 +01:00
};
typedef boost::shared_ptr<PlaylistItem> PlaylistItemPtr;
typedef QList<PlaylistItemPtr> PlaylistItemList;
2009-12-24 20:16:07 +01:00
Q_DECLARE_METATYPE(PlaylistItemPtr)
Q_DECLARE_METATYPE(QList<PlaylistItemPtr>)
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::Options)
2009-12-29 17:12:08 +01:00
2009-12-24 20:16:07 +01:00
#endif // PLAYLISTITEM_H