From 51b7db5f40f0e6c7fffe5a272ed1df6b320b7229 Mon Sep 17 00:00:00 2001 From: liyigang Date: Tue, 9 Jul 2024 10:51:01 +0800 Subject: [PATCH 1/5] fix: After manually mounting SMB, the network is disconnected and the card is stuck Move the file creation operation to the thread for processing Log: After manually mounting SMB, the network is disconnected and the card is stuck Bug: https://pms.uniontech.com/bug-view-257855.html --- .../fileoperations.cpp | 4 +- .../fileoperationseventreceiver.cpp | 157 ++++++++++-------- .../fileoperationseventreceiver.h | 14 +- .../templatemenuscene/templatemenuscene.cpp | 3 +- .../view/operator/fileoperatorproxy.cpp | 2 +- .../utils/fileoperatorhelper.cpp | 1 + .../utils/fileviewmenuhelper.cpp | 2 +- .../dfmplugin-vault/utils/vaultfilehelper.cpp | 30 +--- .../dfmplugin-vault/utils/vaultfilehelper.h | 6 +- .../ut_fileoperationseventreceiver.cpp | 20 +-- .../utils/ut_vaultfilehelper.cpp | 8 +- 11 files changed, 127 insertions(+), 120 deletions(-) diff --git a/src/plugins/common/core/dfmplugin-fileoperations/fileoperations.cpp b/src/plugins/common/core/dfmplugin-fileoperations/fileoperations.cpp index f834fea9d9..0be179698c 100644 --- a/src/plugins/common/core/dfmplugin-fileoperations/fileoperations.cpp +++ b/src/plugins/common/core/dfmplugin-fileoperations/fileoperations.cpp @@ -217,13 +217,15 @@ void FileOperations::initEventHandle() static_cast(&FileOperationsEventReceiver::handleOperationTouchFile)); + const QString, + const bool)>(&FileOperationsEventReceiver::handleOperationTouchFile)); dpfSignalDispatcher->subscribe(GlobalEventType::kTouchFile, FileOperationsEventReceiver::instance(), static_cast(&FileOperationsEventReceiver::handleOperationTouchFile)); dpfSignalDispatcher->subscribe(GlobalEventType::kCreateSymlink, diff --git a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp index b59c8c5cd1..82d21998b7 100644 --- a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp +++ b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp @@ -650,75 +650,85 @@ bool FileOperationsEventReceiver::doMkdir(const quint64 windowId, const QUrl &ur } QString FileOperationsEventReceiver::doTouchFilePremature(const quint64 windowId, const QUrl &url, const CreateFileType fileType, const QString &suffix, - const QVariant &custom, AbstractJobHandler::OperatorCallback callbackImmediately) + const QVariant &custom, AbstractJobHandler::OperatorCallback callbackImmediately, const QUrl &tempUrl) { - const QString newPath = newDocmentName(url, suffix, fileType); - if (newPath.isEmpty()) - return newPath; - - QUrl urlNew; - urlNew.setScheme(url.scheme()); - urlNew.setPath(newPath); - - if (dfmbase::FileUtils::isLocalFile(url)) { - if (callbackImmediately) { - AbstractJobHandler::CallbackArgus args(new QMap); - args->insert(AbstractJobHandler::CallbackKey::kWindowId, QVariant::fromValue(windowId)); - args->insert(AbstractJobHandler::CallbackKey::kSourceUrls, QVariant::fromValue(QList() << url)); - args->insert(AbstractJobHandler::CallbackKey::kTargets, QVariant::fromValue(QList() << QUrl::fromLocalFile(newPath))); - args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); - callbackImmediately(args); + QString errorStr; + if (tempUrl.isValid()) { + if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_TouchFile", windowId, url, tempUrl, suffix, true, custom, callbackImmediately, &errorStr)) { + dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kTouchFileResult, + windowId, QList() << url, tempUrl.isValid(), QString()); + return url.path(); } - - return doTouchFilePractically(windowId, urlNew) ? newPath : QString(); } else { - QString error; - if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_TouchFile", windowId, url, urlNew, fileType, suffix, custom, callbackImmediately, &error)) { + if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_TouchFile", windowId, url, fileType, suffix, custom, callbackImmediately, &errorStr)) { dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kTouchFileResult, - windowId, QList() << url, true, error); + windowId, QList() << url, tempUrl.isValid(), QString()); return url.path(); } - - return doTouchFilePractically(windowId, url) ? url.path() : QString(); } -} -QString FileOperationsEventReceiver::doTouchFilePremature(const quint64 windowId, const QUrl &url, const QUrl &tempUrl, const QString &suffix, const QVariant &custom, AbstractJobHandler::OperatorCallback callbackImmediately) -{ - auto fileInfo = InfoFactory::create(tempUrl); - if (!fileInfo) - return QString(); - const QString &newPath = newDocmentName(url, fileInfo->nameOf(FileInfo::FileNameInfoType::kCompleteBaseName), - suffix.isEmpty() ? fileInfo->nameOf(FileInfo::FileNameInfoType::kSuffix) : suffix); - if (newPath.isEmpty()) - return QString(); + QFutureWatcher *watcher = new QFutureWatcher(); + QObject::connect(watcher, &QFutureWatcher::finished, [this, windowId, watcher, url, + suffix, custom, callbackImmediately, tempUrl]() { + auto result = watcher->result(); + QString error = watcher->property("error").toString(); + QUrl templateUrl = watcher->property("templateUrl").toUrl(); + QUrl targetUrl = watcher->property("targetUrl").toUrl(); + watcher->deleteLater(); + if (!result) { + dialogManager->showErrorDialog(tr("Failed to create the file"), error); + } - QUrl urlNew; - urlNew.setScheme(url.scheme()); - urlNew.setPath(newPath); + dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kTouchFileResult, + windowId, QList() << url, result, error); + if (result) + saveFileOperation({ url }, {}, GlobalEventType::kDeleteFiles, { url }, {}, + GlobalEventType::kTouchFile, false, templateUrl); - if (dfmbase::FileUtils::isLocalFile(url)) { if (callbackImmediately) { AbstractJobHandler::CallbackArgus args(new QMap); args->insert(AbstractJobHandler::CallbackKey::kWindowId, QVariant::fromValue(windowId)); args->insert(AbstractJobHandler::CallbackKey::kSourceUrls, QVariant::fromValue(QList() << url)); - args->insert(AbstractJobHandler::CallbackKey::kTargets, QVariant::fromValue(QList() << QUrl::fromLocalFile(newPath))); + args->insert(AbstractJobHandler::CallbackKey::kTargets, + QVariant::fromValue(QList() << targetUrl)); args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); callbackImmediately(args); } - - return doTouchFilePractically(windowId, urlNew, tempUrl) ? newPath : QString(); - } else { - QString error; - if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_TouchCustomFile", windowId, url, urlNew, tempUrl, suffix, custom, callbackImmediately, &error)) { - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kTouchFileResult, - windowId, QList() << url, true, error); - return url.path(); + }); + watcher->setFuture(QtConcurrent::run([this, url, fileType, suffix, custom, callbackImmediately, watcher, tempUrl]() { + QString newPath; + if (tempUrl.isValid()) { + auto fileInfo = InfoFactory::create(tempUrl); + if (!fileInfo) { + watcher->setProperty("error", QString("get empty target file name!")); + return false; + } + newPath = newDocmentName(url, fileInfo->nameOf(FileInfo::FileNameInfoType::kCompleteBaseName), + suffix.isEmpty() ? fileInfo->nameOf(FileInfo::FileNameInfoType::kSuffix) : suffix); + } else { + newPath = newDocmentName(url, suffix, fileType); } + if (newPath.isEmpty()) { + watcher->setProperty("error", QString("get empty target file name!")); + return false; + } + QUrl urlNew; + urlNew.setScheme(url.scheme()); + urlNew.setPath(newPath); + watcher->setProperty("targetUrl", urlNew); - return doTouchFilePractically(windowId, url, tempUrl) ? url.path() : QString(); - } + DFMBASE_NAMESPACE::LocalFileHandler fileHandler; + QUrl templateUrl = fileHandler.touchFile(urlNew, tempUrl); + + if (!templateUrl.isValid()) + watcher->setProperty("error", fileHandler.errorString()); + + watcher->setProperty("templateUrl", templateUrl); + return templateUrl.isValid(); + + })); + return ""; } void FileOperationsEventReceiver::saveFileOperation(const QList &sourcesUrls, @@ -1135,22 +1145,31 @@ void FileOperationsEventReceiver::handleOperationMkdir(const quint64 windowId, doMkdir(windowId, url, custom, callback); } -bool FileOperationsEventReceiver::doTouchFilePractically(const quint64 windowId, const QUrl &url, const QUrl &tempUrl /*= QUrl()*/) +void FileOperationsEventReceiver::doTouchFilePractically(const quint64 windowId, const QUrl &url, const QUrl &tempUrl /*= QUrl()*/) { QString error; - - DFMBASE_NAMESPACE::LocalFileHandler fileHandler; - auto templateUrl = fileHandler.touchFile(url, tempUrl); - if (!templateUrl.isValid()) { - error = fileHandler.errorString(); - dialogManager->showErrorDialog(tr("Failed to create the file"), error); - } - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kTouchFileResult, - windowId, QList() << url, templateUrl.isValid(), error); - if (templateUrl.isValid()) - saveFileOperation({ url }, {}, GlobalEventType::kDeleteFiles, { url }, {}, GlobalEventType::kTouchFile, false, templateUrl); - - return templateUrl.isValid(); + QFutureWatcher *watcher = new QFutureWatcher(); + QObject::connect(watcher, &QFutureWatcher::finished, [this, windowId, watcher, url, tempUrl]() { + auto futureResult = watcher->result(); + QUrl templateUrl = watcher->property("templateUrl").toUrl(); + QString error = watcher->property("error").toString(); + dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kTouchFileResult, + windowId, QList() << url, futureResult, error); + if (futureResult) { + saveFileOperation({ url }, {}, GlobalEventType::kDeleteFiles, { url }, {}, + GlobalEventType::kTouchFile, false, templateUrl); + } else { + dialogManager->showErrorDialog(tr("Failed to create the file"), error); + } + }); + watcher->setFuture(QtConcurrent::run([url, watcher, tempUrl]() { + DFMBASE_NAMESPACE::LocalFileHandler fileHandler; + auto templateUrl = fileHandler.touchFile(url, tempUrl); + if (!templateUrl.isValid()) + watcher->setProperty("error", fileHandler.errorString()); + + return tempUrl.isValid(); + })); } QString FileOperationsEventReceiver::handleOperationTouchFile(const quint64 windowId, @@ -1164,9 +1183,11 @@ QString FileOperationsEventReceiver::handleOperationTouchFile(const quint64 wind QString FileOperationsEventReceiver::handleOperationTouchFile(const quint64 windowId, const QUrl url, const QUrl tempUrl, - const QString suffix) + const QString suffix, const bool isLoadTmp) { - return doTouchFilePremature(windowId, url, tempUrl, suffix, QVariant(), nullptr); + Q_UNUSED(isLoadTmp); + return doTouchFilePremature(windowId, url, Global::CreateFileType::kCreateFileTypeUnknow, + suffix, QVariant(), nullptr, tempUrl); } void FileOperationsEventReceiver::handleOperationTouchFile(const quint64 windowId, @@ -1182,11 +1203,13 @@ void FileOperationsEventReceiver::handleOperationTouchFile(const quint64 windowI void FileOperationsEventReceiver::handleOperationTouchFile(const quint64 windowId, const QUrl url, const QUrl tempUrl, - const QString suffix, + const QString suffix, const bool isLoadTmp, const QVariant custom, AbstractJobHandler::OperatorCallback callbackImmediately) { - doTouchFilePremature(windowId, url, tempUrl, suffix, custom, callbackImmediately); + Q_UNUSED(isLoadTmp); + doTouchFilePremature(windowId, url, Global::CreateFileType::kCreateFileTypeUnknow, + suffix, custom, callbackImmediately, tempUrl); } bool FileOperationsEventReceiver::handleOperationLinkFile(const quint64 windowId, diff --git a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.h b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.h index bda68f9b01..d119ac9fc0 100644 --- a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.h +++ b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.h @@ -136,7 +136,8 @@ public slots: QString handleOperationTouchFile(const quint64 windowId, const QUrl url, const QUrl tempUrl, - const QString suffix); + const QString suffix, + const bool isLoadTmp); void handleOperationTouchFile(const quint64 windowId, const QUrl url, const DFMBASE_NAMESPACE::Global::CreateFileType fileType, @@ -147,6 +148,7 @@ public slots: const QUrl url, const QUrl tempUrl, const QString suffix, + const bool isLoadTmp, const QVariant custom, DFMBASE_NAMESPACE::AbstractJobHandler::OperatorCallback callbackImmediately); @@ -263,12 +265,10 @@ public slots: QString doTouchFilePremature(const quint64 windowId, const QUrl &url, const DFMBASE_NAMESPACE::Global::CreateFileType fileType, const QString &suffix, const QVariant &custom, - DFMBASE_NAMESPACE::AbstractJobHandler::OperatorCallback callbackImmediately); - QString doTouchFilePremature(const quint64 windowId, const QUrl &url, - const QUrl &tempUrl, const QString &suffix, - const QVariant &custom, - DFMBASE_NAMESPACE::AbstractJobHandler::OperatorCallback callbackImmediately); - bool doTouchFilePractically(const quint64 windowId, const QUrl &url, const QUrl &tempUrl = QUrl()); + DFMBASE_NAMESPACE::AbstractJobHandler::OperatorCallback callbackImmediately, + const QUrl &tempUrl = QUrl()); + + void doTouchFilePractically(const quint64 windowId, const QUrl &url, const QUrl &tempUrl = QUrl()); void saveFileOperation(const QList &sourcesUrls, const QList &targetUrls, DFMBASE_NAMESPACE::GlobalEventType type, const QList &redoSourcesUrls, const QList &redoTargetUrls, diff --git a/src/plugins/common/core/dfmplugin-menu/templatemenuscene/templatemenuscene.cpp b/src/plugins/common/core/dfmplugin-menu/templatemenuscene/templatemenuscene.cpp index fa2bee5b55..b4ed091718 100644 --- a/src/plugins/common/core/dfmplugin-menu/templatemenuscene/templatemenuscene.cpp +++ b/src/plugins/common/core/dfmplugin-menu/templatemenuscene/templatemenuscene.cpp @@ -108,7 +108,8 @@ bool TemplateMenuScene::triggered(QAction *action) d->windowId, d->currentDir, QUrl::fromLocalFile(action->data().toString()), - ""); + QString(), + true); return true; } diff --git a/src/plugins/desktop/core/ddplugin-canvas/view/operator/fileoperatorproxy.cpp b/src/plugins/desktop/core/ddplugin-canvas/view/operator/fileoperatorproxy.cpp index d5be69338f..6647f9cc94 100644 --- a/src/plugins/desktop/core/ddplugin-canvas/view/operator/fileoperatorproxy.cpp +++ b/src/plugins/desktop/core/ddplugin-canvas/view/operator/fileoperatorproxy.cpp @@ -155,7 +155,7 @@ void FileOperatorProxy::touchFile(const CanvasView *view, const QPoint pos, cons QPair funcData(FileOperatorProxyPrivate::kCallBackTouchFile, data); QVariant custom = QVariant::fromValue(funcData); - dpfSignalDispatcher->publish(GlobalEventType::kTouchFile, view->winId(), view->model()->rootUrl(), source, QString(), custom, d->callBack); + dpfSignalDispatcher->publish(GlobalEventType::kTouchFile, view->winId(), view->model()->rootUrl(), source, QString(), true, custom, d->callBack); } void FileOperatorProxy::touchFolder(const CanvasView *view, const QPoint pos) diff --git a/src/plugins/filemanager/core/dfmplugin-workspace/utils/fileoperatorhelper.cpp b/src/plugins/filemanager/core/dfmplugin-workspace/utils/fileoperatorhelper.cpp index 6e0eb11bbd..1b542ebfa8 100644 --- a/src/plugins/filemanager/core/dfmplugin-workspace/utils/fileoperatorhelper.cpp +++ b/src/plugins/filemanager/core/dfmplugin-workspace/utils/fileoperatorhelper.cpp @@ -64,6 +64,7 @@ void FileOperatorHelper::touchFiles(const FileView *view, const QUrl &source) url, source, QString(), + true, GlobalEventType::kTouchFile, callBack); } diff --git a/src/plugins/filemanager/core/dfmplugin-workspace/utils/fileviewmenuhelper.cpp b/src/plugins/filemanager/core/dfmplugin-workspace/utils/fileviewmenuhelper.cpp index 41cbcedcf7..b1f5800d45 100644 --- a/src/plugins/filemanager/core/dfmplugin-workspace/utils/fileviewmenuhelper.cpp +++ b/src/plugins/filemanager/core/dfmplugin-workspace/utils/fileviewmenuhelper.cpp @@ -80,7 +80,7 @@ void FileViewMenuHelper::showEmptyAreaMenu() dpfSignalDispatcher->publish("dfmplugin_workspace", "signal_ReportLog_MenuData", act->text(), urls); scene->triggered(act); } - delete scene; + scene->deleteLater(); } void FileViewMenuHelper::showNormalMenu(const QModelIndex &index, const Qt::ItemFlags &indexFlags) diff --git a/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.cpp b/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.cpp index 4df1d1f503..c2a72d0542 100644 --- a/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.cpp +++ b/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.cpp @@ -163,50 +163,34 @@ bool VaultFileHelper::makeDir(const quint64 windowId, const QUrl url, } bool VaultFileHelper::touchFile(const quint64 windowId, - const QUrl url, const QUrl &targetUrl, + const QUrl url, const DFMGLOBAL_NAMESPACE::CreateFileType type, const QString &suffix, const QVariant &custom, AbstractJobHandler::OperatorCallback callback, QString *error) { + Q_UNUSED(error); if (url.scheme() != scheme()) return false; const QUrl dirUrl = transUrlsToLocal({ url }).first(); - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kTouchFile, windowId, dirUrl, type, suffix); - - if (callback) { - AbstractJobHandler::CallbackArgus args(new QMap); - args->insert(AbstractJobHandler::CallbackKey::kWindowId, QVariant::fromValue(windowId)); - args->insert(AbstractJobHandler::CallbackKey::kSourceUrls, QVariant::fromValue(QList() << url)); - args->insert(AbstractJobHandler::CallbackKey::kTargets, QVariant::fromValue(QList() << targetUrl)); - args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); - callback(args); - } + dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kTouchFile, windowId, dirUrl, type, suffix, custom, callback); return true; } -bool VaultFileHelper::touchCustomFile(const quint64 windowId, const QUrl url, const QUrl &targetUrl, - const QUrl tempUrl, const QString &suffix, +bool VaultFileHelper::touchCustomFile(const quint64 windowId, const QUrl url, + const QUrl tempUrl, const QString &suffix, const bool isLoadTmp, const QVariant &custom, AbstractJobHandler::OperatorCallback callback, QString *error) { + Q_UNUSED(error); if (url.scheme() != scheme()) return false; const QUrl dirUrl = transUrlsToLocal({ url }).first(); dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kTouchFile, - windowId, dirUrl, tempUrl, suffix); - - if (callback) { - AbstractJobHandler::CallbackArgus args(new QMap); - args->insert(AbstractJobHandler::CallbackKey::kWindowId, QVariant::fromValue(windowId)); - args->insert(AbstractJobHandler::CallbackKey::kSourceUrls, QVariant::fromValue(QList() << url)); - args->insert(AbstractJobHandler::CallbackKey::kTargets, QVariant::fromValue(QList() << targetUrl)); - args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); - callback(args); - } + windowId, dirUrl, tempUrl, suffix, isLoadTmp, custom, callback); return true; } diff --git a/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.h b/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.h index 53c93a90fb..961f36dd05 100644 --- a/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.h +++ b/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.h @@ -43,13 +43,13 @@ class VaultFileHelper : public QObject const QUrl url, const QUrl &targetUrl, const QVariant custom, DFMBASE_NAMESPACE::AbstractJobHandler::OperatorCallback callback); bool touchFile(const quint64 windowId, - const QUrl url, const QUrl &targetUrl, + const QUrl url, const DFMGLOBAL_NAMESPACE::CreateFileType type, const QString &suffix, const QVariant &custom, DFMBASE_NAMESPACE::AbstractJobHandler::OperatorCallback callback, QString *error); - bool touchCustomFile(const quint64 windowId, const QUrl url, const QUrl &targetUrl, + bool touchCustomFile(const quint64 windowId, const QUrl url, const QUrl tempUrl, - const QString &suffix, const QVariant &custom, + const QString &suffix, const bool isLoadTmp, const QVariant &custom, DFMBASE_NAMESPACE::AbstractJobHandler::OperatorCallback callback, QString *error); bool writeUrlsToClipboard(const quint64 windowId, const DFMBASE_NAMESPACE::ClipBoard::ClipboardAction action, const QList urls); diff --git a/tests/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/ut_fileoperationseventreceiver.cpp b/tests/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/ut_fileoperationseventreceiver.cpp index 22a7535ede..03f6a11abc 100644 --- a/tests/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/ut_fileoperationseventreceiver.cpp +++ b/tests/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/ut_fileoperationseventreceiver.cpp @@ -215,10 +215,10 @@ TEST_F(UT_FileOperationsEventReceiver, testHandleOperationTouchFile) EXPECT_TRUE(op != nullptr); QUrl url = QUrl::fromLocalFile(QDir::currentPath()); EXPECT_TRUE(op->handleOperationTouchFile(0, QUrl(), Global::CreateFileType::kCreateFileTypeText, QString()).isEmpty()); - EXPECT_TRUE(op->handleOperationTouchFile(0, QUrl(), url, QString()).isEmpty()); + EXPECT_TRUE(op->handleOperationTouchFile(0, QUrl(), url, QString(), true).isEmpty()); AbstractJobHandler::OperatorCallback callback = [](const AbstractJobHandler::CallbackArgus){}; EXPECT_NO_FATAL_FAILURE(op->handleOperationTouchFile(0, QUrl(), Global::CreateFileType::kCreateFileTypeText, QString(), QVariant(), callback)); - EXPECT_NO_FATAL_FAILURE(op->handleOperationTouchFile(0, QUrl(), url, QString(), QVariant(), callback)); + EXPECT_NO_FATAL_FAILURE(op->handleOperationTouchFile(0, QUrl(), url, QString(), true, QVariant(), callback)); stub_ext::StubExt stub; stub.set_lamda(&DialogManager::showErrorDialog,[]{}); @@ -227,7 +227,7 @@ TEST_F(UT_FileOperationsEventReceiver, testHandleOperationTouchFile) auto publishFun = static_cast(&EventDispatcherManager::publish); stub.set_lamda(publishFun, [] {return true;}); EXPECT_TRUE(op->handleOperationTouchFile(0, url, Global::CreateFileType::kCreateFileTypeText, QString()).isEmpty()); - EXPECT_TRUE(op->handleOperationTouchFile(0, url, QUrl(), QString()).isEmpty()); + EXPECT_TRUE(op->handleOperationTouchFile(0, url, QUrl(), QString(), true).isEmpty()); stub.set_lamda(&FileUtils::isLocalFile,[]{ return false; }); typedef bool (EventSequenceManager::*RunFunc)(const QString &, const QString &, quint64, const QUrl &, QUrl &, @@ -236,7 +236,7 @@ TEST_F(UT_FileOperationsEventReceiver, testHandleOperationTouchFile) auto runFunc = static_cast(&EventSequenceManager::run); stub.set_lamda(runFunc, [] {return true;}); EXPECT_TRUE(op->handleOperationTouchFile(0, url, Global::CreateFileType::kCreateFileTypeText, QString()).isEmpty()); - EXPECT_TRUE(op->handleOperationTouchFile(0, url, QUrl(), QString()).isEmpty()); + EXPECT_TRUE(op->handleOperationTouchFile(0, url, QUrl(), QString(), true).isEmpty()); } TEST_F(UT_FileOperationsEventReceiver, testHandleOperationLinkFile) @@ -602,7 +602,7 @@ TEST_F(UT_FileOperationsEventReceiver, testDoTouchFilePractically) typedef bool (EventDispatcherManager::*PublishFun)(dpf::EventType, quint64, QList &, bool &, QString &); auto publishFun = static_cast(&EventDispatcherManager::publish); stub.set_lamda(publishFun, [] {return false;}); - EXPECT_FALSE(op->doTouchFilePractically(0, url, QUrl())); + EXPECT_NO_FATAL_FAILURE(op->doTouchFilePractically(0, url, QUrl())); } TEST_F(UT_FileOperationsEventReceiver, testDoTouchFilePremature) @@ -611,7 +611,7 @@ TEST_F(UT_FileOperationsEventReceiver, testDoTouchFilePremature) EXPECT_TRUE(op != nullptr); QUrl url = QUrl::fromLocalFile(QDir::currentPath()); stub_ext::StubExt stub; - stub.set_lamda(&FileOperationsEventReceiver::doTouchFilePractically,[]{return false;}); + stub.set_lamda(&FileOperationsEventReceiver::doTouchFilePractically,[]{return;}); AbstractJobHandler::OperatorCallback callback = [](const AbstractJobHandler::CallbackArgus){}; EXPECT_TRUE(op->doTouchFilePremature(0, QUrl(), Global::CreateFileType::kCreateFileTypeText, "", QVariant(), callback).isEmpty()); @@ -637,11 +637,11 @@ TEST_F(UT_FileOperationsEventReceiver, testDoTouchFilePremature1) EXPECT_TRUE(op != nullptr); QUrl url = QUrl::fromLocalFile(QDir::currentPath()); stub_ext::StubExt stub; - stub.set_lamda(&FileOperationsEventReceiver::doTouchFilePractically,[]{return false;}); + stub.set_lamda(&FileOperationsEventReceiver::doTouchFilePractically,[]{return;}); AbstractJobHandler::OperatorCallback callback = [](const AbstractJobHandler::CallbackArgus){}; - EXPECT_TRUE(op->doTouchFilePremature(0, QUrl(), url, "", QVariant(), callback).isEmpty()); + EXPECT_TRUE(op->doTouchFilePremature(0, QUrl(), Global::CreateFileType::kCreateFileTypeUnknow, "", QVariant(), callback, url).isEmpty()); - EXPECT_TRUE(op->doTouchFilePremature(0, url, url, "", QVariant(), callback).isEmpty()); + EXPECT_TRUE(op->doTouchFilePremature(0, url, Global::CreateFileType::kCreateFileTypeUnknow, "", QVariant(), callback, url).isEmpty()); stub.set_lamda(&FileUtils::isLocalFile, []{return false;}); typedef bool (EventSequenceManager::*RunFunc)(const QString &, const QString &, quint64, const QUrl &, QUrl &, const QUrl &, @@ -652,7 +652,7 @@ TEST_F(UT_FileOperationsEventReceiver, testDoTouchFilePremature1) typedef bool (EventDispatcherManager::*PublishFun1)(dpf::EventType, quint64, QList &, bool &&, QString &); auto publishFun1 = static_cast(&EventDispatcherManager::publish); stub.set_lamda(publishFun1, [] {return false;}); - EXPECT_TRUE(!op->doTouchFilePremature(0, url, url, "", QVariant(), callback).isEmpty()); + EXPECT_TRUE(!op->doTouchFilePremature(0, url, Global::CreateFileType::kCreateFileTypeUnknow, "", QVariant(), callback, url).isEmpty()); op->handleOperationCleanSaveOperationsStack(); } diff --git a/tests/plugins/filemanager/dfmplugin-vault/utils/ut_vaultfilehelper.cpp b/tests/plugins/filemanager/dfmplugin-vault/utils/ut_vaultfilehelper.cpp index e384c5a719..06fc806c88 100644 --- a/tests/plugins/filemanager/dfmplugin-vault/utils/ut_vaultfilehelper.cpp +++ b/tests/plugins/filemanager/dfmplugin-vault/utils/ut_vaultfilehelper.cpp @@ -255,7 +255,6 @@ TEST(UT_VaultFileHelper, touchFile_one) { QString error; bool isOk = VaultFileHelper::instance()->touchFile(0, QUrl("file:///UT_TEST"), - QUrl("file:///UT_TEST/UT_TEST1"), CreateFileType::kCreateFileTypeFolder, "", QVariant(""), UTVaultFileHelperCallBackOne, &error); @@ -273,7 +272,6 @@ TEST(UT_VaultFileHelper, touchFile_two) QString error; bool isOk = VaultFileHelper::instance()->touchFile(0, QUrl("dfmvault:///UT_TEST"), - QUrl("dfmvault:///UT_TEST/UT_TEST1"), CreateFileType::kCreateFileTypeFolder, "", QVariant(""), UTVaultFileHelperCallBackOne, &error); @@ -285,8 +283,7 @@ TEST(UT_VaultFileHelper, touchCustomFile_one) { QString error; bool isOk = VaultFileHelper::instance()->touchCustomFile(0, QUrl("file:///UT_TEST"), - QUrl("file:///UT_TEST/UT_TEST1"), - QUrl("file:///UT_TEST/UT_TEMP"), "", + QUrl("file:///UT_TEST/UT_TEMP"), "", true, QVariant(""), UTVaultFileHelperCallBackOne, &error); @@ -303,8 +300,7 @@ TEST(UT_VaultFileHelper, touchCustomFile_two) QString error; bool isOk = VaultFileHelper::instance()->touchCustomFile(0, QUrl("dfmvault:///UT_TEST"), - QUrl("dfmvault:///UT_TEST/UT_TEST1"), - QUrl("file:///UT_TEST/UT_TEMP"), "", + QUrl("file:///UT_TEST/UT_TEMP"), "", true, QVariant(""), UTVaultFileHelperCallBackOne, &error); From 204d1745e908edb679b9df84f8ffe69874697f34 Mon Sep 17 00:00:00 2001 From: liyigang Date: Tue, 9 Jul 2024 14:16:55 +0800 Subject: [PATCH 2/5] fix: After manually mounting SMB, the network is disconnected and the card is stuck Move the mkdir operation only to the thread Log: After manually mounting SMB, the network is disconnected and the card is stuck Bug: https://pms.uniontech.com/bug-view-257855.html --- .../fileoperationseventreceiver.cpp | 82 +++++++++---------- .../dfmplugin-vault/utils/vaultfilehelper.cpp | 14 +--- .../dfmplugin-vault/utils/vaultfilehelper.h | 2 +- .../utils/ut_vaultfilehelper.cpp | 2 - 4 files changed, 41 insertions(+), 59 deletions(-) diff --git a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp index 82d21998b7..d079b03a94 100644 --- a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp +++ b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp @@ -590,7 +590,7 @@ JobHandlePointer FileOperationsEventReceiver::doCleanTrash(const quint64 windowI if (info) { count = info->countChildFile(); } - if (DialogManagerInstance->showClearTrashDialog(count) != QDialog::Accepted) return nullptr; + if (DialogManagerInstance->showClearTrashDialog(static_cast(count)) != QDialog::Accepted) return nullptr; } QList urls = std::move(sources); @@ -607,46 +607,47 @@ bool FileOperationsEventReceiver::doMkdir(const quint64 windowId, const QUrl &ur const QVariant &custom, AbstractJobHandler::OperatorCallback callback, const bool useUrlPath) { - QString newPath = useUrlPath ? url.path() : newDocmentName(url, QString(), CreateFileType::kCreateFileTypeFolder); - if (newPath.isEmpty()) - return false; - - QUrl targetUrl; - targetUrl.setScheme(url.scheme()); - targetUrl.setPath(newPath); - - bool ok = false; QString error; - if (!dfmbase::FileUtils::isLocalFile(url)) { - if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_MakeDir", windowId, url, targetUrl, custom, callback)) { - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kMkdirResult, - windowId, QList() << url, true, error); - return true; - } - } - - DFMBASE_NAMESPACE::LocalFileHandler fileHandler; - ok = fileHandler.mkdir(targetUrl); - if (!ok) { - error = fileHandler.errorString(); - dialogManager->showErrorDialog(tr("Failed to create the directory"), error); + if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_MakeDir", windowId, url, custom, callback)) { + return true; } + QFutureWatcher *watcher = new QFutureWatcher(); + QObject::connect(watcher, &QFutureWatcher::finished, [this, windowId, watcher, url, custom, callback]() { + auto result = watcher->result(); + QUrl targetUrl = watcher->property("targetUrl").toUrl(); + QString error = watcher->property("error").toString(); + dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kMkdirResult, + windowId, QList() << url, result, error); + saveFileOperation({ targetUrl }, {}, GlobalEventType::kDeleteFiles, { targetUrl }, {}, GlobalEventType::kMkdir); - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kMkdirResult, - windowId, QList() << url, ok, error); - saveFileOperation({ targetUrl }, {}, GlobalEventType::kDeleteFiles, { targetUrl }, {}, GlobalEventType::kMkdir); - - if (callback) { - AbstractJobHandler::CallbackArgus args(new QMap); - args->insert(AbstractJobHandler::CallbackKey::kWindowId, QVariant::fromValue(windowId)); - args->insert(AbstractJobHandler::CallbackKey::kSourceUrls, QVariant::fromValue(QList() << url)); - args->insert(AbstractJobHandler::CallbackKey::kTargets, QVariant::fromValue(QList() << targetUrl)); - args->insert(AbstractJobHandler::CallbackKey::kSuccessed, QVariant::fromValue(ok)); - args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); - callback(args); - } + if (callback) { + AbstractJobHandler::CallbackArgus args(new QMap); + args->insert(AbstractJobHandler::CallbackKey::kWindowId, QVariant::fromValue(windowId)); + args->insert(AbstractJobHandler::CallbackKey::kSourceUrls, QVariant::fromValue(QList() << url)); + args->insert(AbstractJobHandler::CallbackKey::kTargets, QVariant::fromValue(QList() << targetUrl)); + args->insert(AbstractJobHandler::CallbackKey::kSuccessed, QVariant::fromValue(result)); + args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); + callback(args); + } + }); + watcher->setFuture(QtConcurrent::run([this, url, custom, callback, watcher, useUrlPath]() { + QString newPath = useUrlPath ? url.path() : newDocmentName(url, QString(), CreateFileType::kCreateFileTypeFolder); + if (newPath.isEmpty()) { + watcher->setProperty("error", "make dir the new path is empty!"); + return false; + } - return ok; + QUrl targetUrl; + targetUrl.setScheme(url.scheme()); + targetUrl.setPath(newPath); + watcher->setProperty("targetUrl", targetUrl); + DFMBASE_NAMESPACE::LocalFileHandler fileHandler; + auto result = fileHandler.mkdir(targetUrl); + if (!result) + watcher->setProperty("error", fileHandler.errorString()); + return result; + })); + return true; } QString FileOperationsEventReceiver::doTouchFilePremature(const quint64 windowId, const QUrl &url, const CreateFileType fileType, const QString &suffix, @@ -654,20 +655,15 @@ QString FileOperationsEventReceiver::doTouchFilePremature(const quint64 windowId { QString errorStr; if (tempUrl.isValid()) { - if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_TouchFile", windowId, url, tempUrl, suffix, true, custom, callbackImmediately, &errorStr)) { - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kTouchFileResult, - windowId, QList() << url, tempUrl.isValid(), QString()); + if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_TouchCustomFile", windowId, url, tempUrl, suffix, true, custom, callbackImmediately, &errorStr)) { return url.path(); } } else { if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_TouchFile", windowId, url, fileType, suffix, custom, callbackImmediately, &errorStr)) { - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kTouchFileResult, - windowId, QList() << url, tempUrl.isValid(), QString()); return url.path(); } } - QFutureWatcher *watcher = new QFutureWatcher(); QObject::connect(watcher, &QFutureWatcher::finished, [this, windowId, watcher, url, suffix, custom, callbackImmediately, tempUrl]() { diff --git a/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.cpp b/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.cpp index c2a72d0542..84c7be61c2 100644 --- a/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.cpp +++ b/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.cpp @@ -139,7 +139,6 @@ bool VaultFileHelper::renameFile(const quint64 windowId, const QUrl oldUrl, cons } bool VaultFileHelper::makeDir(const quint64 windowId, const QUrl url, - const QUrl &targetUrl, const QVariant custom, AbstractJobHandler::OperatorCallback callback) { @@ -147,18 +146,7 @@ bool VaultFileHelper::makeDir(const quint64 windowId, const QUrl url, return false; const QUrl dirUrl = transUrlsToLocal({ url }).first(); - if (dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kMkdir, windowId, dirUrl)) { - if (callback) { - AbstractJobHandler::CallbackArgus args(new QMap); - args->insert(AbstractJobHandler::CallbackKey::kWindowId, QVariant::fromValue(windowId)); - args->insert(AbstractJobHandler::CallbackKey::kSourceUrls, QVariant::fromValue(QList() << url)); - args->insert(AbstractJobHandler::CallbackKey::kTargets, QVariant::fromValue(QList() << targetUrl)); - args->insert(AbstractJobHandler::CallbackKey::kSuccessed, QVariant::fromValue(true)); - args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); - callback(args); - } - } - + dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kMkdir, windowId, dirUrl, custom, callback); return true; } diff --git a/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.h b/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.h index 961f36dd05..f83796081b 100644 --- a/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.h +++ b/src/plugins/filemanager/dfmplugin-vault/utils/vaultfilehelper.h @@ -40,7 +40,7 @@ class VaultFileHelper : public QObject bool renameFile(const quint64 windowId, const QUrl oldUrl, const QUrl newUrl, const DFMBASE_NAMESPACE::AbstractJobHandler::JobFlags flags); bool makeDir(const quint64 windowId, - const QUrl url, const QUrl &targetUrl, + const QUrl url, const QVariant custom, DFMBASE_NAMESPACE::AbstractJobHandler::OperatorCallback callback); bool touchFile(const quint64 windowId, const QUrl url, diff --git a/tests/plugins/filemanager/dfmplugin-vault/utils/ut_vaultfilehelper.cpp b/tests/plugins/filemanager/dfmplugin-vault/utils/ut_vaultfilehelper.cpp index 06fc806c88..2ad66c88bb 100644 --- a/tests/plugins/filemanager/dfmplugin-vault/utils/ut_vaultfilehelper.cpp +++ b/tests/plugins/filemanager/dfmplugin-vault/utils/ut_vaultfilehelper.cpp @@ -222,7 +222,6 @@ TEST(UT_VaultFileHelper, renameFile_two) TEST(UT_VaultFileHelper, makeDir_one) { bool isOk = VaultFileHelper::instance()->makeDir(0, QUrl("file:///UT_TEST"), - QUrl("dfmvault:///UT_TEST1"), QVariant(1), nullptr); @@ -244,7 +243,6 @@ TEST(UT_VaultFileHelper, makeDir_two) }); bool isOk = VaultFileHelper::instance()->makeDir(0, QUrl("dfmvault:///UT_TEST"), - QUrl("dfmvault:///UT_TEST1"), QVariant(1), UTVaultFileHelperCallBackOne); From b250e8f62d30d435bbbbd2dc734f04c046b4ffbd Mon Sep 17 00:00:00 2001 From: liyigang Date: Tue, 9 Jul 2024 15:07:34 +0800 Subject: [PATCH 3/5] fix: After manually mounting SMB, the network is disconnected and the card is stuck Move the operation of creating linked files to the thread Log: After manually mounting SMB, the network is disconnected and the card is stuck Bug: https://pms.uniontech.com/bug-view-257855.html --- .../fileoperationseventreceiver.cpp | 64 +++++++++++-------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp index d079b03a94..c5b6de6f1e 100644 --- a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp +++ b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp @@ -1214,37 +1214,47 @@ bool FileOperationsEventReceiver::handleOperationLinkFile(const quint64 windowId const bool force, const bool silence) { - bool ok = false; QString error; - if (!dfmbase::FileUtils::isLocalFile(url)) { - if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_LinkFile", windowId, url, link, force, silence)) { - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kCreateSymlinkResult, - windowId, QList() << url << link, true, error); - return true; - } + if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_LinkFile", windowId, url, link, force, silence)) { + return true; } - DFMBASE_NAMESPACE::LocalFileHandler fileHandler; - // check link - if (force) { - FileInfoPointer toInfo = InfoFactory::create(link); - if (toInfo && toInfo->exists()) { - DFMBASE_NAMESPACE::LocalFileHandler fileHandlerDelete; - fileHandlerDelete.deleteFile(link); + QFutureWatcher *watcher = new QFutureWatcher(); + QObject::connect(watcher, &QFutureWatcher::finished, [this, windowId, watcher, url, + link]() { + auto result = watcher->result(); + QString error = watcher->property("error").toString(); + QUrl urlValid = watcher->property("urlValid").toUrl(); + watcher->deleteLater(); + if (!result) { + dialogManager->showErrorDialog(tr("link file error"), error); } - } - QUrl urlValid = link; - if (silence) { - urlValid = checkTargetUrl(link); - } - ok = fileHandler.createSystemLink(url, urlValid); - if (!ok) { - error = fileHandler.errorString(); - dialogManager->showErrorDialog(tr("link file error"), error); - } - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kCreateSymlinkResult, - windowId, QList() << url << urlValid, ok, error); - return ok; + dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kCreateSymlinkResult, + windowId, QList() << url << urlValid, result, error); + }); + watcher->setFuture(QtConcurrent::run([this, watcher, url, link, force, silence](){ + DFMBASE_NAMESPACE::LocalFileHandler fileHandler; + // check link + if (force) { + FileInfoPointer toInfo = InfoFactory::create(link); + if (toInfo && toInfo->exists()) { + DFMBASE_NAMESPACE::LocalFileHandler fileHandlerDelete; + fileHandlerDelete.deleteFile(link); + } + } + QUrl urlValid = link; + if (silence) { + urlValid = checkTargetUrl(link); + } + watcher->setProperty("urlValid", urlValid); + auto result = fileHandler.createSystemLink(url, urlValid); + if (!result) { + watcher->setProperty("error", fileHandler.errorString()); + } + return result; + })); + + return true; } void FileOperationsEventReceiver::handleOperationLinkFile(const quint64 windowId, From 73ee76420daa63b55b0008253e7e0217e9b8b3d1 Mon Sep 17 00:00:00 2001 From: liyigang Date: Tue, 9 Jul 2024 15:19:42 +0800 Subject: [PATCH 4/5] fix: After manually mounting SMB, the network is disconnected and the card is stuck Move the operation of setting file permissions to the thread Log: After manually mounting SMB, the network is disconnected and the card is stuck Bug: https://pms.uniontech.com/bug-view-257855.html --- .../fileoperationseventreceiver.cpp | 69 +++++++++++-------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp index c5b6de6f1e..18cc994afe 100644 --- a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp +++ b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp @@ -618,7 +618,8 @@ bool FileOperationsEventReceiver::doMkdir(const quint64 windowId, const QUrl &ur QString error = watcher->property("error").toString(); dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kMkdirResult, windowId, QList() << url, result, error); - saveFileOperation({ targetUrl }, {}, GlobalEventType::kDeleteFiles, { targetUrl }, {}, GlobalEventType::kMkdir); + if (result) + saveFileOperation({ targetUrl }, {}, GlobalEventType::kDeleteFiles, { targetUrl }, {}, GlobalEventType::kMkdir); if (callback) { AbstractJobHandler::CallbackArgus args(new QMap); @@ -629,6 +630,7 @@ bool FileOperationsEventReceiver::doMkdir(const quint64 windowId, const QUrl &ur args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); callback(args); } + watcher->deleteLater(); }); watcher->setFuture(QtConcurrent::run([this, url, custom, callback, watcher, useUrlPath]() { QString newPath = useUrlPath ? url.path() : newDocmentName(url, QString(), CreateFileType::kCreateFileTypeFolder); @@ -671,7 +673,6 @@ QString FileOperationsEventReceiver::doTouchFilePremature(const quint64 windowId QString error = watcher->property("error").toString(); QUrl templateUrl = watcher->property("templateUrl").toUrl(); QUrl targetUrl = watcher->property("targetUrl").toUrl(); - watcher->deleteLater(); if (!result) { dialogManager->showErrorDialog(tr("Failed to create the file"), error); } @@ -691,6 +692,7 @@ QString FileOperationsEventReceiver::doTouchFilePremature(const quint64 windowId args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); callbackImmediately(args); } + watcher->deleteLater(); }); watcher->setFuture(QtConcurrent::run([this, url, fileType, suffix, custom, callbackImmediately, watcher, tempUrl]() { QString newPath; @@ -1157,6 +1159,7 @@ void FileOperationsEventReceiver::doTouchFilePractically(const quint64 windowId, } else { dialogManager->showErrorDialog(tr("Failed to create the file"), error); } + watcher->deleteLater(); }); watcher->setFuture(QtConcurrent::run([url, watcher, tempUrl]() { DFMBASE_NAMESPACE::LocalFileHandler fileHandler; @@ -1164,7 +1167,7 @@ void FileOperationsEventReceiver::doTouchFilePractically(const quint64 windowId, if (!templateUrl.isValid()) watcher->setProperty("error", fileHandler.errorString()); - return tempUrl.isValid(); + return templateUrl.isValid(); })); } @@ -1225,12 +1228,13 @@ bool FileOperationsEventReceiver::handleOperationLinkFile(const quint64 windowId auto result = watcher->result(); QString error = watcher->property("error").toString(); QUrl urlValid = watcher->property("urlValid").toUrl(); - watcher->deleteLater(); + if (!result) { dialogManager->showErrorDialog(tr("link file error"), error); } dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kCreateSymlinkResult, windowId, QList() << url << urlValid, result, error); + watcher->deleteLater(); }); watcher->setFuture(QtConcurrent::run([this, watcher, url, link, force, silence](){ DFMBASE_NAMESPACE::LocalFileHandler fileHandler; @@ -1282,32 +1286,41 @@ bool FileOperationsEventReceiver::handleOperationSetPermission(const quint64 win const QUrl url, const QFileDevice::Permissions permissions) { + // hook events QString error; - bool ok = false; - if (!dfmbase::FileUtils::isLocalFile(url)) { - // hook events - bool hookOk = false; - if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_SetPermission", windowId, url, permissions, &hookOk, &error)) { - if (!hookOk) - dialogManager->showErrorDialog(tr("Failed to modify file permissions"), error); - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kSetPermissionResult, windowId, QList() << url, hookOk, error); - return hookOk; - } + bool hookOk = false; + if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_SetPermission", windowId, url, permissions, &hookOk, &error)) { + if (!hookOk) + dialogManager->showErrorDialog(tr("Failed to modify file permissions"), error); + dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kSetPermissionResult, windowId, QList() << url, hookOk, error); + return hookOk; } - DFMBASE_NAMESPACE::LocalFileHandler fileHandler; - ok = fileHandler.setPermissions(url, permissions); - if (!ok) { - error = fileHandler.errorString(); - dialogManager->showErrorDialog(tr("Failed to modify file permissions"), error); - } - FileInfoPointer info = InfoFactory::create(url); - info->refresh(); - fmInfo("set file permissions successed, file : %s, permissions : %d !", url.path().toStdString().c_str(), - static_cast(permissions)); - // TODO:: set file permissions finished need to send set file permissions finished event - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kSetPermissionResult, - windowId, QList() << url, ok, error); - return ok; + QFutureWatcher *watcher = new QFutureWatcher(); + QObject::connect(watcher, &QFutureWatcher::finished, [this, windowId, watcher, url]() { + auto result = watcher->result(); + QString error = watcher->property("error").toString(); + if (!result) + dialogManager->showErrorDialog(tr("Failed to modify file permissions"), error); + // TODO:: set file permissions finished need to send set file permissions finished event + dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kSetPermissionResult, + windowId, QList() << url, result, error); + watcher->deleteLater(); + }); + + watcher->setFuture(QtConcurrent::run([watcher, url, permissions](){ + DFMBASE_NAMESPACE::LocalFileHandler fileHandler; + bool result = fileHandler.setPermissions(url, permissions); + if (!result) { + watcher->setProperty("error", fileHandler.errorString()); + } + FileInfoPointer info = InfoFactory::create(url); + info->refresh(); + fmInfo("set file permissions successed, file : %s, permissions : %d !", url.path().toStdString().c_str(), + static_cast(permissions)); + return result; + })); + + return true; } void FileOperationsEventReceiver::handleOperationSetPermission(const quint64 windowId, From 07a5a9a79e4ce422a1ee39b8b3a29ab5bec06bc9 Mon Sep 17 00:00:00 2001 From: liyigang Date: Wed, 10 Jul 2024 10:00:06 +0800 Subject: [PATCH 5/5] fix: After manually mounting SMB, the network is disconnected and the card is stuck Move renaming operation to thread Log: After manually mounting SMB, the network is disconnected and the card is stuck Bug: https://pms.uniontech.com/bug-view-257855.html --- .../fileoperationseventreceiver.cpp | 332 +++++++++--------- .../fileoperationseventreceiver.h | 15 +- 2 files changed, 182 insertions(+), 165 deletions(-) diff --git a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp index 18cc994afe..07e92cfcfe 100644 --- a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp +++ b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.cpp @@ -277,76 +277,118 @@ bool FileOperationsEventReceiver::redo(const quint64 windowId, const QVariantMap return true; } -bool FileOperationsEventReceiver::doRenameFiles(const quint64 windowId, const QList &urls, const QPair &pair, - const QPair &pair2, - const RenameTypes type, QMap &successUrls, QString &errorMsg, - const QVariant custom, DFMBASE_NAMESPACE::AbstractJobHandler::OperatorCallback callback) +bool FileOperationsEventReceiver::doRenameFiles(QFutureWatcher *watcher, + const QList &urls, + const QPair &pair, + const QPair &pair2, + const FileOperationsEventReceiver::RenameTypes type, + QMap &successUrls, QString &errorMsg) { DFMBASE_NAMESPACE::LocalFileHandler fileHandler; - bool ok = false, renameDesktop = true; + bool result = false, renameDesktop = true; + QMap needDealUrls; switch (type) { case RenameTypes::kBatchRepalce: { auto tmpurls = urls; - QMap needDealUrls; renameDesktop = doRenameDesktopFiles(tmpurls, pair, needDealUrls, successUrls); QMap needDealUrls1 = FileUtils::fileBatchReplaceText(tmpurls, pair); for (auto it = needDealUrls1.begin(); it != needDealUrls1.end(); ++it) { needDealUrls.insert(it.key(), it.value()); } - if (callback) { - AbstractJobHandler::CallbackArgus args(new QMap); - args->insert(AbstractJobHandler::CallbackKey::kWindowId, QVariant::fromValue(windowId)); - args->insert(AbstractJobHandler::CallbackKey::kSourceUrls, QVariant::fromValue(QList() << needDealUrls.keys())); - args->insert(AbstractJobHandler::CallbackKey::kTargets, QVariant::fromValue(QList() << needDealUrls.values())); - args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); - callback(args); + if (needDealUrls1.isEmpty() || !renameDesktop) { + result = renameDesktop; + break; } - - if (needDealUrls1.isEmpty() || !renameDesktop) - return false; - ok = fileHandler.renameFilesBatch(needDealUrls1, successUrls); + result = fileHandler.renameFilesBatch(needDealUrls1, successUrls); break; } case RenameTypes::kBatchCustom: { - QMap needDealUrls = FileUtils::fileBatchCustomText(urls, pair); - if (callback) { - AbstractJobHandler::CallbackArgus args(new QMap); - args->insert(AbstractJobHandler::CallbackKey::kWindowId, QVariant::fromValue(windowId)); - args->insert(AbstractJobHandler::CallbackKey::kSourceUrls, QVariant::fromValue(QList() << needDealUrls.keys())); - args->insert(AbstractJobHandler::CallbackKey::kTargets, QVariant::fromValue(QList() << needDealUrls.values())); - args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); - callback(args); - } - ok = fileHandler.renameFilesBatch(needDealUrls, successUrls); + needDealUrls = FileUtils::fileBatchCustomText(urls, pair); + result = fileHandler.renameFilesBatch(needDealUrls, successUrls); break; } case RenameTypes::kBatchAppend: { - QMap needDealUrls = FileUtils::fileBatchAddText(urls, pair2); - if (callback) { - AbstractJobHandler::CallbackArgus args(new QMap); - args->insert(AbstractJobHandler::CallbackKey::kWindowId, QVariant::fromValue(windowId)); - args->insert(AbstractJobHandler::CallbackKey::kSourceUrls, QVariant::fromValue(QList() << needDealUrls.keys())); - args->insert(AbstractJobHandler::CallbackKey::kTargets, QVariant::fromValue(QList() << needDealUrls.values())); - args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); - callback(args); - } - ok = fileHandler.renameFilesBatch(needDealUrls, successUrls); + needDealUrls = FileUtils::fileBatchAddText(urls, pair2); + result = fileHandler.renameFilesBatch(needDealUrls, successUrls); break; } } - if (!ok) { + watcher->setProperty("needDealUrls", QVariant::fromValue(needDealUrls)); + if (!result && renameDesktop) { errorMsg = fileHandler.errorString(); - DialogManagerInstance->showErrorDialog(tr("Rename file error"), errorMsg); + watcher->setProperty("error", fileHandler.errorString()); } for (const auto &scUrl : successUrls.keys()) { ClipBoard::instance()->replaceClipboardUrl(scUrl, successUrls.value(scUrl)); } - return ok; + return result; } -bool FileOperationsEventReceiver::doRenameDesktopFile(const quint64 windowId, const QUrl oldUrl, const QUrl newUrl, const dfmbase::AbstractJobHandler::JobFlags flags) +void FileOperationsEventReceiver::doRenameFilesByThread(const quint64 windowId, const QList urls, + const QPair replacePair, + const QPair AddPair, + const RenameTypes type, const QVariant custom, + AbstractJobHandler::OperatorCallback callback) +{ + if (callback) { + if (type == RenameTypes::kBatchAppend && + dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_RenameFilesAddText", + windowId, urls, AddPair, custom, callback)) + return; + if (type != RenameTypes::kBatchAppend && dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_RenameFiles", + windowId, urls, replacePair, type == RenameTypes::kBatchRepalce, + custom, callback)) + return; + } else { + if (type == RenameTypes::kBatchAppend && + dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_RenameFilesAddText", windowId, urls, AddPair)) + return; + if (type != RenameTypes::kBatchAppend && dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_RenameFiles", + windowId, urls, replacePair, type == RenameTypes::kBatchRepalce)) + return; + } + + QFutureWatcher *watcher = new QFutureWatcher(); + QObject::connect(watcher, &QFutureWatcher::finished, [this, windowId, watcher, urls,custom, callback]() { + auto futureResult = watcher->result(); + QString error = watcher->property("error").toString(); + QMap successUrls = watcher->property("successUrls").value>(); + QMap needDealUrls = watcher->property("needDealUrls").value>(); + if (!futureResult) { + DialogManagerInstance->showErrorDialog(tr("Rename file error"), error); + } + if (callback) { + AbstractJobHandler::CallbackArgus args(new QMap); + args->insert(AbstractJobHandler::CallbackKey::kWindowId, QVariant::fromValue(windowId)); + args->insert(AbstractJobHandler::CallbackKey::kSourceUrls, QVariant::fromValue(QList() << needDealUrls.keys())); + args->insert(AbstractJobHandler::CallbackKey::kTargets, QVariant::fromValue(QList() << needDealUrls.values())); + args->insert(AbstractJobHandler::CallbackKey::kCustom, custom); + callback(args); + } + // publish result + dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult, + windowId, successUrls, futureResult, error); + if (!successUrls.isEmpty()) + saveFileOperation(successUrls.values(), successUrls.keys(), GlobalEventType::kRenameFiles, + successUrls.keys(), successUrls.values(), GlobalEventType::kRenameFiles); + watcher->deleteLater(); + }); + + watcher->setFuture(QtConcurrent::run([this, watcher, urls, replacePair, AddPair, type](){ + bool result = false; + QMap successUrls; + QString error; + result = doRenameFiles(watcher, urls, replacePair, AddPair, type, successUrls, error); + watcher->setProperty("successUrls", QVariant::fromValue(successUrls)); + return result; + })); + + return; +} + +bool FileOperationsEventReceiver::doRenameDesktopFile(QFutureWatcher *watcher, const QUrl oldUrl, const QUrl newUrl, const AbstractJobHandler::JobFlags flags) { const QString &desktopPath = oldUrl.toLocalFile(); Properties desktop(desktopPath, "Desktop Entry"); @@ -377,21 +419,14 @@ bool FileOperationsEventReceiver::doRenameDesktopFile(const quint64 windowId, co desktop.set(key, newFileInfo->displayOf(DisPlayInfoType::kFileDisplayName)); desktop.set("X-Deepin-Vendor", QStringLiteral("user-custom")); - if (desktop.save(desktopPath, "Desktop Entry")) { - QMap renamed { { oldUrl, newUrl } }; - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult, - windowId, renamed, true, ""); + if (!desktop.save(desktopPath, "Desktop Entry")) + return false; - if (!flags.testFlag(AbstractJobHandler::JobFlag::kRedo)) { - const QString path = QFileInfo(desktopPath).absoluteDir().absoluteFilePath(oldName); - saveFileOperation({ oldUrl }, { QUrl::fromLocalFile(path) }, GlobalEventType::kRenameFile, - { QUrl::fromLocalFile(path) }, { oldUrl }, - GlobalEventType::kRenameFile, flags.testFlag(AbstractJobHandler::JobFlag::kRevocation)); - } - return true; + if (!flags.testFlag(AbstractJobHandler::JobFlag::kRedo)) { + const QString path = QFileInfo(desktopPath).absoluteDir().absoluteFilePath(oldName); + watcher->setProperty("targetUrl", QUrl::fromLocalFile(path)); } - - return false; + return true; } bool FileOperationsEventReceiver::doRenameDesktopFiles(QList &urls, const QPair pair, QMap &needDealUrls, QMap &successUrls) @@ -987,44 +1022,67 @@ bool FileOperationsEventReceiver::handleOperationRenameFile(const quint64 window const AbstractJobHandler::JobFlag flags) { Q_UNUSED(windowId); - bool ok = false; - QString error; - bool isSymLink { DFMIO::DFileInfo(oldUrl).attribute(DFMIO::DFileInfo::AttributeID::kStandardIsSymlink).toBool() }; - if (FileUtils::isDesktopFile(oldUrl) && !isSymLink) - return doRenameDesktopFile(windowId, oldUrl, newUrl, flags); + if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_RenameFile", windowId, oldUrl, newUrl, flags)) + return true; + QFutureWatcher *watcher = new QFutureWatcher(); + QObject::connect(watcher, &QFutureWatcher::finished, [this, windowId, watcher, oldUrl, newUrl, flags]() { + auto futureResult = watcher->result(); + QString renameError = watcher->property("renameError").toString(); + QString sameNameRrror = watcher->property("sameNameRrror").toString(); + if (!futureResult) { + if (sameNameRrror.isEmpty()) { + dialogManager->showRenameBusyErrDialog(); + } else { + dialogManager->showRenameNameSameErrorDialog(sameNameRrror); + } + } else { + ClipBoard::instance()->replaceClipboardUrl(oldUrl, newUrl); + AbstractJobHandler::JobFlags tmFlags = flags; + QUrl targetUrl = watcher->property("targetUrl").toUrl(); + if (!tmFlags.testFlag(AbstractJobHandler::JobFlag::kRedo)) { + if (!targetUrl.isValid()) { + saveFileOperation({ newUrl }, { oldUrl }, GlobalEventType::kRenameFile, + { oldUrl }, { newUrl }, GlobalEventType::kRenameFile, + tmFlags.testFlag(AbstractJobHandler::JobFlag::kRevocation)); + } else { + saveFileOperation({ oldUrl }, { targetUrl }, GlobalEventType::kRenameFile, + { targetUrl }, { oldUrl }, + GlobalEventType::kRenameFile, tmFlags.testFlag(AbstractJobHandler::JobFlag::kRevocation)); + } + } + } + // TODO:: file renameFile finished need to send file renameFile finished event + QMap renamedFiles { { oldUrl, newUrl } }; + dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult, + windowId, renamedFiles, futureResult, renameError); + watcher->deleteLater(); + }); - if (!dfmbase::FileUtils::isLocalFile(oldUrl)) { - if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_RenameFile", windowId, oldUrl, newUrl, flags)) - return true; - } + watcher->setFuture(QtConcurrent::run([this, watcher, oldUrl, newUrl, flags](){ + bool result = false; + QString error; + bool isSymLink { DFMIO::DFileInfo(oldUrl).attribute(DFMIO::DFileInfo::AttributeID::kStandardIsSymlink).toBool() }; + if (FileUtils::isDesktopFile(oldUrl) && !isSymLink) + return doRenameDesktopFile(watcher, oldUrl, newUrl, flags); + + // async fileinfo need wait file quer over todo:: liyigang + FileInfoPointer toFileInfo = InfoFactory::create(newUrl, Global::CreateFileInfoType::kCreateFileInfoSync); + if (toFileInfo && toFileInfo->exists()) { + watcher->setProperty("sameNameRrror", toFileInfo->nameOf(NameInfoType::kFileName)); + return false; + } - // async fileinfo need wait file quer over todo:: liyigang - FileInfoPointer toFileInfo = InfoFactory::create(newUrl, Global::CreateFileInfoType::kCreateFileInfoSync); - if (toFileInfo && toFileInfo->exists()) { - dialogManager->showRenameNameSameErrorDialog(toFileInfo->nameOf(NameInfoType::kFileName)); - return false; - } + DFMBASE_NAMESPACE::LocalFileHandler fileHandler; + result = fileHandler.renameFile(oldUrl, newUrl); + if (!result) { + error = fileHandler.errorString(); + watcher->setProperty("renameError", fileHandler.errorString()); + } + return result; + })); - DFMBASE_NAMESPACE::LocalFileHandler fileHandler; - ok = fileHandler.renameFile(oldUrl, newUrl); - if (!ok) { - error = fileHandler.errorString(); - dialogManager->showRenameBusyErrDialog(); - } - // TODO:: file renameFile finished need to send file renameFile finished event - QMap renamedFiles { { oldUrl, newUrl } }; - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult, - windowId, renamedFiles, ok, error); - if (ok) - ClipBoard::instance()->replaceClipboardUrl(oldUrl, newUrl); - - AbstractJobHandler::JobFlags tmFlags = flags; - if (!tmFlags.testFlag(AbstractJobHandler::JobFlag::kRedo)) - saveFileOperation({ newUrl }, { oldUrl }, GlobalEventType::kRenameFile, - { oldUrl }, { newUrl }, GlobalEventType::kRenameFile, - tmFlags.testFlag(AbstractJobHandler::JobFlag::kRevocation)); - return ok; + return true; } void FileOperationsEventReceiver::handleOperationRenameFile(const quint64 windowId, @@ -1046,88 +1104,42 @@ void FileOperationsEventReceiver::handleOperationRenameFile(const quint64 window } } -bool FileOperationsEventReceiver::handleOperationRenameFiles(const quint64 windowId, const QList urls, const QPair pair, const bool replace) +bool FileOperationsEventReceiver::handleOperationRenameFiles(const quint64 windowId, + const QList urls, + const QPair pair, + const bool replace) { - QMap successUrls; - bool ok = false; - QString error; - if (!urls.isEmpty() && !dfmbase::FileUtils::isLocalFile(urls.first())) { - if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_RenameFiles", windowId, urls, pair, replace)) - return true; - } - - RenameTypes type = RenameTypes::kBatchRepalce; - if (!replace) - type = RenameTypes::kBatchCustom; - ok = doRenameFiles(windowId, urls, pair, {}, type, successUrls, error); - - // publish result - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult, - windowId, successUrls, ok, error); - if (!successUrls.isEmpty()) - saveFileOperation(successUrls.values(), successUrls.keys(), GlobalEventType::kRenameFiles, - successUrls.keys(), successUrls.values(), GlobalEventType::kRenameFiles); - - return ok; + doRenameFilesByThread(windowId, urls, pair, {}, replace ? RenameTypes::kBatchRepalce : RenameTypes::kBatchCustom); + return true; } -void FileOperationsEventReceiver::handleOperationRenameFiles(const quint64 windowId, const QList urls, const QPair pair, const bool replace, const QVariant custom, AbstractJobHandler::OperatorCallback callback) +void FileOperationsEventReceiver::handleOperationRenameFiles(const quint64 windowId, + const QList urls, + const QPair pair, + const bool replace, const QVariant custom, + AbstractJobHandler::OperatorCallback callback) { - QMap successUrls; - QString error; - RenameTypes type = RenameTypes::kBatchRepalce; - if (!replace) - type = RenameTypes::kBatchCustom; - bool ok = doRenameFiles(windowId, urls, pair, {}, type, successUrls, error, custom, callback); - // publish result - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult, - windowId, successUrls, ok, error); - if (!successUrls.isEmpty()) - saveFileOperation(successUrls.values(), successUrls.keys(), GlobalEventType::kRenameFiles, - successUrls.keys(), successUrls.values(), GlobalEventType::kRenameFiles); + doRenameFilesByThread(windowId, urls, pair, {}, + replace ? RenameTypes::kBatchRepalce : RenameTypes::kBatchCustom, + custom, callback); } -bool FileOperationsEventReceiver::handleOperationRenameFiles(const quint64 windowId, const QList urls, const QPair pair) +bool FileOperationsEventReceiver::handleOperationRenameFiles(const quint64 windowId, + const QList urls, + const QPair pair) { - QMap successUrls; - bool ok = false; - QString error; - if (!urls.isEmpty() && !dfmbase::FileUtils::isLocalFile(urls.first())) { - if (dpfHookSequence->run("dfmplugin_fileoperations", "hook_Operation_RenameFilesAddText", windowId, urls, pair)) { - - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult, - windowId, successUrls, true, error); - if (!successUrls.isEmpty()) - saveFileOperation(successUrls.values(), successUrls.keys(), GlobalEventType::kRenameFiles, - successUrls.keys(), successUrls.values(), GlobalEventType::kRenameFiles); - - return true; - } - } - - ok = doRenameFiles(windowId, urls, {}, pair, RenameTypes::kBatchAppend, successUrls, error); - - // publish result - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult, - windowId, successUrls, ok, error); - if (!successUrls.isEmpty()) - saveFileOperation(successUrls.values(), successUrls.keys(), GlobalEventType::kRenameFiles, - successUrls.keys(), successUrls.values(), GlobalEventType::kRenameFiles); - - return ok; + doRenameFilesByThread(windowId, urls, {}, pair, RenameTypes::kBatchAppend); + return true; } -void FileOperationsEventReceiver::handleOperationRenameFiles(const quint64 windowId, const QList urls, const QPair pair, const QVariant custom, AbstractJobHandler::OperatorCallback callback) +void FileOperationsEventReceiver::handleOperationRenameFiles(const quint64 windowId, + const QList urls, + const QPair pair, + const QVariant custom, + AbstractJobHandler::OperatorCallback callback) { - QMap successUrls; - QString error; - bool ok = doRenameFiles(windowId, urls, {}, pair, RenameTypes::kBatchAppend, successUrls, error, custom, callback); - // publish result - dpfSignalDispatcher->publish(DFMBASE_NAMESPACE::GlobalEventType::kRenameFileResult, - windowId, successUrls, ok, error); - if (!successUrls.isEmpty()) - saveFileOperation(successUrls.values(), successUrls.keys(), GlobalEventType::kRenameFiles, - successUrls.keys(), successUrls.values(), GlobalEventType::kRenameFiles); + doRenameFilesByThread(windowId, urls, {}, pair, RenameTypes::kBatchAppend, + custom, callback); } bool FileOperationsEventReceiver::handleOperationMkdir(const quint64 windowId, const QUrl url) diff --git a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.h b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.h index d119ac9fc0..5a736609f6 100644 --- a/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.h +++ b/src/plugins/common/core/dfmplugin-fileoperations/fileoperationsevent/fileoperationseventreceiver.h @@ -227,14 +227,19 @@ public slots: DFMBASE_NAMESPACE::AbstractJobHandler::OperatorHandleCallback handle); bool redo(const quint64 windowId, const QVariantMap &ret, DFMBASE_NAMESPACE::AbstractJobHandler::OperatorHandleCallback handle); - - bool doRenameFiles(const quint64 windowId, const QList &urls, + bool doRenameFiles(QFutureWatcher *watcher, const QList &urls, const QPair &pair, const QPair &pair2, const RenameTypes type, - QMap &successUrls, QString &errorMsg, - const QVariant custom = QVariant(), DFMBASE_NAMESPACE::AbstractJobHandler::OperatorCallback callback = nullptr); - bool doRenameDesktopFile(const quint64 windowId, + QMap &successUrls, QString &errorMsg); + void doRenameFilesByThread(const quint64 windowId, + const QList urls, + const QPair replacePair, + const QPair AddPair, + const RenameTypes type, + const QVariant custom = QVariant(), + DFMBASE_NAMESPACE::AbstractJobHandler::OperatorCallback callback = nullptr); + bool doRenameDesktopFile(QFutureWatcher *watcher, const QUrl oldUrl, const QUrl newUrl, const DFMBASE_NAMESPACE::AbstractJobHandler::JobFlags flags);