Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
DBusMenuModel.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 <PhosphorServiceSni/phosphorservicesni_export.h>
7
8#include <QAbstractListModel>
9#include <QString>
10
11#include <memory>
12
14
25class PHOSPHORSERVICESNI_EXPORT DBusMenuModel : public QAbstractListModel
26{
27 Q_OBJECT
28 Q_DISABLE_COPY_MOVE(DBusMenuModel)
29 Q_PROPERTY(QString service READ service WRITE setService NOTIFY sourceChanged)
30 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY sourceChanged)
31 Q_PROPERTY(int rootId READ rootId WRITE setRootId NOTIFY rootIdChanged)
32 Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
33 // Mirror of rowCount(): QAbstractListModel doesn't expose count
34 // as a property, so QML's `model.count` evaluates to undefined
35 // without this. Worth keeping the API symmetric with
36 // StatusNotifierItemModel.
37 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
38
39public:
53 Q_ENUM(Roles)
54
55 explicit DBusMenuModel(QObject* parent = nullptr);
56 ~DBusMenuModel() override;
57
58 [[nodiscard]] QString service() const;
59 void setService(const QString& service);
60
61 [[nodiscard]] QString path() const;
62 void setPath(const QString& path);
63
64 [[nodiscard]] int rootId() const;
65 void setRootId(int id);
66
67 [[nodiscard]] bool valid() const;
68
69 [[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override;
70 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
71 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
72
74 Q_INVOKABLE void triggerItem(int row);
78 Q_INVOKABLE int aboutToShowSubmenu(int row);
81 Q_INVOKABLE void aboutToShow();
87 Q_INVOKABLE void aboutToHide();
93 Q_INVOKABLE void refresh();
94
95Q_SIGNALS:
104 void loaded();
110 void loadFailed(const QString& message);
111
112private:
113 class Private;
114 std::unique_ptr<Private> d;
115};
116
117} // namespace PhosphorServiceSni
void loadFailed(const QString &message)
Fired when a GetLayout call returns a DBus error: usually means the SNI item advertised a Menu path t...
QHash< int, QByteArray > roleNames() const override
void aboutToHide()
Tell the item we're hiding this menu.
void loaded()
Fires on EVERY successful GetLayout: not just transitions from invalid → valid.
void triggerItem(int row)
Fire a click event at the given row. Calls Event(id, "clicked", ...).
void setPath(const QString &path)
void setService(const QString &service)
int aboutToShowSubmenu(int row)
Call AboutToShow on row's submenu (if it has one) and return its id: the QML layer uses that id as th...
Roles
Definition DBusMenuModel.h:40
@ ToggleStateRole
0 = off, 1 = on, -1 = indeterminate
Definition DBusMenuModel.h:49
@ ToggleTypeRole
"checkmark" | "radio" | empty
Definition DBusMenuModel.h:48
@ ShortcutRole
Definition DBusMenuModel.h:51
@ TypeRole
"standard" | "separator"
Definition DBusMenuModel.h:42
@ IconImageRole
raw QImage (kept for C++ use; not usable as Image.source)
Definition DBusMenuModel.h:47
@ EnabledRole
Definition DBusMenuModel.h:44
@ LabelRole
menu text, ampersands already stripped for accel
Definition DBusMenuModel.h:43
@ VisibleRole
Definition DBusMenuModel.h:45
@ IconUrlRole
data:image/png;base64,... URL: bind to Image.source
Definition DBusMenuModel.h:46
@ ChildrenDisplayRole
"submenu" if this entry has children, else empty
Definition DBusMenuModel.h:50
@ IdRole
Definition DBusMenuModel.h:41
DBusMenuModel(QObject *parent=nullptr)
QVariant data(const QModelIndex &index, int role) const override
void aboutToShow()
Tell the item we're about to display this menu: required by the spec before showing the root.
void refresh()
Force a fresh GetLayout against the current service/path.
int rowCount(const QModelIndex &parent={}) const override
Definition DBusMenuModel.h:13