1 /* === This file is part of Calamares - <https://calamares.io> ===
2  *
3  *   SPDX-FileCopyrightText: 2019-2020 Adriaan de Groot <groot@kde.org>
4  *   SPDX-License-Identifier: GPL-3.0-or-later
5  *
6  *   Calamares is Free Software: see the License-Identifier above.
7  *
8  *
9  */
10 
11 #ifndef CALAMARES_REQUIREMENTSMODEL_H
12 #define CALAMARES_REQUIREMENTSMODEL_H
13 
14 #include "Requirement.h"
15 
16 #include "DllMacro.h"
17 
18 #include <QAbstractListModel>
19 #include <QMutex>
20 
21 namespace Calamares
22 {
23 class RequirementsChecker;
24 
25 /** @brief System requirements from each module and their checked-status
26  *
27  * A Calamares module can have system requirements (e.g. check for
28  * internet, or amount of RAM, or an available disk) which can
29  * be stated and checked.
30  *
31  * This model collects those requirements, can run the checks, and
32  * reports on the overall status of those checks.
33  */
34 class DLLEXPORT RequirementsModel : public QAbstractListModel
35 {
36     friend class RequirementsChecker;
37 
38     Q_OBJECT
39     Q_PROPERTY( bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL )
40     Q_PROPERTY( bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL )
41     Q_PROPERTY( QString progressMessage READ progressMessage NOTIFY progressMessageChanged FINAL )
42 
43 public:
44     using QAbstractListModel::QAbstractListModel;
45 
46     enum Roles : short
47     {
48         Name,
49         Satisfied,
50         Mandatory,
51         Details,
52         NegatedText,
53         HasDetails
54     };
55     // No Q_ENUM because these are exposed through roleNames()
56 
57     ///@brief Are all the requirements satisfied?
satisfiedRequirements()58     bool satisfiedRequirements() const { return m_satisfiedRequirements; }
59     ///@brief Are all the **mandatory** requirements satisfied?
satisfiedMandatory()60     bool satisfiedMandatory() const { return m_satisfiedMandatory; }
61     ///@brief Message (from an ongoing check) about progress
progressMessage()62     QString progressMessage() const { return m_progressMessage; }
63 
64 
65     QVariant data( const QModelIndex& index, int role ) const override;
66     int rowCount( const QModelIndex& ) const override;
count()67     int count() const { return m_requirements.count(); }
68 
69     ///@brief Debugging tool, describe the checking-state
70     void describe() const;
71 
72 signals:
73     void satisfiedRequirementsChanged( bool value );
74     void satisfiedMandatoryChanged( bool value );
75     void progressMessageChanged( QString message );
76 
77 protected:
78     QHash< int, QByteArray > roleNames() const override;
79 
80     ///@brief Append some requirements; resets the model
81     void addRequirementsList( const Calamares::RequirementsList& requirements );
82 
83     ///@brief Update progress message (called by the checker)
84     void setProgressMessage( const QString& m );
85 
86 private:
87     ///@brief Implementation for {set,add}RequirementsList
88     void changeRequirementsList();
89 
90     QString m_progressMessage;
91     QMutex m_addLock;
92     RequirementsList m_requirements;
93     bool m_satisfiedRequirements = false;
94     bool m_satisfiedMandatory = false;
95 };
96 
97 }  // namespace Calamares
98 
99 #endif
100