File indexing completed on 2024-06-16 05:09:54
0001 /* 0002 SPDX-FileCopyrightText: 2010 Jacopo De Simoi <wilderkde@gmail.com> 0003 SPDX-FileCopyrightText: 2014 Lukáš Tinkl <ltinkl@redhat.com> 0004 SPDX-FileCopyrightText: 2024 Fushan Wen <qydwhotmail@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include <QHash> 0012 #include <QObject> 0013 #include <QString> 0014 #include <qqmlregistration.h> 0015 0016 #include <Solid/Device> 0017 #include <solid/solidnamespace.h> 0018 0019 /** 0020 * @brief Class which triggers solid notifications 0021 * 0022 * This is an internal class which listens to solid errors and route them via dbus to an 0023 * appropriate visualization (e.g. the plasma device notifier applet); if such visualization is not available 0024 * errors are shown via regular notifications 0025 * 0026 * @author Jacopo De Simoi <wilderkde at gmail.com> 0027 */ 0028 0029 class KSolidNotify : public QObject 0030 { 0031 Q_OBJECT 0032 QML_ELEMENT 0033 0034 Q_PROPERTY(QString lastUdi READ lastUdi NOTIFY lastUdiChanged) 0035 0036 // Error type 0037 Q_PROPERTY(Solid::ErrorType lastErrorType READ lastErrorType NOTIFY lastErrorTypeChanged) 0038 0039 // Error title 0040 Q_PROPERTY(QString lastMessage READ lastMessage NOTIFY lastMessageChanged) 0041 0042 // Device description 0043 Q_PROPERTY(QString lastDescription READ lastDescription NOTIFY lastDescriptionChanged) 0044 0045 // Error icon 0046 Q_PROPERTY(QString lastIcon READ lastIcon NOTIFY lastIconChanged) 0047 0048 public: 0049 explicit KSolidNotify(QObject *parent = nullptr); 0050 0051 QString lastUdi() const; 0052 Solid::ErrorType lastErrorType() const; 0053 QString lastMessage() const; 0054 QString lastDescription() const; 0055 QString lastIcon() const; 0056 0057 Q_INVOKABLE void clearMessage(); 0058 0059 Q_SIGNALS: 0060 void lastUdiChanged(); 0061 void lastErrorTypeChanged(); 0062 void lastMessageChanged(); 0063 void lastDescriptionChanged(); 0064 void lastIconChanged(); 0065 0066 void blockingAppsReady(const QStringList &apps); 0067 0068 private Q_SLOTS: 0069 void onDeviceAdded(const QString &udi); 0070 void onDeviceRemoved(const QString &udi); 0071 0072 private: 0073 enum class SolidReplyType { 0074 Setup, 0075 Teardown, 0076 Eject, 0077 }; 0078 0079 void onSolidReply(SolidReplyType type, Solid::ErrorType error, const QVariant &errorData, const QString &udi); 0080 void notify(Solid::ErrorType error, const QString &errorMessage, const QString &errorData, const QString &udi, const QString &icon); 0081 0082 void connectSignals(Solid::Device &device); 0083 bool isSafelyRemovable(const QString &udi) const; 0084 void queryBlockingApps(const QString &devicePath); 0085 0086 QHash<QString, Solid::Device> m_devices; 0087 Solid::ErrorType m_lastErrorType = static_cast<Solid::ErrorType>(0); 0088 QString m_lastUdi; 0089 QString m_lastMessage; 0090 QString m_lastDescription; 0091 QString m_lastIcon; 0092 };