func:删除文件/夹成功。
This commit is contained in:
@@ -122,6 +122,16 @@ void ClientCore::handleAsk(QSharedPointer<FrameBuffer> frame)
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (msg.command == STRMSG_AC_DEL_FILEDIR) {
|
||||
msg.command = STRMSG_AC_ANSWER_DEL_FILEDIR;
|
||||
msg.msg = Util::Delete(msg.fromPath);
|
||||
if (!Send<InfoMsg>(msg, FBT_MSGINFO_ANSWER, frame->fid)) {
|
||||
auto logMsg = tr("给") + frame->fid + tr("返回删除结果消息失败。");
|
||||
qCritical() << logMsg;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// 未知信息
|
||||
qWarning() << QString(tr("未知询问信息类型:%1")).arg(msg.command);
|
||||
}
|
||||
|
||||
@@ -545,18 +545,85 @@ void FileManager::OperNewFolder()
|
||||
|
||||
void FileManager::OperDelete()
|
||||
{
|
||||
QList<QTableWidgetItem*> datas;
|
||||
if (!CheckSelect(datas)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 确认是否删除
|
||||
int ret = QMessageBox::question(this, tr("确认删除"), tr("确定要删除%1吗?").arg(datas[1]->text()),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
||||
|
||||
if (ret != QMessageBox::Yes) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto name = Util::Join(GetRoot(), datas[1]->text());
|
||||
auto type = datas[3]->text();
|
||||
|
||||
if (!isRemote_) {
|
||||
QString ret = Util::Delete(name);
|
||||
if (ret.isEmpty()) {
|
||||
QMessageBox::information(this, tr("提示"), tr("删除成功"));
|
||||
int row = datas[0]->row();
|
||||
ui->tableWidget->removeRow(row);
|
||||
} else {
|
||||
QMessageBox::information(this, tr("提示"), ret);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
WaitOper oper(this);
|
||||
oper.SetClient(cliCore_);
|
||||
oper.SetType(STRMSG_AC_DEL_FILEDIR, STRMSG_AC_ANSWER_DEL_FILEDIR);
|
||||
oper.SetPath(name, "", "");
|
||||
|
||||
LoadingDialog checking(this);
|
||||
checking.setTipsText("正在删除...");
|
||||
connect(&oper, &WaitOper::sigCheckOver, &checking, &LoadingDialog::cancelBtnClicked);
|
||||
connect(cliCore_, &ClientCore::sigMsgAnswer, &oper, &WaitOper::recvFrame);
|
||||
|
||||
oper.start();
|
||||
checking.exec();
|
||||
|
||||
std::shared_ptr<void> recv(nullptr, [&oper](void*) { oper.wait(); });
|
||||
|
||||
if (checking.isUserCancel()) {
|
||||
oper.interrupCheck();
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查结果
|
||||
auto msg = oper.GetMsg();
|
||||
if (msg.msg == STR_NONE || !msg.msg.isEmpty()) {
|
||||
QMessageBox::information(this, tr("提示"), QString(tr("删除失败=>%1")).arg(msg.msg));
|
||||
} else {
|
||||
QMessageBox::information(this, tr("提示"), QString(tr("删除成功。")));
|
||||
ui->tableWidget->removeRow(datas[0]->row());
|
||||
}
|
||||
}
|
||||
|
||||
bool FileManager::CheckSelect(QList<QTableWidgetItem*>& ret)
|
||||
{
|
||||
ret = ui->tableWidget->selectedItems();
|
||||
if (ret.isEmpty()) {
|
||||
QMessageBox::information(this, tr("提示"), tr("请选择一项。"));
|
||||
return false;
|
||||
}
|
||||
if (ret.size() % 5 != 0) {
|
||||
QMessageBox::information(this, tr("提示"), tr("请选择单行。"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileManager::OperRename()
|
||||
{
|
||||
auto datas = ui->tableWidget->selectedItems();
|
||||
if (datas.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (datas.size() % 5 != 0) {
|
||||
QMessageBox::information(this, tr("提示"), tr("请选择单行进行重命名。"));
|
||||
QList<QTableWidgetItem*> datas;
|
||||
if (!CheckSelect(datas)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto curName = datas[1]->text();
|
||||
auto curType = datas[3]->text();
|
||||
|
||||
@@ -574,6 +641,9 @@ void FileManager::OperRename()
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
QString oldName = Util::Join(GetRoot(), curName);
|
||||
QString newName = Util::Join(GetRoot(), text);
|
||||
@@ -612,13 +682,8 @@ void FileManager::OperRename()
|
||||
auto msg = oper.GetMsg();
|
||||
if (msg.msg == STR_NONE || !msg.msg.isEmpty()) {
|
||||
QMessageBox::information(this, tr("提示"), QString(tr("重命名失败=>%1")).arg(msg.msg));
|
||||
return;
|
||||
}
|
||||
if (msg.msg.isEmpty()) {
|
||||
datas[1]->setText(text);
|
||||
return;
|
||||
} else {
|
||||
QMessageBox::information(this, tr("提示"), QString(tr("重命名失败=>%1")).arg(msg.msg));
|
||||
datas[1]->setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <FileTrans.h>
|
||||
#include <InfoDirFile.h>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QMenu>
|
||||
#include <QMutex>
|
||||
#include <QWidget>
|
||||
@@ -86,7 +87,8 @@ private:
|
||||
void OperNewFolder();
|
||||
void OperDelete();
|
||||
void OperRename();
|
||||
|
||||
bool CheckSelect(QList<QTableWidgetItem*>& ret);
|
||||
|
||||
public slots:
|
||||
void evtHome();
|
||||
void evtFile();
|
||||
|
||||
@@ -91,10 +91,8 @@ enum FileCheckState {
|
||||
// 字符串标识
|
||||
#define STRMSG_AC_CHECK_FILE_EXIST "requestCheckFileExist"
|
||||
#define STRMSG_AC_ANSWER_FILE_EXIST "answerCheckFileExist"
|
||||
#define STRMSG_AC_DEL_FILE "requestDelFile"
|
||||
#define STRMSG_AC_ANSWER_DEL_FILE "answerDelFile"
|
||||
#define STRMSG_AC_DEL_DIR "requestDelDir"
|
||||
#define STRMSG_AC_ANSWER_DEL_DIR "answerDelDir"
|
||||
#define STRMSG_AC_DEL_FILEDIR "requestDelFileDir"
|
||||
#define STRMSG_AC_ANSWER_DEL_FILEDIR "answerDelFileDir"
|
||||
#define STRMSG_AC_RENAME_FILEDIR "requestRenameFileDir"
|
||||
#define STRMSG_AC_ANSWER_RENAME_FILEDIR "answerRenameFileDir"
|
||||
#define STRMSG_AC_NEW_DIR "requestNewDir"
|
||||
|
||||
@@ -158,7 +158,7 @@ QString Util::Rename(const QString& from, const QString& to, bool isDir)
|
||||
if (dir.rename(from, to)) {
|
||||
return "";
|
||||
}
|
||||
return tr("请确认是否有权限或者被占用。");
|
||||
return tr("请确认是否无权限操作或者被占用。");
|
||||
} else {
|
||||
QFile f(from);
|
||||
if (f.rename(to)) {
|
||||
@@ -253,3 +253,30 @@ void GlobalData::SetConfigPath(const std::string& path)
|
||||
{
|
||||
ConfigPath_ = path;
|
||||
}
|
||||
|
||||
QString Util::Delete(const QString& path)
|
||||
{
|
||||
QFileInfo fileInfo(path);
|
||||
|
||||
if (!fileInfo.exists()) {
|
||||
return tr("文件或目录不存在: %1").arg(path);
|
||||
}
|
||||
|
||||
if (fileInfo.isFile()) {
|
||||
QFile file(path);
|
||||
if (file.remove()) {
|
||||
return "";
|
||||
} else {
|
||||
return tr("删除文件失败: %1").arg(file.errorString());
|
||||
}
|
||||
} else if (fileInfo.isDir()) {
|
||||
QDir dir(path);
|
||||
if (dir.removeRecursively()) {
|
||||
return "";
|
||||
} else {
|
||||
return tr("删除目录失败,确认是否占用或者无权限操作。");
|
||||
}
|
||||
} else {
|
||||
return tr("不支持的文件类型: %1").arg(path);
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ public:
|
||||
static bool FileExist(const QString& path);
|
||||
static bool DirExist(const QString& path, bool isFilePath);
|
||||
static QString Rename(const QString& from, const QString& to, bool isDir);
|
||||
static QString Delete(const QString& path);
|
||||
static QString UUID();
|
||||
static QVector<QString> GetLocalDrivers();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user