void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection Direction) { if (FileNum != fileNum || FriendId != friendId || Direction != direction) return; // state = tsProcessing; QDateTime newtime = QDateTime::currentDateTime(); int timediff = lastUpdate.secsTo(newtime); if (timediff <= 0) return; qint64 diff = BytesSent - lastBytesSent; if (diff < 0) { qWarning() << "FileTransferInstance::onFileTransferInfo: Negative transfer speed !"; diff = 0; } long rawspeed = diff / timediff; speed = getHumanReadableSize(rawspeed)+"/s"; size = getHumanReadableSize(Filesize); if (!rawspeed) return; int etaSecs = (Filesize - BytesSent) / rawspeed; QTime etaTime(0,0); etaTime = etaTime.addSecs(etaSecs); eta = etaTime.toString("mm:ss"); lastUpdate = newtime; lastBytesSent = BytesSent; emit stateUpdated(); }
void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection Direction) { if (FileNum != fileNum || FriendId != friendId || Direction != direction) return; // state = tsProcessing; QDateTime now = QDateTime::currentDateTime(); if (lastUpdateTime.secsTo(now) < 1) //update every 1s return; int timediff = startTime.secsTo(now); if (timediff <= 0) return; long rawspeed = BytesSent / timediff; speed = getHumanReadableSize(rawspeed)+"/s"; size = getHumanReadableSize(Filesize); totalBytes = Filesize; if (!rawspeed) return; int etaSecs = (Filesize - BytesSent) / rawspeed; QTime etaTime(0,0); etaTime = etaTime.addSecs(etaSecs); eta = etaTime.toString("mm:ss"); lastBytesSent = BytesSent; lastUpdateTime = now; emit stateUpdated(); }
QString CFileTransferAction::drawProgressBar() { QString content; content += "<tr><td>" + GetHumanReadableSize(m_File->GetFileSize()) + "</td>"; content += "<td align=center>" + GetHumanReadableSize(m_File->GetSpeed()) + "/s</td>"; int etaSecs = 0; if(m_File->GetSpeed()) etaSecs = (m_File->GetFileSize() - m_File->GetDoneSize()) / m_File->GetSpeed(); QTime etaTime(0,0); etaTime = etaTime.addSecs(etaSecs); content += "<td align=right>" + tr("ETA: ") + etaTime.toString("hh:mm:ss") + "</td>"; content += "</tr><tr><td colspan=3>"; if(m_File->GetError() == CFileTransfer::AbortError || m_File->GetError() != CFileTransfer::NoError) content += QImage2Html(drawProgressBarImg(1, m_ProgBarWidth, m_ProgBarHeight, Qt::red, Qt::red)); else content += QImage2Html(drawProgressBarImg((double)m_File->GetDoneSize()/(double)m_File->GetFileSize(), m_ProgBarWidth, m_ProgBarHeight)); content += "</td></tr>"; return content; }