Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
StatusNotifierItemModel.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// Qt's MOC needs fully-defined pointer types for Q_PROPERTY, signal
9// parameters, and Q_INVOKABLE returns (qmetatype.h's
10// `checkTypeIsSuitableForMetaType` static-asserts `is_complete<T>`).
11// Forward decls compile in older Qt but fail with Qt ≥ 6.10.
14
15#include <QAbstractListModel>
16
17#include <memory>
18
19namespace PhosphorServiceSni {
20
25class PHOSPHORSERVICESNI_EXPORT StatusNotifierItemModel : public QAbstractListModel
26{
27 Q_OBJECT
28 Q_DISABLE_COPY_MOVE(StatusNotifierItemModel)
30 // `count` mirrors rowCount() and emits countChanged on every
31 // insert/remove. QAbstractListModel does NOT expose this by
32 // default: QML's `model.count` binding silently evaluates to
33 // `undefined` without it, and any `visible: model.count > 0`
34 // expression collapses to false, hiding the whole tray.
35 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
36
37public:
38 enum Roles {
39 IdRole = Qt::UserRole + 1,
43 // Icon URL forms: bind to QML's Image.source (a QUrl). The
44 // underlying QImage is published to the
45 // `image://phosphor-service-icontheme/` provider as a
46 // side-effect of model attachment / item icon changes. The
47 // URL host is resolved through
48 // PhosphorServiceIconTheme::imageProviderUrlHost() at publish
49 // time so any rename there propagates here without a hidden
50 // string-match.
54 // Raw QImage forms: kept for C++ consumers / future ImageItem
55 // bindings. Not directly usable as Image.source.
66 };
67 Q_ENUM(Roles)
68
69 explicit StatusNotifierItemModel(QObject* parent = nullptr);
71
72 [[nodiscard]] StatusNotifierHost* host() const;
74
75 [[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override;
76 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
77 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
78
83 Q_INVOKABLE void activate(int row, int x, int y);
84 Q_INVOKABLE void secondaryActivate(int row, int x, int y);
85 Q_INVOKABLE void contextMenu(int row, int x, int y);
86 Q_INVOKABLE void scroll(int row, int delta, const QString& orientation);
88
89Q_SIGNALS:
92
93private:
94 class Private;
95 std::unique_ptr<Private> d;
96
97 void connectItem(StatusNotifierItem* item);
98 void onItemAdded(StatusNotifierItem* item);
99 void onItemRemoved(StatusNotifierItem* item);
100 void onItemDataChanged(StatusNotifierItem* item);
101 void onItemIconChanged(StatusNotifierItem* item);
102 [[nodiscard]] int rowFor(StatusNotifierItem* item) const;
103};
104
105} // namespace PhosphorServiceSni
The shell-side counterpart to StatusNotifierWatcher.
Definition StatusNotifierHost.h:31
void secondaryActivate(int row, int x, int y)
void contextMenu(int row, int x, int y)
QVariant data(const QModelIndex &index, int role) const override
StatusNotifierItemModel(QObject *parent=nullptr)
void scroll(int row, int delta, const QString &orientation)
void activate(int row, int x, int y)
QML-friendly action invocations: looks up the item by row and dispatches.
void setHost(StatusNotifierHost *host)
Roles
Definition StatusNotifierItemModel.h:38
@ MenuPathRole
Definition StatusNotifierItemModel.h:61
@ ItemObjectRole
the raw StatusNotifierItem* for Q_INVOKABLE methods
Definition StatusNotifierItemModel.h:65
@ AttentionIconUrlRole
Definition StatusNotifierItemModel.h:53
@ ToolTipTitleRole
Definition StatusNotifierItemModel.h:59
@ TitleRole
Definition StatusNotifierItemModel.h:40
@ IconUrlRole
Definition StatusNotifierItemModel.h:51
@ DBusServiceRole
Definition StatusNotifierItemModel.h:63
@ IconImageRole
Definition StatusNotifierItemModel.h:56
@ OverlayIconUrlRole
Definition StatusNotifierItemModel.h:52
@ DBusPathRole
Definition StatusNotifierItemModel.h:64
@ CategoryRole
Definition StatusNotifierItemModel.h:41
@ ItemIsMenuRole
Definition StatusNotifierItemModel.h:62
@ IdRole
Definition StatusNotifierItemModel.h:39
@ AttentionIconImageRole
Definition StatusNotifierItemModel.h:58
@ StatusRole
Definition StatusNotifierItemModel.h:42
@ ToolTipBodyRole
Definition StatusNotifierItemModel.h:60
@ OverlayIconImageRole
Definition StatusNotifierItemModel.h:57
PhosphorServiceSni::StatusNotifierItem * itemAt(int row) const
StatusNotifierHost * host() const
QHash< int, QByteArray > roleNames() const override
int rowCount(const QModelIndex &parent={}) const override
One system-tray item.
Definition StatusNotifierItem.h:21
Definition DBusMenuModel.h:13