update: add dray trigger task.

This commit is contained in:
2025-06-18 14:53:56 +08:00
parent 5dcf638e62
commit a53657df30
14 changed files with 289 additions and 62 deletions

View File

@@ -164,3 +164,8 @@ QString ClientCore::GetRemoteID()
{ {
return remoteID_; return remoteID_;
} }
QString ClientCore::GetOwnID()
{
return ownID_;
}

View File

@@ -51,6 +51,7 @@ public:
void SetFrameCall(FrameBufferType type, const std::function<void(QSharedPointer<FrameBuffer>)>& call); void SetFrameCall(FrameBufferType type, const std::function<void(QSharedPointer<FrameBuffer>)>& call);
void SetRemoteID(const QString& id); void SetRemoteID(const QString& id);
QString GetRemoteID(); QString GetRemoteID();
QString GetOwnID();
public: public:
QMutex conMutex_; QMutex conMutex_;

View File

@@ -1,9 +1,12 @@
#include "FileTrans.h" #include "FileTrans.h"
#include <QFileInfo> #include <QFileInfo>
FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore) FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore)
{ {
RegisterFrameCall(); RegisterFrameCall();
downTask_ = QSharedPointer<DoTransTask>::create();
sendTask_ = QSharedPointer<DoTransTask>::create();
} }
/* /*
@@ -21,24 +24,33 @@ void FileTrans::ReqSendFile(const TransTask& task)
info.toPath = task.remotePath; info.toPath = task.remotePath;
info.fromPath = task.localPath; info.fromPath = task.localPath;
sendTask_->file.setFileName(info.fromPath);
if (!sendTask_->file.open(QIODevice::ReadOnly)) {
qCritical() << QString(tr("open file [%1] failed.")).arg(info.fromPath);
sendTask_->state = TaskState::STATE_NONE;
return;
}
QFileInfo fileInfo(info.fromPath); QFileInfo fileInfo(info.fromPath);
if (fileInfo.exists()) { if (fileInfo.exists()) {
qint64 size = fileInfo.size(); qint64 size = fileInfo.size();
info.permissions = static_cast<quint32>(fileInfo.permissions()); info.permissions = static_cast<quint32>(fileInfo.permissions());
info.size = size; info.size = size;
} else { } else {
sigError(QString(tr("File [%1] not exit.")).arg(info.fromPath)); qCritical() << QString(tr("File [%1] not exit.")).arg(info.fromPath);
sendTask_->file.close();
return; return;
} }
if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_REQ_SEND, task.remoteId)) { if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_REQ_SEND, task.remoteId)) {
sigError(QString(tr("send req send failed: %1")).arg(info.msg)); qCritical() << QString(tr("send req send failed: %1")).arg(info.msg);
sendTask_.state = TaskState::STATE_NONE; sendTask_->state = TaskState::STATE_NONE;
sendTask_->file.close();
return; return;
} }
sendTask_.state = TaskState::STATE_RUNNING; sendTask_->state = TaskState::STATE_RUNNING;
sendTask_.totalSize = info.size; sendTask_->totalSize = info.size;
sendTask_.tranSize = 0; sendTask_->tranSize = 0;
} }
void FileTrans::ReqDownFile(const TransTask& task) void FileTrans::ReqDownFile(const TransTask& task)
@@ -50,31 +62,38 @@ void FileTrans::ReqDownFile(const TransTask& task)
info.toPath = task.localPath; info.toPath = task.localPath;
info.fromPath = task.remotePath; info.fromPath = task.remotePath;
if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_REQ_DOWN, task.remoteId)) { downTask_->file.setFileName(Util::Get2FilePath(task.remotePath, task.localPath));
sigError(QString(tr("send req send failed: %1")).arg(info.msg)); if (!downTask_->file.open(QIODevice::WriteOnly)) {
sendTask_.state = TaskState::STATE_NONE; qCritical() << QString(tr("open file [%1] failed.")).arg(downTask_->file.fileName());
downTask_->state = TaskState::STATE_NONE;
return; return;
} }
sendTask_.state = TaskState::STATE_RUNNING; if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_REQ_DOWN, task.remoteId)) {
qCritical() << QString(tr("send req send failed: %1")).arg(info.msg);
sendTask_->state = TaskState::STATE_NONE;
sendTask_->file.close();
return;
}
sendTask_->state = TaskState::STATE_RUNNING;
} }
qint32 FileTrans::GetSendProgress() qint32 FileTrans::GetSendProgress()
{ {
if (sendTask_.state != TaskState::STATE_RUNNING) { if (sendTask_->state != TaskState::STATE_RUNNING) {
return -1; return -1;
} }
double per = (sendTask_.tranSize * 100.0) / sendTask_.totalSize; double per = (sendTask_->tranSize * 100.0) / sendTask_->totalSize;
return per; return per;
} }
qint32 FileTrans::GetDownProgress() qint32 FileTrans::GetDownProgress()
{ {
if (downTask_.state != TaskState::STATE_RUNNING) { if (downTask_->state != TaskState::STATE_RUNNING) {
return -1; return -1;
} }
double per = (downTask_.tranSize * 100.0) / downTask_.totalSize; double per = (downTask_->tranSize * 100.0) / downTask_->totalSize;
return per; return per;
} }
@@ -100,7 +119,7 @@ void FileTrans::fbtReqSend(QSharedPointer<FrameBuffer> frame)
// judge is same client's same file. // judge is same client's same file.
// recv is single thread recv, judge idle // recv is single thread recv, judge idle
if (downTask_.state == TaskState::STATE_RUNNING) { if (downTask_->state == TaskState::STATE_RUNNING) {
info.msg = QString(tr("busy...")); info.msg = QString(tr("busy..."));
clientCore_->Send<InfoMsg>(info, FBT_CLI_CANOT_SEND, frame->fid); clientCore_->Send<InfoMsg>(info, FBT_CLI_CANOT_SEND, frame->fid);
return; return;
@@ -108,29 +127,29 @@ void FileTrans::fbtReqSend(QSharedPointer<FrameBuffer> frame)
// recv // recv
auto newerPath = Util::Get2FilePath(info.fromPath, info.toPath); auto newerPath = Util::Get2FilePath(info.fromPath, info.toPath);
downTask_.file.setFileName(newerPath); downTask_->file.setFileName(newerPath);
if (!downTask_.file.open(QIODevice::WriteOnly)) { if (!downTask_->file.open(QIODevice::WriteOnly)) {
info.msg = QString(tr("open file failed: %1")).arg(newerPath); info.msg = QString(tr("open file failed: %1")).arg(newerPath);
qCritical() << info.msg; qCritical() << info.msg;
if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_CANOT_SEND, frame->fid)) { if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_CANOT_SEND, frame->fid)) {
qCritical() << QString(tr("open recv file:%2 failed, and reply %2 failed.")).arg(info.msg).arg(frame->fid); qCritical() << QString(tr("open recv file:%2 failed, and reply %2 failed.")).arg(info.msg).arg(frame->fid);
downTask_.file.close(); downTask_->file.close();
return; return;
} }
return; return;
} }
downTask_.totalSize = info.size; downTask_->totalSize = info.size;
downTask_.tranSize = 0; downTask_->tranSize = 0;
downTask_.permission = info.permissions; downTask_->permission = info.permissions;
info.msg = QString(tr("open recv file success: %1")).arg(newerPath); info.msg = QString(tr("open recv file success: %1")).arg(newerPath);
if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_CAN_SEND, frame->fid)) { if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_CAN_SEND, frame->fid)) {
qCritical() << QString(tr("open recv file:%2 success, but reply %2 failed.")).arg(info.msg).arg(frame->fid); qCritical() << QString(tr("open recv file:%2 success, but reply %2 failed.")).arg(info.msg).arg(frame->fid);
downTask_.file.close(); downTask_->file.close();
return; return;
} }
downTask_.state = TaskState::STATE_RUNNING; downTask_->state = TaskState::STATE_RUNNING;
} }
// The other party requests to download, prepare to send. // The other party requests to download, prepare to send.
@@ -157,10 +176,10 @@ void FileTrans::fbtReqDown(QSharedPointer<FrameBuffer> frame)
void FileTrans::fbtTransDone(QSharedPointer<FrameBuffer> frame) void FileTrans::fbtTransDone(QSharedPointer<FrameBuffer> frame)
{ {
auto info = infoUnpack<InfoMsg>(frame->data); auto info = infoUnpack<InfoMsg>(frame->data);
if (downTask_.file.isOpen()) { if (downTask_->file.isOpen()) {
downTask_.file.close(); downTask_->file.close();
downTask_.state = TaskState::STATE_FINISH; downTask_->state = TaskState::STATE_FINISH;
qInfo() << QString(tr("recv file:%1 success.")).arg(downTask_.file.fileName()); qInfo() << QString(tr("recv file:%1 success.")).arg(downTask_->file.fileName());
clientCore_->Send<InfoMsg>(info, FBT_CLI_CAN_DOWN, frame->fid); clientCore_->Send<InfoMsg>(info, FBT_CLI_CAN_DOWN, frame->fid);
return; return;
} }
@@ -172,6 +191,9 @@ void FileTrans::fbtCanDown(QSharedPointer<FrameBuffer> frame)
{ {
// ready to recv file. // ready to recv file.
auto info = infoUnpack<InfoMsg>(frame->data); auto info = infoUnpack<InfoMsg>(frame->data);
downTask_->permission = info.permissions;
downTask_->totalSize = info.size;
downTask_->tranSize = 0;
qDebug() << QString(tr("start trans file:%1.")).arg(info.fromPath); qDebug() << QString(tr("start trans file:%1.")).arg(info.fromPath);
} }
@@ -183,36 +205,44 @@ void FileTrans::fbtCanotDown(QSharedPointer<FrameBuffer> frame)
void FileTrans::fbtFileBuffer(QSharedPointer<FrameBuffer> frame) void FileTrans::fbtFileBuffer(QSharedPointer<FrameBuffer> frame)
{ {
if (downTask_.state != TaskState::STATE_RUNNING) { if (downTask_->state != TaskState::STATE_RUNNING) {
return; return;
} }
// For the sake of efficiency, not verify the legality of the file // For the sake of efficiency, not verify the legality of the file
auto ws = downTask_.file.write(frame->data.constData(), frame->data.size()); auto ws = downTask_->file.write(frame->data.constData(), frame->data.size());
if (ws != frame->data.size()) { if (ws != frame->data.size()) {
downTask_.state = TaskState::STATE_FAILED; downTask_->state = TaskState::STATE_FAILED;
InfoMsg info; InfoMsg info;
info.msg = downTask_.file.errorString(); info.msg = downTask_->file.errorString();
clientCore_->Send<InfoMsg>(info, FBT_CLI_TRANS_FAILED, frame->fid); clientCore_->Send<InfoMsg>(info, FBT_CLI_TRANS_FAILED, frame->fid);
downTask_->file.close();
} }
downTask_->tranSize += ws;
} }
void FileTrans::fbtCanotSend(QSharedPointer<FrameBuffer> frame) void FileTrans::fbtCanotSend(QSharedPointer<FrameBuffer> frame)
{ {
InfoMsg info = infoUnpack<InfoMsg>(frame->data); InfoMsg info = infoUnpack<InfoMsg>(frame->data);
qCritical() << QString(tr("request file:%1 failed. reason:%2")).arg(info.fromPath).arg(info.msg); qCritical() << QString(tr("request file:%1 failed. reason:%2")).arg(info.fromPath).arg(info.msg);
if (sendTask_->file.isOpen()) {
sendTask_->file.close();
}
} }
void FileTrans::fbtCanSend(QSharedPointer<FrameBuffer> frame) void FileTrans::fbtCanSend(QSharedPointer<FrameBuffer> frame)
{ {
InfoMsg info = infoUnpack<InfoMsg>(frame->data);
qInfo() << QString(tr("start trans file:%1 to %2")).arg(info.fromPath).arg(frame->fid);
SendFile(sendTask_);
} }
void FileTrans::fbtTransFailed(QSharedPointer<FrameBuffer> frame) void FileTrans::fbtTransFailed(QSharedPointer<FrameBuffer> frame)
{ {
qCritical() << QString(tr("trans file:%1 failed.")).arg(downTask_.file.fileName()); qCritical() << QString(tr("trans file:%1 failed.")).arg(downTask_->file.fileName());
if (downTask_.file.isOpen()) { if (downTask_->file.isOpen()) {
downTask_.file.close(); downTask_->file.close();
} }
downTask_.state = TaskState::STATE_FAILED; downTask_->state = TaskState::STATE_FAILED;
} }
void FileTrans::SendFile(const QSharedPointer<DoTransTask>& task) void FileTrans::SendFile(const QSharedPointer<DoTransTask>& task)
@@ -251,11 +281,9 @@ void SendThread::run()
suc = false; suc = false;
break; break;
} }
task_->tranSize += br;
} }
if (!suc) {
task_->file.close(); task_->file.close();
}
} }
void SendThread::setTask(const QSharedPointer<DoTransTask>& task) void SendThread::setTask(const QSharedPointer<DoTransTask>& task)

View File

@@ -62,9 +62,6 @@ public:
qint32 GetSendProgress(); qint32 GetSendProgress();
qint32 GetDownProgress(); qint32 GetDownProgress();
signals:
void sigError(const QString& err);
private: private:
void fbtReqSend(QSharedPointer<FrameBuffer> frame); void fbtReqSend(QSharedPointer<FrameBuffer> frame);
void fbtReqDown(QSharedPointer<FrameBuffer> frame); void fbtReqDown(QSharedPointer<FrameBuffer> frame);
@@ -81,8 +78,8 @@ private:
void SendFile(const QSharedPointer<DoTransTask>& task); void SendFile(const QSharedPointer<DoTransTask>& task);
private: private:
DoTransTask downTask_; QSharedPointer<DoTransTask> downTask_;
DoTransTask sendTask_; QSharedPointer<DoTransTask> sendTask_;
QMutex lMut_; QMutex lMut_;
QMutex rMut_; QMutex rMut_;

View File

@@ -29,12 +29,22 @@ void FileManager::SetModeStr(const QString& modeStr, int type, ClientCore* clien
fileHelper_->registerPathCall([this](const QString& path) { ShowPath(path); }); fileHelper_->registerPathCall([this](const QString& path) { ShowPath(path); });
fileHelper_->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); }); fileHelper_->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); });
} else { } else {
cliCore_ = clientCore;
auto remotePtr = std::make_shared<RemoteFile>(); auto remotePtr = std::make_shared<RemoteFile>();
remotePtr->registerPathCall([this](const QString& path) { ShowPath(path); }); remotePtr->registerPathCall([this](const QString& path) { ShowPath(path); });
remotePtr->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); }); remotePtr->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); });
remotePtr->setClientCore(clientCore); remotePtr->setClientCore(clientCore);
ui->tableWidget->setIsRemote(true);
ui->tableWidget->setOwnIDCall([this]() { return cliCore_->GetOwnID(); });
ui->tableWidget->setRemoteIDCall([this]() { return cliCore_->GetRemoteID(); });
fileHelper_ = remotePtr; fileHelper_ = remotePtr;
} }
ui->tableWidget->setBasePathCall([this]() { return curRoot_; });
}
void FileManager::SetOtherSidePathCall(const std::function<QString()>& call)
{
ui->tableWidget->setOtherSidePathCall(call);
} }
void FileManager::InitControl() void FileManager::InitControl()
@@ -72,10 +82,9 @@ void FileManager::InitControl()
void FileManager::InitMenu(bool remote) void FileManager::InitMenu(bool remote)
{ {
if (remote) { if (remote) {
//auto acDown = new QAction(tr("Download")); // auto acDown = new QAction(tr("Download"));
} } else {
else { // auto acUp = new QAction(tr("Upload"));
//auto acUp = new QAction(tr("Upload"));
} }
} }

View File

@@ -21,6 +21,8 @@ public:
public: public:
void SetModeStr(const QString& modeStr, int type = 0, ClientCore* clientCore = nullptr); void SetModeStr(const QString& modeStr, int type = 0, ClientCore* clientCore = nullptr);
void SetOtherSidePathCall(const std::function<QString()>& call);
QString GetCurRoot();
private: private:
void InitControl(); void InitControl();
@@ -38,6 +40,7 @@ private:
Ui::FileManager* ui; Ui::FileManager* ui;
QString curRoot_; QString curRoot_;
QMenu* menu_; QMenu* menu_;
ClientCore* cliCore_;
std::shared_ptr<DirFileHelper> fileHelper_; std::shared_ptr<DirFileHelper> fileHelper_;
}; };

View File

@@ -1,9 +1,12 @@
#include "cusTableWidget.h" #include "cusTableWidget.h"
#include <InfoDirFile.h>
#include <InfoPack.hpp>
#include <QApplication> #include <QApplication>
#include <QDrag> #include <QDrag>
#include <QMimeData> #include <QMimeData>
#include <QPainter> #include <QPainter>
#include "FileControl.h"
CustomTableWidget::CustomTableWidget(QWidget* parent) : QTableWidget(parent) CustomTableWidget::CustomTableWidget(QWidget* parent) : QTableWidget(parent)
{ {
@@ -13,6 +16,36 @@ CustomTableWidget::~CustomTableWidget()
{ {
} }
void CustomTableWidget::setIsRemote(bool isRemote)
{
isRemote_ = isRemote;
}
void CustomTableWidget::setBasePathCall(const std::function<QString()>& call)
{
basePathCall_ = call;
}
void CustomTableWidget::setOtherSidePathCall(const std::function<QString()>& call)
{
otherSideCall_ = call;
}
QString FileManager::GetCurRoot()
{
return curRoot_;
}
void CustomTableWidget::setOwnIDCall(const std::function<QString()>& call)
{
oidCall_ = call;
}
void CustomTableWidget::setRemoteIDCall(const std::function<QString()>& call)
{
ridCall_ = call;
}
void CustomTableWidget::dropEvent(QDropEvent* event) void CustomTableWidget::dropEvent(QDropEvent* event)
{ {
if (!event->mimeData()->hasFormat("application/x-custom-data")) { if (!event->mimeData()->hasFormat("application/x-custom-data")) {
@@ -31,6 +64,25 @@ void CustomTableWidget::dragEnterEvent(QDragEnterEvent* event)
} }
if (event->mimeData()->hasFormat("application/x-custom-data")) { if (event->mimeData()->hasFormat("application/x-custom-data")) {
event->acceptProposedAction(); event->acceptProposedAction();
auto dirinfo = infoUnpack<DirFileInfoVec>(event->mimeData()->data("application/x-custom-data"));
QVector<TransTask> tasks;
// generate task
for (const auto& df : dirinfo.vec) {
TransTask task;
task.isUpload = isRemote_;
task.localId = oidCall_();
task.remoteId = ridCall_();
if (isRemote_) {
task.remotePath = basePathCall_();
task.localPath = Util::Join(otherSideCall_(), df.name);
}
else {
task.remotePath = Util::Join(otherSideCall_(), df.name);
task.localPath = basePathCall_();
}
tasks.push_back(task);
}
emit sigTasks(tasks);
} else { } else {
event->ignore(); event->ignore();
} }
@@ -48,18 +100,20 @@ void CustomTableWidget::mouseMoveEvent(QMouseEvent* event)
QDrag* drag = new QDrag(this); QDrag* drag = new QDrag(this);
QMimeData* mimeData = new QMimeData; QMimeData* mimeData = new QMimeData;
QStringList selectedTexts; DirFileInfoVec v;
v.root = basePathCall_();
foreach (QTableWidgetItem* item, selectedItems()) { foreach (QTableWidgetItem* item, selectedItems()) {
if (item->column() == 1) { if (item->column() == 1) {
selectedTexts << item->text(); DirFileInfo df;
df.name = item->text();
} }
} }
mimeData->setData("application/x-custom-data", selectedTexts.join("|").toUtf8()); mimeData->setData("application/x-custom-data", infoPack<DirFileInfoVec>(v));
drag->setMimeData(mimeData); drag->setMimeData(mimeData);
QPixmap pixmap(100, 50); QPixmap pixmap(100, 50);
pixmap.fill(Qt::lightGray); pixmap.fill(Qt::lightGray);
QPainter painter(&pixmap); QPainter painter(&pixmap);
painter.drawText(pixmap.rect(), Qt::AlignCenter, QString("%1 ITEM").arg(selectedTexts.count())); painter.drawText(pixmap.rect(), Qt::AlignCenter, QString("%1 ITEM").arg(v.vec.size()));
drag->setPixmap(pixmap); drag->setPixmap(pixmap);
drag->exec(Qt::CopyAction | Qt::MoveAction); drag->exec(Qt::CopyAction | Qt::MoveAction);
} }

View File

@@ -1,8 +1,9 @@
#ifndef CUSTOM_TABLEWIDET_H #ifndef CUSTOM_TABLEWIDET_H
#define CUSTOM_TABLEWIDET_H #define CUSTOM_TABLEWIDET_H
#include <QTableWidget> #include <FileTrans.h>
#include <QDropEvent> #include <QDropEvent>
#include <QTableWidget>
class CustomTableWidget : public QTableWidget class CustomTableWidget : public QTableWidget
{ {
@@ -11,6 +12,16 @@ public:
explicit CustomTableWidget(QWidget* parent = nullptr); explicit CustomTableWidget(QWidget* parent = nullptr);
~CustomTableWidget() override; ~CustomTableWidget() override;
signals:
void sigTasks(const QVector<TransTask>& tasks);
public:
void setIsRemote(bool isRemote);
void setBasePathCall(const std::function<QString()>& call);
void setOtherSidePathCall(const std::function<QString()>& call);
void setOwnIDCall(const std::function<QString()>& call);
void setRemoteIDCall(const std::function<QString()>& call);
protected: protected:
void dropEvent(QDropEvent* event) override; void dropEvent(QDropEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event); void dragEnterEvent(QDragEnterEvent* event);
@@ -18,7 +29,12 @@ protected:
void mousePressEvent(QMouseEvent* event) override; void mousePressEvent(QMouseEvent* event) override;
protected: protected:
bool isRemote_{false};
QPoint startPos_; QPoint startPos_;
std::function<QString()> basePathCall_;
std::function<QString()> otherSideCall_;
std::function<QString()> oidCall_;
std::function<QString()> ridCall_;
}; };
#endif #endif

View File

@@ -7,6 +7,11 @@
TransForm::TransForm(QWidget* parent) : QDialog(parent), ui(new Ui::TransForm) TransForm::TransForm(QWidget* parent) : QDialog(parent), ui(new Ui::TransForm)
{ {
ui->setupUi(this); ui->setupUi(this);
connect(this, &TransForm::sigProgress, this, &TransForm::setProgress);
connect(this, &TransForm::sigDone, this, &TransForm::handleDone);
connect(this, &TransForm::sigFailed, this, &TransForm::handleFailed);
connect(this, &TransForm::sigSetUi, this, &TransForm::handleUI);
} }
TransForm::~TransForm() TransForm::~TransForm()
@@ -28,12 +33,77 @@ void TransForm::SetTasks(const QVector<TransTask>& tasks)
void TransForm::startTask() void TransForm::startTask()
{ {
for (auto& task : tasks_) { for (auto& task : tasks_) {
sigSetUi(task);
if (task.isUpload) {
fileTrans_->ReqSendFile(task);
while (true) {
auto progress = fileTrans_->GetSendProgress();
if (progress < 0) {
sigFailed();
break;
}
if (progress >= 100.0) {
sigDone();
break;
}
sigProgress(progress);
QThread::msleep(10);
}
} else {
fileTrans_->ReqDownFile(task);
while (true) {
auto progress = fileTrans_->GetDownProgress();
if (progress < 0) {
sigFailed();
break;
}
if (progress >= 100.0) {
sigDone();
break;
}
sigProgress(progress);
QThread::msleep(10);
}
}
}
}
void TransForm::setProgress(double val)
{
ui->progressBar->setValue(val);
}
void TransForm::handleFailed()
{
ui->progressBar->setValue(0);
}
void TransForm::handleDone()
{
ui->progressBar->setValue(0);
}
void TransForm::handleUI(const TransTask& task)
{
if (task.isUpload) {
ui->edFrom->setText(task.localId);
ui->edTo->setText(task.remoteId);
ui->pedFrom->setPlainText(task.localPath);
ui->pedTo->setPlainText(task.remotePath);
}
else {
ui->edFrom->setText(task.localId);
ui->edTo->setText(task.remoteId);
ui->pedFrom->setPlainText(task.remotePath);
ui->pedTo->setPlainText(task.localPath);
} }
} }
void TransForm::showEvent(QShowEvent* event) void TransForm::showEvent(QShowEvent* event)
{ {
QDialog::showEvent(event); QDialog::showEvent(event);
startTask(); workTh_ = new TranFromTh(this);
fileTrans_->moveToThread(workTh_);
connect(workTh_, &QThread::finished, fileTrans_, &QObject::deleteLater);
workTh_->start();
} }

View File

@@ -2,14 +2,16 @@
#define TRANSFORM_H #define TRANSFORM_H
#include <ClientCore.h> #include <ClientCore.h>
#include <FileTrans.h>
#include <QDialog> #include <QDialog>
#include <QFile> #include <QFile>
#include <FileTrans.h> #include <QThread>
namespace Ui { namespace Ui {
class TransForm; class TransForm;
} }
class TranFromTh;
class TransForm : public QDialog class TransForm : public QDialog
{ {
Q_OBJECT Q_OBJECT
@@ -21,18 +23,50 @@ public:
public: public:
void SetClientCore(ClientCore* clientCore); void SetClientCore(ClientCore* clientCore);
void SetTasks(const QVector<TransTask>& tasks); void SetTasks(const QVector<TransTask>& tasks);
void startTask();
signals:
void sigProgress(double val);
void sigFailed();
void sigDone();
void sigSetUi(const TransTask& task);
private: private:
void startTask(); void setProgress(double val);
void handleFailed();
void handleDone();
void handleUI(const TransTask& task);
protected: protected:
void showEvent(QShowEvent* event) override; void showEvent(QShowEvent* event) override;
private: private:
TranFromTh* workTh_{};
QVector<TransTask> tasks_; QVector<TransTask> tasks_;
FileTrans* fileTrans_{}; FileTrans* fileTrans_{};
ClientCore* clientCore_{}; ClientCore* clientCore_{};
Ui::TransForm* ui; Ui::TransForm* ui;
}; };
class TranFromTh : public QThread
{
Q_OBJECT
public:
explicit TranFromTh(TransForm* tf, QObject* parent = nullptr) : QThread(parent), tf_(tf)
{
}
protected:
void run() override
{
if (tf_) {
tf_->startTask();
}
}
private:
TransForm* tf_;
};
#endif // TRANSFORM_H #endif // TRANSFORM_H

View File

@@ -1,10 +1,10 @@
#include "frelayGUI.h" #include "frelayGUI.h"
#include <QSplitter>
#include <QLabel> #include <QLabel>
#include <QSplitter>
#include <fversion.h>
#include "./ui_frelayGUI.h" #include "./ui_frelayGUI.h"
#include <fversion.h>
static LogPrint* logPrint = nullptr; static LogPrint* logPrint = nullptr;
@@ -44,7 +44,9 @@ void frelayGUI::InitControl()
localFile_ = new FileManager(this); localFile_ = new FileManager(this);
remoteFile_ = new FileManager(this); remoteFile_ = new FileManager(this);
localFile_->SetModeStr(tr("Local:")); localFile_->SetModeStr(tr("Local:"));
localFile_->SetOtherSidePathCall([this]() { return remoteFile_->GetCurRoot(); });
remoteFile_->SetModeStr(tr("Remote:"), 1, clientCore_); remoteFile_->SetModeStr(tr("Remote:"), 1, clientCore_);
remoteFile_->SetOtherSidePathCall([this]() { return localFile_->GetCurRoot(); });
tabWidget_ = new QTabWidget(this); tabWidget_ = new QTabWidget(this);
} }

View File

@@ -1,4 +1,4 @@
# frelay # frelay
A tool that uses a relay server to upload and download files from remote clients. A tool that uses a relay server to upload and download files from remote clients.
@@ -7,5 +7,7 @@ A tool that uses a relay server to upload and download files from remote clients
1. Minimal configuration—simply start a server, connect to it, and begin transferring files. 1. Minimal configuration—simply start a server, connect to it, and begin transferring files.
2. If you frequently transfer the same files repeatedly, frelay offers a local-remote file mapping feature for one-click transfers. 2. If you frequently transfer the same files repeatedly, frelay offers a local-remote file mapping feature for one-click transfers.
## Disclaimer ## Disclaimer And Warning
This tool is solely designed for simple file transmission between clients via a relay server. It does not include any security validation logic to prevent data attacks or similar threats. It is primarily intended for temporary, non-sensitive file transfers. Please close the software or disconnect from the relay server when not in use. This tool is solely designed for simple file transmission between clients via a relay server. It does not include any security validation logic to prevent data attacks or similar threats. It is primarily intended for temporary, non-sensitive file transfers. Please close the software or disconnect from the relay server when not in use.
The software may contain unexpected bugs that could corrupt or lose your files. Please ensure proper backups or use it only for non-critical file transfers.

View File

@@ -33,6 +33,11 @@ QString Util::GetUserHome()
return homePath; return homePath;
} }
QString Util::Join(const QString& path, const QString& name)
{
return QDir::cleanPath(path + QDir::separator() + name);
}
void Util::InitLogger(const QString& logPath, const QString& mark) void Util::InitLogger(const QString& logPath, const QString& mark)
{ {
auto file_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(logPath.toStdString(), 1024 * 1024 * 50, 3); auto file_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(logPath.toStdString(), 1024 * 1024 * 50, 3);

View File

@@ -14,6 +14,7 @@ public:
static QString GetUserHome(); static QString GetUserHome();
static void InitLogger(const QString& logPath, const QString& mark); static void InitLogger(const QString& logPath, const QString& mark);
static QString Get2FilePath(const QString& file, const QString& directory); static QString Get2FilePath(const QString& file, const QString& directory);
static QString Join(const QString& path, const QString& name);
static void ConsoleMsgHander(QtMsgType type, const QMessageLogContext& context, const QString& msg); static void ConsoleMsgHander(QtMsgType type, const QMessageLogContext& context, const QString& msg);
}; };