diff --git a/src/DirectMpvPlayerBackend.cpp b/src/DirectMpvPlayerBackend.cpp index 0102614..20367fe 100644 --- a/src/DirectMpvPlayerBackend.cpp +++ b/src/DirectMpvPlayerBackend.cpp @@ -109,6 +109,7 @@ DirectMpvPlayerBackend::DirectMpvPlayerBackend(QQuickItem* parent) mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "demuxer-cache-duration", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_NONE); + mpv_observe_property(mpv, 0, "playlist", MPV_FORMAT_NONE); mpv_set_wakeup_callback(mpv, wakeup, this); if (mpv_initialize(mpv) < 0) @@ -425,6 +426,20 @@ DirectMpvPlayerBackend::playerCommand(const Enums::Commands& cmd, break; } + case Enums::Commands::GetPlaylist: { + + return getProperty("playlist"); + + break; + } + + case Enums::Commands::SetPlaylistPos: { + + command(QVariantList() << "set" << "playlist-pos" << args); + + break; + } + default: { qDebug() << "Command not found: " << cmd; break; @@ -553,6 +568,8 @@ DirectMpvPlayerBackend::handle_mpv_event(mpv_event* event) emit tracksChanged(); } else if (strcmp(prop->name, "audio-device-list") == 0) { emit audioDevicesChanged(); + } else if (strcmp(prop->name, "playlist") == 0) { + emit playlistChanged(); } #ifdef DISCORD updateDiscord(); diff --git a/src/DirectMpvPlayerBackend.h b/src/DirectMpvPlayerBackend.h index d351b44..ff5a0ca 100644 --- a/src/DirectMpvPlayerBackend.h +++ b/src/DirectMpvPlayerBackend.h @@ -82,6 +82,7 @@ signals: void durationStringChanged(const QString& string); void tracksChanged(); void audioDevicesChanged(); + void playlistChanged(); private slots: void doUpdate(); diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index 1093cd9..a2ad726 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -148,6 +148,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent) mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "demuxer-cache-duration", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_NONE); + mpv_observe_property(mpv, 0, "playlist", MPV_FORMAT_NONE); mpv_set_wakeup_callback(mpv, wakeup, this); if (mpv_initialize(mpv) < 0) @@ -415,6 +416,20 @@ MpvPlayerBackend::playerCommand(const Enums::Commands& cmd, break; } + case Enums::Commands::GetPlaylist: { + + return getProperty("playlist"); + + break; + } + + case Enums::Commands::SetPlaylistPos: { + + command(QVariantList() << "set" << "playlist-pos" << args); + + break; + } + default: { qDebug() << "Command not found: " << cmd; break; @@ -520,6 +535,8 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event) emit tracksChanged(); } else if (strcmp(prop->name, "audio-device-list") == 0) { emit audioDevicesChanged(); + } else if (strcmp(prop->name, "playlist") == 0) { + emit playlistChanged(); } #ifdef DISCORD updateDiscord(); diff --git a/src/MpvPlayerBackend.h b/src/MpvPlayerBackend.h index dd12599..acfa4a7 100644 --- a/src/MpvPlayerBackend.h +++ b/src/MpvPlayerBackend.h @@ -64,6 +64,8 @@ signals: void durationStringChanged(const QString& string); void tracksChanged(); void audioDevicesChanged(); + void playlistChanged(); + private slots: void doUpdate(); diff --git a/src/enums.hpp b/src/enums.hpp index c646472..4d3b153 100644 --- a/src/enums.hpp +++ b/src/enums.hpp @@ -44,7 +44,9 @@ enum class Commands : int GetTracks = 20, ForwardFrame = 21, BackwardFrame = 22, - SetTrack = 23 + SetTrack = 23, + GetPlaylist = 24, + SetPlaylistPos = 25 }; Q_ENUM_NS(Commands) enum class Backends : int diff --git a/src/qml/MainMenu.qml b/src/qml/MainMenu.qml index f618dac..df62692 100644 --- a/src/qml/MainMenu.qml +++ b/src/qml/MainMenu.qml @@ -124,6 +124,89 @@ MenuBar { } } + Dialog { + id: playlistDialog + title: "Playlist" + height: 480 + width: 720 + modality: Qt.NonModal + + onAccepted: { + console.log("ok") + } + Component.onCompleted: { + player.titleChanged.connect(updatePlaylistMenu) + player.playlistChanged.connect(updatePlaylistMenu) + } + function updatePlaylistMenu() { + var playlist = player.playerCommand(Enums.Commands.GetPlaylist) + playlistModel.clear() + for (var thing in playlist) { + var item = playlist[thing] + playlistModel.append({ + "playlistItemTitle": item["title"], + "playlistItemFilename": item["filename"], + "current": item["current"], + "playlistPos": thing + }) + + } + + } + + Component { + id: playlistDelegate + Item { + id: playlistItem + width: playlistDialog.width; height: 0 + Button { + height: parent.height + id: playlistItemButton + font.pixelSize: 12 + contentItem: Text { + id: playlistItemText + font: parent.font + color: "white" + text: playlistItemButton.text + height: parent.height + horizontalAlignment: Text.AlignLeft + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + } + + onClicked: { + player.playerCommand(Enums.Commands.SetPlaylistPos, playlistPos) + } + background: Rectangle { color: current ? "orange" : "transparent" } + } + + + Component.onCompleted: { + var itemText = "" + if (typeof playlistItemTitle !== "undefined") { + itemText += 'Title: ' + playlistItemTitle + "
" + playlistItem.height += 30 + } + if (typeof playlistItemFilename !== "undefined") { + itemText += 'Filename: ' + playlistItemFilename + "
" + playlistItem.height += 30 + } + playlistItemText.text = itemText + } + } + } + + ListView { + id: playlistListView + anchors.fill: parent + model: ListModel { id: playlistModel } + delegate: playlistDelegate + highlight: Item {} + focus: true + } + + } + delegate: MenuBarItem { id: menuBarItem @@ -480,6 +563,13 @@ MenuBar { player.toggleOnTop() } } + Action { + text: translate.getTranslation("PLAYLIST_MENU", + i18n.language) + onTriggered: { + playlistDialog.open() + } + } } CustomMenu { id: aboutMenuBarItem diff --git a/src/qml/translations.js b/src/qml/translations.js index f54829a..d1a8bc2 100644 --- a/src/qml/translations.js +++ b/src/qml/translations.js @@ -42,7 +42,8 @@ var translations = { TOGGLE_ALWAYS_ON_TOP: "Toggle Always On Top", DISABLE_TRACK: "Disable Track", AUDIO_DEVICES: "Audio Devices", - UPDATE: "Update" + UPDATE: "Update", + PLAYLIST_MENU: "Playlist Menu" }, spanish: { SAVE_SCREENSHOT: "Guardar captura en",