Skip to content

Commit

Permalink
refacotr: [burn] Optimizing isBlank
Browse files Browse the repository at this point in the history
For determining empty discs for DVD-/+RW, the unified wrapper interface `DeviceUtils::isBlankOpticalDisc` is used.

Log: code optimizing
  • Loading branch information
Johnson-zs authored and deepin-bot[bot] committed Jul 25, 2023
1 parent 88a0f92 commit cb9d5bc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
15 changes: 15 additions & 0 deletions src/dfm-base/base/device/deviceutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <dfm-base/dbusservice/global_server_defines.h>

#include <dfm-io/dfile.h>
#include <dfm-burn/dburn_global.h>

#include <QVector>
#include <QDebug>
Expand All @@ -28,6 +29,7 @@

using namespace dfmbase;
using namespace GlobalServerDefines::DeviceProperty;
DFM_BURN_USE_NS

QString DeviceUtils::getBlockDeviceId(const QString &deviceDesc)
{
Expand Down Expand Up @@ -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<MediaType>(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)
Expand Down
1 change: 1 addition & 0 deletions src/dfm-base/base/device/deviceutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <QDir>

using namespace dfmplugin_burn;
DFMBASE_USE_NAMESPACE
using namespace GlobalServerDefines;
DFMBASE_USE_NAMESPACE

BurnEventReceiver::BurnEventReceiver(QObject *parent)
: QObject(parent)
Expand Down Expand Up @@ -83,7 +83,8 @@ void BurnEventReceiver::handlePasteTo(const QList<QUrl> &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<FileInfo>(urls.front()) };
static const QSet<QString> imageTypes { Global::Mime::kTypeCdImage, Global::Mime::kTypeISO9660Image };

Expand Down
8 changes: 1 addition & 7 deletions src/plugins/common/dfmplugin-burn/utils/burnjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,7 @@ bool AbstractBurnJob::readyToWork()
return false;
}

bool blank { qvariant_cast<bool>(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<MediaType>(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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString>(map[DeviceProperty::kMountPoint]);
isBlank = { qvariant_cast<bool>(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<MediaType>(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<QString>(map[DeviceProperty::kDevice]);

if (curDev.isEmpty()) {
qWarning() << "Error url: " << url << "Cannot acquire dev";
return false;
Expand Down

0 comments on commit cb9d5bc

Please sign in to comment.