File indexing completed on 2024-05-05 17:33:20
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 <QObject> 0011 0012 class QDateTime; 0013 class AbstractResource; 0014 0015 /** 0016 * \class AbstractBackendUpdater AbstractBackendUpdater.h "AbstractBackendUpdater.h" 0017 * 0018 * \brief This is the base class for all abstract classes, which handle system upgrades. 0019 * 0020 * While implementing this is not mandatory for all backends (you can also use the 0021 * StandardBackendUpdater, which just uses the functions in the ResourcesBackend to 0022 * update the packages), it is recommended for many. 0023 * 0024 * Before starting the update, the AbstractBackendUpdater will have to keep a list of 0025 * packages, which are about to be upgraded. First, all packages have to be inserted 0026 * into this list in the \prepare method and they can then be changed by the user through 0027 * the \addResources and \removeResources functions. 0028 * 0029 * When \start is called, the AbstractBackendUpdater should start the update and report its 0030 * progress through the rest of methods outlined in this API documentation. 0031 * 0032 * @see addResources 0033 * @see removeResources 0034 * @see start 0035 * @see prepare 0036 */ 0037 class DISCOVERCOMMON_EXPORT AbstractBackendUpdater : public QObject 0038 { 0039 Q_OBJECT 0040 Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) 0041 Q_PROPERTY(bool isCancelable READ isCancelable NOTIFY cancelableChanged) 0042 Q_PROPERTY(bool isProgressing READ isProgressing NOTIFY progressingChanged) 0043 Q_PROPERTY(bool needsReboot READ needsReboot NOTIFY needsRebootChanged) 0044 Q_PROPERTY(quint64 downloadSpeed READ downloadSpeed NOTIFY downloadSpeedChanged) 0045 Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) 0046 public: 0047 enum State { 0048 None, 0049 Downloading, 0050 Installing, 0051 Done, 0052 }; 0053 Q_ENUM(State) 0054 0055 /** 0056 * Constructs an AbstractBackendUpdater 0057 */ 0058 explicit AbstractBackendUpdater(QObject *parent = nullptr); 0059 0060 /** 0061 * This method is called, when Discover switches to the updates view. 0062 * Here the backend should mark all upgradeable packages as to be upgraded. 0063 */ 0064 virtual void prepare() = 0; 0065 0066 /** 0067 * @returns true if the backend contains packages which can be updated 0068 */ 0069 virtual bool hasUpdates() const = 0; 0070 /** 0071 * @returns the progress of the update in percent 0072 */ 0073 virtual qreal progress() const = 0; 0074 0075 /** 0076 * This method is used to remove resources from the list of packages 0077 * marked to be upgraded. It will potentially be called before \start. 0078 */ 0079 virtual void removeResources(const QList<AbstractResource *> &apps) = 0; 0080 /** 0081 * This method is used to add resource to the list of packages marked to be upgraded. 0082 * It will potentially be called before \start. 0083 */ 0084 virtual void addResources(const QList<AbstractResource *> &apps) = 0; 0085 0086 /** 0087 * @returns the list of updateable resources in the system 0088 */ 0089 virtual QList<AbstractResource *> toUpdate() const = 0; 0090 0091 /** 0092 * @returns the QDateTime when the last update happened 0093 */ 0094 virtual QDateTime lastUpdate() const = 0; 0095 0096 /** 0097 * @returns whether the updater can currently be canceled or not 0098 * @see cancelableChanged 0099 */ 0100 virtual bool isCancelable() const = 0; 0101 /** 0102 * @returns whether the updater is currently running or not 0103 * this property decides, if there will be progress reporting in the GUI. 0104 * This has to stay true during the whole transaction! 0105 * @see progressingChanged 0106 */ 0107 virtual bool isProgressing() const = 0; 0108 0109 /** 0110 * @returns whether @p res is marked for update 0111 */ 0112 virtual bool isMarked(AbstractResource *res) const = 0; 0113 0114 virtual void fetchChangelog() const; 0115 0116 /** 0117 * @returns the size of all the packages set to update combined 0118 */ 0119 virtual double updateSize() const = 0; 0120 0121 /** 0122 * @returns the speed at which we are downloading 0123 */ 0124 virtual quint64 downloadSpeed() const = 0; 0125 0126 void enableNeedsReboot(); 0127 void enableReadyToReboot(); 0128 0129 bool isReadyToReboot() const; 0130 bool needsReboot() const; 0131 0132 virtual void setOfflineUpdates(bool useOfflineUpdates); 0133 0134 public Q_SLOTS: 0135 /** 0136 * If \isCancelable is true during the transaction, this method has 0137 * to be implemented and will potentially be called when the user 0138 * wants to cancel the update. 0139 */ 0140 virtual void cancel(); 0141 /** 0142 * This method starts the update. All packages which are in \toUpdate 0143 * are going to be updated. 0144 * 0145 * From this moment on the AbstractBackendUpdater should continuously update 0146 * the other methods to show its progress. 0147 * 0148 * @see progress 0149 * @see progressChanged 0150 * @see isProgressing 0151 * @see progressingChanged 0152 */ 0153 virtual void start() = 0; 0154 0155 /** 0156 * Answers a proceed request 0157 */ 0158 virtual void proceed() 0159 { 0160 } 0161 0162 void setErrorMessage(const QString &errorMessage); 0163 QString errorMessage() const 0164 { 0165 return m_errorMessage; 0166 } 0167 0168 Q_SIGNALS: 0169 /** 0170 * The AbstractBackendUpdater should Q_EMIT this signal when the progress changed. 0171 * @see progress 0172 */ 0173 void progressChanged(qreal progress); 0174 /** 0175 * The AbstractBackendUpdater should Q_EMIT this signal when the cancelable property changed. 0176 * @see isCancelable 0177 */ 0178 void cancelableChanged(bool cancelable); 0179 /** 0180 * The AbstractBackendUpdater should Q_EMIT this signal when the progressing property changed. 0181 * @see isProgressing 0182 */ 0183 void progressingChanged(bool progressing); 0184 /** 0185 * The AbstractBackendUpdater should Q_EMIT this signal when the status detail changed. 0186 * @see statusDetail 0187 */ 0188 void statusDetailChanged(const QString &msg); 0189 /** 0190 * The AbstractBackendUpdater should Q_EMIT this signal when the status message changed. 0191 * @see statusMessage 0192 */ 0193 void statusMessageChanged(const QString &msg); 0194 /** 0195 * The AbstractBackendUpdater should Q_EMIT this signal when the download speed changed. 0196 * @see downloadSpeed 0197 */ 0198 void downloadSpeedChanged(quint64 downloadSpeed); 0199 0200 /** 0201 * Provides the @p progress of a specific @p resource in a percentage. 0202 */ 0203 void resourceProgressed(AbstractResource *resource, qreal progress, AbstractBackendUpdater::State state); 0204 0205 void passiveMessage(const QString &message); 0206 0207 /** 0208 * Provides a message to be shown to the user 0209 * 0210 * The user gets to acknowledge and proceed or cancel the transaction. 0211 * 0212 * @sa proceed(), cancel() 0213 */ 0214 void proceedRequest(const QString &title, const QString &description); 0215 0216 /** 0217 * A fatal error was found on distro packaging. Provide a @p message to show 0218 * in a modal dialog that should lead the user towards reporting the problem.. 0219 */ 0220 void distroErrorMessage(const QString &message); 0221 0222 /** 0223 * emitted when the updater decides it needs to reboot 0224 */ 0225 void needsRebootChanged(); 0226 0227 /** emitted when we find a new errorMessage to display */ 0228 void errorMessageChanged(); 0229 0230 private: 0231 bool m_needsReboot = false; 0232 bool m_readyToReboot = false; 0233 QString m_errorMessage; 0234 };