Flat model exposing ONE level of a com.canonical.dbusmenu tree at a time.
More...
#include <PhosphorServiceSni/DBusMenuModel.h>
|
| enum | Roles {
IdRole = Qt::UserRole + 1
, TypeRole
, LabelRole
, EnabledRole
,
VisibleRole
, IconUrlRole
, IconImageRole
, ToggleTypeRole
,
ToggleStateRole
, ChildrenDisplayRole
, ShortcutRole
} |
|
| void | sourceChanged () |
| void | rootIdChanged () |
| void | validChanged () |
| void | countChanged () |
| void | loaded () |
| | Fires on EVERY successful GetLayout: not just transitions from invalid → valid.
|
| void | loadFailed (const QString &message) |
| | Fired when a GetLayout call returns a DBus error: usually means the SNI item advertised a Menu path that's stale, broken, or implemented as something other than canonical dbusmenu.
|
|
| | DBusMenuModel (QObject *parent=nullptr) |
| | ~DBusMenuModel () override |
| QString | service () const |
| void | setService (const QString &service) |
| QString | path () const |
| void | setPath (const QString &path) |
| int | rootId () const |
| void | setRootId (int id) |
| bool | valid () const |
| int | rowCount (const QModelIndex &parent={}) const override |
| QVariant | data (const QModelIndex &index, int role) const override |
| QHash< int, QByteArray > | roleNames () const override |
| void | triggerItem (int row) |
| | Fire a click event at the given row. Calls Event(id, "clicked", ...).
|
| 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 the rootId for the cascaded child model.
|
| void | aboutToShow () |
| | Tell the item we're about to display this menu: required by the spec before showing the root.
|
| void | aboutToHide () |
| | Tell the item we're hiding this menu.
|
| void | refresh () |
| | Force a fresh GetLayout against the current service/path.
|
Flat model exposing ONE level of a com.canonical.dbusmenu tree at a time.
Tree mode (QAbstractItemModel) is awkward to drive from QML: most shells render submenus as cascading popups instead, so each popup binds a fresh DBusMenuModel pointing at a different rootId.
Construct one with the SNI item's dbusService + the menu object path from StatusNotifierItem::menuPath(). The model then drives itself: GetLayout on construction, LayoutUpdated/ItemsPropertiesUpdated signals to refresh.
◆ Roles
| Enumerator |
|---|
| IdRole | |
| TypeRole | "standard" | "separator"
|
| LabelRole | menu text, ampersands already stripped for accel
|
| EnabledRole | |
| VisibleRole | |
| IconUrlRole | data:image/png;base64,... URL: bind to Image.source
|
| IconImageRole | raw QImage (kept for C++ use; not usable as Image.source)
|
| ToggleTypeRole | "checkmark" | "radio" | empty
|
| ToggleStateRole | 0 = off, 1 = on, -1 = indeterminate
|
| ChildrenDisplayRole | "submenu" if this entry has children, else empty
|
| ShortcutRole | |
◆ DBusMenuModel()
| PhosphorServiceSni::DBusMenuModel::DBusMenuModel |
( |
QObject * | parent = nullptr | ) |
|
|
explicit |
◆ ~DBusMenuModel()
| PhosphorServiceSni::DBusMenuModel::~DBusMenuModel |
( |
| ) |
|
|
override |
◆ aboutToHide()
| void PhosphorServiceSni::DBusMenuModel::aboutToHide |
( |
| ) |
|
Tell the item we're hiding this menu.
Fires closed Event in LIFO order for every level previously opened via aboutToShow / aboutToShowSubmenu. Safe to call without a paired aboutToShow (no events fired in that case) so QML can wire it to a debounced dismiss handler without tracking opened-state itself.
◆ aboutToShow()
| void PhosphorServiceSni::DBusMenuModel::aboutToShow |
( |
| ) |
|
Tell the item we're about to display this menu: required by the spec before showing the root.
Idempotent on repeated calls.
◆ aboutToShowSubmenu()
| int PhosphorServiceSni::DBusMenuModel::aboutToShowSubmenu |
( |
int | row | ) |
|
Call AboutToShow on row's submenu (if it has one) and return its id: the QML layer uses that id as the rootId for the cascaded child model.
◆ countChanged
| void PhosphorServiceSni::DBusMenuModel::countChanged |
( |
| ) |
|
|
signal |
◆ data()
| QVariant PhosphorServiceSni::DBusMenuModel::data |
( |
const QModelIndex & | index, |
|
|
int | role ) const |
|
nodiscardoverride |
◆ loaded
| void PhosphorServiceSni::DBusMenuModel::loaded |
( |
| ) |
|
|
signal |
Fires on EVERY successful GetLayout: not just transitions from invalid → valid.
Used by QML to remap the popup when the same menu is re-opened (validChanged stays silent in that case because the bool didn't change).
◆ loadFailed
| void PhosphorServiceSni::DBusMenuModel::loadFailed |
( |
const QString & | message | ) |
|
|
signal |
Fired when a GetLayout call returns a DBus error: usually means the SNI item advertised a Menu path that's stale, broken, or implemented as something other than canonical dbusmenu.
QML can listen and dismiss the popup so the user doesn't stare at an empty floating box.
◆ path()
| QString PhosphorServiceSni::DBusMenuModel::path |
( |
| ) |
const |
|
nodiscard |
◆ refresh()
| void PhosphorServiceSni::DBusMenuModel::refresh |
( |
| ) |
|
Force a fresh GetLayout against the current service/path.
Used by the QML side when re-opening the SAME menu: setService/ setPath early-return when values are unchanged, so without this the model never re-fetches and never re-fires loaded, leaving the popup unable to remap.
◆ roleNames()
| QHash< int, QByteArray > PhosphorServiceSni::DBusMenuModel::roleNames |
( |
| ) |
const |
|
nodiscardoverride |
◆ rootId()
| int PhosphorServiceSni::DBusMenuModel::rootId |
( |
| ) |
const |
|
nodiscard |
◆ rootIdChanged
| void PhosphorServiceSni::DBusMenuModel::rootIdChanged |
( |
| ) |
|
|
signal |
◆ rowCount()
| int PhosphorServiceSni::DBusMenuModel::rowCount |
( |
const QModelIndex & | parent = {} | ) |
const |
|
nodiscardoverride |
◆ service()
| QString PhosphorServiceSni::DBusMenuModel::service |
( |
| ) |
const |
|
nodiscard |
◆ setPath()
| void PhosphorServiceSni::DBusMenuModel::setPath |
( |
const QString & | path | ) |
|
◆ setRootId()
| void PhosphorServiceSni::DBusMenuModel::setRootId |
( |
int | id | ) |
|
◆ setService()
| void PhosphorServiceSni::DBusMenuModel::setService |
( |
const QString & | service | ) |
|
◆ sourceChanged
| void PhosphorServiceSni::DBusMenuModel::sourceChanged |
( |
| ) |
|
|
signal |
◆ triggerItem()
| void PhosphorServiceSni::DBusMenuModel::triggerItem |
( |
int | row | ) |
|
Fire a click event at the given row. Calls Event(id, "clicked", ...).
◆ valid()
| bool PhosphorServiceSni::DBusMenuModel::valid |
( |
| ) |
const |
|
nodiscard |
◆ validChanged
| void PhosphorServiceSni::DBusMenuModel::validChanged |
( |
| ) |
|
|
signal |
The documentation for this class was generated from the following file: