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 <PhosphorServices/phosphorservices_export.h>
7
8#include <QAbstractListModel>
9#include <QPointer>
10#include <QQmlEngine>
11#include <QString>
12
13#include <memory>
14
16
27class PHOSPHORSERVICES_EXPORT DBusMenuModel : public QAbstractListModel
28{
29 Q_OBJECT
30 Q_DISABLE_COPY_MOVE(DBusMenuModel)
31 QML_ELEMENT
32 Q_PROPERTY(QString service READ service WRITE setService NOTIFY sourceChanged)
33 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY sourceChanged)
34 Q_PROPERTY(int rootId READ rootId WRITE setRootId NOTIFY rootIdChanged)
35 Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
36 // Mirror of rowCount() — QAbstractListModel doesn't expose count
37 // as a property, so QML's `model.count` evaluates to undefined
38 // without this. Worth keeping the API symmetric with
39 // StatusNotifierItemModel.
40 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
41
42public:
56 Q_ENUM(Roles)
57
58 explicit DBusMenuModel(QObject* parent = nullptr);
59 ~DBusMenuModel() override;
60
61 [[nodiscard]] QString service() const;
62 void setService(const QString& service);
63
64 [[nodiscard]] QString path() const;
65 void setPath(const QString& path);
66
67 [[nodiscard]] int rootId() const;
68 void setRootId(int id);
69
70 [[nodiscard]] bool valid() const;
71
72 [[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override;
73 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
74 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
75
77 Q_INVOKABLE void triggerItem(int row);
81 Q_INVOKABLE int aboutToShowSubmenu(int row);
84 Q_INVOKABLE void aboutToShow();
85 Q_INVOKABLE void aboutToHide();
91 Q_INVOKABLE void refresh();
92
93Q_SIGNALS:
102 void loaded();
108 void loadFailed(const QString& message);
109
110private:
111 class Private;
112 std::unique_ptr<Private> d;
113};
114
115} // namespace PhosphorServices
Flat model exposing ONE level of a com.canonical.dbusmenu tree at a time.
Definition DBusMenuModel.h:28
QVariant data(const QModelIndex &index, int role) const override
void refresh()
Force a fresh GetLayout against the current service/path.
Roles
Definition DBusMenuModel.h:43
@ ChildrenDisplayRole
"submenu" if this entry has children, else empty
Definition DBusMenuModel.h:53
@ ShortcutRole
Definition DBusMenuModel.h:54
@ ToggleStateRole
0 = off, 1 = on, -1 = indeterminate
Definition DBusMenuModel.h:52
@ EnabledRole
Definition DBusMenuModel.h:47
@ LabelRole
menu text, ampersands already stripped for accel
Definition DBusMenuModel.h:46
@ ToggleTypeRole
"checkmark" | "radio" | empty
Definition DBusMenuModel.h:51
@ IconImageRole
raw QImage (kept for C++ use; not usable as Image.source)
Definition DBusMenuModel.h:50
@ IconUrlRole
data:image/png;base64,... URL — bind to Image.source
Definition DBusMenuModel.h:49
@ TypeRole
"standard" | "separator"
Definition DBusMenuModel.h:45
@ VisibleRole
Definition DBusMenuModel.h:48
QHash< int, QByteArray > roleNames() const override
void loaded()
Fires on EVERY successful GetLayout — not just transitions from invalid → valid.
void aboutToShow()
Tell the item we're about to display this menu — required by the spec before showing the root.
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 t...
void triggerItem(int row)
Fire a click event at the given row. Calls Event(id, "clicked", ...).
void loadFailed(const QString &message)
Fired when a GetLayout call returns a DBus error — usually means the SNI item advertised a Menu path ...
Definition DBusMenuModel.h:15