mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Improve file sending
Improve the Widget, properly handle finished/cancelled tranfers
This commit is contained in:
parent
ec69308efc
commit
c18d63553d
|
@ -180,7 +180,10 @@ void ChatForm::onSliderRangeChanged()
|
|||
|
||||
void ChatForm::startFileSend(ToxFile *file)
|
||||
{
|
||||
QLabel *author = new QLabel(Widget::getInstance()->getUsername()), *date = new QLabel();
|
||||
if (file->friendId != f->friendId)
|
||||
return;
|
||||
QLabel *author = new QLabel(Widget::getInstance()->getUsername());
|
||||
QLabel *date = new QLabel(QTime::currentTime().toString("mm:ss"));
|
||||
QScrollBar* scroll = chatArea->verticalScrollBar();
|
||||
lockSliderToBottom = scroll && scroll->value() == scroll->maximum();
|
||||
author->setAlignment(Qt::AlignTop | Qt::AlignRight);
|
||||
|
@ -207,4 +210,6 @@ void ChatForm::startFileSend(ToxFile *file)
|
|||
curRow++;
|
||||
|
||||
connect(Widget::getInstance()->getCore(), &Core::fileTransferInfo, fileTrans, &FileTransfertWidget::onFileTransferInfo);
|
||||
connect(Widget::getInstance()->getCore(), &Core::fileTransferCancelled, fileTrans, &FileTransfertWidget::onFileTransferCancelled);
|
||||
connect(Widget::getInstance()->getCore(), &Core::fileTransferFinished, fileTrans, &FileTransfertWidget::onFileTransferFinished);
|
||||
}
|
||||
|
|
14
core.cpp
14
core.cpp
|
@ -161,7 +161,9 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive
|
|||
if (chunkSize == -1)
|
||||
{
|
||||
qWarning("Core::onFileControlCallback: Error getting preffered chunk size, aborting file send");
|
||||
// TODO: Warn the Friend* that we're aborting (emit)
|
||||
file->status = ToxFile::STOPPED;
|
||||
emit static_cast<Core*>(core)->fileTransferFinished(file);
|
||||
tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
|
||||
return;
|
||||
}
|
||||
chunkSize = std::min(chunkSize, file->fileData.size());
|
||||
|
@ -169,7 +171,9 @@ void Core::onFileControlCallback(Tox* tox, int32_t friendnumber, uint8_t receive
|
|||
if (tox_file_send_data(tox, friendnumber, filenumber, (uint8_t*)toSend.data(), toSend.size()) == -1)
|
||||
{
|
||||
qWarning("Core::onFileControlCallback: Error sending first data chunk, aborting");
|
||||
// TODO: Warn the Friend* that we're aborting (emit)
|
||||
file->status = ToxFile::STOPPED;
|
||||
emit static_cast<Core*>(core)->fileTransferFinished(file);
|
||||
tox_file_send_control(tox, file->friendId, 0, file->fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
@ -264,7 +268,6 @@ void Core::sendFile(int32_t friendId, QString Filename, QByteArray data)
|
|||
if (fileNum == -1)
|
||||
{
|
||||
qWarning() << "Core::sendFile: Can't create the Tox file sender";
|
||||
// TODO: Notify Widget (with the friendId), Widget will notify the chatForm
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -369,7 +372,8 @@ void Core::fileHeartbeat()
|
|||
{
|
||||
qWarning("Core::fileHeartbeat: Error getting preffered chunk size, aborting file send");
|
||||
file.status = ToxFile::STOPPED;
|
||||
// TODO: Warn the Friend* and the peer that we're aborting (emit and tox_control_...)
|
||||
emit fileTransferFinished(&file);
|
||||
tox_file_send_control(tox, file.friendId, 0, file.fileNum, TOX_FILECONTROL_KILL, nullptr, 0);
|
||||
return;
|
||||
}
|
||||
chunkSize = std::min(chunkSize, file.fileData.size());
|
||||
|
@ -387,7 +391,7 @@ void Core::fileHeartbeat()
|
|||
qDebug("Core::fileHeartbeat: Transfer finished");
|
||||
tox_file_send_control(tox, file.friendId, 0, file.fileNum, TOX_FILECONTROL_FINISHED, nullptr, 0);
|
||||
file.status = ToxFile::STOPPED; // TODO: Remove it from the list and return;
|
||||
// TODO: Notify the Friend* that we're done sending (emit)
|
||||
emit fileTransferFinished(&file);
|
||||
}
|
||||
else
|
||||
qDebug() << QString("Core::fileHeartbeat: sent %1/%2 bytes").arg(file.bytesSent).arg(file.fileData.size());
|
||||
|
|
|
@ -11,12 +11,14 @@ FileTransfertWidget::FileTransfertWidget(ToxFile *File)
|
|||
QFont prettysmall;
|
||||
prettysmall.setPixelSize(10);
|
||||
QPalette greybg;
|
||||
greybg.setColor(QPalette::Window, Qt::gray);
|
||||
greybg.setColor(QPalette::Window, QColor(209,209,209));
|
||||
greybg.setColor(QPalette::Base, QColor(150,150,150));
|
||||
setPalette(greybg);
|
||||
setAutoFillBackground(true);
|
||||
|
||||
setFixedSize(250,50);
|
||||
setLayout(mainLayout);
|
||||
mainLayout->setMargin(0);
|
||||
|
||||
filename->setText(file->fileName);
|
||||
filename->setFont(prettysmall);
|
||||
|
@ -27,6 +29,8 @@ FileTransfertWidget::FileTransfertWidget(ToxFile *File)
|
|||
eta->setText("00:00");
|
||||
eta->setFont(prettysmall);
|
||||
progress->setValue(0);
|
||||
progress->setMinimumHeight(11);
|
||||
progress->setFont(prettysmall);
|
||||
|
||||
topright->setIcon(QIcon("img/button icons/no_2x.png"));
|
||||
if (file->direction == ToxFile::SENDING)
|
||||
|
@ -34,8 +38,18 @@ FileTransfertWidget::FileTransfertWidget(ToxFile *File)
|
|||
else
|
||||
bottomright->setIcon(QIcon("img/button icons/yes_2x.png"));
|
||||
|
||||
topright->setIconSize(QSize(25,25));
|
||||
bottomright->setIconSize(QSize(25,25));
|
||||
QPalette toxgreen;
|
||||
toxgreen.setColor(QPalette::Button, QColor(107,194,96)); // Tox Green
|
||||
topright->setIconSize(QSize(10,10));
|
||||
topright->setFixedSize(24,24);
|
||||
topright->setFlat(true);
|
||||
topright->setAutoFillBackground(true);
|
||||
topright->setPalette(toxgreen);
|
||||
bottomright->setIconSize(QSize(10,10));
|
||||
bottomright->setFixedSize(24,24);
|
||||
bottomright->setFlat(true);
|
||||
bottomright->setAutoFillBackground(true);
|
||||
bottomright->setPalette(toxgreen);
|
||||
|
||||
mainLayout->addWidget(pic);
|
||||
mainLayout->addLayout(infoLayout);
|
||||
|
@ -44,12 +58,18 @@ FileTransfertWidget::FileTransfertWidget(ToxFile *File)
|
|||
infoLayout->addWidget(filename);
|
||||
infoLayout->addLayout(textLayout);
|
||||
infoLayout->addWidget(progress);
|
||||
infoLayout->setMargin(5);
|
||||
|
||||
textLayout->addWidget(size);
|
||||
textLayout->addWidget(speed);
|
||||
textLayout->addWidget(eta);
|
||||
textLayout->setMargin(0);
|
||||
textLayout->setSpacing(5);
|
||||
|
||||
buttonLayout->addWidget(topright);
|
||||
buttonLayout->addWidget(bottomright);
|
||||
buttonLayout->setMargin(0);
|
||||
buttonLayout->setSpacing(2);
|
||||
}
|
||||
|
||||
QString FileTransfertWidget::getHumanReadableSize(int size)
|
||||
|
@ -86,10 +106,30 @@ void FileTransfertWidget::onFileTransferInfo(ToxFile* File)
|
|||
|
||||
void FileTransfertWidget::onFileTransferCancelled(ToxFile* File)
|
||||
{
|
||||
|
||||
if (File != file)
|
||||
return;
|
||||
progress->hide();
|
||||
speed->hide();
|
||||
eta->hide();
|
||||
topright->hide();
|
||||
bottomright->hide();
|
||||
QPalette toxred;
|
||||
toxred.setColor(QPalette::Window, QColor(200,78,78)); // Tox Red
|
||||
setPalette(toxred);
|
||||
}
|
||||
|
||||
void FileTransfertWidget::onFileTransferFinished(ToxFile* File)
|
||||
{
|
||||
|
||||
if (File != file)
|
||||
return;
|
||||
progress->hide();
|
||||
speed->hide();
|
||||
eta->hide();
|
||||
topright->setIcon(QIcon("img/button icons/yes_2x.png"));
|
||||
buttonLayout->addStretch();
|
||||
buttonLayout->setSpacing(0);
|
||||
bottomright->hide();
|
||||
QPalette toxgreen;
|
||||
toxgreen.setColor(QPalette::Window, QColor(107,194,96)); // Tox Green
|
||||
setPalette(toxgreen);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user