all: replace list properties with ObjectModels

This commit is contained in:
outfoxxed 2024-05-23 17:28:07 -07:00
parent 6326f60ce2
commit 5016dbf0d4
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
11 changed files with 201 additions and 152 deletions

View file

@ -4,14 +4,13 @@
#include <qdbusinterface.h>
#include <qdbusservicewatcher.h>
#include <qhash.h>
#include <qlist.h>
#include <qloggingcategory.h>
#include <qobject.h>
#include <qqmlintegration.h>
#include <qqmllist.h>
#include <qtmetamacros.h>
#include <qtypes.h>
#include "../../core/model.hpp"
#include "player.hpp"
namespace qs::service::mpris {
@ -22,15 +21,12 @@ class MprisWatcher: public QObject {
QML_NAMED_ELEMENT(Mpris);
QML_SINGLETON;
/// All connected MPRIS players.
Q_PROPERTY(QQmlListProperty<MprisPlayer> players READ players NOTIFY playersChanged);
Q_PROPERTY(ObjectModel<MprisPlayer>* players READ players CONSTANT);
public:
explicit MprisWatcher(QObject* parent = nullptr);
[[nodiscard]] QQmlListProperty<MprisPlayer> players();
signals:
void playersChanged();
[[nodiscard]] ObjectModel<MprisPlayer>* players();
private slots:
void onServiceRegistered(const QString& service);
@ -39,15 +35,12 @@ private slots:
void onPlayerDestroyed(QObject* object);
private:
static qsizetype playersCount(QQmlListProperty<MprisPlayer>* property);
static MprisPlayer* playerAt(QQmlListProperty<MprisPlayer>* property, qsizetype index);
void registerExisting();
void registerPlayer(const QString& address);
QDBusServiceWatcher serviceWatcher;
QHash<QString, MprisPlayer*> mPlayers;
QList<MprisPlayer*> readyPlayers;
ObjectModel<MprisPlayer> readyPlayers {this};
};
} // namespace qs::service::mpris