File indexing completed on 2024-05-12 05:37:10
0001 /* 0002 SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QAbstractItemModel> 0010 #include <QPointer> 0011 0012 #include <KConfigWatcher> 0013 0014 #include <Plasma/Containment> 0015 0016 class QDBusPendingCallWatcher; 0017 class QDBusServiceWatcher; 0018 class QQuickItem; 0019 0020 namespace Plasma 0021 { 0022 class Service; 0023 } 0024 class PlasmoidRegistry; 0025 class PlasmoidModel; 0026 class SystemTraySettings; 0027 class StatusNotifierModel; 0028 class SystemTrayModel; 0029 class SortedSystemTrayModel; 0030 class KJob; 0031 0032 class SystemTray : public Plasma::Containment 0033 { 0034 Q_OBJECT 0035 Q_PROPERTY(QAbstractItemModel *systemTrayModel READ sortedSystemTrayModel CONSTANT) 0036 Q_PROPERTY(QAbstractItemModel *configSystemTrayModel READ configSystemTrayModel CONSTANT) 0037 0038 public: 0039 SystemTray(QObject *parent, const KPluginMetaData &data, const QVariantList &args); 0040 ~SystemTray() override; 0041 0042 void init() override; 0043 0044 void restoreContents(KConfigGroup &group) override; 0045 0046 QAbstractItemModel *sortedSystemTrayModel(); 0047 0048 QAbstractItemModel *configSystemTrayModel(); 0049 0050 // Invokable utilities 0051 /** 0052 * Given an AppletInterface pointer, shows a proper context menu for it 0053 */ 0054 Q_INVOKABLE void showPlasmoidMenu(QQuickItem *appletInterface, int x, int y); 0055 0056 /** 0057 * Shows the context menu for a statusnotifieritem 0058 */ 0059 Q_INVOKABLE void showStatusNotifierContextMenu(KJob *job, QQuickItem *statusNotifierIcon); 0060 0061 /** 0062 * Find out global coordinates for a popup given local MouseArea 0063 * coordinates 0064 */ 0065 Q_INVOKABLE QPointF popupPosition(QQuickItem *visualParent, int x, int y); 0066 0067 /** 0068 * @brief isSystemTrayApplet checks if applet is allowed in the System Tray 0069 * @param appletId also known as plugin Id 0070 * @return true if it is a system tray applet, otherwise false 0071 */ 0072 Q_INVOKABLE bool isSystemTrayApplet(const QString &appletId); 0073 0074 /** 0075 * Needed to preserve keyboard navigation 0076 */ 0077 Q_INVOKABLE void stackItemBefore(QQuickItem *newItem, QQuickItem *beforeItem); 0078 0079 Q_INVOKABLE void stackItemAfter(QQuickItem *newItem, QQuickItem *afterItem); 0080 0081 private Q_SLOTS: 0082 // synchronizes with configuration and deletes not allowed applets 0083 void onEnabledAppletsChanged(); 0084 // creates an applet *if not already existing* 0085 void startApplet(const QString &pluginId); 0086 // deletes/stops all instances of a given applet 0087 void stopApplet(const QString &pluginId); 0088 0089 private: 0090 SystemTrayModel *systemTrayModel(); 0091 0092 KConfigWatcher::Ptr m_configWatcher; 0093 bool m_xwaylandClientsScale = true; 0094 0095 QPointer<SystemTraySettings> m_settings; 0096 QPointer<PlasmoidRegistry> m_plasmoidRegistry; 0097 0098 PlasmoidModel *m_plasmoidModel = nullptr; 0099 StatusNotifierModel *m_statusNotifierModel = nullptr; 0100 SystemTrayModel *m_systemTrayModel = nullptr; 0101 SortedSystemTrayModel *m_sortedSystemTrayModel = nullptr; 0102 SortedSystemTrayModel *m_configSystemTrayModel = nullptr; 0103 0104 QHash<QString /*plugin id*/, int /*config group*/> m_configGroupIds; 0105 };