Changeset View
Standalone View
applets/systemtray/systemtray.h
Show All 29 Lines | |||||
30 | class QDBusConnection; | 30 | class QDBusConnection; | ||
31 | class QQuickItem; | 31 | class QQuickItem; | ||
32 | namespace Plasma { | 32 | namespace Plasma { | ||
33 | class Service; | 33 | class Service; | ||
34 | } | 34 | } | ||
35 | class PlasmoidModel; | 35 | class PlasmoidModel; | ||
36 | class StatusNotifierModel; | 36 | class StatusNotifierModel; | ||
37 | class SystemTrayModel; | 37 | class SystemTrayModel; | ||
38 | class SortedSystemTrayModel; | ||||
38 | 39 | | |||
39 | class SystemTray : public Plasma::Containment | 40 | class SystemTray : public Plasma::Containment | ||
40 | { | 41 | { | ||
41 | Q_OBJECT | 42 | Q_OBJECT | ||
42 | Q_PROPERTY(QAbstractItemModel* systemTrayModel READ systemTrayModel CONSTANT) | 43 | Q_PROPERTY(QAbstractItemModel* systemTrayModel READ systemTrayModel CONSTANT) | ||
43 | Q_PROPERTY(QAbstractItemModel* availablePlasmoids READ availablePlasmoids CONSTANT) | 44 | Q_PROPERTY(QAbstractItemModel* configSystemTrayModel READ configSystemTrayModel CONSTANT) | ||
44 | Q_PROPERTY(QStringList allowedPlasmoids READ allowedPlasmoids WRITE setAllowedPlasmoids NOTIFY allowedPlasmoidsChanged) | 45 | Q_PROPERTY(QStringList allowedPlasmoids READ allowedPlasmoids WRITE setAllowedPlasmoids NOTIFY allowedPlasmoidsChanged) | ||
45 | Q_PROPERTY(QStringList defaultPlasmoids READ defaultPlasmoids CONSTANT) | | |||
46 | 46 | | |||
47 | public: | 47 | public: | ||
48 | SystemTray( QObject *parent, const QVariantList &args ); | 48 | SystemTray( QObject *parent, const QVariantList &args ); | ||
49 | ~SystemTray() override; | 49 | ~SystemTray() override; | ||
50 | 50 | | |||
51 | void init() override; | 51 | void init() override; | ||
52 | 52 | | |||
53 | void restoreContents(KConfigGroup &group) override; | 53 | void restoreContents(KConfigGroup &group) override; | ||
54 | void restorePlasmoids(); | 54 | void restorePlasmoids(); | ||
55 | 55 | | |||
56 | QAbstractItemModel* systemTrayModel(); | 56 | void configChanged() override; | ||
57 | 57 | | |||
58 | QStringList defaultPlasmoids() const; | 58 | QAbstractItemModel *systemTrayModel(); | ||
59 | 59 | | |||
60 | QAbstractItemModel* availablePlasmoids(); | 60 | QAbstractItemModel *configSystemTrayModel(); | ||
61 | 61 | | |||
62 | QStringList allowedPlasmoids() const; | 62 | QStringList allowedPlasmoids() const; | ||
63 | void setAllowedPlasmoids(const QStringList &allowed); | 63 | void setAllowedPlasmoids(const QStringList &allowed); | ||
64 | 64 | | |||
65 | //Creates an applet *if not already existing* | 65 | //Creates an applet *if not already existing* | ||
66 | void newTask(const QString &task); | 66 | void newTask(const QString &task); | ||
67 | 67 | | |||
68 | //cleans all instances of a given applet | 68 | //cleans all instances of a given applet | ||
Show All 17 Lines | |||||
86 | Q_INVOKABLE void showStatusNotifierContextMenu(KJob *job, QQuickItem *statusNotifierIcon); | 86 | Q_INVOKABLE void showStatusNotifierContextMenu(KJob *job, QQuickItem *statusNotifierIcon); | ||
87 | 87 | | |||
88 | /** | 88 | /** | ||
89 | * Find out global coordinates for a popup given local MouseArea | 89 | * Find out global coordinates for a popup given local MouseArea | ||
90 | * coordinates | 90 | * coordinates | ||
91 | */ | 91 | */ | ||
92 | Q_INVOKABLE QPointF popupPosition(QQuickItem* visualParent, int x, int y); | 92 | Q_INVOKABLE QPointF popupPosition(QQuickItem* visualParent, int x, int y); | ||
93 | 93 | | |||
94 | /** | 94 | Q_INVOKABLE bool isSystemTrayApplet(const QString &appletId); | ||
95 | * Reparent the item "before" with the same parent as the item "after", | | |||
96 | * then restack it before it, using QQuickITem::stackBefore. | | |||
97 | * used to quickly reorder icons in the systray (or hidden popup) | | |||
98 | * @see QQuickITem::stackBefore | | |||
99 | */ | | |||
100 | Q_INVOKABLE void reorderItemBefore(QQuickItem* before, QQuickItem* after); | | |||
101 | 95 | | |||
102 | /** | 96 | /** | ||
103 | * Reparent the item "after" with the same parent as the item "before", | 97 | * @returns a Plasma::Service given a source name | ||
104 | * then restack it after it, using QQuickITem::stackAfter. | 98 | * @param source source name we want a service of | ||
105 | * used to quickly reorder icons in the systray (or hidden popup) | | |||
106 | * @see QQuickITem::stackAfter | | |||
107 | */ | 99 | */ | ||
108 | Q_INVOKABLE void reorderItemAfter(QQuickItem* after, QQuickItem* before); | 100 | Q_INVOKABLE Plasma::Service *serviceForSource(const QString &source); | ||
kossebau: Hi. Seeing this code, I have a question: from what I understood so far, for this method to be… | |||||
I don't know, this code was there before my changes, I've just done some refactoring here. kmaterka: I don't know, this code was there before my changes, I've just done some refactoring here. | |||||
Thanks for your reply. Okay, so seems you did not hit anything related. Thing is, you added here, whereas the JavaScript code before was calling serviceForSource() on a Plasma::DataSource class, which does not return the type "Plasma::Service *", but "QObject *", cmp. its method definition Q_INVOKABLE QObject *serviceForSource(const QString &source); and the JavaScript engine for a plain QObject simply exposes any Q_INVOKABLEs and slot methods, that's why no extra registration would be needed (AFAIK). So still a mystery to me why this here seems to work, too bad :) kossebau: Thanks for your reply. Okay, so seems you did not hit anything related.
Thing is, you added
``… | |||||
Oh, OK, now I remember, sorry for misinforming you... I haven't had any problems with this, it "Just Worked" :) Maybe it should return just plain QObject*, I'm not experienced in this area, what do you think? kmaterka: Oh, OK, now I remember, sorry for misinforming you...
I haven't had any problems with this, it… | |||||
I guess if this works and no-one reported errors, it should be fine. Also not fully experienced, but hit some issues elsewhere and now trying to understand the magic. Though right now confused by what I read in the docs, what I see in existing code and what my tweak & see experiments deliver (with different result each time, meh). So ignore for now. I have this on my list, and if I ever understood things fully and then would see some issue here, I will come back to this and ping you :) kossebau: I guess if this works and no-one reported errors, it should be fine.
Also not fully… | |||||
109 | | ||||
110 | Q_INVOKABLE bool isSystemTrayApplet(const QString &appletId); | | |||
111 | 101 | | |||
112 | private Q_SLOTS: | 102 | private Q_SLOTS: | ||
113 | void serviceNameFetchFinished(QDBusPendingCallWatcher* watcher, const QDBusConnection &connection); | 103 | void serviceNameFetchFinished(QDBusPendingCallWatcher* watcher, const QDBusConnection &connection); | ||
114 | void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner); | 104 | void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner); | ||
115 | 105 | | |||
116 | private: | 106 | private: | ||
117 | void serviceRegistered(const QString &service); | 107 | void serviceRegistered(const QString &service); | ||
118 | void serviceUnregistered(const QString &service); | 108 | void serviceUnregistered(const QString &service); | ||
119 | 109 | | |||
120 | Q_SIGNALS: | 110 | Q_SIGNALS: | ||
121 | void allowedPlasmoidsChanged(); | 111 | void allowedPlasmoidsChanged(); | ||
112 | void configurationChanged(const KConfigGroup &config); | ||||
122 | 113 | | |||
123 | private: | 114 | private: | ||
124 | void initDBusActivatables(); | 115 | void initDBusActivatables(); | ||
125 | QStringList m_defaultPlasmoids; | 116 | QStringList m_defaultPlasmoids; | ||
126 | QHash<QString /*plugin name*/, KPluginMetaData> m_systrayApplets; | 117 | QHash<QString /*plugin name*/, KPluginMetaData> m_systrayApplets; | ||
127 | QHash<QString /*plugin name*/, QRegExp /*DBus Service*/> m_dbusActivatableTasks; | 118 | QHash<QString /*plugin name*/, QRegExp /*DBus Service*/> m_dbusActivatableTasks; | ||
128 | 119 | | |||
129 | QStringList m_allowedPlasmoids; | 120 | QStringList m_allowedPlasmoids; | ||
130 | PlasmoidModel *m_availablePlasmoidsModel; | | |||
131 | StatusNotifierModel *m_statusNotifierModel; | 121 | StatusNotifierModel *m_statusNotifierModel; | ||
132 | SystemTrayModel *m_systemTrayModel; | 122 | SystemTrayModel *m_systemTrayModel; | ||
123 | SortedSystemTrayModel *m_sortedSystemTrayModel; | ||||
124 | SortedSystemTrayModel *m_configSystemTrayModel; | ||||
133 | QHash<QString, int> m_knownPlugins; | 125 | QHash<QString, int> m_knownPlugins; | ||
134 | QHash<QString, int> m_dbusServiceCounts; | 126 | QHash<QString, int> m_dbusServiceCounts; | ||
135 | }; | 127 | }; | ||
136 | 128 | | |||
137 | #endif | 129 | #endif |
Hi. Seeing this code, I have a question: from what I understood so far, for this method to be useable from the JavaScript inside QML, the type "Plasma::Service *" needs to be registered with at least
or
Yet I have not found any code in Plasma related projects which calls this.
The module org.kde.plasma.core only has code to register the unnamespaced type name ""Service*" (indirectly via qmlRegisterInterface<Plasma::Service>("Service"); which internally calls the equivalent of qRegisterMetaType<Plasma::Service *>("Service*");.
And the namespace in the registered type name string seems important, things broke elsewhere if the type signature used in the Q_INVOKABLE was different WRT namespace compared to the registered type name string.
Do you remember anything related or would have some insights?