mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-04 01:42:44 +00:00
Implement playlist model and UI
This commit is contained in:
parent
e04ec364c1
commit
f09593c245
13 changed files with 309 additions and 36 deletions
|
@ -41,6 +41,7 @@
|
|||
#include "../model/playlist.h"
|
||||
#include "../support/jsonconv.h"
|
||||
#include "../viewmodel/item.h"
|
||||
#include "../viewmodel/playlist.h"
|
||||
#include "../apiclient.h"
|
||||
#include "itemmodel.h"
|
||||
|
||||
|
@ -83,8 +84,8 @@ public:
|
|||
|
||||
// Current Item and queue informatoion
|
||||
Q_PROPERTY(QObject *item READ item NOTIFY itemChanged)
|
||||
// Q_PROPERTY(QAbstractItemModel *queue READ queue NOTIFY queueChanged)
|
||||
Q_PROPERTY(int queueIndex READ queueIndex NOTIFY queueIndexChanged)
|
||||
Q_PROPERTY(Jellyfin::ViewModel::Playlist *queue READ queue NOTIFY queueChanged)
|
||||
|
||||
// Current media player related property getters
|
||||
Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
|
||||
|
@ -105,7 +106,7 @@ public:
|
|||
QObject *mediaObject() const { return m_mediaPlayer; }
|
||||
qint64 position() const { return m_mediaPlayer->position(); }
|
||||
qint64 duration() const { return m_mediaPlayer->duration(); }
|
||||
//ItemModel *queue() const { return m_queue; }
|
||||
ViewModel::Playlist *queue() const { return m_displayQueue; }
|
||||
int queueIndex() const { return m_queueIndex; }
|
||||
|
||||
// Current media player related property getters
|
||||
|
@ -129,7 +130,7 @@ signals:
|
|||
void mediaObjectChanged(QObject *newMediaObject);
|
||||
void positionChanged(qint64 newPosition);
|
||||
void durationChanged(qint64 newDuration);
|
||||
//void queueChanged(ItemModel *newQue);
|
||||
void queueChanged(QAbstractItemModel *newQueue);
|
||||
void queueIndexChanged(int newIndex);
|
||||
void playbackStateChanged(QMediaPlayer::State newState);
|
||||
void mediaStatusChanged(QMediaPlayer::MediaStatus newMediaStatus);
|
||||
|
@ -198,6 +199,8 @@ private:
|
|||
QSharedPointer<Model::Item> m_nextItem;
|
||||
/// The currently played item that will be shown in the GUI
|
||||
ViewModel::Item *m_displayItem = new ViewModel::Item(this);
|
||||
/// The currently played queue that will be shown in the GUI
|
||||
ViewModel::Playlist *m_displayQueue = nullptr;
|
||||
|
||||
// Properties for making the streaming request.
|
||||
QString m_streamUrl;
|
||||
|
|
|
@ -21,36 +21,81 @@
|
|||
|
||||
#include <optional>
|
||||
|
||||
#include <QAtomicInteger>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QAbstractListModel>
|
||||
#include <QByteArray>
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QQueue>
|
||||
#include <QWaitCondition>
|
||||
#include <QtMultimedia/QMediaPlaylist>
|
||||
#include <QSharedPointer>
|
||||
#include <QVariant>
|
||||
|
||||
#include "../apiclient.h"
|
||||
#include "../model/playlist.h"
|
||||
#include "itemmodel.h"
|
||||
|
||||
namespace Jellyfin {
|
||||
namespace ViewModel {
|
||||
|
||||
/**
|
||||
* @brief Playlist/queue that can be exposed to the UI. It also containts the playlist-related logic,
|
||||
* which is mostly relevant
|
||||
* @brief Indicator in which part of the playing queue a given item is positioned.
|
||||
*/
|
||||
/*class Playlist : public ItemModel {
|
||||
class NowPlayingSection {
|
||||
Q_GADGET
|
||||
public:
|
||||
enum Value {
|
||||
Queue,
|
||||
NowPlaying,
|
||||
};
|
||||
Q_ENUM(Value);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Playlist/queue that can be exposed to QML.
|
||||
*/
|
||||
class Playlist : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
friend class ItemUrlFetcherThread;
|
||||
public:
|
||||
explicit Playlist(ApiClient *apiClient, QObject *parent = nullptr);
|
||||
enum RoleNames {
|
||||
// Item properties
|
||||
name = Qt::UserRole + 1,
|
||||
artists,
|
||||
runTimeTicks,
|
||||
|
||||
// Non-item properties
|
||||
playing,
|
||||
section,
|
||||
};
|
||||
explicit Playlist(Model::Playlist *data, QObject *parent = nullptr);
|
||||
|
||||
QVariant data(const QModelIndex &parent, int role = Qt::DisplayRole) const override;
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
|
||||
private slots:
|
||||
void onItemsAdded(const QModelIndex &parent, int startIndex, int endIndex);
|
||||
void onItemsMoved(const QModelIndex &parent, int startIndex, int endIndex, const QModelIndex &destination, int destinationRow);
|
||||
void onItemsRemoved(const QModelIndex &parent, int startIndex, int endIndex);
|
||||
void onItemsReset();
|
||||
};*/
|
||||
void onBeforePlaylistCleared();
|
||||
void onPlaylistCleared();
|
||||
void onBeforeItemsAddedToList(int startIndex, int amount);
|
||||
void onBeforeItemsAddedToQueue(int startIndex, int amount);
|
||||
void onItemsAddedToList();
|
||||
void onItemsAddedToQueue();
|
||||
void onBeforeItemsRemovedFromList(int startIndex, int amount);
|
||||
void onBeforeItemsRemovedFromQueue(int startIndex, int amount);
|
||||
void onItemsRemovedFromList();
|
||||
void onItemsRemovedFromQueue();
|
||||
void onReshuffled();
|
||||
void onPlayingItemChanged();
|
||||
private:
|
||||
Model::Playlist *m_data;
|
||||
// The index of the last played item.
|
||||
int m_lastPlayedRow = -1;
|
||||
|
||||
/**
|
||||
* @param index The index, from 0..rowCount();
|
||||
* @return True if the item at the current index is being played, false otherwise.
|
||||
*/
|
||||
bool isPlaying(int index) const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue