Skip to content

Commit

Permalink
Added display for downloadspeed
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertKrajewski committed Dec 29, 2014
1 parent 1b9853b commit 5f53a9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions filedownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ int FileDownloader::startNextDownload(QString fileName, QString courseName, QStr
ui->dateinameLabel->setText(fileName);
ui->progressBar->setFormat(QString("%v ") % correctUnit(itemSize) % " / %m " % correctUnit(itemSize));
ui->progressBar->setMaximum(correctSize(itemSize));
ui->downloadSpeedLabel->setText("");

times.actime = 0;
times.modtime = time;
Expand All @@ -65,6 +66,8 @@ int FileDownloader::startNextDownload(QString fileName, QString courseName, QStr
return 0;
}

downloadTime.start();

// Start des Requests
reply = manager->get(QNetworkRequest(fileUrl));
QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgressSlot(qint64,qint64)));
Expand All @@ -83,6 +86,10 @@ void FileDownloader::downloadProgressSlot(qint64 bytesReceived, qint64 bytesTota
// Aktualisieren der Progressbar anhand der Größe der empfangenen Bytes
ui->progressBar->setValue(correctSize(bytesReceived));
ui->progressBar->update();

// Downloadgeschwindigkeit in kB/s
int downloadSpeed = bytesReceived * 1000 / downloadTime.elapsed() / 1024;
ui->downloadSpeedLabel->setText(QString::number(downloadSpeed) % " kB/s");
}

/// Abspeichern von empfangenen Dateiteilen
Expand Down
2 changes: 2 additions & 0 deletions filedownloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class FileDownloader : public QDialog
QString correctUnit(qint64 bytes);
qint64 correctSize(qint64 bytes);

QTime downloadTime;

private slots:
void downloadProgressSlot(qint64,qint64);
void readyReadSlot();
Expand Down

0 comments on commit 5f53a9b

Please sign in to comment.