2024-06-01 13:30:04 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
|
|
|
|
* Copyright (C) 2024 Tom Zander <tom@flowee.org>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2024-05-31 21:51:57 +02:00
|
|
|
#ifndef BLOCKHEADERSCHECKER_H
|
|
|
|
|
#define BLOCKHEADERSCHECKER_H
|
|
|
|
|
|
2024-06-01 13:30:04 +02:00
|
|
|
#include <QFile>
|
|
|
|
|
#include <QNetworkAccessManager>
|
2024-05-31 21:51:57 +02:00
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
|
|
class BlockHeadersChecker : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2024-06-01 13:30:04 +02:00
|
|
|
Q_PROPERTY(int wantedHeight READ wantedHeight WRITE setWantedHeight NOTIFY wantedHeightChanged FINAL)
|
2024-06-03 10:49:26 +02:00
|
|
|
Q_PROPERTY(int totalDownload READ totalDownload NOTIFY totalDownloadChanged FINAL)
|
|
|
|
|
Q_PROPERTY(int bytesDownloaded READ bytesDownloaded NOTIFY bytesDownloadedChanged FINAL)
|
2024-06-30 22:27:32 +02:00
|
|
|
Q_PROPERTY(Status status READ status NOTIFY statusChanged FINAL)
|
2024-05-31 21:51:57 +02:00
|
|
|
public:
|
|
|
|
|
BlockHeadersChecker(QObject *parent = nullptr);
|
|
|
|
|
|
2024-06-03 10:49:26 +02:00
|
|
|
enum Status {
|
|
|
|
|
Unset,
|
2024-06-03 20:32:45 +02:00
|
|
|
NoDownloadNeeded,
|
2024-06-03 10:49:26 +02:00
|
|
|
Checking,
|
|
|
|
|
Downloading,
|
|
|
|
|
Verifying,
|
2024-06-03 20:32:45 +02:00
|
|
|
Success,
|
2024-06-03 10:49:26 +02:00
|
|
|
|
|
|
|
|
DiskFailure,
|
|
|
|
|
NetworkFailure
|
|
|
|
|
};
|
|
|
|
|
Q_ENUM(Status)
|
|
|
|
|
|
2024-06-01 13:30:04 +02:00
|
|
|
int wantedHeight() const;
|
|
|
|
|
void setWantedHeight(int h);
|
|
|
|
|
|
2024-06-03 10:49:26 +02:00
|
|
|
/// the download progress in bytes
|
2024-06-01 13:30:04 +02:00
|
|
|
void setBytesDownloaded(int count);
|
|
|
|
|
int bytesDownloaded();
|
|
|
|
|
|
2024-06-03 10:49:26 +02:00
|
|
|
/// the download target in bytes
|
|
|
|
|
int totalDownload() const;
|
|
|
|
|
void setTotalDownload(int newTotalDownload);
|
|
|
|
|
|
|
|
|
|
void setStatus(Status newStatus);
|
2024-06-30 22:27:32 +02:00
|
|
|
Status status() const;
|
2024-06-03 10:49:26 +02:00
|
|
|
|
2024-06-29 11:57:47 +02:00
|
|
|
Q_INVOKABLE void restart();
|
|
|
|
|
|
2024-06-01 13:30:04 +02:00
|
|
|
signals:
|
|
|
|
|
void wantedHeightChanged();
|
|
|
|
|
void bytesDownloadedChanged();
|
2024-06-03 10:49:26 +02:00
|
|
|
void totalDownloadChanged();
|
|
|
|
|
void statusChanged();
|
2024-06-30 22:27:32 +02:00
|
|
|
// helper signal for threading.
|
|
|
|
|
void finishUp(Status status);
|
2024-06-01 13:30:04 +02:00
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void startChecking();
|
|
|
|
|
void headerReturned();
|
|
|
|
|
void downloadFinished();
|
|
|
|
|
void onBytesDownloaded();
|
|
|
|
|
|
|
|
|
|
private:
|
2024-06-30 22:27:32 +02:00
|
|
|
void processNewHeaders();
|
|
|
|
|
|
2024-06-01 13:30:04 +02:00
|
|
|
int m_wantedHeight = 0;
|
|
|
|
|
int m_checkpoint = 0; // start download at checkpoint-height
|
|
|
|
|
int m_downloadTo = 0; // download to this point (we have the rest)
|
2024-06-03 10:49:26 +02:00
|
|
|
int m_totalDownload = 0;
|
2024-06-01 13:30:04 +02:00
|
|
|
int m_bytesDownloaded = 0; // download progress
|
|
|
|
|
|
|
|
|
|
QNetworkAccessManager m_network;
|
|
|
|
|
QNetworkReply *m_headerReply = nullptr;
|
|
|
|
|
QNetworkReply *m_downloadReply = nullptr;
|
|
|
|
|
QFile *m_newHeaders = nullptr;
|
2024-06-03 10:49:26 +02:00
|
|
|
Status m_status = Unset;
|
2024-05-31 21:51:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|