update: add dray trigger task.
This commit is contained in:
@@ -29,12 +29,22 @@ void FileManager::SetModeStr(const QString& modeStr, int type, ClientCore* clien
|
||||
fileHelper_->registerPathCall([this](const QString& path) { ShowPath(path); });
|
||||
fileHelper_->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); });
|
||||
} else {
|
||||
cliCore_ = clientCore;
|
||||
auto remotePtr = std::make_shared<RemoteFile>();
|
||||
remotePtr->registerPathCall([this](const QString& path) { ShowPath(path); });
|
||||
remotePtr->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); });
|
||||
remotePtr->setClientCore(clientCore);
|
||||
ui->tableWidget->setIsRemote(true);
|
||||
ui->tableWidget->setOwnIDCall([this]() { return cliCore_->GetOwnID(); });
|
||||
ui->tableWidget->setRemoteIDCall([this]() { return cliCore_->GetRemoteID(); });
|
||||
fileHelper_ = remotePtr;
|
||||
}
|
||||
ui->tableWidget->setBasePathCall([this]() { return curRoot_; });
|
||||
}
|
||||
|
||||
void FileManager::SetOtherSidePathCall(const std::function<QString()>& call)
|
||||
{
|
||||
ui->tableWidget->setOtherSidePathCall(call);
|
||||
}
|
||||
|
||||
void FileManager::InitControl()
|
||||
@@ -72,10 +82,9 @@ void FileManager::InitControl()
|
||||
void FileManager::InitMenu(bool remote)
|
||||
{
|
||||
if (remote) {
|
||||
//auto acDown = new QAction(tr("Download"));
|
||||
}
|
||||
else {
|
||||
//auto acUp = new QAction(tr("Upload"));
|
||||
// auto acDown = new QAction(tr("Download"));
|
||||
} else {
|
||||
// auto acUp = new QAction(tr("Upload"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ public:
|
||||
|
||||
public:
|
||||
void SetModeStr(const QString& modeStr, int type = 0, ClientCore* clientCore = nullptr);
|
||||
void SetOtherSidePathCall(const std::function<QString()>& call);
|
||||
QString GetCurRoot();
|
||||
|
||||
private:
|
||||
void InitControl();
|
||||
@@ -38,6 +40,7 @@ private:
|
||||
Ui::FileManager* ui;
|
||||
QString curRoot_;
|
||||
QMenu* menu_;
|
||||
ClientCore* cliCore_;
|
||||
std::shared_ptr<DirFileHelper> fileHelper_;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include "cusTableWidget.h"
|
||||
|
||||
#include <InfoDirFile.h>
|
||||
#include <InfoPack.hpp>
|
||||
#include <QApplication>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QPainter>
|
||||
#include "FileControl.h"
|
||||
|
||||
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)
|
||||
{
|
||||
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")) {
|
||||
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 {
|
||||
event->ignore();
|
||||
}
|
||||
@@ -48,18 +100,20 @@ void CustomTableWidget::mouseMoveEvent(QMouseEvent* event)
|
||||
QDrag* drag = new QDrag(this);
|
||||
QMimeData* mimeData = new QMimeData;
|
||||
|
||||
QStringList selectedTexts;
|
||||
DirFileInfoVec v;
|
||||
v.root = basePathCall_();
|
||||
foreach (QTableWidgetItem* item, selectedItems()) {
|
||||
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);
|
||||
QPixmap pixmap(100, 50);
|
||||
pixmap.fill(Qt::lightGray);
|
||||
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->exec(Qt::CopyAction | Qt::MoveAction);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#ifndef CUSTOM_TABLEWIDET_H
|
||||
#define CUSTOM_TABLEWIDET_H
|
||||
|
||||
#include <QTableWidget>
|
||||
#include <FileTrans.h>
|
||||
#include <QDropEvent>
|
||||
#include <QTableWidget>
|
||||
|
||||
class CustomTableWidget : public QTableWidget
|
||||
{
|
||||
@@ -11,6 +12,16 @@ public:
|
||||
explicit CustomTableWidget(QWidget* parent = nullptr);
|
||||
~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:
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
void dragEnterEvent(QDragEnterEvent* event);
|
||||
@@ -18,7 +29,12 @@ protected:
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
|
||||
protected:
|
||||
bool isRemote_{false};
|
||||
QPoint startPos_;
|
||||
std::function<QString()> basePathCall_;
|
||||
std::function<QString()> otherSideCall_;
|
||||
std::function<QString()> oidCall_;
|
||||
std::function<QString()> ridCall_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,11 @@
|
||||
TransForm::TransForm(QWidget* parent) : QDialog(parent), ui(new Ui::TransForm)
|
||||
{
|
||||
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()
|
||||
@@ -28,12 +33,77 @@ void TransForm::SetTasks(const QVector<TransTask>& tasks)
|
||||
void TransForm::startTask()
|
||||
{
|
||||
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)
|
||||
{
|
||||
QDialog::showEvent(event);
|
||||
startTask();
|
||||
workTh_ = new TranFromTh(this);
|
||||
fileTrans_->moveToThread(workTh_);
|
||||
connect(workTh_, &QThread::finished, fileTrans_, &QObject::deleteLater);
|
||||
workTh_->start();
|
||||
}
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
#define TRANSFORM_H
|
||||
|
||||
#include <ClientCore.h>
|
||||
#include <FileTrans.h>
|
||||
#include <QDialog>
|
||||
#include <QFile>
|
||||
#include <FileTrans.h>
|
||||
#include <QThread>
|
||||
|
||||
namespace Ui {
|
||||
class TransForm;
|
||||
}
|
||||
|
||||
class TranFromTh;
|
||||
class TransForm : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -21,18 +23,50 @@ public:
|
||||
public:
|
||||
void SetClientCore(ClientCore* clientCore);
|
||||
void SetTasks(const QVector<TransTask>& tasks);
|
||||
void startTask();
|
||||
|
||||
signals:
|
||||
void sigProgress(double val);
|
||||
void sigFailed();
|
||||
void sigDone();
|
||||
void sigSetUi(const TransTask& task);
|
||||
|
||||
private:
|
||||
void startTask();
|
||||
void setProgress(double val);
|
||||
void handleFailed();
|
||||
void handleDone();
|
||||
void handleUI(const TransTask& task);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
|
||||
private:
|
||||
TranFromTh* workTh_{};
|
||||
QVector<TransTask> tasks_;
|
||||
FileTrans* fileTrans_{};
|
||||
ClientCore* clientCore_{};
|
||||
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
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "frelayGUI.h"
|
||||
|
||||
#include <QSplitter>
|
||||
#include <QLabel>
|
||||
#include <QSplitter>
|
||||
#include <fversion.h>
|
||||
|
||||
#include "./ui_frelayGUI.h"
|
||||
#include <fversion.h>
|
||||
|
||||
static LogPrint* logPrint = nullptr;
|
||||
|
||||
@@ -44,7 +44,9 @@ void frelayGUI::InitControl()
|
||||
localFile_ = new FileManager(this);
|
||||
remoteFile_ = new FileManager(this);
|
||||
localFile_->SetModeStr(tr("Local:"));
|
||||
localFile_->SetOtherSidePathCall([this]() { return remoteFile_->GetCurRoot(); });
|
||||
remoteFile_->SetModeStr(tr("Remote:"), 1, clientCore_);
|
||||
remoteFile_->SetOtherSidePathCall([this]() { return localFile_->GetCurRoot(); });
|
||||
|
||||
tabWidget_ = new QTabWidget(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user