Changeset View
Standalone View
applets/systemtray/systemtray.h
Show All 34 Lines | |||||
35 | class PlasmoidModel; | 35 | class PlasmoidModel; | ||
36 | class StatusNotifierModel; | 36 | class StatusNotifierModel; | ||
37 | class SystemTrayModel; | 37 | class SystemTrayModel; | ||
38 | class SortedSystemTrayModel; | 38 | class SortedSystemTrayModel; | ||
39 | 39 | | |||
40 | class SystemTray : public Plasma::Containment | 40 | class SystemTray : public Plasma::Containment | ||
41 | { | 41 | { | ||
42 | Q_OBJECT | 42 | Q_OBJECT | ||
43 | Q_PROPERTY(QAbstractItemModel* systemTrayModel READ systemTrayModel CONSTANT) | ||||
43 | Q_PROPERTY(QAbstractItemModel* configSystemTrayModel READ configSystemTrayModel CONSTANT) | 44 | Q_PROPERTY(QAbstractItemModel* configSystemTrayModel READ configSystemTrayModel CONSTANT) | ||
44 | Q_PROPERTY(QAbstractItemModel* availablePlasmoids READ availablePlasmoids CONSTANT) | | |||
45 | Q_PROPERTY(QStringList allowedPlasmoids READ allowedPlasmoids WRITE setAllowedPlasmoids NOTIFY allowedPlasmoidsChanged) | 45 | Q_PROPERTY(QStringList allowedPlasmoids READ allowedPlasmoids WRITE setAllowedPlasmoids NOTIFY allowedPlasmoidsChanged) | ||
46 | Q_PROPERTY(QStringList defaultPlasmoids READ defaultPlasmoids CONSTANT) | | |||
47 | 46 | | |||
48 | public: | 47 | public: | ||
49 | SystemTray( QObject *parent, const QVariantList &args ); | 48 | SystemTray( QObject *parent, const QVariantList &args ); | ||
50 | ~SystemTray() override; | 49 | ~SystemTray() override; | ||
51 | 50 | | |||
52 | void init() override; | 51 | void init() override; | ||
53 | 52 | | |||
54 | void restoreContents(KConfigGroup &group) override; | 53 | void restoreContents(KConfigGroup &group) override; | ||
55 | void restorePlasmoids(); | 54 | void restorePlasmoids(); | ||
56 | 55 | | |||
57 | QAbstractItemModel *configSystemTrayModel(); | 56 | void configChanged() override; | ||
58 | 57 | | |||
59 | QStringList defaultPlasmoids() const; | 58 | QAbstractItemModel *systemTrayModel(); | ||
60 | 59 | | |||
61 | QAbstractItemModel* availablePlasmoids(); | 60 | QAbstractItemModel *configSystemTrayModel(); | ||
62 | 61 | | |||
63 | QStringList allowedPlasmoids() const; | 62 | QStringList allowedPlasmoids() const; | ||
64 | void setAllowedPlasmoids(const QStringList &allowed); | 63 | void setAllowedPlasmoids(const QStringList &allowed); | ||
65 | 64 | | |||
66 | //Creates an applet *if not already existing* | 65 | //Creates an applet *if not already existing* | ||
67 | void newTask(const QString &task); | 66 | void newTask(const QString &task); | ||
68 | 67 | | |||
69 | //cleans all instances of a given applet | 68 | //cleans all instances of a given applet | ||
Show All 17 Lines | |||||
87 | Q_INVOKABLE void showStatusNotifierContextMenu(KJob *job, QQuickItem *statusNotifierIcon); | 86 | Q_INVOKABLE void showStatusNotifierContextMenu(KJob *job, QQuickItem *statusNotifierIcon); | ||
88 | 87 | | |||
89 | /** | 88 | /** | ||
90 | * Find out global coordinates for a popup given local MouseArea | 89 | * Find out global coordinates for a popup given local MouseArea | ||
91 | * coordinates | 90 | * coordinates | ||
92 | */ | 91 | */ | ||
93 | Q_INVOKABLE QPointF popupPosition(QQuickItem* visualParent, int x, int y); | 92 | Q_INVOKABLE QPointF popupPosition(QQuickItem* visualParent, int x, int y); | ||
94 | 93 | | |||
95 | /** | 94 | Q_INVOKABLE bool isSystemTrayApplet(const QString &appletId); | ||
96 | * Reparent the item "before" with the same parent as the item "after", | | |||
97 | * then restack it before it, using QQuickITem::stackBefore. | | |||
98 | * used to quickly reorder icons in the systray (or hidden popup) | | |||
99 | * @see QQuickITem::stackBefore | | |||
100 | */ | | |||
101 | Q_INVOKABLE void reorderItemBefore(QQuickItem* before, QQuickItem* after); | | |||
102 | 95 | | |||
103 | /** | 96 | /** | ||
104 | * Reparent the item "after" with the same parent as the item "before", | 97 | * @returns a Plasma::Service given a source name | ||
105 | * then restack it after it, using QQuickITem::stackAfter. | 98 | * @param source source name we want a service of | ||
106 | * used to quickly reorder icons in the systray (or hidden popup) | | |||
107 | * @see QQuickITem::stackAfter | | |||
108 | */ | 99 | */ | ||
109 | 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… | |||||
110 | | ||||
111 | Q_INVOKABLE bool isSystemTrayApplet(const QString &appletId); | | |||
112 | 101 | | |||
113 | private Q_SLOTS: | 102 | private Q_SLOTS: | ||
114 | void serviceNameFetchFinished(QDBusPendingCallWatcher* watcher, const QDBusConnection &connection); | 103 | void serviceNameFetchFinished(QDBusPendingCallWatcher* watcher, const QDBusConnection &connection); | ||
115 | void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner); | 104 | void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner); | ||
116 | 105 | | |||
117 | private: | 106 | private: | ||
118 | void serviceRegistered(const QString &service); | 107 | void serviceRegistered(const QString &service); | ||
119 | void serviceUnregistered(const QString &service); | 108 | void serviceUnregistered(const QString &service); | ||
120 | 109 | | |||
121 | Q_SIGNALS: | 110 | Q_SIGNALS: | ||
122 | void allowedPlasmoidsChanged(); | 111 | void allowedPlasmoidsChanged(); | ||
112 | void configurationChanged(const KConfigGroup &config); | ||||
123 | 113 | | |||
124 | private: | 114 | private: | ||
125 | void initDBusActivatables(); | 115 | void initDBusActivatables(); | ||
126 | QStringList m_defaultPlasmoids; | 116 | QStringList m_defaultPlasmoids; | ||
127 | QHash<QString /*plugin name*/, KPluginMetaData> m_systrayApplets; | 117 | QHash<QString /*plugin name*/, KPluginMetaData> m_systrayApplets; | ||
128 | QHash<QString /*plugin name*/, QRegExp /*DBus Service*/> m_dbusActivatableTasks; | 118 | QHash<QString /*plugin name*/, QRegExp /*DBus Service*/> m_dbusActivatableTasks; | ||
129 | 119 | | |||
130 | QStringList m_allowedPlasmoids; | 120 | QStringList m_allowedPlasmoids; | ||
131 | PlasmoidModel *m_availablePlasmoidsModel; | | |||
132 | StatusNotifierModel *m_statusNotifierModel; | 121 | StatusNotifierModel *m_statusNotifierModel; | ||
133 | SystemTrayModel *m_systemTrayModel; | 122 | SystemTrayModel *m_systemTrayModel; | ||
123 | SortedSystemTrayModel *m_sortedSystemTrayModel; | ||||
134 | SortedSystemTrayModel *m_configSystemTrayModel; | 124 | SortedSystemTrayModel *m_configSystemTrayModel; | ||
135 | QHash<QString, int> m_knownPlugins; | 125 | QHash<QString, int> m_knownPlugins; | ||
136 | QHash<QString, int> m_dbusServiceCounts; | 126 | QHash<QString, int> m_dbusServiceCounts; | ||
137 | }; | 127 | }; | ||
138 | 128 | | |||
139 | #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?