2026-07-02_14_31_VX5 韩国
This commit is contained in:
@@ -36,7 +36,12 @@ FileManageWidget::FileManageWidget(QWidget *parent) :
|
||||
connect(ui->systemFileListView, &QListWidget::itemSelectionChanged, this, &FileManageWidget::refreshButtonsStatus);
|
||||
connect(ui->udiskFileListView, &QListWidget::itemSelectionChanged, this, &FileManageWidget::refreshButtonsStatus);
|
||||
|
||||
updateUDiskDevList();
|
||||
m_hasUDisk = checkUDiskPresent();
|
||||
onUDiskStateChanged();
|
||||
|
||||
m_udiskCheckTimer = new QTimer(this);
|
||||
connect(m_udiskCheckTimer, &QTimer::timeout, this, &FileManageWidget::onUDiskCheckTimeout);
|
||||
m_udiskCheckTimer->start(1000);
|
||||
|
||||
m_focusedListView = ui->systemFileListView;
|
||||
m_focusedListView->setFocus();
|
||||
@@ -47,6 +52,7 @@ FileManageWidget::FileManageWidget(QWidget *parent) :
|
||||
|
||||
FileManageWidget::~FileManageWidget()
|
||||
{
|
||||
m_udiskCheckTimer->stop();
|
||||
ui->systemFileListView->removeEventFilter(this);
|
||||
ui->udiskFileListView->removeEventFilter(this);
|
||||
delete ui;
|
||||
@@ -94,20 +100,22 @@ void FileManageWidget::onFilterCBoxSelectChanged(int i)
|
||||
}
|
||||
|
||||
m_currFilterType = i;
|
||||
updateFileListView(ui->systemFileListView);
|
||||
updateFileListView(ui->udiskFileListView);
|
||||
refreshFileList(ui->systemFileListView);
|
||||
if (m_hasUDisk) {
|
||||
refreshFileList(ui->udiskFileListView);
|
||||
}
|
||||
}
|
||||
|
||||
void FileManageWidget::onExportBtnClicked()
|
||||
{
|
||||
copyFiles(ui->systemFileListView, ui->udiskFileListView);
|
||||
updateFileListView(ui->udiskFileListView);
|
||||
refreshFileList(ui->udiskFileListView);
|
||||
}
|
||||
|
||||
void FileManageWidget::onImportBtnClicked()
|
||||
{
|
||||
copyFiles(ui->udiskFileListView, ui->systemFileListView);
|
||||
updateFileListView(ui->systemFileListView);
|
||||
refreshFileList(ui->systemFileListView);
|
||||
}
|
||||
|
||||
void FileManageWidget::onSelectAllBtnClicked()
|
||||
@@ -138,37 +146,59 @@ void FileManageWidget::onDelSelectedBtnClicked()
|
||||
qInfo() << "Delete: " << filename << ", result: " << ret;
|
||||
}
|
||||
|
||||
updateFileListView(m_focusedListView);
|
||||
refreshFileList(m_focusedListView);
|
||||
}
|
||||
|
||||
void FileManageWidget::updateUDiskDevList()
|
||||
bool FileManageWidget::checkUDiskPresent()
|
||||
{
|
||||
bool hasUDisk = false;
|
||||
QFile mountsFile("/proc/mounts");
|
||||
if (mountsFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QTextStream in(&mountsFile);
|
||||
while (!in.atEnd()) {
|
||||
const QString line = in.readLine();
|
||||
if (line.contains("/udisk ")) {
|
||||
hasUDisk = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
QString mountsContent = QString::fromLocal8Bit(mountsFile.readAll());
|
||||
mountsFile.close();
|
||||
if (mountsContent.lastIndexOf("/udisk ") != -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!hasUDisk) {
|
||||
QDir dir(UDISK_DOC_ROOT_DIR);
|
||||
hasUDisk = dir.exists();
|
||||
bool FileManageWidget::ensureUDiskDocDir()
|
||||
{
|
||||
QDir dir(UDISK_DOC_ROOT_DIR);
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkpath(UDISK_DOC_ROOT_DIR)) {
|
||||
qCritical() << "Cannot create UDisk doc dir:" << UDISK_DOC_ROOT_DIR;
|
||||
return false;
|
||||
}
|
||||
qInfo() << "Created UDisk doc dir:" << UDISK_DOC_ROOT_DIR;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileManageWidget::onUDiskCheckTimeout()
|
||||
{
|
||||
bool hasUDisk = checkUDiskPresent();
|
||||
if (hasUDisk == m_hasUDisk) {
|
||||
return;
|
||||
}
|
||||
m_hasUDisk = hasUDisk;
|
||||
onUDiskStateChanged();
|
||||
}
|
||||
|
||||
void FileManageWidget::onUDiskStateChanged()
|
||||
{
|
||||
ui->udiskSelectBox->clear();
|
||||
if (hasUDisk) {
|
||||
if (m_hasUDisk) {
|
||||
ui->udiskSelectBox->addItem(tr("U盘"));
|
||||
ui->udiskSelectBox->setCurrentIndex(0);
|
||||
if (ensureUDiskDocDir()) {
|
||||
refreshFileList(ui->udiskFileListView);
|
||||
} else {
|
||||
ui->udiskFileListView->clear();
|
||||
}
|
||||
} else {
|
||||
ui->udiskFileListView->clear();
|
||||
}
|
||||
|
||||
updateFileListView(ui->udiskFileListView);
|
||||
}
|
||||
|
||||
void FileManageWidget::refreshButtonsStatus()
|
||||
@@ -187,15 +217,14 @@ void FileManageWidget::refreshButtonsStatus()
|
||||
ui->selectAllBtn->setEnabled(m_focusedListView->count() != selectedItems.size());
|
||||
}
|
||||
|
||||
int FileManageWidget::updateFileListView(QListWidget* listView)
|
||||
int FileManageWidget::refreshFileList(QListWidget* listView)
|
||||
{
|
||||
QString searchPath = listView->property("searchPath").toString();
|
||||
|
||||
// 判断目录是否存在
|
||||
QDir dir(searchPath);
|
||||
if(!dir.exists()) {
|
||||
qCritical() << "Cannot open path: " << searchPath;
|
||||
return -1;
|
||||
if (!dir.exists()) {
|
||||
listView->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 根据过滤类型设置过滤器字符串
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QListWidget>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Ui {
|
||||
class FileManageWidget;
|
||||
@@ -33,13 +34,16 @@ private slots:
|
||||
void onSelectAllBtnClicked();
|
||||
void onCancelAllBtnClicked();
|
||||
void onDelSelectedBtnClicked();
|
||||
void updateUDiskDevList();
|
||||
void onUDiskCheckTimeout();
|
||||
|
||||
void refreshButtonsStatus();
|
||||
|
||||
private:
|
||||
|
||||
int updateFileListView(QListWidget* listView);
|
||||
bool checkUDiskPresent();
|
||||
bool ensureUDiskDocDir();
|
||||
int refreshFileList(QListWidget* listView);
|
||||
void onUDiskStateChanged();
|
||||
|
||||
void copyFiles(QListWidget* from, QListWidget* to);
|
||||
|
||||
@@ -48,10 +52,12 @@ private:
|
||||
int m_currFilterType;
|
||||
QListWidget* m_focusedListView = nullptr;
|
||||
|
||||
// 用于文件显示列表中,存放每个文件名对应的绝对路径所用的数据键
|
||||
static constexpr int AbsPathRole = Qt::UserRole + 1;
|
||||
|
||||
QTimer* m_udiskCheckTimer = nullptr;
|
||||
bool m_hasUDisk = false;
|
||||
|
||||
void applyStyleSheet(); // 应用样式表
|
||||
};
|
||||
|
||||
#endif // FILEMANAGEWIDGET_H
|
||||
#endif // FILEMANAGEWIDGET_H
|
||||
Reference in New Issue
Block a user