File indexing completed on 2024-04-14 15:39:43

0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0002 // SPDX-FileCopyrightText: 2020-2021 Harald Sitter <sitter@kde.org>
0003 
0004 #pragma once
0005 
0006 #include <QObject>
0007 
0008 namespace Solid
0009 {
0010 class Device;
0011 }
0012 
0013 class Device : public QObject
0014 {
0015     Q_OBJECT
0016     Q_CLASSINFO("D-Bus Interface", "org.kde.kded.smart.Device")
0017     Q_PROPERTY(QString udi READ udi CONSTANT)
0018     Q_PROPERTY(QString product READ product CONSTANT)
0019     Q_PROPERTY(QString path READ path CONSTANT)
0020     /**
0021      * A list of hints at problems that aren't failures.
0022      * This may be non-empty even when failure is true, failure does outrank this information though!
0023      * An instability is for example a pre-fail attribute or a self-test failure.
0024      * They may point at (imminent) problems but may just as well be nothing. Think of them as soft failures.
0025      */
0026     Q_PROPERTY(QStringList instabilities READ instabilities WRITE setInstabilities NOTIFY instabilitiesChanged)
0027     // We dbus-expose objects without adaptor so the property API reflects the dbus API
0028     // and so be mindful of what is available as writable property.
0029     // 'failed' is writable for ease of testing and nothing more.
0030     Q_PROPERTY(bool failed READ failed WRITE setFailed NOTIFY failedChanged)
0031     Q_PROPERTY(bool ignore READ ignore WRITE setIgnore NOTIFY ignoreChanged)
0032     Q_PROPERTY(QString advancedReport READ advancedReport NOTIFY advancedReportChanged)
0033 public:
0034     Device(const QString &udi_, const QString &product_, const QString &path_, QObject *parent = nullptr);
0035     explicit Device(const Solid::Device &solidDevice, QObject *parent = nullptr);
0036 
0037     bool operator==(const Device &other) const;
0038 
0039     bool failed() const;
0040     void setFailed(bool failed);
0041 
0042     bool ignore() const;
0043     void setIgnore(bool ignore);
0044 
0045     QString udi() const
0046     {
0047         return m_udi;
0048     }
0049 
0050     QString product() const
0051     {
0052         return m_product;
0053     }
0054 
0055     QString path() const
0056     {
0057         return m_path;
0058     }
0059 
0060     QStringList instabilities() const;
0061     void setInstabilities(const QStringList &instabilities);
0062 
0063     QString advancedReport() const;
0064     void setAdvancedReport(const QString &report);
0065     Q_SIGNAL void advancedReportChanged();
0066 
0067 signals:
0068     void instabilitiesChanged();
0069     void failedChanged();
0070     void ignoreChanged();
0071 
0072 private:
0073     const QString m_udi;
0074     const QString m_product;
0075     const QString m_path;
0076     QStringList m_instabilities;
0077     bool m_failed = false;
0078     bool m_ignored = false;
0079     QString m_advancedReport;
0080 };