From cb9d5bce73220e7098af9fbf4893a8acf9e2c278 Mon Sep 17 00:00:00 2001 From: Zhang Sheng Date: Mon, 24 Jul 2023 15:35:27 +0800 Subject: [PATCH] refacotr: [burn] Optimizing `isBlank` For determining empty discs for DVD-/+RW, the unified wrapper interface `DeviceUtils::isBlankOpticalDisc` is used. Log: code optimizing --- src/dfm-base/base/device/deviceutils.cpp | 15 +++++++++++++++ src/dfm-base/base/device/deviceutils.h | 1 + .../dfmplugin-burn/events/burneventreceiver.cpp | 5 +++-- .../common/dfmplugin-burn/utils/burnjob.cpp | 8 +------- .../views/opticalmediawidget.cpp | 10 ++-------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/dfm-base/base/device/deviceutils.cpp b/src/dfm-base/base/device/deviceutils.cpp index ab63c54a1e..063e6c00a2 100644 --- a/src/dfm-base/base/device/deviceutils.cpp +++ b/src/dfm-base/base/device/deviceutils.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -28,6 +29,7 @@ using namespace dfmbase; using namespace GlobalServerDefines::DeviceProperty; +DFM_BURN_USE_NS QString DeviceUtils::getBlockDeviceId(const QString &deviceDesc) { @@ -204,6 +206,19 @@ bool DeviceUtils::isWorkingOpticalDiscId(const QString &id) return false; } +bool DeviceUtils::isBlankOpticalDisc(const QString &id) +{ + // for dvd+rw/dvd-rw disc, erase operation only overwrite some blocks which used to present filesystem, + // so the blank field is still false even if it can be write datas from the beginning, + auto &&map = DevProxyMng->queryBlockInfo(id); + bool isBlank { map[kOpticalBlank].toBool() }; + auto mediaType { static_cast(map[kOpticalMediaType].toUInt()) }; + if (mediaType == MediaType::kDVD_PLUS_RW || mediaType == MediaType::kDVD_RW) + isBlank |= map[kSizeTotal].toULongLong() == map[kSizeFree].toULongLong(); + + return isBlank; +} + bool DeviceUtils::isSamba(const QUrl &url) { if (url.scheme() == Global::Scheme::kSmb) diff --git a/src/dfm-base/base/device/deviceutils.h b/src/dfm-base/base/device/deviceutils.h index d32867fdad..1bd7b350da 100644 --- a/src/dfm-base/base/device/deviceutils.h +++ b/src/dfm-base/base/device/deviceutils.h @@ -43,6 +43,7 @@ class DeviceUtils static bool isAutoMountAndOpenEnable(); static bool isWorkingOpticalDiscDev(const QString &dev); static bool isWorkingOpticalDiscId(const QString &id); + static bool isBlankOpticalDisc(const QString &id); static bool isSamba(const QUrl &url); static bool isFtp(const QUrl &url); diff --git a/src/plugins/common/dfmplugin-burn/events/burneventreceiver.cpp b/src/plugins/common/dfmplugin-burn/events/burneventreceiver.cpp index 03ffa0224c..512b185bcf 100644 --- a/src/plugins/common/dfmplugin-burn/events/burneventreceiver.cpp +++ b/src/plugins/common/dfmplugin-burn/events/burneventreceiver.cpp @@ -25,8 +25,8 @@ #include using namespace dfmplugin_burn; -DFMBASE_USE_NAMESPACE using namespace GlobalServerDefines; +DFMBASE_USE_NAMESPACE BurnEventReceiver::BurnEventReceiver(QObject *parent) : QObject(parent) @@ -83,7 +83,8 @@ void BurnEventReceiver::handlePasteTo(const QList &urls, const QUrl &dest, destDir.setFilter(QDir::Filter::AllEntries | QDir::Filter::NoDotAndDotDot); QString devId { DeviceUtils::getBlockDeviceId(dev) }; auto &&map = DevProxyMng->queryBlockInfo(devId); - bool isBlank { map[DeviceProperty::kOpticalBlank].toBool() }; + bool isBlank { DeviceUtils::isBlankOpticalDisc(devId) }; + auto fi { InfoFactory::create(urls.front()) }; static const QSet imageTypes { Global::Mime::kTypeCdImage, Global::Mime::kTypeISO9660Image }; diff --git a/src/plugins/common/dfmplugin-burn/utils/burnjob.cpp b/src/plugins/common/dfmplugin-burn/utils/burnjob.cpp index 5b0531680a..d81137cf07 100644 --- a/src/plugins/common/dfmplugin-burn/utils/burnjob.cpp +++ b/src/plugins/common/dfmplugin-burn/utils/burnjob.cpp @@ -203,13 +203,7 @@ bool AbstractBurnJob::readyToWork() return false; } - bool blank { qvariant_cast(map[DeviceProperty::kOpticalBlank]) }; - // for dvd+rw/dvd-rw disc, erase operation only overwrite some blocks which used to present filesystem, - // so the blank field is still false even if it can be write datas from the beginning, - auto mediaType { static_cast(map[DeviceProperty::kOpticalMediaType].toUInt()) }; - if (mediaType == MediaType::kDVD_PLUS_RW || mediaType == MediaType::kDVD_RW) - blank |= map[DeviceProperty::kSizeTotal].toULongLong() == map[DeviceProperty::kSizeFree].toULongLong(); - + bool blank { DeviceUtils::isBlankOpticalDisc(curDevId) }; if (blank) { QString tag = curDevId.mid(curDevId.lastIndexOf("/") + 1); QUrl url(QString("burn:///dev/%1/disc_files/").arg(tag)); diff --git a/src/plugins/filemanager/dfmplugin-optical/views/opticalmediawidget.cpp b/src/plugins/filemanager/dfmplugin-optical/views/opticalmediawidget.cpp index 215030f0df..fda62b3053 100644 --- a/src/plugins/filemanager/dfmplugin-optical/views/opticalmediawidget.cpp +++ b/src/plugins/filemanager/dfmplugin-optical/views/opticalmediawidget.cpp @@ -44,15 +44,9 @@ bool OpticalMediaWidget::updateDiscInfo(const QUrl &url, bool retry) devId = { DeviceUtils::getBlockDeviceId(dev) }; auto &&map = DevProxyMng->queryBlockInfo(devId); QString &&mnt = qvariant_cast(map[DeviceProperty::kMountPoint]); - isBlank = { qvariant_cast(map[DeviceProperty::kOpticalBlank]) }; - - // for dvd+rw/dvd-rw disc, erase operation only overwrite some blocks which used to present filesystem, - // so the blank field is still false even if it can be write datas from the beginning, - auto mediaType { static_cast(map[DeviceProperty::kOpticalMediaType].toUInt()) }; - if (mediaType == MediaType::kDVD_PLUS_RW || mediaType == MediaType::kDVD_RW) - isBlank |= map[DeviceProperty::kSizeTotal].toULongLong() == map[DeviceProperty::kSizeFree].toULongLong(); - + isBlank = DeviceUtils::isBlankOpticalDisc(devId); curDev = qvariant_cast(map[DeviceProperty::kDevice]); + if (curDev.isEmpty()) { qWarning() << "Error url: " << url << "Cannot acquire dev"; return false;