mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 11:35:24 +01:00
Add python bindings for Playlist and PlaylistManager
This commit is contained in:
parent
cfbbd3665c
commit
cdac0c6c86
@ -723,6 +723,7 @@ if(HAVE_SCRIPTING)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/sipclementinePlaylistItemOptions.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/sipclementinePlaylistItemPtr.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/sipclementineQList0100PlaylistItemPtr.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/sipclementineQList0100Song.cpp
|
||||
)
|
||||
endif(HAVE_SCRIPTING_PYTHON)
|
||||
endif(HAVE_SCRIPTING)
|
||||
|
@ -5,7 +5,9 @@
|
||||
|
||||
%Include engine_fwd.sip
|
||||
%Include player.sip
|
||||
%Include playlist.sip
|
||||
%Include playlistitem.sip
|
||||
%Include playlistmanager.sip
|
||||
%Include pythonengine.sip
|
||||
%Include scriptinterface.sip
|
||||
%Include song.sip
|
||||
|
139
src/scripting/python/playlist.sip
Normal file
139
src/scripting/python/playlist.sip
Normal file
@ -0,0 +1,139 @@
|
||||
class Playlist : QAbstractListModel {
|
||||
|
||||
%TypeHeaderCode
|
||||
#include "playlist/playlist.h"
|
||||
%End
|
||||
|
||||
public:
|
||||
enum Column {
|
||||
Column_Title,
|
||||
Column_Artist,
|
||||
Column_Album,
|
||||
Column_AlbumArtist,
|
||||
Column_Composer,
|
||||
Column_Length,
|
||||
Column_Track,
|
||||
Column_Disc,
|
||||
Column_Year,
|
||||
Column_Genre,
|
||||
|
||||
Column_BPM,
|
||||
Column_Bitrate,
|
||||
Column_Samplerate,
|
||||
Column_Filename,
|
||||
Column_BaseFilename,
|
||||
Column_Filesize,
|
||||
Column_Filetype,
|
||||
Column_DateCreated,
|
||||
Column_DateModified,
|
||||
|
||||
Column_Rating,
|
||||
Column_PlayCount,
|
||||
Column_SkipCount,
|
||||
Column_LastPlayed,
|
||||
Column_Score,
|
||||
|
||||
Column_Comment,
|
||||
|
||||
ColumnCount
|
||||
};
|
||||
|
||||
enum Role {
|
||||
Role_IsCurrent,
|
||||
Role_IsPaused,
|
||||
Role_StopAfter,
|
||||
Role_QueuePosition,
|
||||
Role_CanSetRating,
|
||||
};
|
||||
|
||||
static const char* kRowsMimetype;
|
||||
static const char* kPlayNowMimetype;
|
||||
|
||||
static bool CompareItems(int column, Qt::SortOrder order,
|
||||
PlaylistItemPtr a, PlaylistItemPtr b);
|
||||
|
||||
static QString column_name(Column column);
|
||||
static bool column_is_editable(Column column);
|
||||
static bool set_column_value(Song& song, Column column, const QVariant& value);
|
||||
|
||||
// Accessors
|
||||
QSortFilterProxyModel* proxy() const;
|
||||
// Queue* queue() const;
|
||||
|
||||
int id() const;
|
||||
|
||||
int current_row() const;
|
||||
int last_played_row() const;
|
||||
int next_row() const;
|
||||
int previous_row() const;
|
||||
|
||||
const QModelIndex current_index() const;
|
||||
|
||||
bool stop_after_current() const;
|
||||
bool is_dynamic() const;
|
||||
|
||||
const PlaylistItemPtr& item_at(int index) const;
|
||||
const bool has_item_at(int index) const;
|
||||
|
||||
PlaylistItemPtr current_item() const;
|
||||
|
||||
PlaylistItem::Options current_item_options() const;
|
||||
Song current_item_metadata() const;
|
||||
|
||||
PlaylistItemList library_items_by_id(int id) const;
|
||||
|
||||
SongList GetAllSongs() const;
|
||||
quint64 GetTotalLength() const; // in seconds
|
||||
|
||||
// PlaylistSequence* sequence() const { return playlist_sequence_; }
|
||||
|
||||
QUndoStack* undo_stack() const;
|
||||
|
||||
// ColumnAlignmentMap column_alignments() const { return column_alignments_; }
|
||||
// void set_column_alignments(const ColumnAlignmentMap& column_alignments);
|
||||
void set_column_align_left(int column);
|
||||
void set_column_align_center(int column);
|
||||
void set_column_align_right(int column);
|
||||
|
||||
// Scrobbling
|
||||
int scrobble_point() const;
|
||||
bool has_scrobbled() const;
|
||||
void set_scrobbled(bool v);
|
||||
|
||||
// Changing the playlist
|
||||
QModelIndex InsertItems(const PlaylistItemList& items, int pos = -1, bool enqueue = false);
|
||||
QModelIndex InsertLibraryItems(const SongList& items, int pos = -1, bool enqueue = false);
|
||||
QModelIndex InsertSongs(const SongList& items, int pos = -1, bool enqueue = false);
|
||||
QModelIndex InsertSongsOrLibraryItems(const SongList& items, int pos = -1, bool enqueue = 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);
|
||||
void StopAfter(int row);
|
||||
void ReloadItems(const QList<int>& rows);
|
||||
|
||||
// Changes rating of a song to the given value asynchronously
|
||||
void RateSong(const QModelIndex& index, double rating);
|
||||
|
||||
public slots:
|
||||
void set_current_row(int index);
|
||||
|
||||
void Clear();
|
||||
void Shuffle();
|
||||
|
||||
void RepopulateDynamicPlaylist();
|
||||
void TurnOffDynamicPlaylist();
|
||||
|
||||
signals:
|
||||
void CurrentSongChanged(const Song& metadata);
|
||||
void EditingFinished(const QModelIndex& index);
|
||||
void PlayRequested(const QModelIndex& index);
|
||||
|
||||
// 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);
|
||||
|
||||
private:
|
||||
Playlist();
|
||||
};
|
75
src/scripting/python/playlistmanager.sip
Normal file
75
src/scripting/python/playlistmanager.sip
Normal file
@ -0,0 +1,75 @@
|
||||
class PlaylistManager : QObject {
|
||||
|
||||
%TypeHeaderCode
|
||||
#include "playlist/playlistmanager.h"
|
||||
%End
|
||||
|
||||
public:
|
||||
int current_id() const;
|
||||
int active_id() const;
|
||||
|
||||
Playlist* playlist(int id) const;
|
||||
Playlist* current() const;
|
||||
Playlist* active() const;
|
||||
|
||||
const QItemSelection& selection(int id) const;
|
||||
const QItemSelection& current_selection() const;
|
||||
const QItemSelection& active_selection() const;
|
||||
|
||||
QString name(int index) const;
|
||||
|
||||
// LibraryBackend* library_backend() const;
|
||||
// PlaylistBackend* playlist_backend() const;
|
||||
// PlaylistSequence* sequence() const;
|
||||
// PlaylistParser* parser() const;
|
||||
|
||||
public slots:
|
||||
void New(const QString& name, const SongList& songs = SongList());
|
||||
void Load(const QString& filename);
|
||||
void Save(int id, const QString& filename);
|
||||
void Rename(int id, const QString& new_name);
|
||||
void Remove(int id);
|
||||
void ChangePlaylistOrder(const QList<int>& ids);
|
||||
|
||||
void SetCurrentPlaylist(int id);
|
||||
void SetActivePlaylist(int id);
|
||||
void SetActiveToCurrent();
|
||||
|
||||
void SelectionChanged(const QItemSelection& selection);
|
||||
|
||||
// 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);
|
||||
// Rate current song using 0.0 - 1.0 scale.
|
||||
void RateCurrentSong(double rating);
|
||||
|
||||
// void PlaySmartPlaylist(smart_playlists::GeneratorPtr generator, bool as_new, bool clear);
|
||||
|
||||
signals:
|
||||
void PlaylistManagerInitialized();
|
||||
|
||||
void PlaylistAdded(int id, const QString& name);
|
||||
void PlaylistRemoved(int id);
|
||||
void PlaylistRenamed(int id, const QString& new_name);
|
||||
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);
|
||||
|
||||
private:
|
||||
PlaylistManager();
|
||||
};
|
@ -89,6 +89,7 @@ Script* PythonEngine::CreateScript(const QString& path,
|
||||
|
||||
// Add objects to the module
|
||||
AddObject(manager()->data().player_, sipType_Player, "player");
|
||||
AddObject(manager()->data().playlists_, sipType_PlaylistManager, "playlists");
|
||||
AddObject(this, sipType_PythonEngine, "pythonengine");
|
||||
|
||||
// Create a module for scripts
|
||||
|
@ -132,3 +132,4 @@ public:
|
||||
// Comparison functions
|
||||
bool IsMetadataEqual(const Song& other) const;
|
||||
};
|
||||
typedef QList<Song> SongList;
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
class LanguageEngine;
|
||||
class Player;
|
||||
class PlaylistManager;
|
||||
class Script;
|
||||
|
||||
class ScriptManager : public QAbstractListModel {
|
||||
@ -51,10 +52,14 @@ public:
|
||||
};
|
||||
|
||||
struct GlobalData {
|
||||
GlobalData() : player_(NULL) {}
|
||||
GlobalData(Player* player) : player_(player) {}
|
||||
GlobalData() {}
|
||||
GlobalData(Player* player, PlaylistManager* playlists)
|
||||
: player_(player),
|
||||
playlists_(playlists)
|
||||
{}
|
||||
|
||||
Player* player_;
|
||||
PlaylistManager* playlists_;
|
||||
};
|
||||
|
||||
static const char* kSettingsGroup;
|
||||
|
@ -332,7 +332,7 @@ MainWindow::MainWindow(QWidget* parent)
|
||||
connect(ui_->action_queue_manager, SIGNAL(triggered()), SLOT(ShowQueueManager()));
|
||||
|
||||
#ifdef HAVE_SCRIPTING
|
||||
scripts_->Init(ScriptManager::GlobalData(player_));
|
||||
scripts_->Init(ScriptManager::GlobalData(player_, playlists_));
|
||||
connect(ui_->action_script_manager, SIGNAL(triggered()), SLOT(ShowScriptDialog()));
|
||||
#else
|
||||
ui_->action_script_manager->setEnabled(false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user