1 /* 2 SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 7 #pragma once 8 9 #include <QAbstractItemModel> 10 #include <QRegExp> 11 12 #include <Plasma/Containment> 13 14 class QDBusPendingCallWatcher; 15 class QDBusServiceWatcher; 16 class QQuickItem; 17 namespace Plasma 18 { 19 class Service; 20 } 21 class PlasmoidRegistry; 22 class PlasmoidModel; 23 class SystemTraySettings; 24 class StatusNotifierModel; 25 class SystemTrayModel; 26 class SortedSystemTrayModel; 27 28 class SystemTray : public Plasma::Containment 29 { 30 Q_OBJECT 31 Q_PROPERTY(QAbstractItemModel *systemTrayModel READ sortedSystemTrayModel CONSTANT) 32 Q_PROPERTY(QAbstractItemModel *configSystemTrayModel READ configSystemTrayModel CONSTANT) 33 34 public: 35 SystemTray(QObject *parent, const QVariantList &args); 36 ~SystemTray() override; 37 38 void init() override; 39 40 void restoreContents(KConfigGroup &group) override; 41 42 QAbstractItemModel *sortedSystemTrayModel(); 43 44 QAbstractItemModel *configSystemTrayModel(); 45 46 // Invokable utilities 47 /** 48 * Given an AppletInterface pointer, shows a proper context menu for it 49 */ 50 Q_INVOKABLE void showPlasmoidMenu(QQuickItem *appletInterface, int x, int y); 51 52 /** 53 * Shows the context menu for a statusnotifieritem 54 */ 55 Q_INVOKABLE void showStatusNotifierContextMenu(KJob *job, QQuickItem *statusNotifierIcon); 56 57 /** 58 * Find out global coordinates for a popup given local MouseArea 59 * coordinates 60 */ 61 Q_INVOKABLE QPointF popupPosition(QQuickItem *visualParent, int x, int y); 62 63 /** 64 * @brief isSystemTrayApplet checks if applet is allowed in the System Tray 65 * @param appletId also known as plugin Id 66 * @return true if it is a system tray applet, otherwise false 67 */ 68 Q_INVOKABLE bool isSystemTrayApplet(const QString &appletId); 69 70 private Q_SLOTS: 71 // synchronizes with configuration and deletes not allowed applets 72 void onEnabledAppletsChanged(); 73 // creates an applet *if not already existing* 74 void startApplet(const QString &pluginId); 75 // deletes/stops all instances of a given applet 76 void stopApplet(const QString &pluginId); 77 78 private: 79 SystemTrayModel *systemTrayModel(); 80 81 QPointer<SystemTraySettings> m_settings; 82 QPointer<PlasmoidRegistry> m_plasmoidRegistry; 83 84 PlasmoidModel *m_plasmoidModel; 85 StatusNotifierModel *m_statusNotifierModel; 86 SystemTrayModel *m_systemTrayModel; 87 SortedSystemTrayModel *m_sortedSystemTrayModel; 88 SortedSystemTrayModel *m_configSystemTrayModel; 89 90 QHash<QString /*plugin id*/, int /*config group*/> m_configGroupIds; 91 }; 92