Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/plugins/data-transfer/core/gui/transfer/resultdisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "resultdisplay.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QHBoxLayout>
#include <QLabel>
#include <QToolButton>
Expand Down Expand Up @@ -67,7 +69,8 @@ void ResultDisplayWidget::initUI()
&ResultDisplayWidget::addResult);
#ifdef linux
connect(TransferHelper::instance(), &TransferHelper::transferFinished, this, [this] {
TransferHelper::instance()->sendMessage("add_result", processText);
TransferHelper::instance()->sendMessage(
"add_result", QString::fromUtf8(QJsonDocument(processText).toJson(QJsonDocument::Compact)));
});
#endif
}
Expand Down Expand Up @@ -107,8 +110,11 @@ void ResultDisplayWidget::addResult(QString name, bool success, QString reason)
setStatus(false);

resultWindow->updateContent(name, reason, success);
QString res = success ? "true" : "false";
processText.append(name + " " + res + " " + reason + ";");
QJsonObject obj;
obj["name"] = name;
obj["success"] = success;
obj["reason"] = reason;
processText.append(obj);
}

void ResultDisplayWidget::clear()
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data-transfer/core/gui/transfer/resultdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define RESULTDISPLAYWIDGET_H

#include <QFrame>
#include <QJsonArray>
#include "../type_defines.h"
class QTextBrowser;
class QLabel;
Expand Down Expand Up @@ -37,7 +38,7 @@ public slots:

private:
ResultWindow *resultWindow { nullptr };
QString processText;
QJsonArray processText;
QLabel *iconLabel { nullptr };
QLabel *titileLabel { nullptr };
QLabel *tiptextlabel { nullptr };
Expand Down
13 changes: 10 additions & 3 deletions src/plugins/data-transfer/core/gui/transfer/transferringwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "errorwidget.h"

#include <QJsonDocument>
#include <QJsonObject>

#include <QHBoxLayout>
#include <QLabel>
#include <QDebug>
Expand Down Expand Up @@ -202,9 +205,13 @@ void TransferringWidget::updateProcess(const QString &tpye, const QString &conte
timeLabel->setText(QString(tr("Transfer will be completed in --")));
#ifdef linux
//通知对方进程情况
QString mes = tpye + " " + content + " " + QString::number(progressbar) + " "
+ QString::number(estimatedtime) + ";";
TransferHelper::instance()->sendMessage("transfer_content", mes);
QJsonObject obj;
obj["type"] = tpye;
obj["content"] = content;
obj["progressbar"] = progressbar;
obj["estimatedtime"] = estimatedtime;
TransferHelper::instance()->sendMessage(
"transfer_content", QString::fromUtf8(QJsonDocument(obj).toJson(QJsonDocument::Compact)));
#endif
}
}
Expand Down
33 changes: 23 additions & 10 deletions src/plugins/data-transfer/core/utils/transferworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <QDebug>
#include <QCoreApplication>
#include <QFile>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>

#pragma execution_character_set("utf-8")
TransferHandle::TransferHandle()
Expand Down Expand Up @@ -350,11 +353,15 @@ void TransferHandle::handleMiscMessage(QString jsonmsg)
if (miscJson.has_member("add_result")) {
QString result = miscJson.get("add_result").as_c_str();
LOG << "add_result" << result.data();
for (QString str : result.split(";")) {
auto res = str.split(" ");
if (res.size() != 3)
continue;
emit TransferHelper::instance()->addResult(res.at(0), res.at(1) == "true", res.at(2));
QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8());
if (doc.isArray()) {
for (const QJsonValue &value : doc.array()) {
QJsonObject obj = value.toObject();
emit TransferHelper::instance()->addResult(
obj.value("name").toString(),
obj.value("success").toBool(),
obj.value("reason").toString());
}
}
emit TransferHelper::instance()->transferFinished();
}
Expand All @@ -376,11 +383,17 @@ void TransferHandle::handleMiscMessage(QString jsonmsg)

if (miscJson.has_member("transfer_content")) {
QString result = miscJson.get("transfer_content").as_c_str();
for (QString str : result.split(";")) {
auto res = str.split(" ");
if (res.size() != 4)
continue;
emit TransferHelper::instance()->transferContent(res.at(0), res.at(1), res.at(2).toInt(), res.at(3).toInt());
QJsonDocument doc = QJsonDocument::fromJson(result.toUtf8());
QJsonArray contents = doc.isArray() ? doc.array() : QJsonArray();
if (doc.isObject())
contents.append(doc.object());
for (const QJsonValue &value : contents) {
QJsonObject obj = value.toObject();
emit TransferHelper::instance()->transferContent(
obj.value("type").toString(),
obj.value("content").toString(),
obj.value("progressbar").toInt(),
obj.value("estimatedtime").toInt());
}
}
}
Expand Down
Loading