From fc764859db192dececf211f1cd1258552fbe7cb4 Mon Sep 17 00:00:00 2001 From: xust Date: Mon, 8 Jan 2024 14:59:41 +0800 Subject: [PATCH] fix: [sidebar] sidebar not hidden internal disks as title. Log: as title. Bug: https://pms.uniontech.com/bug-view-238733.html --- src/dfm-base/base/device/devicemanager.cpp | 8 +------- src/dfm-base/base/device/deviceutils.cpp | 20 +++++++++++++++++++ src/dfm-base/base/device/deviceutils.h | 3 +++ .../watcher/computeritemwatcher.cpp | 3 ++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/dfm-base/base/device/devicemanager.cpp b/src/dfm-base/base/device/devicemanager.cpp index 6eb7230786..27ca90ca13 100644 --- a/src/dfm-base/base/device/devicemanager.cpp +++ b/src/dfm-base/base/device/devicemanager.cpp @@ -81,14 +81,8 @@ QStringList DeviceManager::getAllBlockDevID(DeviceQueryOptions opts) if (opts.testFlag(DeviceQueryOption::kOptical) && !data.value(DeviceProperty::kOptical).toBool()) continue; - - bool isSystem = data.value(DeviceProperty::kHintSystem).toBool() - || data.value(DeviceProperty::kConnectionBus).toString() != "usb"; - if (data.value(DeviceProperty::kOpticalDrive).toBool()) - isSystem = false; - if (opts.testFlag(DeviceQueryOption::kSystem) - && !isSystem) + && !DeviceUtils::isSystemDisk(data)) continue; if (opts.testFlag(DeviceQueryOption::kLoop) && !data.value(DeviceProperty::kIsLoopDevice).toBool()) diff --git a/src/dfm-base/base/device/deviceutils.cpp b/src/dfm-base/base/device/deviceutils.cpp index 72390199b2..83ae0a14d0 100644 --- a/src/dfm-base/base/device/deviceutils.cpp +++ b/src/dfm-base/base/device/deviceutils.cpp @@ -672,6 +672,26 @@ QString DeviceUtils::bindPathTransform(const QString &path, bool toDevice) return bindPath; } +bool DeviceUtils::isSystemDisk(const QVariantHash &devInfo) +{ + bool isSystem = devInfo.value(GlobalServerDefines::DeviceProperty::kHintSystem).toBool() + || devInfo.value(GlobalServerDefines::DeviceProperty::kConnectionBus).toString() != "usb"; + if (devInfo.value(GlobalServerDefines::DeviceProperty::kOpticalDrive).toBool()) + isSystem = false; + return isSystem; +} + +bool DeviceUtils::isSystemDisk(const QVariantMap &devInfo) +{ + QVariantHash hash; + QMapIterator iter(devInfo); + while (iter.hasNext()) { + iter.next(); + hash.insert(iter.key(), iter.value()); + } + return isSystemDisk(hash); +} + bool DeviceUtils::findDlnfsPath(const QString &target, Compare func) { Q_ASSERT(func); diff --git a/src/dfm-base/base/device/deviceutils.h b/src/dfm-base/base/device/deviceutils.h index 6009ff62bd..c97c37c49e 100644 --- a/src/dfm-base/base/device/deviceutils.h +++ b/src/dfm-base/base/device/deviceutils.h @@ -81,6 +81,9 @@ class DeviceUtils // otherwise convert the path to the mount point name static QString bindPathTransform(const QString &path, bool toDevice); + static bool isSystemDisk(const QVariantHash &devInfo); + static bool isSystemDisk(const QVariantMap &devInfo); + private: static bool hasMatch(const QString &txt, const QString &rex); using Compare = std::function; diff --git a/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.cpp b/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.cpp index 607333f889..09a9b6ea11 100644 --- a/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.cpp +++ b/src/plugins/filemanager/core/dfmplugin-computer/watcher/computeritemwatcher.cpp @@ -644,10 +644,11 @@ QVariantMap ComputerItemWatcher::makeSidebarItem(DFMEntryFileInfoPointer info) QString visableName; QString reportName = "Unknown Disk"; QString subGroup = Global::Scheme::kComputer; + if (info->extraProperty(DeviceProperty::kIsLoopDevice).toBool()) { visableKey = kItemVisiableControlKeys[1]; visableName = kItemVisiableControlNames[1]; - } else if (info->extraProperty(DeviceProperty::kHintSystem).toBool()) { + } else if (DeviceUtils::isSystemDisk(info->extraProperties())) { visableKey = kItemVisiableControlKeys[0]; visableName = kItemVisiableControlNames[0]; reportName = info->targetUrl().path() == "/" ? "System Disk" : "Data Disk";