1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

filetransferwidget: fixed pause button, ETA, font size, resource usage

This commit is contained in:
krepa098 2015-01-04 12:04:30 +01:00
parent f630583e59
commit ea467152aa
4 changed files with 42 additions and 30 deletions

View File

@ -91,38 +91,44 @@ void FileTransferWidget::onFileTransferInfo(ToxFile file)
fileInfo = file; fileInfo = file;
// update progress if(fileInfo.status == ToxFile::TRANSMITTING)
qreal progress = static_cast<qreal>(file.bytesSent) / static_cast<qreal>(file.filesize);
ui->progressBar->setValue(static_cast<int>(progress * 100.0));
// eta, speed
QTime now = QTime::currentTime();
qreal deltaSecs = lastTick.msecsTo(now) / 1000.0;
if(deltaSecs >= 1.0)
{ {
qint64 deltaBytes = file.bytesSent - lastBytesSent; // update progress
qint64 bytesPerSec = static_cast<int>(static_cast<qreal>(deltaBytes) / deltaSecs); qreal progress = static_cast<qreal>(file.bytesSent) / static_cast<qreal>(file.filesize);
ui->progressBar->setValue(static_cast<int>(progress * 100.0));
if(bytesPerSec > 0) // eta, speed
QTime now = QTime::currentTime();
qreal deltaSecs = lastTick.msecsTo(now) / 1000.0;
if(deltaSecs >= 1.0)
{ {
QTime toGo(0,0,file.filesize / bytesPerSec); qint64 deltaBytes = file.bytesSent - lastBytesSent;
ui->etaLabel->setText(toGo.toString("mm:ss")); qint64 bytesPerSec = static_cast<int>(static_cast<qreal>(deltaBytes) / deltaSecs);
}
else
{
ui->etaLabel->setText("--:--");
}
ui->progressLabel->setText(getHumanReadableSize(bytesPerSec) + "/s"); if(bytesPerSec > 0)
{
QTime toGo = QTime(0,0).addSecs(file.filesize / bytesPerSec);
ui->etaLabel->setText(toGo.toString("mm:ss"));
}
else
{
ui->etaLabel->setText("--:--");
}
lastTick = now; ui->progressLabel->setText(getHumanReadableSize(bytesPerSec) + "/s");
lastBytesSent = file.bytesSent;
lastTick = now;
lastBytesSent = file.bytesSent;
}
}
else if(fileInfo.status == ToxFile::PAUSED)
{
ui->etaLabel->setText("--:--");
ui->progressLabel->setText(getHumanReadableSize(0) + "/s");
} }
setupButtons(); update();
repaint();
} }
void FileTransferWidget::onFileTransferAccepted(ToxFile file) void FileTransferWidget::onFileTransferAccepted(ToxFile file)
@ -161,6 +167,9 @@ void FileTransferWidget::onFileTransferPaused(ToxFile file)
fileInfo = file; fileInfo = file;
ui->etaLabel->setText("--:--");
ui->progressLabel->setText(getHumanReadableSize(0) + "/s");
setStyleSheet(Style::getStylesheet(":/ui/fileTransferInstance/grey.css")); setStyleSheet(Style::getStylesheet(":/ui/fileTransferInstance/grey.css"));
Style::repolish(this); Style::repolish(this);
@ -254,20 +263,20 @@ void FileTransferWidget::handleButton(QPushButton *btn)
{ {
if(btn->objectName() == "cancel") if(btn->objectName() == "cancel")
Core::getInstance()->cancelFileSend(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->cancelFileSend(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "pause") else if(btn->objectName() == "pause")
Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "resume") else if(btn->objectName() == "resume")
Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->pauseResumeFileSend(fileInfo.friendId, fileInfo.fileNum);
} }
else else
{ {
if(btn->objectName() == "cancel") if(btn->objectName() == "cancel")
Core::getInstance()->cancelFileRecv(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->cancelFileRecv(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "pause") else if(btn->objectName() == "pause")
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "resume") else if(btn->objectName() == "resume")
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "accept") else if(btn->objectName() == "accept")
{ {
QString path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(fileInfo.fileName)); QString path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(fileInfo.fileName));
acceptTransfer(path); acceptTransfer(path);

View File

@ -8,6 +8,7 @@ QFrame {
QLabel { QLabel {
color:white; color:white;
font:@medium;
} }
QPushButton { QPushButton {

View File

@ -8,6 +8,7 @@ QFrame {
QLabel { QLabel {
color:white; color:white;
font:@medium;
} }
QPushButton { QPushButton {

View File

@ -8,6 +8,7 @@ QFrame {
QLabel { QLabel {
color:black; color:black;
font:@medium;
} }
QPushButton { QPushButton {