2009-12-24 20:16:07 +01:00
|
|
|
#ifndef PLAYLIST_H
|
|
|
|
#define PLAYLIST_H
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
#include <QList>
|
|
|
|
|
|
|
|
#include "playlistitem.h"
|
|
|
|
#include "song.h"
|
2009-12-30 00:17:54 +01:00
|
|
|
#include "radioitem.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-26 22:35:45 +01:00
|
|
|
class RadioService;
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
class Playlist : public QAbstractListModel {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2010-03-07 21:06:00 +01:00
|
|
|
friend class PlaylistManager ;
|
2009-12-24 20:16:07 +01:00
|
|
|
public:
|
|
|
|
Playlist(QObject* parent = 0);
|
|
|
|
~Playlist();
|
|
|
|
|
|
|
|
enum Column {
|
|
|
|
Column_Title = 0,
|
|
|
|
Column_Artist,
|
|
|
|
Column_Album,
|
2010-03-07 23:46:41 +01:00
|
|
|
Column_AlbumArtist,
|
|
|
|
Column_Composer,
|
2009-12-24 20:16:07 +01:00
|
|
|
Column_Length,
|
|
|
|
Column_Track,
|
2009-12-30 05:05:33 +01:00
|
|
|
Column_Disc,
|
|
|
|
Column_Year,
|
|
|
|
Column_Genre,
|
|
|
|
|
|
|
|
Column_BPM,
|
|
|
|
Column_Bitrate,
|
|
|
|
Column_Samplerate,
|
|
|
|
Column_Filename,
|
|
|
|
Column_Filesize,
|
2010-03-07 23:46:41 +01:00
|
|
|
Column_Filetype,
|
|
|
|
Column_DateCreated,
|
|
|
|
Column_DateModified,
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
ColumnCount
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Role {
|
|
|
|
Role_IsCurrent = Qt::UserRole + 1,
|
|
|
|
Role_IsPaused,
|
|
|
|
Role_StopAfter,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* kRowsMimetype;
|
|
|
|
static const char* kSettingsGroup;
|
|
|
|
|
|
|
|
static bool CompareItems(int column, Qt::SortOrder order,
|
|
|
|
const PlaylistItem* a, const PlaylistItem* b);
|
|
|
|
|
2010-03-07 21:06:00 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// Accessors
|
2009-12-29 20:57:33 +01:00
|
|
|
int current_index() const;
|
|
|
|
int next_index() const;
|
|
|
|
int previous_index() const;
|
2009-12-27 00:43:38 +01:00
|
|
|
bool stop_after_current() const;
|
2009-12-29 20:57:33 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
PlaylistItem* item_at(int index) const { return items_[index]; }
|
2009-12-29 20:57:33 +01:00
|
|
|
PlaylistItem* current_item() const;
|
|
|
|
|
2009-12-29 17:15:21 +01:00
|
|
|
PlaylistItem::Options current_item_options() const;
|
2009-12-29 20:57:33 +01:00
|
|
|
Song current_item_metadata() const;
|
2010-03-06 16:33:57 +01:00
|
|
|
|
2010-03-07 21:06:00 +01:00
|
|
|
const QString & GetTitle() const { return title_ ; }
|
2010-03-06 16:33:57 +01:00
|
|
|
void SetTitle(const QString& title) { title_ = title; }
|
2010-03-07 21:06:00 +01:00
|
|
|
|
|
|
|
void SetPlaylistIndex( int ipos ) { index_ = ipos ; }
|
|
|
|
int GetPlaylistIndex() const { return index_ ; }
|
2009-12-29 20:57:33 +01:00
|
|
|
|
|
|
|
// Scrobbling
|
|
|
|
int scrobble_point() const { return scrobble_point_; }
|
|
|
|
bool has_scrobbled() const { return has_scrobbled_; }
|
|
|
|
void set_scrobbled(bool v) { has_scrobbled_ = v; }
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// Changing the playlist
|
|
|
|
QModelIndex InsertItems(const QList<PlaylistItem*>& items, int after = -1);
|
|
|
|
QModelIndex InsertSongs(const SongList& items, int after = -1);
|
2009-12-30 00:17:54 +01:00
|
|
|
QModelIndex InsertRadioStations(const QList<RadioItem*>& items, int after = -1);
|
2010-02-24 23:26:01 +01:00
|
|
|
QModelIndex InsertStreamUrls(const QList<QUrl>& urls, int after = -1);
|
2009-12-24 23:44:12 +01:00
|
|
|
QModelIndex InsertPaths(QList<QUrl> urls, int after = -1);
|
2009-12-24 20:16:07 +01:00
|
|
|
void StopAfter(int row);
|
2010-01-16 17:12:47 +01:00
|
|
|
void ReloadItems(const QList<int>& rows);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// QAbstractListModel
|
|
|
|
int rowCount(const QModelIndex& = QModelIndex()) const { return items_.count(); }
|
|
|
|
int columnCount(const QModelIndex& = QModelIndex()) const { return ColumnCount; }
|
|
|
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
QStringList mimeTypes() const;
|
|
|
|
Qt::DropActions supportedDropActions() const;
|
|
|
|
QMimeData* mimeData(const QModelIndexList& indexes) const;
|
|
|
|
bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
|
|
|
|
void sort(int column, Qt::SortOrder order);
|
|
|
|
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
|
|
|
|
|
|
|
|
public slots:
|
2009-12-29 20:57:33 +01:00
|
|
|
void set_current_index(int index);
|
2009-12-24 20:16:07 +01:00
|
|
|
void Paused();
|
|
|
|
void Playing();
|
|
|
|
void Stopped();
|
2009-12-26 16:21:36 +01:00
|
|
|
void IgnoreSorting(bool value) { ignore_sorting_ = value; }
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-26 23:15:57 +01:00
|
|
|
void ClearStreamMetadata();
|
|
|
|
void SetStreamMetadata(const QUrl& url, const Song& song);
|
|
|
|
|
2010-01-14 13:27:50 +01:00
|
|
|
void Clear();
|
2010-02-04 00:56:41 +01:00
|
|
|
void Shuffle();
|
2010-01-14 13:27:50 +01:00
|
|
|
|
2010-01-08 15:52:05 +01:00
|
|
|
signals:
|
|
|
|
void CurrentSongChanged(const Song& metadata);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
private:
|
|
|
|
void SetCurrentIsPaused(bool paused);
|
2009-12-29 20:57:33 +01:00
|
|
|
void UpdateScrobblePoint();
|
2010-03-07 21:06:00 +01:00
|
|
|
|
|
|
|
// Persistence
|
|
|
|
void SaveR() const;
|
|
|
|
void RestoreR();
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
QList<PlaylistItem*> items_;
|
|
|
|
|
|
|
|
QPersistentModelIndex current_item_;
|
|
|
|
QPersistentModelIndex stop_after_;
|
|
|
|
bool current_is_paused_;
|
|
|
|
|
2009-12-29 20:57:33 +01:00
|
|
|
int scrobble_point_;
|
|
|
|
bool has_scrobbled_;
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Hack to stop QTreeView::setModel sorting the playlist
|
2009-12-26 16:21:36 +01:00
|
|
|
bool ignore_sorting_;
|
2010-03-06 16:33:57 +01:00
|
|
|
QString title_;
|
2010-03-07 21:06:00 +01:00
|
|
|
int index_ ;
|
2009-12-24 20:16:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PLAYLIST_H
|