diff options
Diffstat (limited to 'api/logic/net/NetAction.h')
-rw-r--r-- | api/logic/net/NetAction.h | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/api/logic/net/NetAction.h b/api/logic/net/NetAction.h index a533c317..08e40a29 100644 --- a/api/logic/net/NetAction.h +++ b/api/logic/net/NetAction.h @@ -1,4 +1,4 @@ -/* Copyright 2013-2017 MultiMC Contributors +/* Copyright 2013-2018 MultiMC Contributors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,10 @@ enum JobStatus Job_Finished, Job_Failed, Job_Aborted, + /* + * FIXME: @NUKE this confuses the task failing with us having a fallback in the form of local data. Clear up the confusion. + * Same could be true for aborted task - the presence of pre-existing result is a separate concern + */ Job_Failed_Proceed }; @@ -43,18 +47,26 @@ protected: public: virtual ~NetAction() {}; -public: - virtual qint64 totalProgress() const + bool isRunning() const { - return m_total_progress; + return m_status == Job_InProgress; } - virtual qint64 currentProgress() const + bool isFinished() const { - return m_progress; + return m_status >= Job_Finished; } - virtual qint64 numberOfFailures() const + bool wasSuccessful() const { - return m_failures; + return m_status == Job_Finished || m_status == Job_Failed_Proceed; + } + + qint64 totalProgress() const + { + return m_total_progress; + } + qint64 currentProgress() const + { + return m_progress; } virtual bool abort() { @@ -64,25 +76,10 @@ public: { return false; } - -public: - /// the network reply - unique_qobject_ptr<QNetworkReply> m_reply; - - /// source URL - QUrl m_url; - - /// The file's status - JobStatus m_status = Job_NotStarted; - - /// index within the parent job - int m_index_within_job = 0; - - qint64 m_progress = 0; - qint64 m_total_progress = 1; - - /// number of failures up to this point - int m_failures = 0; + QUrl url() + { + return m_url; + } signals: void started(int index); @@ -91,14 +88,28 @@ signals: void failed(int index); void aborted(int index); -protected -slots: +protected slots: virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) = 0; virtual void downloadError(QNetworkReply::NetworkError error) = 0; virtual void downloadFinished() = 0; virtual void downloadReadyRead() = 0; -public -slots: +public slots: virtual void start() = 0; + +public: + /// index within the parent job, FIXME: nuke + int m_index_within_job = 0; + + /// the network reply + unique_qobject_ptr<QNetworkReply> m_reply; + + /// source URL + QUrl m_url; + + qint64 m_progress = 0; + qint64 m_total_progress = 1; + +protected: + JobStatus m_status = Job_NotStarted; }; |