From ec394c122bd87446f765c923d91cc792dad3c361 Mon Sep 17 00:00:00 2001 From: Veli Date: Wed, 6 Mar 2019 01:18:33 +0300 Subject: [PATCH] Fix errors in servers and small changes --- src/broadcast/SeamlessClient.cpp | 7 ++++- src/broadcast/SeamlessServer.cpp | 2 +- src/ui/MainWindow.cpp | 48 +++++++++++++++++++++++++++++--- src/ui/MainWindow.ui | 6 ++-- src/ui/ShowTransferDialog.cpp | 5 +++- src/ui/ShowTransferDialog.ui | 2 +- src/util/TransferUtils.cpp | 2 +- 7 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/broadcast/SeamlessClient.cpp b/src/broadcast/SeamlessClient.cpp index 0d7ca5b..a57c4a9 100644 --- a/src/broadcast/SeamlessClient.cpp +++ b/src/broadcast/SeamlessClient.cpp @@ -184,6 +184,11 @@ void SeamlessClient::run() // We do receive the file here ... if (tcpServer.waitForNewConnection(TIMEOUT_SOCKET_DEFAULT)) { if (tcpServer.hasPendingConnections()) { + if (transferObject.flag != TransferObject::Flag::Running) { + transferObject.flag = TransferObject::Flag::Running; + gDbSignal->update(transferObject); + } + auto *socket = tcpServer.nextPendingConnection(); auto lastDataAvailable = clock(); auto fileSize = static_cast(transferObject.fileSize); @@ -200,7 +205,7 @@ void SeamlessClient::run() // make sure when about to complete notify the last bits if (clock() - lastUpdate > - 2000 || currentFile.size() < fileSize) { + 2000 || currentFile.size() == fileSize) { auto size = currentFile.size(); emit gTaskMgr->taskByteTransferred(m_groupId, m_deviceId, TransferObject::Incoming, diff --git a/src/broadcast/SeamlessServer.cpp b/src/broadcast/SeamlessServer.cpp index 64b67e6..de708c5 100644 --- a/src/broadcast/SeamlessServer.cpp +++ b/src/broadcast/SeamlessServer.cpp @@ -113,7 +113,7 @@ void SeamlessServer::connected(CSActiveConnection *connection) if (transferObject.flag != TransferObject::Flag::Running) { transferObject.flag = TransferObject::Flag::Running; - gDatabase->update(transferObject); + gDbSignal->update(transferObject); } QTcpSocket socket; diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index d2daf42..c7467e1 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -183,16 +183,56 @@ void MainWindow::showTransferRequest(const QString &deviceId, groupid groupId, i messageBox.setText(QString("Receive files from %1, %2 in total?") .arg(device.nickname) .arg(filesTotal)); - auto *okButton = messageBox.addButton(QMessageBox::StandardButton::Ok); + auto *okButton = messageBox.addButton(QMessageBox::StandardButton::Yes); + auto *noButton = messageBox.addButton(QMessageBox::StandardButton::No); messageBox.addButton(QMessageBox::StandardButton::Ignore); connect(okButton, &QPushButton::pressed, [groupId, deviceId]() { - auto *client = new SeamlessClient(groupId, deviceId, true); - client->start(); + TransferUtils::startTransfer(groupId, deviceId); }); messageBox.exec(); - showTransfer(groupId); + + auto *clickedButton = messageBox.clickedButton(); + auto accepted = clickedButton != noButton; + + auto *thread = new GThread([groupId, deviceId, accepted](GThread *thread) { + TransferGroup group(groupId); + NetworkDevice copyDevice(deviceId); + TransferAssignee assignee(groupId, deviceId); + + if (gDbSignal->reconstruct(group) && gDbSignal->reconstruct(copyDevice) && + gDbSignal->reconstruct(assignee)) { + if (!accepted) + gDbSignal->remove(group); + + DeviceConnection connection(deviceId, assignee.connectionAdapter); + + if (gDbSignal->reconstruct(connection)) { + CommunicationBridge bridge; + + try { + auto *activeConnection = bridge.communicate(copyDevice, connection); + + activeConnection->reply({ + {KEYWORD_REQUEST, KEYWORD_REQUEST_RESPONSE}, + {KEYWORD_TRANSFER_GROUP_ID, QVariant(groupId).toLongLong()}, + {KEYWORD_TRANSFER_IS_ACCEPTED, accepted} + }); + + activeConnection->receive(); + } catch (...) { + qDebug() << thread << "Response failed"; + } + } + } else + qDebug() << thread << "Reconstruction failed"; + }, true); + + thread->start(); + + if (okButton == clickedButton) + showTransfer(groupId); } catch (...) { // do nothing } diff --git a/src/ui/MainWindow.ui b/src/ui/MainWindow.ui index f494970..1afe6aa 100644 --- a/src/ui/MainWindow.ui +++ b/src/ui/MainWindow.ui @@ -6,8 +6,8 @@ 0 0 - 833 - 382 + 817 + 464 @@ -674,7 +674,7 @@ 0 0 - 833 + 817 21 diff --git a/src/ui/ShowTransferDialog.cpp b/src/ui/ShowTransferDialog.cpp index 1a2a175..dbdd311 100644 --- a/src/ui/ShowTransferDialog.cpp +++ b/src/ui/ShowTransferDialog.cpp @@ -21,6 +21,8 @@ ShowTransferDialog::ShowTransferDialog(QWidget *parent, groupid groupId) m_ui->transfersTreeView->setModel(m_objectModel); m_ui->errorTreeView->setColumnWidth(0, 250); m_ui->transfersTreeView->setColumnWidth(0, 250); + m_ui->transfersTreeView->setColumnWidth(1, 80); + m_ui->transfersTreeView->setColumnWidth(2, 80); connect(gTaskMgr, &TransferTaskManager::taskAdded, this, &ShowTransferDialog::globalTaskStarted); connect(gTaskMgr, &TransferTaskManager::taskRemoved, this, &ShowTransferDialog::globalTaskFinished); @@ -226,7 +228,8 @@ void ShowTransferDialog::transferItemActivated(const QModelIndex &modelIndex) auto item = m_objectModel->list().at(modelIndex.row()); - if (modelIndex.column() == TransferObjectModel::Status && item.flag == TransferObject::Interrupted) { + if (modelIndex.column() == TransferObjectModel::Status && item.flag != TransferObject::Done + && item.flag != TransferObject::Removed) { item.flag = TransferObject::Pending; gDatabase->update(item); } else if (item.flag == TransferObject::Flag::Done && item.type == TransferObject::Type::Incoming) diff --git a/src/ui/ShowTransferDialog.ui b/src/ui/ShowTransferDialog.ui index f3e6973..a8c2f11 100644 --- a/src/ui/ShowTransferDialog.ui +++ b/src/ui/ShowTransferDialog.ui @@ -133,7 +133,7 @@ - Choose + Change diff --git a/src/util/TransferUtils.cpp b/src/util/TransferUtils.cpp index c9c683c..00cf444 100644 --- a/src/util/TransferUtils.cpp +++ b/src/util/TransferUtils.cpp @@ -331,6 +331,6 @@ QList TransferUtils::getPaths(const QList &urls) void TransferUtils::startTransfer(groupid groupId, const QString &deviceId) { - auto *client = new SeamlessClient(groupId, deviceId); + auto *client = new SeamlessClient(groupId, deviceId, true); client->start(); }