func:重命名功能完成。
This commit is contained in:
@@ -112,6 +112,16 @@ void ClientCore::handleAsk(QSharedPointer<FrameBuffer> frame)
|
|||||||
}
|
}
|
||||||
return;
|
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);
|
qWarning() << QString(tr("未知询问信息类型:%1")).arg(msg.command);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QInputDialog>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -15,6 +16,7 @@
|
|||||||
#include <RemoteFile.h>
|
#include <RemoteFile.h>
|
||||||
|
|
||||||
#include "Form/FileInfoForm.h"
|
#include "Form/FileInfoForm.h"
|
||||||
|
#include "Form/Loading.h"
|
||||||
#include "GuiUtil/Public.h"
|
#include "GuiUtil/Public.h"
|
||||||
#include "ui_FileControl.h"
|
#include "ui_FileControl.h"
|
||||||
|
|
||||||
@@ -313,7 +315,7 @@ void FileManager::RefreshTab()
|
|||||||
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
|
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
|
||||||
ui->tableWidget->setItem(i, 4, item);
|
ui->tableWidget->setItem(i, 4, item);
|
||||||
|
|
||||||
if (i % 10 == 0) {
|
if (i % 50 == 0) {
|
||||||
QGuiApplication::processEvents();
|
QGuiApplication::processEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -547,10 +549,77 @@ void FileManager::OperDelete()
|
|||||||
|
|
||||||
void FileManager::OperRename()
|
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();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::WaitMsg()
|
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()
|
QString FileManager::GetRoot()
|
||||||
@@ -603,7 +672,7 @@ void FileManager::doubleClick(int row, int column)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto type = ui->tableWidget->item(row, 3)->text();
|
auto type = ui->tableWidget->item(row, 3)->text();
|
||||||
if (type != "Dir") {
|
if (type != STR_DIR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,3 +680,80 @@ void FileManager::doubleClick(int row, int column)
|
|||||||
QString np = dir.filePath(item->text());
|
QString np = dir.filePath(item->text());
|
||||||
fileHelper_->GetDirFile(np);
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,6 +27,29 @@ enum class SortMethod {
|
|||||||
SMD_BY_SIZE_ASC,
|
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
|
class FileManager : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -63,7 +86,6 @@ private:
|
|||||||
void OperNewFolder();
|
void OperNewFolder();
|
||||||
void OperDelete();
|
void OperDelete();
|
||||||
void OperRename();
|
void OperRename();
|
||||||
void WaitMsg();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void evtHome();
|
void evtHome();
|
||||||
|
|||||||
@@ -165,10 +165,11 @@ void frelayGUI::HandleTask(const QVector<TransTask>& tasks)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<void> recv(nullptr, [&cond](void*) { cond.wait(); });
|
||||||
|
|
||||||
// 检查结果
|
// 检查结果
|
||||||
auto reTasks = cond.GetTasks();
|
auto reTasks = cond.GetTasks();
|
||||||
if (!CheckTaskResult(reTasks)) {
|
if (!CheckTaskResult(reTasks)) {
|
||||||
cond.wait();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (reTasks.empty()) {
|
if (reTasks.empty()) {
|
||||||
|
|||||||
@@ -96,20 +96,21 @@ enum FileCheckState {
|
|||||||
#define STRMSG_AC_DEL_DIR "requestDelDir"
|
#define STRMSG_AC_DEL_DIR "requestDelDir"
|
||||||
#define STRMSG_AC_ANSWER_DEL_DIR "answerDelDir"
|
#define STRMSG_AC_ANSWER_DEL_DIR "answerDelDir"
|
||||||
#define STRMSG_AC_RENAME_FILEDIR "requestRenameFileDir"
|
#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_NEW_DIR "requestNewDir"
|
||||||
#define STRMSG_AC_ANSWER_NEW_DIR "answerNewDir"
|
#define STRMSG_AC_ANSWER_NEW_DIR "answerNewDir"
|
||||||
#define STRMSG_AC_ASK_FILEINFO "requestFileInfo"
|
#define STRMSG_AC_ASK_FILEINFO "requestFileInfo"
|
||||||
#define STRMSG_AC_ANSWER_FILEINFO "answerFileInfo"
|
#define STRMSG_AC_ANSWER_FILEINFO "answerFileInfo"
|
||||||
#define STRMSG_AC_UP "upAction"
|
#define STRMSG_AC_UP "upAction"
|
||||||
#define STRMSG_AC_DOWN "downAction"
|
#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_FILEEXIT "fileExist"
|
||||||
#define STRMSG_ST_FILENOEXIT "fileNotExist"
|
#define STRMSG_ST_FILENOEXIT "fileNotExist"
|
||||||
#define STRMSG_ST_DIREXIT "dirExist"
|
#define STRMSG_ST_DIREXIT "dirExist"
|
||||||
#define STRMSG_ST_DIRNOEXIT "dirNotExist"
|
#define STRMSG_ST_DIRNOEXIT "dirNotExist"
|
||||||
|
|
||||||
|
#define STR_FILE "File"
|
||||||
|
#define STR_DIR "Dir"
|
||||||
|
#define STR_NONE "None"
|
||||||
|
|
||||||
#endif // PROTOCOL_H
|
#endif // PROTOCOL_H
|
||||||
@@ -24,6 +24,7 @@ struct InfoMsg {
|
|||||||
QString msg;
|
QString msg;
|
||||||
QString fromPath;
|
QString fromPath;
|
||||||
QString toPath;
|
QString toPath;
|
||||||
|
QString type;
|
||||||
quint64 size{};
|
quint64 size{};
|
||||||
quint32 permissions{};
|
quint32 permissions{};
|
||||||
QVector<QString> list;
|
QVector<QString> list;
|
||||||
@@ -31,7 +32,7 @@ struct InfoMsg {
|
|||||||
|
|
||||||
void serialize(QDataStream& data) const
|
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());
|
data << static_cast<qint32>(list.size());
|
||||||
for (const auto& item : list) {
|
for (const auto& item : list) {
|
||||||
data << item;
|
data << item;
|
||||||
@@ -46,7 +47,7 @@ struct InfoMsg {
|
|||||||
|
|
||||||
void deserialize(QDataStream& data)
|
void deserialize(QDataStream& data)
|
||||||
{
|
{
|
||||||
data >> mark >> command >> msg >> fromPath >> toPath >> size >> permissions;
|
data >> mark >> command >> msg >> fromPath >> toPath >> type >> size >> permissions;
|
||||||
|
|
||||||
qint32 listSize;
|
qint32 listSize;
|
||||||
data >> listSize;
|
data >> listSize;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QFileDevice>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
@@ -150,6 +151,23 @@ bool Util::DirExist(const QString& path, bool isFilePath)
|
|||||||
return dir.exists();
|
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()
|
QString Util::UUID()
|
||||||
{
|
{
|
||||||
return QUuid::createUuid().toString().remove("{").remove("}");
|
return QUuid::createUuid().toString().remove("{").remove("}");
|
||||||
@@ -235,4 +253,3 @@ void GlobalData::SetConfigPath(const std::string& path)
|
|||||||
{
|
{
|
||||||
ConfigPath_ = path;
|
ConfigPath_ = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public:
|
|||||||
static QString GetVersion();
|
static QString GetVersion();
|
||||||
static bool FileExist(const QString& path);
|
static bool FileExist(const QString& path);
|
||||||
static bool DirExist(const QString& path, bool isFilePath);
|
static bool DirExist(const QString& path, bool isFilePath);
|
||||||
|
static QString Rename(const QString& from, const QString& to, bool isDir);
|
||||||
static QString UUID();
|
static QString UUID();
|
||||||
static QVector<QString> GetLocalDrivers();
|
static QVector<QString> GetLocalDrivers();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user