diff --git a/src/dfm-base/base/device/deviceproxymanager.cpp b/src/dfm-base/base/device/deviceproxymanager.cpp index 33a0b7c619..640cfe072f 100644 --- a/src/dfm-base/base/device/deviceproxymanager.cpp +++ b/src/dfm-base/base/device/deviceproxymanager.cpp @@ -6,8 +6,10 @@ #include "devicemanager.h" #include "deviceutils.h" #include "private/deviceproxymanager_p.h" +#include #include +#include using namespace dfmbase; static constexpr char kDeviceService[] { "org.deepin.filemanager.server" }; @@ -47,6 +49,20 @@ QStringList DeviceProxyManager::getAllBlockIdsByUUID(const QStringList &uuids, G return devs; } +QStringList DeviceProxyManager::asyncGetAllBlockIdsByUUID(const QStringList &uuids, GlobalServerDefines::DeviceQueryOptions opts) +{ + const auto &&devices = getAllBlockIds(opts); + QStringList devs; + for (const auto &id : devices) { + const auto &&info = asyncQueryBlockInfo(id); + if (info.value("error", QVariant(false)).toBool()) + return devs; + if (uuids.contains(info.value(GlobalServerDefines::DeviceProperty::kUUID).toString())) + devs << id; + } + return devs; +} + QStringList DeviceProxyManager::getAllProtocolIds() { if (d->isDBusRuning() && d->devMngDBus) { @@ -80,6 +96,32 @@ QVariantMap DeviceProxyManager::queryProtocolInfo(const QString &id, bool reload } } +QVariantMap DeviceProxyManager::asyncQueryBlockInfo(const QString &id, bool reload) +{ + if (d->isDBusRuning() && d->devMngDBus) { + auto fun = [=](const QString &id, bool reload) -> QDBusPendingReply { + DeviceManagerInterface devMngDBus(kDeviceService, kDevMngPath, QDBusConnection::sessionBus()); + return devMngDBus.QueryBlockDeviceInfo(id, reload); + }; + return d->asyncQueryInfo(id, reload, fun); + } else { + return queryBlockInfo(id, reload); + } +} + +QVariantMap DeviceProxyManager::asyncQueryProtocolInfo(const QString &id, bool reload) +{ + if (d->isDBusRuning() && d->devMngDBus) { + auto fun = [=](const QString &id, bool reload) -> QDBusPendingReply { + DeviceManagerInterface devMngDBus(kDeviceService, kDevMngPath, QDBusConnection::sessionBus()); + return devMngDBus.QueryProtocolDeviceInfo(id, reload); + }; + return d->asyncQueryInfo(id, reload, fun); + } else { + return queryProtocolInfo(id, reload); + } +} + void DeviceProxyManager::reloadOpticalInfo(const QString &id) { if (d->isDBusRuning() && d->devMngDBus) @@ -345,6 +387,32 @@ void DeviceProxyManagerPrivate::disconnCurrentConnections() currentConnectionType = kNoneConnection; } +QVariantMap DeviceProxyManagerPrivate::asyncQueryInfo(const QString &id, bool reload, std::function(const QString&, bool)> func) +{ + QEventLoop loop; + QFutureWatcher>* fw = new QFutureWatcher>; + FinallyUtil release([&] { + if (fw) { + delete fw; + fw = nullptr; + } + }); + connect(fw, &QFutureWatcher>::finished, [&loop](){ + loop.quit(); + }); + QFuture> ft = + QtConcurrent::run([id, reload, func](){ + QDBusPendingReply reply = func(id, reload); + reply.waitForFinished(); + return reply; + }); + fw->setFuture(ft); + if (loop.exec()) { + return QVariantMap({{"error", true}}); + } + return fw->result(); +} + void DeviceProxyManagerPrivate::addMounts(const QString &id, const QString &mpt) { QString p = mpt.endsWith("/") ? mpt : mpt + "/"; diff --git a/src/dfm-base/base/device/deviceproxymanager.h b/src/dfm-base/base/device/deviceproxymanager.h index 206c837777..b28faabc85 100644 --- a/src/dfm-base/base/device/deviceproxymanager.h +++ b/src/dfm-base/base/device/deviceproxymanager.h @@ -35,9 +35,12 @@ class DeviceProxyManager : public QObject // device info getter QStringList getAllBlockIds(GlobalServerDefines::DeviceQueryOptions opts = GlobalServerDefines::DeviceQueryOption::kNoCondition); QStringList getAllBlockIdsByUUID(const QStringList &uuids, GlobalServerDefines::DeviceQueryOptions opts = GlobalServerDefines::DeviceQueryOption::kNoCondition); + QStringList asyncGetAllBlockIdsByUUID(const QStringList &uuids, GlobalServerDefines::DeviceQueryOptions opts = GlobalServerDefines::DeviceQueryOption::kNoCondition); QStringList getAllProtocolIds(); QVariantMap queryBlockInfo(const QString &id, bool reload = false); QVariantMap queryProtocolInfo(const QString &id, bool reload = false); + QVariantMap asyncQueryBlockInfo(const QString &id, bool reload = false); + QVariantMap asyncQueryProtocolInfo(const QString &id, bool reload = false); // device operation void reloadOpticalInfo(const QString &id); diff --git a/src/dfm-base/base/device/private/deviceproxymanager_p.h b/src/dfm-base/base/device/private/deviceproxymanager_p.h index 506f571e9e..4ef98747f5 100644 --- a/src/dfm-base/base/device/private/deviceproxymanager_p.h +++ b/src/dfm-base/base/device/private/deviceproxymanager_p.h @@ -36,6 +36,8 @@ class DeviceProxyManagerPrivate : public QObject void connectToAPI(); void disconnCurrentConnections(); + QVariantMap asyncQueryInfo(const QString &id, bool reload, std::function(const QString &, bool)> func); + private Q_SLOTS: void addMounts(const QString &id, const QString &mpt); void removeMounts(const QString &id); diff --git a/src/plugins/filemanager/core/dfmplugin-computer/private/computerview_p.h b/src/plugins/filemanager/core/dfmplugin-computer/private/computerview_p.h index 8a02a74659..8df10f7f65 100644 --- a/src/plugins/filemanager/core/dfmplugin-computer/private/computerview_p.h +++ b/src/plugins/filemanager/core/dfmplugin-computer/private/computerview_p.h @@ -21,6 +21,7 @@ class ComputerViewPrivate private: ComputerView *q { nullptr }; ComputerStatusBar *statusBar { nullptr }; + bool exit { false }; }; } #endif // COMPUTERVIEW_P_H diff --git a/src/plugins/filemanager/core/dfmplugin-computer/utils/computerutils.cpp b/src/plugins/filemanager/core/dfmplugin-computer/utils/computerutils.cpp index 0f0d3a9764..cd6b30af28 100644 --- a/src/plugins/filemanager/core/dfmplugin-computer/utils/computerutils.cpp +++ b/src/plugins/filemanager/core/dfmplugin-computer/utils/computerutils.cpp @@ -221,21 +221,23 @@ QStringList ComputerUtils::allValidBlockUUIDs() { const auto &allBlocks = DevProxyMng->getAllBlockIds(GlobalServerDefines::DeviceQueryOption::kNotIgnored).toSet(); QSet uuids; - std::for_each(allBlocks.cbegin(), allBlocks.cend(), [&](const QString &devId) { - const auto &&data = DevProxyMng->queryBlockInfo(devId); + for(const QString &devId : allBlocks) { + const auto &&data = DevProxyMng->asyncQueryBlockInfo(devId); + if (data.value("error", QVariant(false)).toBool()) + return uuids.values(); const auto &&uuid = data.value(GlobalServerDefines::DeviceProperty::kUUID).toString(); // optical item not hidden by dconfig, its uuid might be empty. if (data.value(GlobalServerDefines::DeviceProperty::kOpticalDrive).toBool()) - return; + continue; if (!uuid.isEmpty()) uuids << uuid; - }); + }; return uuids.values(); } QList ComputerUtils::blkDevUrlByUUIDs(const QStringList &uuids) { - const auto &&devIds = DevProxyMng->getAllBlockIdsByUUID(uuids); + const auto &&devIds = DevProxyMng->asyncGetAllBlockIdsByUUID(uuids); QList ret; for (const auto &id : devIds) ret << makeBlockDevUrl(id); diff --git a/src/plugins/filemanager/core/dfmplugin-computer/views/computerview.cpp b/src/plugins/filemanager/core/dfmplugin-computer/views/computerview.cpp index a439aa1c6a..a66fdf1680 100644 --- a/src/plugins/filemanager/core/dfmplugin-computer/views/computerview.cpp +++ b/src/plugins/filemanager/core/dfmplugin-computer/views/computerview.cpp @@ -48,6 +48,7 @@ ComputerView::ComputerView(const QUrl &url, QWidget *parent) ComputerView::~ComputerView() { + dp->exit = true; } QWidget *ComputerView::widget() const @@ -301,6 +302,8 @@ void ComputerView::handleDisksVisible() } const auto &&hiddenPartitions = ComputerItemWatcher::hiddenPartitions(); + if (dp->exit) + return; fmInfo() << "ignored/hidden disks:" << hiddenPartitions; for (int i = 7; i < model->items.count(); i++) { // 7 means where the disk group start. @@ -399,6 +402,8 @@ void ComputerView::handleComputerItemVisible() handleUserDirVisible(); handle3rdEntriesVisible(); handleDisksVisible(); + if (dp->exit) + return; dp->statusBar->itemCounted(dp->visibleItemCount()); }