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

filetransfer: corrected pause/resume behaviour

This commit is contained in:
apprb 2014-09-11 20:36:57 +07:00
parent 6440ef8310
commit 6c5cd7c010
8 changed files with 82 additions and 8 deletions

View File

@ -393,6 +393,14 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive
tox_file_send_control(tox, file->friendId, 1, file->fileNum, TOX_FILECONTROL_FINISHED, nullptr, 0);
removeFileFromQueue((bool)receive_send, file->friendId, file->fileNum);
}
else if (receive_send == 0 && control_type == TOX_FILECONTROL_ACCEPT)
{
emit static_cast<Core*>(core)->fileTransferRemotePausedUnpaused(*file, false);
}
else if ((receive_send == 0 || receive_send == 1) && control_type == TOX_FILECONTROL_PAUSE)
{
emit static_cast<Core*>(core)->fileTransferRemotePausedUnpaused(*file, true);
}
else
{
qDebug() << QString("Core: File control callback, receive_send=%1, control_type=%2")

1
core.h
View File

@ -146,6 +146,7 @@ signals:
void fileDownloadFinished(const QString& path);
void fileTransferPaused(int FriendId, int FileNum, ToxFile::FileDirection direction);
void fileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection direction);
void fileTransferRemotePausedUnpaused(ToxFile file, bool paused);
void avInvite(int friendId, int callIndex, bool video);
void avStart(int friendId, int callIndex, bool video);

View File

@ -30,6 +30,7 @@ FileTransferInstance::FileTransferInstance(ToxFile File)
{
id = Idconter++;
state = tsPending;
remotePaused = false;
filename = File.fileName;
size = getHumanReadableSize(File.filesize);
@ -61,7 +62,7 @@ void FileTransferInstance::onFileTransferInfo(int FriendId, int FileNum, int64_t
if (FileNum != fileNum || FriendId != friendId || Direction != direction)
return;
state = tsProcessing;
// state = tsProcessing;
QDateTime newtime = QDateTime::currentDateTime();
int timediff = lastUpdate.secsTo(newtime);
if (timediff <= 0)
@ -121,6 +122,37 @@ void FileTransferInstance::onFileTransferFinished(ToxFile File)
emit stateUpdated();
}
void FileTransferInstance::onFileTransferAccepted(ToxFile File)
{
if (File.fileNum != fileNum || File.friendId != friendId || File.direction != direction)
return;
remotePaused = false;
state = tsProcessing;
emit stateUpdated();
}
void FileTransferInstance::onFileTransferRemotePausedUnpaused(ToxFile File, bool paused)
{
if (File.fileNum != fileNum || File.friendId != friendId || File.direction != direction)
return;
remotePaused = paused;
emit stateUpdated();
}
void FileTransferInstance::onFileTransferPaused(int FriendId, int FileNum, ToxFile::FileDirection Direction)
{
if (FileNum != fileNum || FriendId != friendId || Direction != direction)
return;
state = tsPaused;
emit stateUpdated();
}
void FileTransferInstance::cancelTransfer()
{
Core::getInstance()->cancelFileSend(friendId, fileNum);
@ -181,19 +213,33 @@ void FileTransferInstance::acceptRecvRequest()
void FileTransferInstance::pauseResumeRecv()
{
if (!(state == tsProcessing || state == tsPaused))
return;
if (remotePaused)
return;
Core::getInstance()->pauseResumeFileRecv(friendId, fileNum);
if (state == tsProcessing)
state = tsPaused;
else state = tsProcessing;
// if (state == tsProcessing)
// state = tsPaused;
// else state = tsProcessing;
emit stateUpdated();
}
void FileTransferInstance::pauseResumeSend()
{
if (!(state == tsProcessing || state == tsPaused))
return;
if (remotePaused)
return;
Core::getInstance()->pauseResumeFileSend(friendId, fileNum);
if (state == tsProcessing)
state = tsPaused;
else state = tsProcessing;
// if (state == tsProcessing)
// state = tsPaused;
// else state = tsProcessing;
emit stateUpdated();
}
@ -220,7 +266,15 @@ QString FileTransferInstance::getHtmlImage()
else if (state == tsPaused)
rightBtnImg = QImage(":/ui/fileTransferInstance/resumeFileButton.png");
else
rightBtnImg = QImage(":/ui/fileTransferInstance/acceptFileButton.png");
{
if (direction == ToxFile::SENDING)
rightBtnImg = QImage(":/ui/fileTransferInstance/pauseGreyFileButton.png");
else
rightBtnImg = QImage(":/ui/fileTransferInstance/acceptFileButton.png");
}
if (remotePaused)
rightBtnImg = QImage(":/ui/fileTransferInstance/pauseGreyFileButton.png");
res = draw2ButtonsForm("silver", leftBtnImg, rightBtnImg);
} else if (state == tsCanceled)

View File

@ -40,6 +40,9 @@ public slots:
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);
void onFileTransferAccepted(ToxFile File);
void onFileTransferPaused(int FriendId, int FileNum, ToxFile::FileDirection Direction);
void onFileTransferRemotePausedUnpaused(ToxFile File, bool paused);
void pressFromHtml(QString);
signals:
@ -65,6 +68,7 @@ private:
uint id;
TransfState state;
bool remotePaused;
QImage pic;
QString filename, size, speed, eta;
QDateTime lastUpdate;

View File

@ -127,6 +127,7 @@
<file>ui/volButton/volButton.css</file>
<file>ui/fileTransferInstance/acceptFileButton.png</file>
<file>ui/fileTransferInstance/pauseFileButton.png</file>
<file>ui/fileTransferInstance/pauseGreyFileButton.png</file>
<file>ui/fileTransferInstance/resumeFileButton.png</file>
<file>ui/fileTransferInstance/stopFileButton.png</file>
<file>ui/fileTransferInstance/emptyLGreenFileButton.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 244 B

After

Width:  |  Height:  |  Size: 403 B

View File

@ -108,6 +108,9 @@ void ChatForm::startFileSend(ToxFile file)
connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo);
connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled);
connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished);
connect(Core::getInstance(), SIGNAL(fileTransferAccepted(ToxFile)), fileTrans, SLOT(onFileTransferAccepted(ToxFile)));
connect(Core::getInstance(), SIGNAL(fileTransferPaused(int,int,ToxFile::FileDirection)), fileTrans, SLOT(onFileTransferPaused(int,int,ToxFile::FileDirection)));
connect(Core::getInstance(), SIGNAL(fileTransferRemotePausedUnpaused(ToxFile,bool)), fileTrans, SLOT(onFileTransferRemotePausedUnpaused(ToxFile,bool)));
QString name = Widget::getInstance()->getUsername();
if (name == previousName)
@ -128,6 +131,9 @@ void ChatForm::onFileRecvRequest(ToxFile file)
connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo);
connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled);
connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished);
connect(Core::getInstance(), SIGNAL(fileTransferAccepted(ToxFile)), fileTrans, SLOT(onFileTransferAccepted(ToxFile)));
connect(Core::getInstance(), SIGNAL(fileTransferPaused(int,int,ToxFile::FileDirection)), fileTrans, SLOT(onFileTransferPaused(int,int,ToxFile::FileDirection)));
connect(Core::getInstance(), SIGNAL(fileTransferRemotePausedUnpaused(ToxFile,bool)), fileTrans, SLOT(onFileTransferRemotePausedUnpaused(ToxFile,bool)));
Widget* w = Widget::getInstance();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->getIsWindowMinimized() || !w->isActiveWindow())