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

281 lines
8.4 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 PLAYLIST_H
#define PLAYLIST_H
#include <QAbstractItemModel>
#include <QList>
#include <boost/shared_ptr.hpp>
2009-12-24 20:16:07 +01:00
#include "playlistitem.h"
#include "playlistsequence.h"
#include "core/song.h"
#include "radio/radioitem.h"
#include "smartplaylists/generator_fwd.h"
2009-12-24 20:16:07 +01:00
class LibraryBackend;
class PlaylistBackend;
2010-05-22 18:36:13 +02:00
class PlaylistFilter;
2010-07-11 17:37:40 +02:00
class Queue;
class RadioService;
class TaskManager;
2009-12-26 22:35:45 +01:00
2010-05-22 18:36:13 +02:00
class QSortFilterProxyModel;
class QUndoStack;
namespace PlaylistUndoCommands {
class InsertItems;
class RemoveItems;
class MoveItems;
}
2009-12-24 20:16:07 +01:00
class Playlist : public QAbstractListModel {
Q_OBJECT
friend class PlaylistUndoCommands::InsertItems;
friend class PlaylistUndoCommands::RemoveItems;
friend class PlaylistUndoCommands::MoveItems;
2009-12-24 20:16:07 +01:00
public:
Playlist(PlaylistBackend* backend,
TaskManager* task_manager,
LibraryBackend* library,
int id,
QObject* parent = 0);
2009-12-24 20:16:07 +01:00
~Playlist();
// Always add new columns to the end of this enum - the values are persisted
2009-12-24 20:16:07 +01:00
enum Column {
Column_Title = 0,
Column_Artist,
Column_Album,
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_BaseFilename,
2009-12-30 05:05:33 +01:00
Column_Filesize,
Column_Filetype,
Column_DateCreated,
Column_DateModified,
2009-12-24 20:16:07 +01:00
Column_Rating,
Column_PlayCount,
Column_SkipCount,
Column_LastPlayed,
Column_Score,
Column_Comment,
2009-12-24 20:16:07 +01:00
ColumnCount
};
enum Role {
Role_IsCurrent = Qt::UserRole + 1,
Role_IsPaused,
Role_StopAfter,
Role_QueuePosition,
Role_CanSetRating,
2009-12-24 20:16:07 +01:00
};
static const char* kRowsMimetype;
static const char* kPlayNowMimetype;
2009-12-24 20:16:07 +01:00
static bool CompareItems(int column, Qt::SortOrder order,
PlaylistItemPtr a, PlaylistItemPtr b);
2009-12-24 20:16:07 +01:00
static QString column_name(Column column);
static bool column_is_editable(Playlist::Column column);
static bool set_column_value(Song& song, Column column, const QVariant& value);
// Persistence
void Save() const;
void Restore();
2009-12-24 20:16:07 +01:00
// Accessors
2010-05-22 18:36:13 +02:00
QSortFilterProxyModel* proxy() const;
2010-07-11 17:37:40 +02:00
Queue* queue() const { return queue_; }
2010-05-22 18:36:13 +02:00
int id() const { return id_; }
2009-12-29 20:57:33 +01:00
int current_index() const;
int last_played_index() const;
2009-12-29 20:57:33 +01:00
int next_index() const;
int previous_index() const;
bool stop_after_current() const;
bool is_dynamic() const { return dynamic_playlist_; }
2009-12-29 20:57:33 +01:00
const PlaylistItemPtr& item_at(int index) const { return items_[index]; }
PlaylistItemPtr current_item() const { return current_item_; }
2009-12-29 20:57:33 +01:00
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;
PlaylistItemList library_items_by_id(int id) const;
2010-05-23 00:20:00 +02:00
SongList GetAllSongs() const;
quint64 GetTotalLength() const; // in seconds
2010-05-23 00:20:00 +02:00
void set_sequence(PlaylistSequence* v);
PlaylistSequence* sequence() const { return playlist_sequence_; }
2009-12-29 20:57:33 +01:00
QUndoStack* undo_stack() const { return undo_stack_; }
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 PlaylistItemList& items, int pos = -1);
QModelIndex InsertLibraryItems(const SongList& items, int pos = -1);
QModelIndex InsertSongs(const SongList& items, int pos = -1);
QModelIndex InsertSongsOrLibraryItems(const SongList& items, int pos = -1);
QModelIndex InsertRadioStations(const QList<RadioItem*>& items, int pos = -1, bool play_now = false);
void InsertSmartPlaylist(smart_playlists::GeneratorPtr generator, int pos = -1, bool play_now = false);
void InsertUrls(const QList<QUrl>& urls, bool play_now, int pos = -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;
bool setData(const QModelIndex &index, const QVariant &value, int role);
2009-12-24 20:16:07 +01:00
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();
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);
void ItemChanged(PlaylistItemPtr item);
2009-12-26 23:15:57 +01:00
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
void ShuffleModeChanged(PlaylistSequence::ShuffleMode mode);
void RepopulateDynamicPlaylist();
void TurnOffDynamicPlaylist();
2010-01-08 15:52:05 +01:00
signals:
void CurrentSongChanged(const Song& metadata);
void EditingFinished(const QModelIndex& index);
void PlayRequested(const QModelIndex& index);
2010-01-08 15:52:05 +01:00
// Signals that the underlying list of items was changed, meaning that
// something was added to it, removed from it or the ordering changed.
void PlaylistChanged();
void DynamicModeChanged(bool dynamic);
void LoadTracksError(const QString& message);
2009-12-24 20:16:07 +01:00
private:
void SetCurrentIsPaused(bool paused);
2009-12-29 20:57:33 +01:00
void UpdateScrobblePoint();
void ReshuffleIndices();
int NextVirtualIndex(int i) const;
int PreviousVirtualIndex(int i) const;
2010-05-22 18:36:13 +02:00
bool FilterContainsVirtualIndex(int i) const;
void TurnOnDynamicPlaylist(smart_playlists::GeneratorPtr gen);
// Modify the playlist without changing the undo stack. These are used by
// our friends in PlaylistUndoCommands
QModelIndex InsertItemsWithoutUndo(const PlaylistItemList& items, int pos);
PlaylistItemList RemoveItemsWithoutUndo(int pos, int count);
void MoveItemsWithoutUndo(const QList<int>& source_rows, int pos);
void MoveItemsWithoutUndo(int start, const QList<int>& dest_rows);
void RemoveItemsNotInQueue();
private slots:
void TracksAboutToBeDequeued(const QModelIndex&, int begin, int end);
void TracksDequeued();
void TracksEnqueued(const QModelIndex&, int begin, int end);
2010-07-11 19:39:11 +02:00
void QueueLayoutChanged();
void SongSaveComplete();
void ItemReloadComplete();
void ItemsLoaded();
2009-12-24 20:16:07 +01:00
private:
bool is_loading_;
2010-05-22 18:36:13 +02:00
PlaylistFilter* proxy_;
2010-07-11 17:37:40 +02:00
Queue* queue_;
2010-05-22 18:36:13 +02:00
QList<QModelIndex> temp_dequeue_change_indexes_;
PlaylistBackend* backend_;
TaskManager* task_manager_;
LibraryBackend* library_;
int id_;
PlaylistItemList items_;
QList<int> virtual_items_; // Contains the indices into items_ in the order
// that they will be played.
// A map of library ID to playlist item - for fast lookups when library
// items change.
QMultiMap<int, PlaylistItemPtr> library_items_by_id_;
2009-12-24 20:16:07 +01:00
QPersistentModelIndex current_item_index_;
QPersistentModelIndex last_played_item_index_;
2009-12-24 20:16:07 +01:00
QPersistentModelIndex stop_after_;
bool current_is_paused_;
int current_virtual_index_;
2009-12-24 20:16:07 +01:00
PlaylistItemPtr current_item_;
bool is_shuffled_;
2009-12-29 20:57:33 +01:00
int scrobble_point_;
bool has_scrobbled_;
PlaylistSequence* playlist_sequence_;
2009-12-24 20:16:07 +01:00
// Hack to stop QTreeView::setModel sorting the playlist
bool ignore_sorting_;
QUndoStack* undo_stack_;
smart_playlists::GeneratorPtr dynamic_playlist_;
2009-12-24 20:16:07 +01:00
};
QDataStream& operator <<(QDataStream&, const Playlist*);
QDataStream& operator >>(QDataStream&, Playlist*&);
2009-12-24 20:16:07 +01:00
#endif // PLAYLIST_H