From f173a5dfa9af19a2f1db6b6fcc7b8b86e647ecc2 Mon Sep 17 00:00:00 2001 From: "Tux3 / Mlkj / !Lev.uXFMLA" Date: Sat, 12 Jul 2014 18:40:01 +0200 Subject: [PATCH] Fix FT progressbar int overflow --- core.cpp | 2 +- core.h | 2 +- widget/filetransfertwidget.cpp | 5 +++-- widget/filetransfertwidget.h | 2 +- widget/widget.cpp | 3 ++- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core.cpp b/core.cpp index 2086c8dd3..fa78d96e5 100644 --- a/core.cpp +++ b/core.cpp @@ -334,7 +334,7 @@ void Core::onFileDataCallback(Tox*, int32_t friendnumber, uint8_t filenumber, co file->file->write((char*)data,length); file->bytesSent += length; - //qDebug() << QString("Core::onFileDataCallback: received %1/%2 bytes").arg(file->fileData.size()).arg(file->filesize); + //qDebug() << QString("Core::onFileDataCallback: received %1/%2 bytes").arg(file->bytesSent).arg(file->filesize); emit static_cast(core)->fileTransferInfo(file->friendId, file->fileNum, file->filesize, file->bytesSent, ToxFile::RECEIVING); } diff --git a/core.h b/core.h index bcff81cb5..91bbee5e2 100644 --- a/core.h +++ b/core.h @@ -219,7 +219,7 @@ signals: void fileUploadFinished(const QString& path); void fileDownloadFinished(const QString& path); void fileTransferPaused(int FriendId, int FileNum, ToxFile::FileDirection direction); - void fileTransferInfo(int FriendId, int FileNum, int Filesize, int BytesSent, ToxFile::FileDirection direction); + void fileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection direction); void avInvite(int friendId, int callIndex, bool video); void avStart(int friendId, int callIndex, bool video); diff --git a/widget/filetransfertwidget.cpp b/widget/filetransfertwidget.cpp index 64600b2f0..952aca2cf 100644 --- a/widget/filetransfertwidget.cpp +++ b/widget/filetransfertwidget.cpp @@ -159,7 +159,7 @@ QString FileTransfertWidget::getHumanReadableSize(int size) return QString().setNum(size / pow(1024, exp),'g',3).append(suffix[exp]); } -void FileTransfertWidget::onFileTransferInfo(int FriendId, int FileNum, int Filesize, int BytesSent, ToxFile::FileDirection Direction) +void FileTransfertWidget::onFileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection Direction) { if (FileNum != fileNum || FriendId != friendId || Direction != direction) return; @@ -167,7 +167,7 @@ void FileTransfertWidget::onFileTransferInfo(int FriendId, int FileNum, int File int timediff = lastUpdate.secsTo(newtime); if (timediff <= 0) return; - int diff = BytesSent - lastBytesSent; + qint64 diff = BytesSent - lastBytesSent; if (diff < 0) { qWarning() << "FileTransfertWidget::onFileTransferInfo: Negative transfer speed !"; @@ -186,6 +186,7 @@ void FileTransfertWidget::onFileTransferInfo(int FriendId, int FileNum, int File progress->setValue(0); else progress->setValue(BytesSent*100/Filesize); + qDebug() << QString("FT: received %1/%2 bytes, progress is %3%").arg(BytesSent).arg(Filesize).arg(BytesSent*100/Filesize); lastUpdate = newtime; lastBytesSent = BytesSent; } diff --git a/widget/filetransfertwidget.h b/widget/filetransfertwidget.h index 06a477484..c5933eeb5 100644 --- a/widget/filetransfertwidget.h +++ b/widget/filetransfertwidget.h @@ -37,7 +37,7 @@ public: FileTransfertWidget(ToxFile File); public slots: - void onFileTransferInfo(int FriendId, int FileNum, int Filesize, int BytesSent, ToxFile::FileDirection Direction); + void onFileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection Direction); void onFileTransferCancelled(int FriendId, int FileNum, ToxFile::FileDirection Direction); void onFileTransferFinished(ToxFile File); diff --git a/widget/widget.cpp b/widget/widget.cpp index 353167cca..c3e6fdf9b 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -202,6 +202,7 @@ Widget::Widget(QWidget *parent) : qRegisterMetaType("vpx_image"); qRegisterMetaType("uint8_t"); qRegisterMetaType("int32_t"); + qRegisterMetaType("int64_t"); qRegisterMetaType("ToxFile"); qRegisterMetaType("ToxFile::FileDirection"); @@ -471,7 +472,7 @@ void Widget::addFriend(int friendId, const QString &userId) connect(newfriend->widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int))); connect(newfriend->widget, SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int))); connect(newfriend->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString))); - connect(newfriend->chatForm, SIGNAL(sendFile(int32_t,QString,QByteArray)), core, SLOT(sendFile(int32_t,QString,QByteArray))); + connect(newfriend->chatForm, SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long))); connect(newfriend->chatForm, SIGNAL(answerCall(int)), core, SLOT(answerCall(int))); connect(newfriend->chatForm, SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int))); connect(newfriend->chatForm, SIGNAL(startCall(int)), core, SLOT(startCall(int)));