File indexing completed on 2024-05-05 17:33:21
0001 /* 0002 * SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #pragma once 0008 0009 #include "discovercommon_export.h" 0010 #include "resources/AbstractBackendUpdater.h" 0011 #include <QDateTime> 0012 #include <QPointer> 0013 #include <QStandardItemModel> 0014 0015 class AbstractResource; 0016 class UpdateTransaction; 0017 class Transaction; 0018 0019 class DISCOVERCOMMON_EXPORT ResourcesUpdatesModel : public QStandardItemModel 0020 { 0021 Q_OBJECT 0022 Q_PROPERTY(bool isProgressing READ isProgressing NOTIFY progressingChanged) 0023 Q_PROPERTY(QDateTime lastUpdate READ lastUpdate NOTIFY progressingChanged) 0024 Q_PROPERTY(qint64 secsToLastUpdate READ secsToLastUpdate NOTIFY progressingChanged) 0025 Q_PROPERTY(Transaction *transaction READ transaction NOTIFY progressingChanged) 0026 Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged) 0027 Q_PROPERTY(bool readyToReboot READ readyToReboot) 0028 Q_PROPERTY(bool useUnattendedUpdates READ useUnattendedUpdates NOTIFY useUnattendedUpdatesChanged) 0029 Q_PROPERTY(QStringList errorMessages READ errorMessages NOTIFY errorMessagesChanged) 0030 public: 0031 explicit ResourcesUpdatesModel(QObject *parent = nullptr); 0032 0033 Q_SCRIPTABLE void prepare(); 0034 0035 void setOfflineUpdates(bool offline); 0036 bool isProgressing() const; 0037 QList<AbstractResource *> toUpdate() const; 0038 QDateTime lastUpdate() const; 0039 double updateSize() const; 0040 void addResources(const QList<AbstractResource *> &resources); 0041 void removeResources(const QList<AbstractResource *> &resources); 0042 0043 qint64 secsToLastUpdate() const; 0044 QVector<AbstractBackendUpdater *> updaters() const 0045 { 0046 return m_updaters; 0047 } 0048 Transaction *transaction() const; 0049 bool needsReboot() const; 0050 bool readyToReboot() const; 0051 bool useUnattendedUpdates() const; 0052 QStringList errorMessages() const; 0053 0054 Q_SIGNALS: 0055 void downloadSpeedChanged(); 0056 void progressingChanged(); 0057 void finished(); 0058 void resourceProgressed(AbstractResource *resource, qreal progress, AbstractBackendUpdater::State state); 0059 void passiveMessage(const QString &message); 0060 void needsRebootChanged(); 0061 void useUnattendedUpdatesChanged(); 0062 void fetchingUpdatesProgressChanged(int percent); 0063 void errorMessagesChanged(); 0064 0065 public Q_SLOTS: 0066 void updateAll(); 0067 0068 private Q_SLOTS: 0069 void updaterDestroyed(QObject *obj); 0070 void message(const QString &msg); 0071 0072 private: 0073 void init(); 0074 void setTransaction(UpdateTransaction *transaction); 0075 0076 QVector<AbstractBackendUpdater *> m_updaters; 0077 bool m_lastIsProgressing; 0078 bool m_offlineUpdates = false; 0079 QPointer<UpdateTransaction> m_transaction; 0080 QStringList m_errorMessages; 0081 };