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
|
|
|
|
|
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>
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-22 22:28:11 +02:00
|
|
|
#include "core/song.h"
|
2010-11-18 21:19:33 +01:00
|
|
|
#include "smartplaylists/generator_fwd.h"
|
2010-05-22 22:28:11 +02:00
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
class LibraryBackend;
|
|
|
|
class Playlist;
|
|
|
|
class PlaylistBackend;
|
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;
|
|
|
|
|
|
|
|
class PlaylistManager : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2010-06-23 15:21:30 +02:00
|
|
|
PlaylistManager(TaskManager* task_manager, QObject *parent = 0);
|
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
|
|
|
|
2010-09-25 17:30:47 +02:00
|
|
|
const QItemSelection& selection(int id) const { return playlists_[id].selection; }
|
|
|
|
const QItemSelection& current_selection() const { return selection(current_id()); }
|
|
|
|
const QItemSelection& active_selection() const { return selection(active_id()); }
|
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
QString name(int index) const { return playlists_[index].name; }
|
|
|
|
|
|
|
|
void Init(LibraryBackend* library_backend, PlaylistBackend* playlist_backend,
|
|
|
|
PlaylistSequence* sequence);
|
|
|
|
|
2010-06-23 15:21:30 +02:00
|
|
|
TaskManager* task_manager() const { return task_manager_; }
|
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_; }
|
2010-05-20 23:21:55 +02:00
|
|
|
|
|
|
|
public slots:
|
2010-05-22 22:28:11 +02:00
|
|
|
void New(const QString& name, const SongList& songs = SongList());
|
2010-05-20 23:21:55 +02:00
|
|
|
void Load(const QString& filename);
|
2010-05-21 12:29:17 +02:00
|
|
|
void Save(int id, const QString& filename);
|
|
|
|
void Rename(int id, const QString& new_name);
|
|
|
|
void Remove(int id);
|
2010-05-21 12:37:24 +02:00
|
|
|
void ChangePlaylistOrder(const QList<int>& ids);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
void SetCurrentPlaylist(int id);
|
|
|
|
void SetActivePlaylist(int id);
|
|
|
|
void SetActiveToCurrent() { SetActivePlaylist(current_id()); }
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-06-13 14:45:05 +02:00
|
|
|
void SelectionChanged(const QItemSelection& selection);
|
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
// Convenience slots that defer to either current() or active()
|
|
|
|
void ClearCurrent();
|
|
|
|
void ShuffleCurrent();
|
|
|
|
void SetActivePlaying();
|
|
|
|
void SetActivePaused();
|
|
|
|
void SetActiveStopped();
|
|
|
|
void SetActiveStreamMetadata(const QUrl& url, const Song& song);
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
void PlaySmartPlaylist(smart_playlists::GeneratorPtr generator, bool as_new, bool clear);
|
2010-10-24 17:38:12 +02:00
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
signals:
|
2010-05-21 12:29:17 +02:00
|
|
|
void PlaylistAdded(int id, const QString& name);
|
|
|
|
void PlaylistRemoved(int id);
|
|
|
|
void PlaylistRenamed(int id, const QString& new_name);
|
2010-05-20 23:21:55 +02:00
|
|
|
void CurrentChanged(Playlist* new_playlist);
|
|
|
|
void ActiveChanged(Playlist* new_playlist);
|
|
|
|
|
2010-05-23 00:20:00 +02:00
|
|
|
void Error(const QString& message);
|
2010-06-12 23:20:53 +02:00
|
|
|
void SummaryTextChanged(const QString& summary);
|
2010-05-23 00:20:00 +02:00
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
// Forwarded from individual playlists
|
|
|
|
void CurrentSongChanged(const Song& song);
|
|
|
|
void PlaylistChanged();
|
|
|
|
void EditingFinished(const QModelIndex& index);
|
2010-06-15 20:24:08 +02:00
|
|
|
void PlayRequested(const QModelIndex& index);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-06-12 23:20:53 +02:00
|
|
|
private slots:
|
|
|
|
void UpdateSummaryText();
|
2010-06-18 16:26:46 +02:00
|
|
|
void SongsDiscovered(const SongList& songs);
|
2010-08-03 16:59:18 +02:00
|
|
|
void LoadFinished(bool success);
|
2010-06-12 23:20:53 +02:00
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
private:
|
|
|
|
Playlist* AddPlaylist(int id, const QString& name);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Data {
|
2010-05-21 12:29:17 +02:00
|
|
|
Data(Playlist* _p = NULL, const QString& _name = QString()) : 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
|
|
|
};
|
|
|
|
|
2010-06-23 15:21:30 +02:00
|
|
|
TaskManager* task_manager_;
|
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_;
|
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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PLAYLISTMANAGER_H
|