func:重命名功能完成。

This commit is contained in:
2025-11-16 19:23:59 +08:00
parent 466b012b4f
commit e24223b32b
8 changed files with 215 additions and 16 deletions

View File

@@ -112,6 +112,16 @@ void ClientCore::handleAsk(QSharedPointer<FrameBuffer> frame)
}
return;
}
if (msg.command == STRMSG_AC_RENAME_FILEDIR) {
msg.command = STRMSG_AC_ANSWER_RENAME_FILEDIR;
msg.msg = Util::Rename(msg.fromPath, msg.toPath, msg.type == STR_DIR);
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);
}

View File

@@ -7,6 +7,7 @@
#include <QDir>
#include <QFile>
#include <QHeaderView>
#include <QInputDialog>
#include <QLineEdit>
#include <QListWidget>
#include <QMessageBox>
@@ -15,6 +16,7 @@
#include <RemoteFile.h>
#include "Form/FileInfoForm.h"
#include "Form/Loading.h"
#include "GuiUtil/Public.h"
#include "ui_FileControl.h"
@@ -313,7 +315,7 @@ void FileManager::RefreshTab()
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
ui->tableWidget->setItem(i, 4, item);
if (i % 10 == 0) {
if (i % 50 == 0) {
QGuiApplication::processEvents();
}
}
@@ -547,10 +549,77 @@ void FileManager::OperDelete()
void FileManager::OperRename()
{
}
auto datas = ui->tableWidget->selectedItems();
if (datas.isEmpty()) {
return;
}
if (datas.size() % 5 != 0) {
QMessageBox::information(this, tr("提示"), tr("请选择单行进行重命名。"));
return;
}
auto curName = datas[1]->text();
auto curType = datas[3]->text();
void FileManager::WaitMsg()
{
QInputDialog dialog(this);
dialog.setWindowTitle("输入");
dialog.setLabelText("请输入新名称:");
dialog.setOkButtonText("确定");
dialog.setCancelButtonText("取消");
dialog.setFixedSize(dialog.minimumSizeHint());
QString text;
if (dialog.exec() == QDialog::Accepted) {
text = dialog.textValue().trimmed();
if (text.isEmpty()) {
return;
}
}
QString oldName = Util::Join(GetRoot(), curName);
QString newName = Util::Join(GetRoot(), text);
if (!isRemote_) {
QString ret = Util::Rename(oldName, newName, curType == STR_DIR);
if (!ret.isEmpty()) {
QMessageBox::information(this, tr("提示"), ret);
} else {
datas[1]->setText(text);
}
return;
}
WaitOper oper(this);
oper.SetClient(cliCore_);
oper.SetType(STRMSG_AC_RENAME_FILEDIR, STRMSG_AC_ANSWER_RENAME_FILEDIR);
oper.SetPath(oldName, newName, curType);
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));
return;
}
if (msg.msg.isEmpty()) {
datas[1]->setText(text);
return;
} else {
QMessageBox::information(this, tr("提示"), QString(tr("重命名失败=>%1")).arg(msg.msg));
}
}
QString FileManager::GetRoot()
@@ -603,7 +672,7 @@ void FileManager::doubleClick(int row, int column)
}
auto type = ui->tableWidget->item(row, 3)->text();
if (type != "Dir") {
if (type != STR_DIR) {
return;
}
@@ -611,3 +680,80 @@ void FileManager::doubleClick(int row, int column)
QString np = dir.filePath(item->text());
fileHelper_->GetDirFile(np);
}
WaitOper::WaitOper(QObject* parent) : WaitThread(parent)
{
}
void WaitOper::run()
{
isAlreadyInter_ = false;
infoMsg_.msg = STR_NONE;
isRun_ = true;
recvMsg_ = false;
InfoMsg msg;
msg.command = sendStrType_;
msg.fromPath = stra_;
msg.toPath = strb_;
msg.type = type_;
auto f = cli_->GetBuffer<InfoMsg>(msg, FBT_MSGINFO_ASK, cli_->GetRemoteID());
if (!ClientCore::syncInvoke(cli_, f)) {
auto errMsg = QString(tr("向%1发送%2请求失败。")).arg(cli_->GetRemoteID()).arg(sendStrType_);
emit sigCheckOver();
qCritical() << errMsg;
return;
}
while (isRun_) {
QThread::msleep(1);
if (isAlreadyInter_) {
qInfo() << tr("线程中断文件操作等待......");
return;
}
if (!recvMsg_) {
continue;
}
break;
}
isAlreadyInter_ = true;
emit sigCheckOver();
auto n = QString(tr("向%1的请求%2处理结束。")).arg(cli_->GetRemoteID()).arg(sendStrType_);
qInfo() << n;
}
void WaitOper::SetType(const QString& sendType, const QString& ansType)
{
sendStrType_ = sendType;
ansStrType_ = ansType;
}
void WaitOper::SetPath(const QString& stra, const QString& strb, const QString& type)
{
stra_ = stra;
strb_ = strb;
type_ = type;
}
InfoMsg WaitOper::GetMsg() const
{
return infoMsg_;
}
void WaitOper::interrupCheck()
{
qWarning() << QString(tr("中断请求处理%1......")).arg(sendStrType_);
WaitThread::interrupCheck();
}
void WaitOper::recvFrame(QSharedPointer<FrameBuffer> frame)
{
InfoMsg info = infoUnpack<InfoMsg>(frame->data);
if (info.command == ansStrType_) {
infoMsg_ = info;
recvMsg_ = true;
return;
}
auto n = tr("收到未知Oper的回复信息:") + info.command;
qInfo() << n;
}

View File

@@ -27,6 +27,29 @@ enum class SortMethod {
SMD_BY_SIZE_ASC,
};
class WaitOper : public WaitThread
{
public:
WaitOper(QObject* parent = nullptr);
public:
void run() override;
void SetType(const QString& sendType, const QString& ansType);
void SetPath(const QString& stra, const QString& strb, const QString& type);
InfoMsg GetMsg() const;
virtual void interrupCheck();
virtual void recvFrame(QSharedPointer<FrameBuffer> frame);
private:
bool recvMsg_{};
InfoMsg infoMsg_{};
QString sendStrType_{};
QString ansStrType_{};
QString stra_;
QString strb_;
QString type_;
};
class FileManager : public QWidget
{
Q_OBJECT
@@ -63,7 +86,6 @@ private:
void OperNewFolder();
void OperDelete();
void OperRename();
void WaitMsg();
public slots:
void evtHome();

View File

@@ -165,10 +165,11 @@ void frelayGUI::HandleTask(const QVector<TransTask>& tasks)
return;
}
std::shared_ptr<void> recv(nullptr, [&cond](void*) { cond.wait(); });
// 检查结果
auto reTasks = cond.GetTasks();
if (!CheckTaskResult(reTasks)) {
cond.wait();
return;
}
if (reTasks.empty()) {

View File

@@ -96,20 +96,21 @@ enum FileCheckState {
#define STRMSG_AC_DEL_DIR "requestDelDir"
#define STRMSG_AC_ANSWER_DEL_DIR "answerDelDir"
#define STRMSG_AC_RENAME_FILEDIR "requestRenameFileDir"
#define STRMSG_AC_ANSWER_FILEDIR "answerRenameFileDir"
#define STRMSG_AC_ANSWER_RENAME_FILEDIR "answerRenameFileDir"
#define STRMSG_AC_NEW_DIR "requestNewDir"
#define STRMSG_AC_ANSWER_NEW_DIR "answerNewDir"
#define STRMSG_AC_ASK_FILEINFO "requestFileInfo"
#define STRMSG_AC_ANSWER_FILEINFO "answerFileInfo"
#define STRMSG_AC_UP "upAction"
#define STRMSG_AC_DOWN "downAction"
#define STRMSG_AC_ACCEPT "acceptAction"
#define STRMSG_AC_REJECT "rejectAction"
#define STRMSG_AC_CANCEL "cancelAction"
#define STRMSG_ST_FILEEXIT "fileExist"
#define STRMSG_ST_FILENOEXIT "fileNotExist"
#define STRMSG_ST_DIREXIT "dirExist"
#define STRMSG_ST_DIRNOEXIT "dirNotExist"
#define STR_FILE "File"
#define STR_DIR "Dir"
#define STR_NONE "None"
#endif // PROTOCOL_H

View File

@@ -24,6 +24,7 @@ struct InfoMsg {
QString msg;
QString fromPath;
QString toPath;
QString type;
quint64 size{};
quint32 permissions{};
QVector<QString> list;
@@ -31,7 +32,7 @@ struct InfoMsg {
void serialize(QDataStream& data) const
{
data << mark << command << msg << fromPath << toPath << size << permissions;
data << mark << command << msg << fromPath << toPath << type << size << permissions;
data << static_cast<qint32>(list.size());
for (const auto& item : list) {
data << item;
@@ -46,7 +47,7 @@ struct InfoMsg {
void deserialize(QDataStream& data)
{
data >> mark >> command >> msg >> fromPath >> toPath >> size >> permissions;
data >> mark >> command >> msg >> fromPath >> toPath >> type >> size >> permissions;
qint32 listSize;
data >> listSize;

View File

@@ -3,6 +3,7 @@
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QFileDevice>
#include <QFileInfo>
#include <QMutex>
#include <QStandardPaths>
@@ -150,6 +151,23 @@ bool Util::DirExist(const QString& path, bool isFilePath)
return dir.exists();
}
QString Util::Rename(const QString& from, const QString& to, bool isDir)
{
if (isDir) {
QDir dir;
if (dir.rename(from, to)) {
return "";
}
return tr("请确认是否有权限或者被占用。");
} else {
QFile f(from);
if (f.rename(to)) {
return "";
}
return f.errorString();
}
}
QString Util::UUID()
{
return QUuid::createUuid().toString().remove("{").remove("}");
@@ -235,4 +253,3 @@ void GlobalData::SetConfigPath(const std::string& path)
{
ConfigPath_ = path;
}

View File

@@ -51,6 +51,7 @@ public:
static QString GetVersion();
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 UUID();
static QVector<QString> GetLocalDrivers();
};