|
|
|
|
@@ -3,6 +3,7 @@
|
|
|
|
|
#include <QDesktopServices>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QListWidget>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QXmlStreamReader>
|
|
|
|
|
#include <QXmlStreamWriter>
|
|
|
|
|
@@ -80,8 +81,10 @@ void Compare::InitControl()
|
|
|
|
|
|
|
|
|
|
connect(ui->btnSave, &QPushButton::clicked, this, &Compare::Save);
|
|
|
|
|
connect(ui->btnLoad, &QPushButton::clicked, this, &Compare::Load);
|
|
|
|
|
connect(ui->btnLeft, &QPushButton::clicked, this, &Compare::TransToLeft);
|
|
|
|
|
connect(ui->btnRight, &QPushButton::clicked, this, &Compare::TransToRight);
|
|
|
|
|
// connect(ui->btnLeft, &QPushButton::clicked, this, &Compare::TransToLeft);
|
|
|
|
|
// connect(ui->btnRight, &QPushButton::clicked, this, &Compare::TransToRight);
|
|
|
|
|
connect(ui->btnTypeDown, &QPushButton::clicked, this, [this]() { FilterFiles(false); });
|
|
|
|
|
connect(ui->btnTypeUpload, &QPushButton::clicked, this, [this]() { FilterFiles(true); });
|
|
|
|
|
connect(ui->btnSearch, &QPushButton::clicked, this, &Compare::Search);
|
|
|
|
|
connect(ui->btnReset, &QPushButton::clicked, this, &Compare::Reset);
|
|
|
|
|
|
|
|
|
|
@@ -376,56 +379,144 @@ void Compare::SetResult(const QVector<CompareItem>& items)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Compare::TransToLeft()
|
|
|
|
|
void Compare::FilterFiles(bool isUpload)
|
|
|
|
|
{
|
|
|
|
|
QVector<TransTask> tasks;
|
|
|
|
|
QModelIndexList indexList = ui->tableWidget->selectionModel()->selectedRows();
|
|
|
|
|
QDialog dialog(this);
|
|
|
|
|
QString title = QString("筛选文件类型(%1)").arg(isUpload ? tr("上传") : tr("下载"));
|
|
|
|
|
dialog.setWindowTitle(title);
|
|
|
|
|
dialog.resize(400, 300);
|
|
|
|
|
QListWidget listWidget(&dialog);
|
|
|
|
|
|
|
|
|
|
if (indexList.size() < 1) {
|
|
|
|
|
QMessageBox::information(this, tr("提示"), tr("请选择要下载的文件。"));
|
|
|
|
|
return;
|
|
|
|
|
listWidget.setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
|
QListWidgetItem* allItem = new QListWidgetItem("*(ALL)");
|
|
|
|
|
allItem->setData(Qt::UserRole, "*");
|
|
|
|
|
allItem->setCheckState(curSelectTypes_.contains("*") ? Qt::Checked : Qt::Unchecked);
|
|
|
|
|
listWidget.addItem(allItem);
|
|
|
|
|
|
|
|
|
|
int rows = ui->tableWidget->rowCount();
|
|
|
|
|
for (int i = 0; i < rows; ++i) {
|
|
|
|
|
QString ext = ui->tableWidget->item(i, 0)->text().split(".").last().toUpper();
|
|
|
|
|
QListWidgetItem* item = new QListWidgetItem(ext);
|
|
|
|
|
item->setData(Qt::UserRole, ext);
|
|
|
|
|
item->setCheckState(curSelectTypes_.contains(ext) ? Qt::Checked : Qt::Unchecked);
|
|
|
|
|
listWidget.addItem(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < indexList.size(); ++i) {
|
|
|
|
|
const QTableWidgetItem* itemF = ui->tableWidget->item(indexList[i].row(), 2);
|
|
|
|
|
const QTableWidgetItem* itemT = ui->tableWidget->item(indexList[i].row(), 1);
|
|
|
|
|
QDialogButtonBox buttons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog);
|
|
|
|
|
connect(&buttons, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
|
|
|
|
|
connect(&buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout layout(&dialog);
|
|
|
|
|
layout.addWidget(&listWidget);
|
|
|
|
|
layout.addWidget(&buttons);
|
|
|
|
|
dialog.setLayout(&layout);
|
|
|
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
|
|
|
|
QVector<QString> selectedTypes;
|
|
|
|
|
for (int i = 0; i < listWidget.count(); ++i) {
|
|
|
|
|
QListWidgetItem* item = listWidget.item(i);
|
|
|
|
|
if (item->checkState() == Qt::Checked) {
|
|
|
|
|
selectedTypes << item->data(Qt::UserRole).toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
curSelectTypes_.clear();
|
|
|
|
|
for (int i = 0; i < selectedTypes.count(); ++i) {
|
|
|
|
|
curSelectTypes_.insert(selectedTypes[i]);
|
|
|
|
|
}
|
|
|
|
|
if (isUpload) {
|
|
|
|
|
TransToRight(true);
|
|
|
|
|
} else {
|
|
|
|
|
TransToLeft(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Compare::TransToLeft(bool useSelectTypes)
|
|
|
|
|
{
|
|
|
|
|
QVector<TransTask> tasks;
|
|
|
|
|
|
|
|
|
|
auto pushTask = [&](const QString& localPath, const QString& remotePath) {
|
|
|
|
|
TransTask task;
|
|
|
|
|
task.taskUUID = Util::UUID();
|
|
|
|
|
task.isUpload = false;
|
|
|
|
|
task.localId = GlobalData::Ins()->GetLocalID();
|
|
|
|
|
task.localPath = itemT->text();
|
|
|
|
|
task.localPath = localPath;
|
|
|
|
|
task.remoteId = GlobalData::Ins()->GetRemoteID();
|
|
|
|
|
task.remotePath = Util::Join(itemF->text(), ui->tableWidget->item(indexList[i].row(), 0)->text());
|
|
|
|
|
task.remotePath = remotePath;
|
|
|
|
|
tasks.push_back(task);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
emit sigTasks(tasks);
|
|
|
|
|
if (useSelectTypes) {
|
|
|
|
|
for (int i = 0; i < ui->tableWidget->rowCount(); ++i) {
|
|
|
|
|
QString ext = ui->tableWidget->item(i, 0)->text().split(".").last().toUpper();
|
|
|
|
|
if (curSelectTypes_.contains(ext)) {
|
|
|
|
|
const QTableWidgetItem* itemF = ui->tableWidget->item(i, 1);
|
|
|
|
|
const QTableWidgetItem* itemT = ui->tableWidget->item(i, 2);
|
|
|
|
|
pushTask(itemT->text(), Util::Join(itemF->text(), ui->tableWidget->item(i, 0)->text()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (tasks.size() > 0) {
|
|
|
|
|
emit sigTasks(tasks);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
QModelIndexList indexList = ui->tableWidget->selectionModel()->selectedRows();
|
|
|
|
|
if (indexList.size() < 1) {
|
|
|
|
|
QMessageBox::information(this, tr("提示"), tr("请选择要下载的文件。"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < indexList.size(); ++i) {
|
|
|
|
|
const QTableWidgetItem* itemF = ui->tableWidget->item(indexList[i].row(), 2);
|
|
|
|
|
const QTableWidgetItem* itemT = ui->tableWidget->item(indexList[i].row(), 1);
|
|
|
|
|
pushTask(itemT->text(), Util::Join(itemF->text(), ui->tableWidget->item(indexList[i].row(), 0)->text()));
|
|
|
|
|
}
|
|
|
|
|
if (tasks.size() > 0) {
|
|
|
|
|
emit sigTasks(tasks);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Compare::TransToRight()
|
|
|
|
|
void Compare::TransToRight(bool useSelectTypes)
|
|
|
|
|
{
|
|
|
|
|
QVector<TransTask> tasks;
|
|
|
|
|
QModelIndexList indexList = ui->tableWidget->selectionModel()->selectedRows();
|
|
|
|
|
|
|
|
|
|
if (indexList.size() < 1) {
|
|
|
|
|
QMessageBox::information(this, tr("提示"), tr("请选择要上传的文件。"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < indexList.size(); ++i) {
|
|
|
|
|
const QTableWidgetItem* itemF = ui->tableWidget->item(indexList[i].row(), 1);
|
|
|
|
|
const QTableWidgetItem* itemT = ui->tableWidget->item(indexList[i].row(), 2);
|
|
|
|
|
auto pushTask = [&](const QString& localPath, const QString& remotePath) {
|
|
|
|
|
TransTask task;
|
|
|
|
|
task.taskUUID = Util::UUID();
|
|
|
|
|
task.isUpload = true;
|
|
|
|
|
task.localId = GlobalData::Ins()->GetLocalID();
|
|
|
|
|
task.localPath = Util::Join(itemF->text(), ui->tableWidget->item(indexList[i].row(), 0)->text());
|
|
|
|
|
task.localPath = localPath;
|
|
|
|
|
task.remoteId = GlobalData::Ins()->GetRemoteID();
|
|
|
|
|
task.remotePath = itemT->text();
|
|
|
|
|
task.remotePath = remotePath;
|
|
|
|
|
tasks.push_back(task);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
emit sigTasks(tasks);
|
|
|
|
|
if (useSelectTypes) {
|
|
|
|
|
for (int i = 0; i < ui->tableWidget->rowCount(); ++i) {
|
|
|
|
|
QString ext = ui->tableWidget->item(i, 0)->text().split(".").last().toUpper();
|
|
|
|
|
if (curSelectTypes_.contains(ext)) {
|
|
|
|
|
const QTableWidgetItem* itemF = ui->tableWidget->item(i, 1);
|
|
|
|
|
const QTableWidgetItem* itemT = ui->tableWidget->item(i, 2);
|
|
|
|
|
pushTask(Util::Join(itemF->text(), ui->tableWidget->item(i, 0)->text()), itemT->text());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (tasks.size() > 0) {
|
|
|
|
|
emit sigTasks(tasks);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
QModelIndexList indexList = ui->tableWidget->selectionModel()->selectedRows();
|
|
|
|
|
if (indexList.size() < 1) {
|
|
|
|
|
QMessageBox::information(this, tr("提示"), tr("请选择要上传的文件。"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < indexList.size(); ++i) {
|
|
|
|
|
const QTableWidgetItem* itemF = ui->tableWidget->item(indexList[i].row(), 1);
|
|
|
|
|
const QTableWidgetItem* itemT = ui->tableWidget->item(indexList[i].row(), 2);
|
|
|
|
|
pushTask(Util::Join(itemF->text(), ui->tableWidget->item(indexList[i].row(), 0)->text()), itemT->text());
|
|
|
|
|
}
|
|
|
|
|
if (tasks.size() > 0) {
|
|
|
|
|
emit sigTasks(tasks);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Compare::deleteSelectedRows()
|
|
|
|
|
|