|
@@ -14,6 +14,29 @@ class Downloader : public QObject
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
|
|
+ struct Status {
|
|
|
+ bool started;
|
|
|
+ double percent;
|
|
|
+
|
|
|
+ quint64 total_bytes;
|
|
|
+ quint64 downloaded_bytes;
|
|
|
+ quint64 current_speed;
|
|
|
+ quint64 average_speed;
|
|
|
+ quint64 elapsed_time;
|
|
|
+ };
|
|
|
+
|
|
|
+ Status operator+(const Status& a, const Status &b) {
|
|
|
+ Status result = {
|
|
|
+ a.started || b.started,
|
|
|
+ (a.percent + b.percent) / 2.0,
|
|
|
+ a.total_bytes + b.total_bytes,
|
|
|
+ a.downloaded_bytes + b.downloaded_bytes,
|
|
|
+ a.average_speed + b.average_speed,
|
|
|
+ qMax(a.elapsed_time, b.elapsed_time)
|
|
|
+ };
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
explicit Downloader(QObject *parent = 0);
|
|
|
private:
|
|
|
Q_DISABLE_COPY(Downloader)
|
|
@@ -30,14 +53,18 @@ public:
|
|
|
quint64 getBytesTotal();
|
|
|
quint64 getBytesDownloaded();
|
|
|
quint64 getElapsedTime();
|
|
|
- quint64 getSpeed();
|
|
|
+ quint64 getCurrentSpeed();
|
|
|
+ quint64 getAverageSpeed();
|
|
|
+
|
|
|
+ Status getDownloadStatus();
|
|
|
+
|
|
|
static QString getSizeFormatted(quint64 bytes);
|
|
|
static QString getSpeedFormatted(quint64 speed_bytes_per_sec);
|
|
|
static QString getElapsedTimeFormatted(quint64 elapsed_time_secs);
|
|
|
|
|
|
signals:
|
|
|
void downloadFinished(Downloader* this_downloader_ptr);
|
|
|
- void progressChanged(Downloader* this_downloader_ptr);
|
|
|
+ void progressChanged(Downloader* this_downloader_ptr, Status status);
|
|
|
|
|
|
public slots:
|
|
|
void start();
|
|
@@ -56,6 +83,8 @@ public:
|
|
|
private:
|
|
|
QTime downloadTime;
|
|
|
quint64 download_speed; // bytes per second
|
|
|
+ quint64 average_speed;
|
|
|
+ quint64 speed_update_ticks;
|
|
|
|
|
|
quint64 bytes_total;
|
|
|
quint64 bytes_downloaded;
|