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

change file eta to be overall average

handles jitter much better
This commit is contained in:
dubslow 2014-09-28 23:10:04 -05:00
parent 940cdfebba
commit a4d42a7136
2 changed files with 11 additions and 10 deletions

View File

@ -28,7 +28,7 @@
uint FileTransferInstance::Idconter = 0;
FileTransferInstance::FileTransferInstance(ToxFile File)
: lastUpdate{QDateTime::currentDateTime()}, lastBytesSent{0},
: lastBytesSent{0},
fileNum{File.fileNum}, friendId{File.friendId}, direction{File.direction}
{
id = Idconter++;
@ -72,16 +72,16 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t
// state = tsProcessing;
QDateTime newtime = QDateTime::currentDateTime();
int timediff = lastUpdate.secsTo(newtime);
int timediff = started.secsTo(newtime);
if (timediff <= 0)
return;
qint64 diff = BytesSent - lastBytesSent;
if (diff < 0)
qint64 totalbytes = BytesSent + lastBytesSent; // bytes sent so far
if (totalbytes < 0)
{
qWarning() << "FileTransferInstance::onFileTransferInfo: Negative transfer speed !";
diff = 0;
totalbytes = 0;
}
long rawspeed = diff / timediff;
long rawspeed = totalbytes / timediff;
speed = getHumanReadableSize(rawspeed)+"/s";
size = getHumanReadableSize(Filesize);
totalBytes = Filesize;
@ -91,8 +91,7 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t
QTime etaTime(0,0);
etaTime = etaTime.addSecs(etaSecs);
eta = etaTime.toString("mm:ss");
lastUpdate = newtime;
lastBytesSent = BytesSent;
lastBytesSent = totalbytes;
emit stateUpdated();
}
@ -197,7 +196,7 @@ void FileTransferInstance::acceptRecvRequest()
QString path;
while (true)
{
path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::current().filePath(filename));
path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(filename));
if (path.isEmpty())
return;
else
@ -217,6 +216,8 @@ void FileTransferInstance::acceptRecvRequest()
Core::getInstance()->acceptFileRecvRequest(friendId, fileNum, path);
state = tsProcessing;
started = QDateTime::currentDateTime();
emit stateUpdated();
}

View File

@ -73,7 +73,7 @@ private:
QImage pic;
QString filename, size, speed, eta;
QString filenameElided;
QDateTime lastUpdate;
QDateTime started;
long long lastBytesSent, totalBytes;
int fileNum;
int friendId;