2025-06-17 17:20:54 +08:00
|
|
|
#include "cusTableWidget.h"
|
2025-06-18 10:19:54 +08:00
|
|
|
|
2025-06-18 14:53:56 +08:00
|
|
|
#include <InfoDirFile.h>
|
|
|
|
|
#include <InfoPack.hpp>
|
2025-06-18 10:19:54 +08:00
|
|
|
#include <QApplication>
|
2025-06-17 17:20:54 +08:00
|
|
|
#include <QDrag>
|
|
|
|
|
#include <QMimeData>
|
|
|
|
|
#include <QPainter>
|
2025-06-18 17:22:15 +08:00
|
|
|
|
2025-06-18 14:53:56 +08:00
|
|
|
#include "FileControl.h"
|
2025-06-17 17:20:54 +08:00
|
|
|
|
2025-06-18 10:19:54 +08:00
|
|
|
CustomTableWidget::CustomTableWidget(QWidget* parent) : QTableWidget(parent)
|
2025-06-17 17:20:54 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CustomTableWidget::~CustomTableWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-18 14:53:56 +08:00
|
|
|
void CustomTableWidget::setIsRemote(bool isRemote)
|
|
|
|
|
{
|
|
|
|
|
isRemote_ = isRemote;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CustomTableWidget::setOwnIDCall(const std::function<QString()>& call)
|
|
|
|
|
{
|
|
|
|
|
oidCall_ = call;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CustomTableWidget::setRemoteIDCall(const std::function<QString()>& call)
|
|
|
|
|
{
|
|
|
|
|
ridCall_ = call;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-17 17:20:54 +08:00
|
|
|
void CustomTableWidget::dropEvent(QDropEvent* event)
|
|
|
|
|
{
|
2025-06-18 17:22:15 +08:00
|
|
|
if (!event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) {
|
2025-06-17 17:20:54 +08:00
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-06-18 17:22:15 +08:00
|
|
|
QByteArray encoded = event->mimeData()->data("application/x-qabstractitemmodeldatalist");
|
|
|
|
|
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
|
|
|
|
|
2025-06-29 00:36:10 +08:00
|
|
|
QStringList parseData;
|
2025-06-19 11:59:32 +08:00
|
|
|
QVector<TransTask> tasks;
|
2025-06-18 17:22:15 +08:00
|
|
|
while (!stream.atEnd()) {
|
|
|
|
|
int row, col;
|
|
|
|
|
QMap<int, QVariant> roleData;
|
|
|
|
|
stream >> row >> col >> roleData;
|
2025-06-29 00:36:10 +08:00
|
|
|
parseData.append(roleData[Qt::DisplayRole].toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < (parseData.size() / 5); ++i) {
|
|
|
|
|
if (parseData[i * 5 + 3] != "File") {
|
2025-11-15 21:54:46 +08:00
|
|
|
qDebug() << QString(tr("暂不支持传输文件夹:%1")).arg(parseData[i * 5 + 1]);
|
2025-06-19 11:59:32 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
TransTask task;
|
2025-11-06 23:12:13 +08:00
|
|
|
task.taskUUID = Util::UUID();
|
2025-06-19 11:59:32 +08:00
|
|
|
task.isUpload = isRemote_;
|
|
|
|
|
task.localId = oidCall_();
|
|
|
|
|
task.remoteId = ridCall_();
|
|
|
|
|
if (isRemote_) {
|
2025-06-20 16:05:37 +08:00
|
|
|
task.remotePath = GlobalData::Ins()->GetRemoteRoot();
|
2025-06-29 00:36:10 +08:00
|
|
|
task.localPath = Util::Join(GlobalData::Ins()->GetLocalRoot(), parseData[i * 5 + 1]);
|
2025-06-19 11:59:32 +08:00
|
|
|
} else {
|
2025-06-20 16:05:37 +08:00
|
|
|
task.localPath = GlobalData::Ins()->GetLocalRoot();
|
2025-06-29 00:36:10 +08:00
|
|
|
task.remotePath = Util::Join(GlobalData::Ins()->GetRemoteRoot(), parseData[i * 5 + 1]);
|
2025-06-19 11:59:32 +08:00
|
|
|
}
|
|
|
|
|
tasks.push_back(task);
|
2025-06-18 17:22:15 +08:00
|
|
|
}
|
2025-11-15 21:54:46 +08:00
|
|
|
|
|
|
|
|
if (tasks.empty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-06-19 11:59:32 +08:00
|
|
|
emit sigTasks(tasks);
|
2025-06-17 17:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-18 10:19:54 +08:00
|
|
|
void CustomTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
2025-06-17 17:20:54 +08:00
|
|
|
{
|
|
|
|
|
const QTableWidget* source = qobject_cast<const QTableWidget*>(event->source());
|
|
|
|
|
if (source == this) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-06-18 17:22:15 +08:00
|
|
|
if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) {
|
2025-06-17 17:20:54 +08:00
|
|
|
event->acceptProposedAction();
|
|
|
|
|
} else {
|
|
|
|
|
event->ignore();
|
|
|
|
|
}
|
2025-06-18 17:22:15 +08:00
|
|
|
}
|