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
|
@ -36,6 +36,7 @@
|
|||
#include "viewmodel/loader.h"
|
||||
#include "viewmodel/modelstatus.h"
|
||||
#include "viewmodel/playbackmanager.h"
|
||||
#include "viewmodel/playlist.h"
|
||||
#include "viewmodel/userdata.h"
|
||||
#include "viewmodel/usermodel.h"
|
||||
#include "viewmodel/user.h"
|
||||
|
|
|
@ -52,6 +52,11 @@ public:
|
|||
/// Returns the current item in the queue
|
||||
QSharedPointer<Item> currentItem();
|
||||
QSharedPointer<Item> nextItem();
|
||||
/**
|
||||
* @return the current index of the playing item if it is in the list. If playing from the queue,
|
||||
* returns -1.
|
||||
*/
|
||||
int currentItemIndexInList() const;
|
||||
|
||||
/**
|
||||
* @brief Determine the previous item to be played.
|
||||
|
@ -63,13 +68,26 @@ public:
|
|||
*/
|
||||
void next();
|
||||
|
||||
// int queueSize() { return m_queue.size(); };
|
||||
int queueSize() { return m_queue.size(); };
|
||||
int listSize() const { return m_list.size(); };
|
||||
int totalSize() const { return m_queue.size() + m_list.size(); }
|
||||
|
||||
QSharedPointer<const Item> listAt(int index) const;
|
||||
/**
|
||||
* @brief Removes all the items from the playlist
|
||||
* @brief Returns the item at the given index of the currently selected playlist, excluding the queue.
|
||||
* @param index
|
||||
* @return The given item.
|
||||
*/
|
||||
QSharedPointer<const Item> listAt(int index) const;
|
||||
|
||||
/**
|
||||
* @brief Returns the item at the given index of the currently queue, excluding the playlist.
|
||||
* @param index
|
||||
* @return The given item.
|
||||
*/
|
||||
QSharedPointer<const Item> queueAt(int index) const;
|
||||
|
||||
/**
|
||||
* @brief Removes all the items from the playlist, but not from the queue.
|
||||
*/
|
||||
void clearList();
|
||||
|
||||
|
@ -83,11 +101,26 @@ public:
|
|||
* @param index The index to start from.
|
||||
*/
|
||||
void play(int index = 0);
|
||||
|
||||
/**
|
||||
* @brief playingFromQueue
|
||||
* @return True if the currently played item comes from the queue.
|
||||
*/
|
||||
bool playingFromQueue() const;
|
||||
|
||||
signals:
|
||||
void beforeListCleared();
|
||||
void listCleared();
|
||||
void itemsAddedToQueue(int index, int count);
|
||||
void itemsAddedToList(int index, int count);
|
||||
void beforeItemsAddedToQueue(int index, int count);
|
||||
void beforeItemsAddedToList(int index, int count);
|
||||
void itemsAddedToQueue();
|
||||
void itemsAddedToList();
|
||||
void beforeItemsRemovedFromQueue(int index, int count);
|
||||
void beforeItemsRemovedFromList(int index, int count);
|
||||
void itemsRemovedFromQueue();
|
||||
void itemsRemovedFromList();
|
||||
void listReshuffled();
|
||||
void currentItemChanged();
|
||||
private:
|
||||
void reshuffle();
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ public:
|
|||
|
||||
virtual int currentItem() const override;
|
||||
virtual int nextItem() const override;
|
||||
virtual int itemAt(int index) const override;
|
||||
|
||||
virtual void previous() override;
|
||||
virtual void next() override;
|
||||
|
@ -122,6 +123,7 @@ public:
|
|||
ListShuffleBase(const Playlist *parent);
|
||||
virtual int currentItem() const override;
|
||||
virtual int nextItem() const override;
|
||||
virtual int itemAt(int index) const override;
|
||||
protected:
|
||||
QVector<int> m_map;
|
||||
};
|
||||
|
|
|
@ -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