Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
MprisPlayerModel.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorServiceMpris/phosphorservicempris_export.h>
7
10
11#include <QAbstractListModel>
12
13namespace PhosphorServiceMpris {
14
15class PHOSPHORSERVICEMPRIS_EXPORT MprisPlayerModel : public QAbstractListModel
16{
17 Q_OBJECT
18 Q_DISABLE_COPY_MOVE(MprisPlayerModel)
19 Q_PROPERTY(PhosphorServiceMpris::MprisHost* host READ host WRITE setHost NOTIFY hostChanged)
20 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
21
22public:
31 Q_ENUM(Roles)
32
33 explicit MprisPlayerModel(QObject* parent = nullptr);
34 ~MprisPlayerModel() override;
35
36 [[nodiscard]] MprisHost* host() const;
38
39 [[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override;
40 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
41 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
42
43Q_SIGNALS:
46
47private Q_SLOTS:
48 void onPlayerAdded(PhosphorServiceMpris::MprisPlayer* player);
49 void onPlayerRemoved(PhosphorServiceMpris::MprisPlayer* player);
50 void onPlayerDataChanged(PhosphorServiceMpris::MprisPlayer* player, const QList<int>& roles);
51
52private:
53 void connectPlayer(MprisPlayer* player);
54
55 MprisHost* m_host = nullptr;
56 // Row mirror owned by the model. rowCount()/data() index into this
57 // list, never the host's, so the begin/end-insert/remove transaction
58 // boundaries always straddle the actual mutation regardless of when
59 // the host emits playerAdded/playerRemoved relative to its own list.
60 QList<MprisPlayer*> m_rows;
61};
62
63} // namespace PhosphorServiceMpris
Definition MprisHost.h:16
MprisPlayerModel(QObject *parent=nullptr)
Roles
Definition MprisPlayerModel.h:23
@ PlaybackStateRole
Definition MprisPlayerModel.h:26
@ IdentityRole
Definition MprisPlayerModel.h:25
@ TrackTitleRole
Definition MprisPlayerModel.h:27
@ TrackArtistRole
Definition MprisPlayerModel.h:28
@ ArtUrlRole
Definition MprisPlayerModel.h:29
@ PlayerRole
Definition MprisPlayerModel.h:24
QVariant data(const QModelIndex &index, int role) const override
QHash< int, QByteArray > roleNames() const override
int rowCount(const QModelIndex &parent={}) const override
Definition MprisPlayer.h:16
Definition MprisHost.h:13