2010-05-20 23:21:55 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-05-20 23:21:55 +02: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLAYLISTMANAGER_H
|
|
|
|
#define PLAYLISTMANAGER_H
|
|
|
|
|
2011-03-13 12:43:44 +01:00
|
|
|
#include <QColor>
|
2010-06-13 14:45:05 +02:00
|
|
|
#include <QItemSelection>
|
2010-05-21 12:29:17 +02:00
|
|
|
#include <QMap>
|
2010-06-13 14:45:05 +02:00
|
|
|
#include <QObject>
|
2013-05-23 20:09:35 +02:00
|
|
|
#include <QSettings>
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-22 22:28:11 +02:00
|
|
|
#include "core/song.h"
|
2013-07-18 00:37:31 +02:00
|
|
|
#include "playlist.h"
|
2010-11-18 21:19:33 +01:00
|
|
|
#include "smartplaylists/generator_fwd.h"
|
2010-05-22 22:28:11 +02:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
class Application;
|
2010-05-20 23:21:55 +02:00
|
|
|
class LibraryBackend;
|
|
|
|
class PlaylistBackend;
|
2011-04-28 22:48:53 +02:00
|
|
|
class PlaylistContainer;
|
2010-05-23 00:20:00 +02:00
|
|
|
class PlaylistParser;
|
2010-05-20 23:21:55 +02:00
|
|
|
class PlaylistSequence;
|
2010-06-23 15:21:30 +02:00
|
|
|
class TaskManager;
|
2010-05-20 23:21:55 +02:00
|
|
|
|
|
|
|
class QModelIndex;
|
|
|
|
class QUrl;
|
|
|
|
|
2011-02-13 19:37:45 +01:00
|
|
|
class PlaylistManagerInterface : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2012-02-12 14:41:50 +01:00
|
|
|
PlaylistManagerInterface(Application* app, QObject* parent)
|
2014-02-07 16:34:20 +01:00
|
|
|
: QObject(parent) {}
|
2011-02-13 19:37:45 +01:00
|
|
|
|
|
|
|
virtual int current_id() const = 0;
|
|
|
|
virtual int active_id() const = 0;
|
|
|
|
|
|
|
|
virtual Playlist* playlist(int id) const = 0;
|
|
|
|
virtual Playlist* current() const = 0;
|
|
|
|
virtual Playlist* active() const = 0;
|
|
|
|
|
|
|
|
// Returns the collection of playlists managed by this PlaylistManager.
|
|
|
|
virtual QList<Playlist*> GetAllPlaylists() const = 0;
|
2011-03-19 10:41:00 +01:00
|
|
|
// Grays out and reloads all deleted songs in all playlists.
|
|
|
|
virtual void InvalidateDeletedSongs() = 0;
|
2011-04-21 23:56:37 +02:00
|
|
|
// Removes all deleted songs from all playlists.
|
|
|
|
virtual void RemoveDeletedSongs() = 0;
|
2011-02-13 19:37:45 +01:00
|
|
|
|
2011-05-29 14:55:18 +02:00
|
|
|
virtual QItemSelection selection(int id) const = 0;
|
|
|
|
virtual QItemSelection current_selection() const = 0;
|
|
|
|
virtual QItemSelection active_selection() const = 0;
|
2011-02-13 19:37:45 +01:00
|
|
|
|
2011-07-13 20:14:14 +02:00
|
|
|
virtual QString GetPlaylistName(int index) const = 0;
|
2011-02-13 19:37:45 +01:00
|
|
|
|
|
|
|
virtual LibraryBackend* library_backend() const = 0;
|
|
|
|
virtual PlaylistBackend* playlist_backend() const = 0;
|
|
|
|
virtual PlaylistSequence* sequence() const = 0;
|
|
|
|
virtual PlaylistParser* parser() const = 0;
|
2011-04-28 22:48:53 +02:00
|
|
|
virtual PlaylistContainer* playlist_container() const = 0;
|
2011-02-13 19:37:45 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public slots:
|
2020-11-27 13:05:53 +01:00
|
|
|
virtual int New(const QString& name, const SongList& songs = SongList(),
|
|
|
|
const QString& special_type = QString()) = 0;
|
2011-02-13 19:37:45 +01:00
|
|
|
virtual void Load(const QString& filename) = 0;
|
2014-10-15 21:57:57 +02:00
|
|
|
virtual void Save(int id, const QString& filename,
|
|
|
|
Playlist::Path path_type) = 0;
|
2011-02-13 19:37:45 +01:00
|
|
|
virtual void Rename(int id, const QString& new_name) = 0;
|
2012-10-31 07:04:22 +01:00
|
|
|
virtual void Delete(int id) = 0;
|
|
|
|
virtual bool Close(int id) = 0;
|
|
|
|
virtual void Open(int id) = 0;
|
2011-02-13 19:37:45 +01:00
|
|
|
virtual void ChangePlaylistOrder(const QList<int>& ids) = 0;
|
|
|
|
|
2018-06-13 22:03:23 +02:00
|
|
|
virtual void Enque(int id, int index) = 0;
|
|
|
|
|
2011-03-10 19:01:35 +01:00
|
|
|
virtual void SongChangeRequestProcessed(const QUrl& url, bool valid) = 0;
|
|
|
|
|
2011-02-13 19:37:45 +01:00
|
|
|
virtual void SetCurrentPlaylist(int id) = 0;
|
|
|
|
virtual void SetActivePlaylist(int id) = 0;
|
|
|
|
virtual void SetActiveToCurrent() = 0;
|
|
|
|
|
|
|
|
virtual void SelectionChanged(const QItemSelection& selection) = 0;
|
|
|
|
|
|
|
|
// Convenience slots that defer to either current() or active()
|
|
|
|
virtual void ClearCurrent() = 0;
|
|
|
|
virtual void ShuffleCurrent() = 0;
|
2012-07-06 00:00:33 +02:00
|
|
|
virtual void RemoveDuplicatesCurrent() = 0;
|
2014-08-24 10:44:27 +02:00
|
|
|
virtual void RemoveUnavailableCurrent() = 0;
|
2011-02-13 19:37:45 +01:00
|
|
|
virtual void SetActivePlaying() = 0;
|
|
|
|
virtual void SetActivePaused() = 0;
|
|
|
|
virtual void SetActiveStopped() = 0;
|
|
|
|
virtual void SetActiveStreamMetadata(const QUrl& url, const Song& song) = 0;
|
|
|
|
// Rate current song using 0.0 - 1.0 scale.
|
|
|
|
virtual void RateCurrentSong(double rating) = 0;
|
|
|
|
// Rate current song using 0 - 5 scale.
|
|
|
|
virtual void RateCurrentSong(int rating) = 0;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
virtual void PlaySmartPlaylist(smart_playlists::GeneratorPtr generator,
|
|
|
|
bool as_new, bool clear) = 0;
|
2011-02-13 19:37:45 +01:00
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
signals:
|
2011-02-13 19:37:45 +01:00
|
|
|
void PlaylistManagerInitialized();
|
|
|
|
|
2013-05-11 23:17:54 +02:00
|
|
|
void PlaylistAdded(int id, const QString& name, bool favorite);
|
2012-10-31 07:04:22 +01:00
|
|
|
void PlaylistDeleted(int id);
|
|
|
|
void PlaylistClosed(int id);
|
2011-02-13 19:37:45 +01:00
|
|
|
void PlaylistRenamed(int id, const QString& new_name);
|
2013-05-11 23:17:54 +02:00
|
|
|
void PlaylistFavorited(int id, bool favorite);
|
2011-02-13 19:37:45 +01:00
|
|
|
void CurrentChanged(Playlist* new_playlist);
|
|
|
|
void ActiveChanged(Playlist* new_playlist);
|
|
|
|
|
|
|
|
void Error(const QString& message);
|
|
|
|
void SummaryTextChanged(const QString& summary);
|
|
|
|
|
|
|
|
// Forwarded from individual playlists
|
|
|
|
void CurrentSongChanged(const Song& song);
|
|
|
|
|
|
|
|
// Signals that one of manager's playlists has changed (new items, new
|
|
|
|
// ordering etc.) - the argument shows which.
|
|
|
|
void PlaylistChanged(Playlist* playlist);
|
|
|
|
void EditingFinished(const QModelIndex& index);
|
|
|
|
void PlayRequested(const QModelIndex& index);
|
|
|
|
};
|
|
|
|
|
|
|
|
class PlaylistManager : public PlaylistManagerInterface {
|
2010-05-20 23:21:55 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
PlaylistManager(Application* app, QObject* parent = nullptr);
|
2010-05-21 12:29:17 +02:00
|
|
|
~PlaylistManager();
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
int current_id() const { return current_; }
|
|
|
|
int active_id() const { return active_; }
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
Playlist* playlist(int id) const { return playlists_[id].p; }
|
|
|
|
Playlist* current() const { return playlist(current_id()); }
|
|
|
|
Playlist* active() const { return playlist(active_id()); }
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2011-01-17 00:46:58 +01:00
|
|
|
// Returns the collection of playlists managed by this PlaylistManager.
|
2011-02-13 19:37:45 +01:00
|
|
|
QList<Playlist*> GetAllPlaylists() const;
|
2011-03-19 10:41:00 +01:00
|
|
|
// Grays out and reloads all deleted songs in all playlists.
|
|
|
|
void InvalidateDeletedSongs();
|
2011-04-21 23:56:37 +02:00
|
|
|
// Removes all deleted songs from all playlists.
|
|
|
|
void RemoveDeletedSongs();
|
2013-04-16 13:57:04 +02:00
|
|
|
// Returns true if the playlist is open
|
|
|
|
bool IsPlaylistOpen(int id);
|
2011-01-17 00:46:58 +01:00
|
|
|
|
2011-03-25 20:16:12 +01:00
|
|
|
// Returns a pretty automatic name for playlist created from the given list of
|
|
|
|
// songs.
|
|
|
|
static QString GetNameForNewPlaylist(const SongList& songs);
|
|
|
|
|
2011-05-29 14:55:18 +02:00
|
|
|
QItemSelection selection(int id) const;
|
|
|
|
QItemSelection current_selection() const { return selection(current_id()); }
|
|
|
|
QItemSelection active_selection() const { return selection(active_id()); }
|
2010-09-25 17:30:47 +02:00
|
|
|
|
2011-07-13 20:14:14 +02:00
|
|
|
QString GetPlaylistName(int index) const { return playlists_[index].name; }
|
2014-02-07 16:34:20 +01:00
|
|
|
bool IsPlaylistFavorite(int index) const {
|
|
|
|
return playlists_[index].p->is_favorite();
|
|
|
|
}
|
2010-05-20 23:21:55 +02:00
|
|
|
|
|
|
|
void Init(LibraryBackend* library_backend, PlaylistBackend* playlist_backend,
|
2011-04-28 22:48:53 +02:00
|
|
|
PlaylistSequence* sequence, PlaylistContainer* playlist_container);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
|
|
|
LibraryBackend* library_backend() const { return library_backend_; }
|
|
|
|
PlaylistBackend* playlist_backend() const { return playlist_backend_; }
|
|
|
|
PlaylistSequence* sequence() const { return sequence_; }
|
2010-05-23 00:20:00 +02:00
|
|
|
PlaylistParser* parser() const { return parser_; }
|
2011-04-28 22:48:53 +02:00
|
|
|
PlaylistContainer* playlist_container() const { return playlist_container_; }
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public slots:
|
2020-11-27 13:05:53 +01:00
|
|
|
int New(const QString& name, const SongList& songs = SongList(),
|
|
|
|
const QString& special_type = QString());
|
2010-05-20 23:21:55 +02:00
|
|
|
void Load(const QString& filename);
|
2014-10-07 00:23:28 +02:00
|
|
|
void Save(int id, const QString& filename, Playlist::Path path_type);
|
2013-05-23 20:09:35 +02:00
|
|
|
// Display a file dialog to let user choose a file before saving the file
|
2017-03-15 18:21:56 +01:00
|
|
|
void SaveWithUI(int id, const QString& playlist_name);
|
2010-05-21 12:29:17 +02:00
|
|
|
void Rename(int id, const QString& new_name);
|
2013-05-11 23:17:54 +02:00
|
|
|
void Favorite(int id, bool favorite);
|
2012-10-31 07:04:22 +01:00
|
|
|
void Delete(int id);
|
2020-11-27 13:05:53 +01:00
|
|
|
void Clear(int id);
|
2012-10-31 07:04:22 +01:00
|
|
|
bool Close(int id);
|
|
|
|
void Open(int id);
|
2010-05-21 12:37:24 +02:00
|
|
|
void ChangePlaylistOrder(const QList<int>& ids);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2018-06-13 22:03:23 +02:00
|
|
|
void Enque(int id, int index);
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
void SetCurrentPlaylist(int id);
|
|
|
|
void SetActivePlaylist(int id);
|
2013-03-20 15:33:53 +01:00
|
|
|
void SetActiveToCurrent();
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-06-13 14:45:05 +02:00
|
|
|
void SelectionChanged(const QItemSelection& selection);
|
|
|
|
|
2012-10-31 07:04:22 +01:00
|
|
|
// Makes a playlist current if it's open already, or opens it and makes it
|
|
|
|
// current if it is hidden.
|
|
|
|
void SetCurrentOrOpen(int id);
|
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
// Convenience slots that defer to either current() or active()
|
|
|
|
void ClearCurrent();
|
|
|
|
void ShuffleCurrent();
|
2012-07-06 00:00:33 +02:00
|
|
|
void RemoveDuplicatesCurrent();
|
2014-08-24 10:44:27 +02:00
|
|
|
void RemoveUnavailableCurrent();
|
2010-05-20 23:21:55 +02:00
|
|
|
void SetActiveStreamMetadata(const QUrl& url, const Song& song);
|
2010-12-17 01:21:20 +01:00
|
|
|
// Rate current song using 0.0 - 1.0 scale.
|
|
|
|
void RateCurrentSong(double rating);
|
|
|
|
// Rate current song using 0 - 5 scale.
|
|
|
|
void RateCurrentSong(int rating);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void PlaySmartPlaylist(smart_playlists::GeneratorPtr generator, bool as_new,
|
|
|
|
bool clear);
|
2010-10-24 17:38:12 +02:00
|
|
|
|
2011-03-10 19:01:35 +01:00
|
|
|
void SongChangeRequestProcessed(const QUrl& url, bool valid);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void InsertUrls(int id, const QList<QUrl>& urls, int pos = -1,
|
|
|
|
bool play_now = false, bool enqueue = false);
|
2015-06-13 16:00:15 +02:00
|
|
|
void InsertSongs(int id, const SongList& songs, int pos = -1,
|
2015-11-27 15:22:59 +01:00
|
|
|
bool play_now = false, bool enqueue = false);
|
2014-02-07 16:34:20 +01:00
|
|
|
// Removes items with given indices from the playlist. This operation is not
|
|
|
|
// undoable.
|
2013-07-31 19:06:29 +02:00
|
|
|
void RemoveItemsWithoutUndo(int id, const QList<int>& indices);
|
2017-05-31 18:59:36 +02:00
|
|
|
// Remove the current playing song
|
|
|
|
void RemoveCurrentSong();
|
2013-07-31 19:06:29 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2012-02-12 14:41:50 +01:00
|
|
|
void SetActivePlaying();
|
|
|
|
void SetActivePaused();
|
|
|
|
void SetActiveStopped();
|
|
|
|
|
2010-12-08 01:09:17 +01:00
|
|
|
void OneOfPlaylistsChanged();
|
2010-06-12 23:20:53 +02:00
|
|
|
void UpdateSummaryText();
|
2010-06-18 16:26:46 +02:00
|
|
|
void SongsDiscovered(const SongList& songs);
|
2015-11-27 15:22:59 +01:00
|
|
|
void ItemsLoadedForSavePlaylist(QFuture<SongList> future,
|
2014-10-07 00:23:28 +02:00
|
|
|
const QString& filename,
|
|
|
|
Playlist::Path path_type);
|
2010-06-12 23:20:53 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
|
|
|
Playlist* AddPlaylist(int id, const QString& name,
|
|
|
|
const QString& special_type, const QString& ui_path,
|
|
|
|
bool favorite);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2010-05-20 23:21:55 +02:00
|
|
|
struct Data {
|
2014-02-21 17:24:49 +01:00
|
|
|
Data(Playlist* _p = nullptr, const QString& _name = QString())
|
2014-02-07 16:34:20 +01:00
|
|
|
: p(_p), name(_name) {}
|
2010-05-20 23:21:55 +02:00
|
|
|
Playlist* p;
|
|
|
|
QString name;
|
2010-09-25 17:30:47 +02:00
|
|
|
QItemSelection selection;
|
2010-05-20 23:21:55 +02:00
|
|
|
};
|
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app_;
|
2010-05-20 23:21:55 +02:00
|
|
|
PlaylistBackend* playlist_backend_;
|
|
|
|
LibraryBackend* library_backend_;
|
|
|
|
PlaylistSequence* sequence_;
|
2010-05-23 00:20:00 +02:00
|
|
|
PlaylistParser* parser_;
|
2011-04-28 22:48:53 +02:00
|
|
|
PlaylistContainer* playlist_container_;
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
// key = id
|
|
|
|
QMap<int, Data> playlists_;
|
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
int current_;
|
|
|
|
int active_;
|
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // PLAYLISTMANAGER_H
|