2020-12-05 13:08:24 +01:00
|
|
|
#pragma once
|
2020-07-01 20:48:19 +02:00
|
|
|
|
|
|
|
|
#include <QObject>
|
2020-12-06 13:15:19 +01:00
|
|
|
#include "util/atomic.hpp"
|
2020-07-01 20:48:19 +02:00
|
|
|
|
|
|
|
|
class curl_handle;
|
|
|
|
|
class progress_dialog;
|
|
|
|
|
|
|
|
|
|
class downloader : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2021-01-12 23:57:26 +01:00
|
|
|
explicit downloader(QWidget* parent = nullptr);
|
|
|
|
|
~downloader();
|
2020-07-01 20:48:19 +02:00
|
|
|
|
|
|
|
|
void start(const std::string& url, bool follow_location, bool show_progress_dialog, const QString& progress_dialog_title = "", bool keep_progress_dialog_open = false, int expected_size = -1);
|
2020-12-18 08:39:54 +01:00
|
|
|
usz update_buffer(char* data, usz size);
|
2020-07-01 20:48:19 +02:00
|
|
|
|
|
|
|
|
void update_progress_dialog(const QString& title);
|
|
|
|
|
void close_progress_dialog();
|
|
|
|
|
|
|
|
|
|
progress_dialog* get_progress_dialog() const;
|
|
|
|
|
|
2020-12-18 08:39:54 +01:00
|
|
|
static std::string get_hash(const char* data, usz size, bool lower_case);
|
2020-09-07 14:10:57 +02:00
|
|
|
|
2020-07-01 20:48:19 +02:00
|
|
|
private Q_SLOTS:
|
|
|
|
|
void handle_buffer_update(int size, int max);
|
|
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
|
void signal_download_error(const QString& error);
|
|
|
|
|
void signal_download_finished(const QByteArray& data);
|
|
|
|
|
void signal_buffer_update(int size, int max);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QWidget* m_parent = nullptr;
|
|
|
|
|
|
|
|
|
|
curl_handle* m_curl = nullptr;
|
|
|
|
|
QByteArray m_curl_buf;
|
2020-12-06 13:15:19 +01:00
|
|
|
atomic_t<bool> m_curl_abort = false;
|
|
|
|
|
atomic_t<bool> m_curl_success = false;
|
2020-07-01 20:48:19 +02:00
|
|
|
double m_actual_download_size = -1.0;
|
|
|
|
|
|
|
|
|
|
progress_dialog* m_progress_dialog = nullptr;
|
2020-12-06 13:15:19 +01:00
|
|
|
atomic_t<bool> m_keep_progress_dialog_open = false;
|
2020-07-01 20:48:19 +02:00
|
|
|
QString m_progress_dialog_title;
|
2021-01-12 23:57:26 +01:00
|
|
|
|
|
|
|
|
QThread* m_thread = nullptr;
|
2020-07-01 20:48:19 +02:00
|
|
|
};
|