Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Fix errors in servers and small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
velitasali committed Mar 5, 2019
1 parent 139203b commit ec394c1
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/broadcast/SeamlessClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<qint64>(transferObject.fileSize);
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/broadcast/SeamlessServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 44 additions & 4 deletions src/ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>833</width>
<height>382</height>
<width>817</width>
<height>464</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -674,7 +674,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>833</width>
<width>817</width>
<height>21</height>
</rect>
</property>
Expand Down
5 changes: 4 additions & 1 deletion src/ui/ShowTransferDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/ui/ShowTransferDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Choose</string>
<string>Change</string>
</property>
</widget>
</item>
Expand Down
2 changes: 1 addition & 1 deletion src/util/TransferUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,6 @@ QList<QString> TransferUtils::getPaths(const QList<QUrl> &urls)

void TransferUtils::startTransfer(groupid groupId, const QString &deviceId)
{
auto *client = new SeamlessClient(groupId, deviceId);
auto *client = new SeamlessClient(groupId, deviceId, true);
client->start();
}

0 comments on commit ec394c1

Please sign in to comment.