Jellyfin Qt
QML Library for interacting with the Jellyfin multimedia server
Loading...
Searching...
No Matches
playlist.h
Go to the documentation of this file.
1/*
2 * Sailfin: a Jellyfin client written using Qt
3 * Copyright (C) 2021 Chris Josten and the Sailfin Contributors.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19#ifndef JELLYFIN_VIEWMODEL_PLAYLIST
20#define JELLYFIN_VIEWMODEL_PLAYLIST
21
22#include <optional>
23
24#include <QAbstractListModel>
25#include <QByteArray>
26#include <QHash>
27#include <QObject>
28#include <QSharedPointer>
29#include <QVariant>
30
31#include "../apiclient.h"
32#include "../model/playlist.h"
33#include "itemmodel.h"
34
35namespace Jellyfin {
36namespace ViewModel {
37
42 Q_GADGET
43public:
49};
50
54class Playlist : public QAbstractListModel {
55 Q_OBJECT
57public:
58 enum RoleNames {
59 // Item properties
60 name = Qt::UserRole + 1,
64
65 // Non-item properties
68 };
69 explicit Playlist(Model::Playlist *data, QObject *parent = nullptr);
70
71 QVariant data(const QModelIndex &parent, int role = Qt::DisplayRole) const override;
72 int rowCount(const QModelIndex &parent) const override;
73 QHash<int, QByteArray> roleNames() const override;
75
76
77private slots:
78 void onBeforePlaylistCleared();
79 void onPlaylistCleared();
80 void onBeforeItemsAddedToList(int startIndex, int amount);
81 void onBeforeItemsAddedToQueue(int startIndex, int amount);
82 void onItemsAddedToList();
83 void onItemsAddedToQueue();
84 void onBeforeItemsRemovedFromList(int startIndex, int amount);
85 void onBeforeItemsRemovedFromQueue(int startIndex, int amount);
86 void onItemsRemovedFromList();
87 void onItemsRemovedFromQueue();
88 void onReshuffled();
89 void onPlayingItemChanged();
90private:
91 Model::Playlist *m_data;
92 // The index of the last played item.
93 int m_lastPlayedRow = -1;
94
99 bool isPlaying(int index) const;
100};
101
102
103
104} // NS ViewModel
105} // NS Jellyfin
106
107#endif //JELLYFIN_VIEWMODEL_PLAYLIST
Model of a playlist, a list of items that can be played.
Definition playlist.h:47
Indicator in which part of the playing queue a given item is positioned.
Definition playlist.h:41
@ NowPlaying
Definition playlist.h:46
@ Queue
Definition playlist.h:45
Playlist/queue that can be exposed to QML.
Definition playlist.h:54
int rowCount(const QModelIndex &parent) const override
Definition playlist.cpp:33
void setPlaylistModel(Model::Playlist *data)
Definition playlist.cpp:48
QHash< int, QByteArray > roleNames() const override
Definition playlist.cpp:37
friend class ItemUrlFetcherThread
Definition playlist.h:56
QVariant data(const QModelIndex &parent, int role=Qt::DisplayRole) const override
Definition playlist.cpp:83
RoleNames
Definition playlist.h:58
@ playing
Definition playlist.h:66
@ artists
Definition playlist.h:61
@ section
Definition playlist.h:67
@ name
Definition playlist.h:60
@ runTimeTicks
Definition playlist.h:63
@ artistItems
Definition playlist.h:62
Playlist(Model::Playlist *data, QObject *parent=nullptr)
Definition playlist.cpp:27