2025-06-17 17:20:54 +08:00
|
|
|
#include "FileControl.h"
|
2025-06-15 14:31:54 +08:00
|
|
|
|
|
|
|
|
#include <LocalFile.h>
|
2025-06-29 00:13:35 +08:00
|
|
|
#include <QClipboard>
|
2025-06-15 14:31:54 +08:00
|
|
|
#include <QDateTime>
|
2025-06-28 23:48:15 +08:00
|
|
|
#include <QDialog>
|
2025-06-15 14:31:54 +08:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QHeaderView>
|
2025-06-28 23:57:46 +08:00
|
|
|
#include <QLineEdit>
|
2025-06-28 23:48:15 +08:00
|
|
|
#include <QListWidget>
|
2025-06-15 14:31:54 +08:00
|
|
|
#include <QTableWidgetItem>
|
|
|
|
|
#include <RemoteFile.h>
|
|
|
|
|
|
2025-06-29 00:13:35 +08:00
|
|
|
#include "GuiUtil/Public.h"
|
2025-06-15 14:31:54 +08:00
|
|
|
#include "ui_FileControl.h"
|
|
|
|
|
|
|
|
|
|
FileManager::FileManager(QWidget* parent) : QWidget(parent), ui(new Ui::FileManager)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
InitControl();
|
2025-06-28 23:48:15 +08:00
|
|
|
InitMenu();
|
2025-06-15 14:31:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileManager::~FileManager()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManager::SetModeStr(const QString& modeStr, int type, ClientCore* clientCore)
|
|
|
|
|
{
|
2025-06-20 09:45:39 +08:00
|
|
|
cliCore_ = clientCore;
|
|
|
|
|
|
2025-06-15 14:31:54 +08:00
|
|
|
ui->lbMode->setText(modeStr);
|
|
|
|
|
if (type == 0) {
|
2025-06-20 16:00:18 +08:00
|
|
|
isRemote_ = false;
|
2025-06-15 14:31:54 +08:00
|
|
|
fileHelper_ = std::make_shared<LocalFile>();
|
|
|
|
|
} else {
|
|
|
|
|
auto remotePtr = std::make_shared<RemoteFile>();
|
|
|
|
|
remotePtr->setClientCore(clientCore);
|
2025-06-20 16:00:18 +08:00
|
|
|
isRemote_ = true;
|
2025-06-18 14:53:56 +08:00
|
|
|
ui->tableWidget->setIsRemote(true);
|
2025-06-15 14:31:54 +08:00
|
|
|
fileHelper_ = remotePtr;
|
2025-10-20 16:40:52 +08:00
|
|
|
connect(cliCore_, &ClientCore::sigDisconnect, this, [this]() { ui->tableWidget->setRowCount(0); });
|
|
|
|
|
connect(cliCore_, &ClientCore::sigOffline, this, [this]() { ui->tableWidget->setRowCount(0); });
|
2025-06-15 14:31:54 +08:00
|
|
|
}
|
2025-06-20 09:45:39 +08:00
|
|
|
|
|
|
|
|
ui->tableWidget->setOwnIDCall([this]() { return cliCore_->GetOwnID(); });
|
|
|
|
|
ui->tableWidget->setRemoteIDCall([this]() { return cliCore_->GetRemoteID(); });
|
2025-06-19 15:37:39 +08:00
|
|
|
|
|
|
|
|
connect(fileHelper_.get(), &DirFileHelper::sigHome, this, &FileManager::ShowPath);
|
|
|
|
|
connect(fileHelper_.get(), &DirFileHelper::sigDirFile, this, &FileManager::ShowFile);
|
2025-06-26 00:19:45 +08:00
|
|
|
|
|
|
|
|
if (type == 0) {
|
|
|
|
|
evtHome();
|
|
|
|
|
evtFile();
|
|
|
|
|
}
|
2025-06-18 14:53:56 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-15 14:31:54 +08:00
|
|
|
void FileManager::InitControl()
|
|
|
|
|
{
|
|
|
|
|
QStringList headers;
|
|
|
|
|
headers << tr("") << tr("FileName") << tr("ModifyTime") << tr("Type") << tr("Size");
|
|
|
|
|
ui->tableWidget->setColumnCount(headers.size());
|
|
|
|
|
ui->tableWidget->setHorizontalHeaderLabels(headers);
|
|
|
|
|
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
|
|
|
|
|
ui->comboBox->setEditable(true);
|
|
|
|
|
// ui->tableWidget->setColumnWidth(0, 50);
|
|
|
|
|
ui->tableWidget->setColumnWidth(1, 300);
|
2025-06-25 23:49:40 +08:00
|
|
|
ui->tableWidget->setColumnWidth(2, 170);
|
2025-06-15 14:31:54 +08:00
|
|
|
ui->tableWidget->setColumnWidth(3, 70);
|
|
|
|
|
ui->tableWidget->setColumnWidth(4, 90);
|
|
|
|
|
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
|
|
|
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
|
|
|
|
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
|
|
|
|
// ui->tableWidget->setStyleSheet("QTableWidget::item:hover { background-color: transparent; }");
|
|
|
|
|
|
2025-06-17 17:20:54 +08:00
|
|
|
ui->tableWidget->setDragEnabled(true);
|
|
|
|
|
ui->tableWidget->viewport()->setAcceptDrops(true);
|
|
|
|
|
ui->tableWidget->setDropIndicatorShown(true);
|
|
|
|
|
ui->tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
2025-06-18 17:22:15 +08:00
|
|
|
ui->tableWidget->setDragDropMode(QAbstractItemView::DragDrop);
|
2025-06-17 17:20:54 +08:00
|
|
|
|
2025-06-28 23:48:15 +08:00
|
|
|
ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
2025-06-15 14:31:54 +08:00
|
|
|
connect(ui->btnHome, &QPushButton::clicked, this, &FileManager::evtHome);
|
|
|
|
|
connect(ui->btnVisit, &QPushButton::clicked, this, &FileManager::evtFile);
|
|
|
|
|
connect(ui->tableWidget, &QTableWidget::cellDoubleClicked, this, &FileManager::doubleClick);
|
|
|
|
|
connect(ui->btnUp, &QPushButton::clicked, this, &FileManager::evtUp);
|
2025-06-18 15:10:28 +08:00
|
|
|
connect(ui->tableWidget, &CustomTableWidget::sigTasks, this,
|
|
|
|
|
[this](const QVector<TransTask>& tasks) { emit sigSendTasks(tasks); });
|
2025-06-28 22:53:42 +08:00
|
|
|
|
2025-06-28 23:48:15 +08:00
|
|
|
connect(ui->tableWidget, &QTableWidget::customContextMenuRequested, this,
|
|
|
|
|
[this](const QPoint& pos) { menu_->exec(QCursor::pos()); });
|
|
|
|
|
|
2025-06-28 22:53:42 +08:00
|
|
|
connect(ui->tableWidget->horizontalHeader(), &QHeaderView::sectionClicked, this, &FileManager::HeaderClicked);
|
2025-10-21 10:12:21 +08:00
|
|
|
|
|
|
|
|
auto* line = ui->comboBox->lineEdit();
|
|
|
|
|
connect(line, &QLineEdit::returnPressed, this, [this]() { ui->btnVisit->click(); });
|
2025-06-15 14:31:54 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-28 23:48:15 +08:00
|
|
|
void FileManager::InitMenu()
|
2025-06-17 17:20:54 +08:00
|
|
|
{
|
2025-06-28 23:48:15 +08:00
|
|
|
menu_ = new QMenu(ui->tableWidget);
|
|
|
|
|
menu_->addAction(tr("Filter"), this, &FileManager::ShowFilterForm);
|
2025-06-29 00:13:35 +08:00
|
|
|
menu_->addAction(tr("FullPath"), this, &FileManager::CopyFullPath);
|
2025-06-28 23:48:15 +08:00
|
|
|
menu_->addSeparator();
|
2025-06-17 17:20:54 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-15 14:31:54 +08:00
|
|
|
void FileManager::ShowPath(const QString& path)
|
|
|
|
|
{
|
2025-06-19 15:37:39 +08:00
|
|
|
QMutexLocker locker(&cbMut_);
|
2025-06-15 14:31:54 +08:00
|
|
|
int existingIndex = ui->comboBox->findText(path);
|
|
|
|
|
if (existingIndex != -1) {
|
|
|
|
|
ui->comboBox->removeItem(existingIndex);
|
|
|
|
|
} else if (ui->comboBox->count() >= 20) {
|
|
|
|
|
ui->comboBox->removeItem(ui->comboBox->count() - 1);
|
|
|
|
|
}
|
|
|
|
|
ui->comboBox->insertItem(0, path);
|
|
|
|
|
ui->comboBox->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManager::ShowFile(const DirFileInfoVec& info)
|
|
|
|
|
{
|
2025-06-19 15:37:39 +08:00
|
|
|
QMutexLocker locker(&tbMut_);
|
2025-06-28 22:53:42 +08:00
|
|
|
currentInfo_ = info;
|
|
|
|
|
SortFileInfo(SortMethod::SMD_BY_TYPE_DESC);
|
2025-06-28 23:48:15 +08:00
|
|
|
GenFilter();
|
|
|
|
|
curSelectTypes_.clear();
|
|
|
|
|
currentShowInfo_ = currentInfo_;
|
2025-06-28 22:53:42 +08:00
|
|
|
RefreshTab();
|
|
|
|
|
ui->tableWidget->resizeColumnToContents(0);
|
|
|
|
|
SetRoot(currentInfo_.root);
|
|
|
|
|
ShowPath(GetRoot());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManager::SetRoot(const QString& path)
|
|
|
|
|
{
|
|
|
|
|
if (isRemote_) {
|
|
|
|
|
GlobalData::Ins()->SetRemoteRoot(path);
|
|
|
|
|
} else {
|
|
|
|
|
GlobalData::Ins()->SetLocalRoot(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManager::SortFileInfo(SortMethod method)
|
|
|
|
|
{
|
|
|
|
|
auto& vec = currentInfo_.vec;
|
|
|
|
|
|
|
|
|
|
switch (method) {
|
|
|
|
|
case SortMethod::SMD_BY_NAME_ASC:
|
|
|
|
|
std::sort(vec.begin(), vec.end(), [](const DirFileInfo& a, const DirFileInfo& b) {
|
|
|
|
|
return QString::compare(a.name, b.name, Qt::CaseInsensitive) < 0;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SortMethod::SMD_BY_NAME_DESC:
|
|
|
|
|
std::sort(vec.begin(), vec.end(), [](const DirFileInfo& a, const DirFileInfo& b) {
|
|
|
|
|
return QString::compare(a.name, b.name, Qt::CaseInsensitive) > 0;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SortMethod::SMD_BY_TIME_ASC:
|
|
|
|
|
std::sort(vec.begin(), vec.end(),
|
|
|
|
|
[](const DirFileInfo& a, const DirFileInfo& b) { return a.lastModified < b.lastModified; });
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SortMethod::SMD_BY_TIME_DESC:
|
|
|
|
|
std::sort(vec.begin(), vec.end(),
|
|
|
|
|
[](const DirFileInfo& a, const DirFileInfo& b) { return a.lastModified > b.lastModified; });
|
|
|
|
|
break;
|
2025-06-15 14:31:54 +08:00
|
|
|
|
2025-06-28 22:53:42 +08:00
|
|
|
case SortMethod::SMD_BY_TYPE_ASC:
|
|
|
|
|
std::sort(vec.begin(), vec.end(), [](const DirFileInfo& a, const DirFileInfo& b) {
|
|
|
|
|
if (a.type == b.type) {
|
|
|
|
|
return QString::compare(a.name, b.name, Qt::CaseInsensitive) < 0;
|
|
|
|
|
}
|
|
|
|
|
return a.type < b.type;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SortMethod::SMD_BY_TYPE_DESC:
|
|
|
|
|
std::sort(vec.begin(), vec.end(), [](const DirFileInfo& a, const DirFileInfo& b) {
|
|
|
|
|
if (a.type == b.type) {
|
|
|
|
|
return QString::compare(a.name, b.name, Qt::CaseInsensitive) < 0;
|
|
|
|
|
}
|
|
|
|
|
return a.type > b.type;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SortMethod::SMD_BY_SIZE_ASC:
|
|
|
|
|
std::sort(vec.begin(), vec.end(), [](const DirFileInfo& a, const DirFileInfo& b) {
|
|
|
|
|
if (a.type == b.type) {
|
|
|
|
|
return a.size < b.size;
|
|
|
|
|
}
|
|
|
|
|
return a.type == FileType::Dir && b.type != FileType::Dir;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SortMethod::SMD_BY_SIZE_DESC:
|
|
|
|
|
std::sort(vec.begin(), vec.end(), [](const DirFileInfo& a, const DirFileInfo& b) {
|
|
|
|
|
if (a.type == b.type) {
|
|
|
|
|
return a.size > b.size;
|
|
|
|
|
}
|
|
|
|
|
return a.type == FileType::Dir && b.type != FileType::Dir;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
std::sort(vec.begin(), vec.end(), [](const DirFileInfo& a, const DirFileInfo& b) {
|
|
|
|
|
return QString::compare(a.name, b.name, Qt::CaseInsensitive) < 0;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManager::RefreshTab()
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->setRowCount(0);
|
2025-06-28 23:48:15 +08:00
|
|
|
ui->tableWidget->setRowCount(currentShowInfo_.vec.size());
|
|
|
|
|
for (int i = 0; i < currentShowInfo_.vec.size(); ++i) {
|
|
|
|
|
const DirFileInfo& fileInfo = currentShowInfo_.vec[i];
|
2025-06-15 14:31:54 +08:00
|
|
|
|
|
|
|
|
// ***********************************************************************************
|
|
|
|
|
auto* iconItem = new QTableWidgetItem("");
|
|
|
|
|
iconItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
iconItem->setFlags(iconItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
ui->tableWidget->setItem(i, 0, iconItem);
|
|
|
|
|
|
|
|
|
|
// ***********************************************************************************
|
|
|
|
|
auto* fileItem = new QTableWidgetItem(fileInfo.name);
|
|
|
|
|
fileItem->setFlags(fileItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
ui->tableWidget->setItem(i, 1, fileItem);
|
|
|
|
|
QDateTime modifyTime = QDateTime::fromMSecsSinceEpoch(fileInfo.lastModified);
|
|
|
|
|
|
|
|
|
|
// ***********************************************************************************
|
|
|
|
|
QString timeStr = modifyTime.toString("yyyy-MM-dd hh:mm:ss");
|
|
|
|
|
auto* timeItem = new QTableWidgetItem(timeStr);
|
|
|
|
|
timeItem->setFlags(timeItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
ui->tableWidget->setItem(i, 2, timeItem);
|
|
|
|
|
|
|
|
|
|
// ***********************************************************************************
|
|
|
|
|
QString typeStr;
|
|
|
|
|
switch (fileInfo.type) {
|
|
|
|
|
case File:
|
|
|
|
|
typeStr = "File";
|
|
|
|
|
iconItem->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileIcon));
|
|
|
|
|
break;
|
|
|
|
|
case Dir:
|
|
|
|
|
typeStr = "Dir";
|
|
|
|
|
iconItem->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
|
break;
|
|
|
|
|
case Link:
|
|
|
|
|
typeStr = "Link";
|
|
|
|
|
break;
|
|
|
|
|
case Other:
|
|
|
|
|
typeStr = "Other";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
typeStr = "Unknown";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ***********************************************************************************
|
|
|
|
|
auto* typeItem = new QTableWidgetItem(typeStr);
|
|
|
|
|
typeItem->setFlags(typeItem->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
ui->tableWidget->setItem(i, 3, typeItem);
|
|
|
|
|
|
|
|
|
|
// ***********************************************************************************
|
|
|
|
|
QString sizeStr;
|
|
|
|
|
if (fileInfo.size < 1024) {
|
|
|
|
|
sizeStr = QString::number(fileInfo.size) + " B";
|
|
|
|
|
} else if (fileInfo.size < 1024 * 1024) {
|
|
|
|
|
sizeStr = QString::number(fileInfo.size / 1024.0, 'f', 2) + " KB";
|
|
|
|
|
} else {
|
|
|
|
|
sizeStr = QString::number(fileInfo.size / (1024.0 * 1024.0), 'f', 2) + " MB";
|
|
|
|
|
}
|
|
|
|
|
QTableWidgetItem* item = nullptr;
|
|
|
|
|
if (fileInfo.type == File) {
|
|
|
|
|
item = new QTableWidgetItem(sizeStr);
|
|
|
|
|
} else {
|
|
|
|
|
item = new QTableWidgetItem("");
|
|
|
|
|
}
|
|
|
|
|
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
|
|
|
|
|
ui->tableWidget->setItem(i, 4, item);
|
|
|
|
|
}
|
2025-06-28 23:57:46 +08:00
|
|
|
ui->tableWidget->scrollToTop();
|
2025-06-20 16:00:18 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-28 22:53:42 +08:00
|
|
|
void FileManager::HeaderClicked(int column)
|
2025-06-20 16:00:18 +08:00
|
|
|
{
|
2025-06-28 22:53:42 +08:00
|
|
|
SortMethod curMed{};
|
|
|
|
|
switch (column) {
|
|
|
|
|
case 1:
|
|
|
|
|
if (sortMedRecord_.count(column)) {
|
|
|
|
|
curMed = sortMedRecord_[column];
|
|
|
|
|
}
|
|
|
|
|
curMed = (curMed == SortMethod::SMD_BY_NAME_ASC ? SortMethod::SMD_BY_NAME_DESC : SortMethod::SMD_BY_NAME_ASC);
|
|
|
|
|
SortFileInfo(curMed);
|
|
|
|
|
sortMedRecord_[column] = curMed;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if (sortMedRecord_.count(column)) {
|
|
|
|
|
curMed = sortMedRecord_[column];
|
|
|
|
|
}
|
|
|
|
|
curMed = (curMed == SortMethod::SMD_BY_TIME_ASC ? SortMethod::SMD_BY_TIME_DESC : SortMethod::SMD_BY_TIME_ASC);
|
|
|
|
|
SortFileInfo(curMed);
|
|
|
|
|
sortMedRecord_[column] = curMed;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
if (sortMedRecord_.count(column)) {
|
|
|
|
|
curMed = sortMedRecord_[column];
|
|
|
|
|
}
|
|
|
|
|
curMed = (curMed == SortMethod::SMD_BY_TYPE_ASC ? SortMethod::SMD_BY_TYPE_DESC : SortMethod::SMD_BY_TYPE_ASC);
|
|
|
|
|
SortFileInfo(curMed);
|
|
|
|
|
sortMedRecord_[column] = curMed;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
if (sortMedRecord_.count(column)) {
|
|
|
|
|
curMed = sortMedRecord_[column];
|
|
|
|
|
}
|
|
|
|
|
curMed = (curMed == SortMethod::SMD_BY_SIZE_ASC ? SortMethod::SMD_BY_SIZE_DESC : SortMethod::SMD_BY_SIZE_ASC);
|
|
|
|
|
SortFileInfo(curMed);
|
|
|
|
|
sortMedRecord_[column] = curMed;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
2025-06-20 16:00:18 +08:00
|
|
|
}
|
2025-06-28 22:53:42 +08:00
|
|
|
QMetaObject::invokeMethod(this, "RefreshTab", Qt::QueuedConnection);
|
2025-06-20 16:00:18 +08:00
|
|
|
}
|
|
|
|
|
|
2025-06-30 01:05:28 +08:00
|
|
|
void FileManager::SetUiCurrentPath(const QString& path)
|
|
|
|
|
{
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ui->comboBox->addItem(path);
|
|
|
|
|
ui->comboBox->setCurrentText(path);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-28 23:48:15 +08:00
|
|
|
void FileManager::FilterFile(const QStringList& selectedTypes)
|
|
|
|
|
{
|
|
|
|
|
if (selectedTypes.contains("*")) {
|
|
|
|
|
currentShowInfo_.vec = currentInfo_.vec;
|
|
|
|
|
QMetaObject::invokeMethod(this, "RefreshTab", Qt::QueuedConnection);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
currentShowInfo_.vec.clear();
|
|
|
|
|
for (const auto& d : currentInfo_.vec) {
|
|
|
|
|
if (d.type == File) {
|
|
|
|
|
auto ext = d.fullPath.lastIndexOf('.');
|
|
|
|
|
if (ext != -1) {
|
|
|
|
|
QString extStr = d.fullPath.mid(ext + 1).toLower();
|
|
|
|
|
if (selectedTypes.contains(extStr)) {
|
|
|
|
|
currentShowInfo_.vec.push_back(d);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QMetaObject::invokeMethod(this, "RefreshTab", Qt::QueuedConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManager::GenFilter()
|
|
|
|
|
{
|
|
|
|
|
fileTypes_.clear();
|
|
|
|
|
for (const auto& fileInfo : currentInfo_.vec) {
|
|
|
|
|
if (fileInfo.type == File) {
|
|
|
|
|
auto ext = fileInfo.fullPath.lastIndexOf('.');
|
|
|
|
|
if (ext != -1) {
|
|
|
|
|
QString extStr = fileInfo.fullPath.mid(ext + 1).toLower();
|
|
|
|
|
fileTypes_.insert(extStr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManager::ShowFilterForm()
|
|
|
|
|
{
|
|
|
|
|
QDialog dialog(this);
|
|
|
|
|
dialog.setWindowTitle("Select file type");
|
|
|
|
|
dialog.resize(400, 300);
|
|
|
|
|
QListWidget listWidget(&dialog);
|
|
|
|
|
|
|
|
|
|
listWidget.setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
|
QListWidgetItem* allItem = new QListWidgetItem("*(ALL)");
|
|
|
|
|
allItem->setData(Qt::UserRole, "*");
|
|
|
|
|
allItem->setCheckState(curSelectTypes_.contains("*") ? Qt::Checked : Qt::Unchecked);
|
|
|
|
|
listWidget.addItem(allItem);
|
|
|
|
|
|
|
|
|
|
for (const QString& ext : fileTypes_) {
|
|
|
|
|
QListWidgetItem* item = new QListWidgetItem(ext);
|
|
|
|
|
item->setData(Qt::UserRole, ext);
|
|
|
|
|
item->setCheckState(curSelectTypes_.contains(ext) ? Qt::Checked : Qt::Unchecked);
|
|
|
|
|
listWidget.addItem(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
QStringList 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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FilterFile(selectedTypes);
|
|
|
|
|
curSelectTypes_.clear();
|
|
|
|
|
for (int i = 0; i < selectedTypes.count(); ++i) {
|
|
|
|
|
curSelectTypes_.insert(selectedTypes[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-29 00:13:35 +08:00
|
|
|
void FileManager::CopyFullPath()
|
|
|
|
|
{
|
|
|
|
|
int row = ui->tableWidget->currentRow();
|
|
|
|
|
if (row < 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QClipboard* clip = QApplication::clipboard();
|
|
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
QString key = ui->tableWidget->item(row, 1)->text();
|
|
|
|
|
for (const auto& d : currentInfo_.vec) {
|
|
|
|
|
if (d.name == key) {
|
|
|
|
|
clip->setText(d.fullPath);
|
|
|
|
|
found = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
|
|
|
|
FTCommon::msg(this, QString(tr("%1 not found.")).arg(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 16:00:18 +08:00
|
|
|
QString FileManager::GetRoot()
|
|
|
|
|
{
|
|
|
|
|
if (isRemote_) {
|
|
|
|
|
return GlobalData::Ins()->GetRemoteRoot();
|
|
|
|
|
} else {
|
|
|
|
|
return GlobalData::Ins()->GetLocalRoot();
|
|
|
|
|
}
|
2025-06-15 14:31:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManager::evtHome()
|
|
|
|
|
{
|
|
|
|
|
auto r = fileHelper_->GetHome();
|
|
|
|
|
auto curPath = ui->comboBox->currentText();
|
2025-06-20 16:00:18 +08:00
|
|
|
SetRoot(curPath);
|
2025-06-15 14:31:54 +08:00
|
|
|
qDebug() << QString(tr("%1 get home ret:%2").arg(__FUNCTION__).arg(r));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManager::evtFile()
|
|
|
|
|
{
|
|
|
|
|
auto curPath = ui->comboBox->currentText();
|
|
|
|
|
auto r = fileHelper_->GetDirFile(curPath);
|
2025-06-20 16:00:18 +08:00
|
|
|
SetRoot(curPath);
|
2025-06-15 14:31:54 +08:00
|
|
|
qDebug() << QString(tr("%1 get files ret:%2").arg(__FUNCTION__).arg(r));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManager::evtUp()
|
|
|
|
|
{
|
2025-06-20 16:00:18 +08:00
|
|
|
QString path(GetRoot());
|
2025-06-15 14:31:54 +08:00
|
|
|
QDir dir(path);
|
2025-06-15 23:49:07 +08:00
|
|
|
path = QDir::cleanPath(dir.absolutePath() + "/..");
|
2025-06-15 14:31:54 +08:00
|
|
|
if (path.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto r = fileHelper_->GetDirFile(path);
|
|
|
|
|
if (r) {
|
2025-06-20 16:00:18 +08:00
|
|
|
SetRoot(path);
|
|
|
|
|
ShowPath(GetRoot());
|
2025-06-15 14:31:54 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileManager::doubleClick(int row, int column)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(column)
|
|
|
|
|
|
|
|
|
|
auto* item = ui->tableWidget->item(row, 1);
|
|
|
|
|
if (item == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto type = ui->tableWidget->item(row, 3)->text();
|
|
|
|
|
if (type != "Dir") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 16:00:18 +08:00
|
|
|
QDir dir(GetRoot());
|
2025-06-15 14:31:54 +08:00
|
|
|
QString np = dir.filePath(item->text());
|
|
|
|
|
fileHelper_->GetDirFile(np);
|
|
|
|
|
}
|