mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #353 from apprb/speed
Fix #351 (File transfers exceed physical limitations)
This commit is contained in:
commit
f58c975668
|
@ -35,6 +35,7 @@ FileTransferInstance::FileTransferInstance(ToxFile File)
|
||||||
id = Idconter++;
|
id = Idconter++;
|
||||||
state = tsPending;
|
state = tsPending;
|
||||||
remotePaused = false;
|
remotePaused = false;
|
||||||
|
lastUpdateTime = QDateTime::currentDateTime();
|
||||||
|
|
||||||
filename = File.fileName;
|
filename = File.fileName;
|
||||||
QFont font;
|
QFont font;
|
||||||
|
@ -76,17 +77,16 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// state = tsProcessing;
|
// state = tsProcessing;
|
||||||
QDateTime newtime = QDateTime::currentDateTime();
|
QDateTime now = QDateTime::currentDateTime();
|
||||||
int timediff = started.secsTo(newtime);
|
if (lastUpdateTime.secsTo(now) < 1) //update every 1s
|
||||||
|
return;
|
||||||
|
|
||||||
|
int timediff = startTime.secsTo(now);
|
||||||
if (timediff <= 0)
|
if (timediff <= 0)
|
||||||
return;
|
return;
|
||||||
qint64 totalbytes = BytesSent + lastBytesSent; // bytes sent so far
|
|
||||||
if (totalbytes < 0)
|
long rawspeed = BytesSent / timediff;
|
||||||
{
|
|
||||||
qWarning() << "FileTransferInstance::onFileTransferInfo: Negative transfer speed !";
|
|
||||||
totalbytes = 0;
|
|
||||||
}
|
|
||||||
long rawspeed = totalbytes / timediff;
|
|
||||||
speed = getHumanReadableSize(rawspeed)+"/s";
|
speed = getHumanReadableSize(rawspeed)+"/s";
|
||||||
size = getHumanReadableSize(Filesize);
|
size = getHumanReadableSize(Filesize);
|
||||||
totalBytes = Filesize;
|
totalBytes = Filesize;
|
||||||
|
@ -96,7 +96,8 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t
|
||||||
QTime etaTime(0,0);
|
QTime etaTime(0,0);
|
||||||
etaTime = etaTime.addSecs(etaSecs);
|
etaTime = etaTime.addSecs(etaSecs);
|
||||||
eta = etaTime.toString("mm:ss");
|
eta = etaTime.toString("mm:ss");
|
||||||
lastBytesSent = totalbytes;
|
lastBytesSent = BytesSent;
|
||||||
|
lastUpdateTime = now;
|
||||||
emit stateUpdated();
|
emit stateUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +143,7 @@ void FileTransferInstance::onFileTransferAccepted(ToxFile File)
|
||||||
|
|
||||||
remotePaused = false;
|
remotePaused = false;
|
||||||
state = tsProcessing;
|
state = tsProcessing;
|
||||||
|
startTime = QDateTime::currentDateTime();
|
||||||
|
|
||||||
emit stateUpdated();
|
emit stateUpdated();
|
||||||
}
|
}
|
||||||
|
@ -221,7 +223,7 @@ void FileTransferInstance::acceptRecvRequest()
|
||||||
Core::getInstance()->acceptFileRecvRequest(friendId, fileNum, path);
|
Core::getInstance()->acceptFileRecvRequest(friendId, fileNum, path);
|
||||||
state = tsProcessing;
|
state = tsProcessing;
|
||||||
|
|
||||||
started = QDateTime::currentDateTime();
|
startTime = QDateTime::currentDateTime();
|
||||||
|
|
||||||
emit stateUpdated();
|
emit stateUpdated();
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ private:
|
||||||
QImage pic;
|
QImage pic;
|
||||||
QString filename, size, speed, eta;
|
QString filename, size, speed, eta;
|
||||||
QString filenameElided;
|
QString filenameElided;
|
||||||
QDateTime started;
|
QDateTime startTime, lastUpdateTime;
|
||||||
long long lastBytesSent, totalBytes;
|
long long lastBytesSent, totalBytes;
|
||||||
int fileNum;
|
int fileNum;
|
||||||
int friendId;
|
int friendId;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user