File indexing completed on 2024-05-12 17:08:51
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 0011 #include <KConfigWatcher> 0012 0013 #include <Plasma/Containment> 0014 0015 #include "config-WaylandProtocols.h" 0016 0017 class QDBusPendingCallWatcher; 0018 class QDBusServiceWatcher; 0019 class QQuickItem; 0020 0021 namespace Plasma 0022 { 0023 class Service; 0024 } 0025 class PlasmoidRegistry; 0026 class PlasmoidModel; 0027 class SystemTraySettings; 0028 class StatusNotifierModel; 0029 class SystemTrayModel; 0030 class SortedSystemTrayModel; 0031 class KJob; 0032 0033 class SystemTray : public Plasma::Containment 0034 { 0035 Q_OBJECT 0036 Q_PROPERTY(QAbstractItemModel *systemTrayModel READ sortedSystemTrayModel CONSTANT) 0037 Q_PROPERTY(QAbstractItemModel *configSystemTrayModel READ configSystemTrayModel CONSTANT) 0038 0039 public: 0040 SystemTray(QObject *parent, const KPluginMetaData &data, const QVariantList &args); 0041 ~SystemTray() override; 0042 0043 void init() override; 0044 0045 void restoreContents(KConfigGroup &group) override; 0046 0047 QAbstractItemModel *sortedSystemTrayModel(); 0048 0049 QAbstractItemModel *configSystemTrayModel(); 0050 0051 // Invokable utilities 0052 /** 0053 * Given an AppletInterface pointer, shows a proper context menu for it 0054 */ 0055 Q_INVOKABLE void showPlasmoidMenu(QQuickItem *appletInterface, int x, int y); 0056 0057 /** 0058 * Shows the context menu for a statusnotifieritem 0059 */ 0060 Q_INVOKABLE void showStatusNotifierContextMenu(KJob *job, QQuickItem *statusNotifierIcon); 0061 0062 /** 0063 * Find out global coordinates for a popup given local MouseArea 0064 * coordinates 0065 */ 0066 Q_INVOKABLE QPointF popupPosition(QQuickItem *visualParent, int x, int y); 0067 0068 /** 0069 * @brief isSystemTrayApplet checks if applet is allowed in the System Tray 0070 * @param appletId also known as plugin Id 0071 * @return true if it is a system tray applet, otherwise false 0072 */ 0073 Q_INVOKABLE bool isSystemTrayApplet(const QString &appletId); 0074 0075 /** 0076 * @brief Emits the "onPressed(mouse)" signal of a MouseArea 0077 * 0078 * This is needed because calling mouseArea.pressed from QML 0079 * only sees the "pressed" property, not the signal 0080 */ 0081 Q_INVOKABLE void emitPressed(QQuickItem *mouseArea, QObject /*QQuickMouseEvent*/ *mouseEvent); 0082 0083 /** 0084 * Needed to preserve keyboard navigation 0085 */ 0086 Q_INVOKABLE void stackItemBefore(QQuickItem *newItem, QQuickItem *beforeItem); 0087 0088 Q_INVOKABLE void stackItemAfter(QQuickItem *newItem, QQuickItem *afterItem); 0089 0090 private Q_SLOTS: 0091 // synchronizes with configuration and deletes not allowed applets 0092 void onEnabledAppletsChanged(); 0093 // creates an applet *if not already existing* 0094 void startApplet(const QString &pluginId); 0095 // deletes/stops all instances of a given applet 0096 void stopApplet(const QString &pluginId); 0097 0098 private: 0099 SystemTrayModel *systemTrayModel(); 0100 0101 #if HAVE_WaylandProtocols 0102 std::unique_ptr<class FractionalScaleManagerV1> m_fractionalScaleManagerV1; 0103 KConfigWatcher::Ptr m_configWatcher; 0104 #endif 0105 bool m_xwaylandClientsScale = true; 0106 0107 QPointer<SystemTraySettings> m_settings; 0108 QPointer<PlasmoidRegistry> m_plasmoidRegistry; 0109 0110 PlasmoidModel *m_plasmoidModel = nullptr; 0111 StatusNotifierModel *m_statusNotifierModel = nullptr; 0112 SystemTrayModel *m_systemTrayModel = nullptr; 0113 SortedSystemTrayModel *m_sortedSystemTrayModel = nullptr; 0114 SortedSystemTrayModel *m_configSystemTrayModel = nullptr; 0115 0116 QHash<QString /*plugin id*/, int /*config group*/> m_configGroupIds; 0117 };