progress.cpp Example File
btfiletransfer/progress.cpp
#include "progress.h"
#include "ui_progress.h"
#include <qbluetoothdeviceinfo.h>
#include <qbluetoothaddress.h>
#include <qbluetoothtransferrequest.h>
#include <qbluetoothtransferreply.h>
QT_USE_NAMESPACE
Progress::Progress(QWidget *parent) :
QDialog(parent),
ui(new Ui::Progress)
{
ui->setupUi(this);
ui->progressBar->setRange(0, 1);
connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(close()));
}
Progress::~Progress()
{
delete ui;
}
void Progress::setStatus(QString title, QString filename) {
ui->titleLabel->setText(title);
ui->statusLabel->setText(filename);
}
void Progress::finished(QBluetoothTransferReply *reply){
if (reply->error() != QBluetoothTransferReply::NoError){
ui->progressBar->setDisabled(true);
ui->statusLabel->setText(tr("Failed: %1").arg(reply->errorString()));
}
else {
ui->statusLabel->setText(tr("Transfer complete"));
}
ui->cancelButton->setText(tr("Dismiss"));
}
void Progress::uploadProgress(qint64 bytesSent, qint64 bytesTotal)
{
if (bytesSent == 0){
start.start();
}
ui->progressBar->setMaximum(bytesTotal);
ui->progressBar->setValue(bytesSent);
if (bytesSent && bytesTotal &&
(start.elapsed() > 1000) &&
(bytesSent > start.elapsed()/1000)) {
ui->statusLabel->setText(tr("Transferring...ETA: %1s")
.arg(((bytesTotal-bytesSent)/(bytesSent/(start.elapsed()/1000)))));
}
}