From 3abda60380b72bb940cceb528db449017d12c5ed Mon Sep 17 00:00:00 2001 From: xust Date: Mon, 21 Jul 2025 15:44:44 +0800 Subject: [PATCH 1/6] feat: Enhance time tracking in DiskBadSectorsDialog Changes: 1. Added real-time tracking for elapsed time during disk checks. 2. Implemented pause functionality to accurately account for time spent paused. 3. Updated progress calculation based on actual elapsed time. Log: Improved time management for disk sector checks, providing a more accurate user experience. Bug: https://pms.uniontech.com/bug-view-324195.html --- .gitignore | 2 +- application/widgets/diskbadsectorsdialog.cpp | 73 +++++++++++++++++--- application/widgets/diskbadsectorsdialog.h | 6 ++ 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 6c964ed6..4de13d8e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,13 +4,13 @@ build .qmake.stash *.qm .cache/* -.claude/* .vscode # AI .cursor/ .cursorindexingignore .specstory/ +.claude/* # debian output debian/.debhelper/ diff --git a/application/widgets/diskbadsectorsdialog.cpp b/application/widgets/diskbadsectorsdialog.cpp index ece9bd56..0d8f8b9d 100644 --- a/application/widgets/diskbadsectorsdialog.cpp +++ b/application/widgets/diskbadsectorsdialog.cpp @@ -22,6 +22,7 @@ #include #include #include +#include DiskBadSectorsDialog::DiskBadSectorsDialog(QWidget *parent) : DDialog(parent) { @@ -644,6 +645,11 @@ void DiskBadSectorsDialog::onStartVerifyButtonClicked() m_usedTimeLabel->setText(tr("Time elapsed:") + "00:00:00"); m_unusedTimeLabel->setText(tr("Time left:") + "00:00:00"); + // 初始化实际时间跟踪 + m_realStartTime = QDateTime::currentMSecsSinceEpoch(); + m_totalPausedTime = 0; + m_isPaused = false; + QFile file("/tmp/CheckData.conf"); if (file.open(QIODevice::ReadWrite | QIODevice::Truncate)) { qDebug() << "File opened successfully"; @@ -798,18 +804,45 @@ void DiskBadSectorsDialog::onCheckTimeOut() m_settings->setValue("CurCylinder",lst.at(1)); m_settings->endGroup(); - qint64 totalTime = m_curCheckTime / m_curCheckNumber * m_totalCheckNumber; - int value = QString::number((float)m_curCheckTime / totalTime,'f', 2).toFloat() * 100; - value > 99 ? value = 99 : value; - - m_progressBar->setValue(value); - qint64 remainingTime = totalTime - m_curCheckTime; - remainingTime < 1000 ? remainingTime = 1000 : remainingTime; + // 使用实际经过时间计算已用时间 + qint64 currentTime = QDateTime::currentMSecsSinceEpoch(); + qint64 realElapsedTime = currentTime - m_realStartTime - m_totalPausedTime; + + // 如果当前是暂停状态,不包括当前暂停期间的时间 + if (m_isPaused && m_pauseStartTime > 0) { + qint64 currentPauseDuration = currentTime - m_pauseStartTime; + realElapsedTime -= currentPauseDuration; + } + + // 确保已用时间不为负数 + if (realElapsedTime < 0) realElapsedTime = 0; + + // 基于柱面检测时间估算总时间(用于剩余时间计算) + qint64 estimatedTotalTime = m_curCheckTime / m_curCheckNumber * m_totalCheckNumber; + + // 计算进度百分比(基于检测数量) + int progressValue = (m_curCheckNumber * 100) / m_totalCheckNumber; + if (progressValue > 99) progressValue = 99; + m_progressBar->setValue(progressValue); + + // 基于实际时间和进度估算剩余时间 + qint64 remainingTime = 0; + if (m_curCheckNumber > 0 && realElapsedTime > 0) { + // 使用实际已用时间来估算剩余时间 + qint64 avgTimePerCylinder = realElapsedTime / m_curCheckNumber; + remainingTime = avgTimePerCylinder * (m_totalCheckNumber - m_curCheckNumber); + } else { + // 回退到基于柱面时间的估算 + remainingTime = estimatedTotalTime - m_curCheckTime; + } + + if (remainingTime < 1000) remainingTime = 1000; + // 显示实际已用时间 qint64 usedHour = 0; qint64 usedMinute = 0; qint64 usedSecond = 0; - mSecsToTime(m_curCheckTime, usedHour, usedMinute, usedSecond); + mSecsToTime(realElapsedTime, usedHour, usedMinute, usedSecond); m_usedTimeLabel->setText(tr("Time elapsed:") + QString("%1:%2:%3").arg(usedHour, 2, 10, QLatin1Char('0')).arg(usedMinute, 2, 10, QLatin1Char('0')).arg(usedSecond, 2, 10, QLatin1Char('0'))); // 时、分、秒为一位数时,十位自动补0 qint64 remainingHour = 0; @@ -871,6 +904,10 @@ void DiskBadSectorsDialog::onStopButtonClicked() m_curType = StatusType::StopCheck; m_cylinderInfoWidget->setChecked(false); + // 记录暂停开始时间 + m_pauseStartTime = QDateTime::currentMSecsSinceEpoch(); + m_isPaused = true; + int checkSize = m_settings->value("SettingData/CheckSize").toInt(); int blockStart = m_settings->value("SettingData/BlockStart").toInt(); int blockEnd = m_settings->value("SettingData/BlockEnd").toInt(); @@ -910,6 +947,14 @@ void DiskBadSectorsDialog::onContinueButtonClicked() m_curType = StatusType::Check; m_cylinderInfoWidget->setChecked(true); + // 累加暂停时间 + if (m_isPaused && m_pauseStartTime > 0) { + qint64 pauseDuration = QDateTime::currentMSecsSinceEpoch() - m_pauseStartTime; + m_totalPausedTime += pauseDuration; + m_isPaused = false; + m_pauseStartTime = 0; + } + int checkSize = m_settings->value("SettingData/CheckSize").toInt(); int blockEnd = m_settings->value("SettingData/BlockEnd").toInt(); int checkNumber = m_settings->value("SettingData/CheckNumber").toInt(); @@ -959,6 +1004,12 @@ void DiskBadSectorsDialog::onAgainVerifyButtonClicked() m_curCheckNumber = 0; m_curCheckTime = 0; + // 重置实际时间跟踪 + m_realStartTime = QDateTime::currentMSecsSinceEpoch(); + m_totalPausedTime = 0; + m_isPaused = false; + m_pauseStartTime = 0; + int checkSize = m_settings->value("SettingData/CheckSize").toInt(); m_blockStart = m_settings->value("SettingData/BlockStart").toInt(); m_blockEnd = m_settings->value("SettingData/BlockEnd").toInt(); @@ -1015,6 +1066,12 @@ void DiskBadSectorsDialog::onResetButtonClicked() m_curRepairTime = 0; m_cylinderInfoWidget->setChecked(false); + // 重置实际时间跟踪 + m_realStartTime = 0; + m_totalPausedTime = 0; + m_isPaused = false; + m_pauseStartTime = 0; + m_verifyComboBox->setCurrentIndex(0); m_startLineEdit->setText("0"); m_startLineEdit->lineEdit()->setPlaceholderText("0"); diff --git a/application/widgets/diskbadsectorsdialog.h b/application/widgets/diskbadsectorsdialog.h index 1f87601c..18e91703 100644 --- a/application/widgets/diskbadsectorsdialog.h +++ b/application/widgets/diskbadsectorsdialog.h @@ -239,6 +239,12 @@ private slots: int m_blockStart = 0; int m_blockEnd = 0; DeviceInfo m_deviceInfo; + + // 实际时间跟踪 + qint64 m_realStartTime = 0; // 检测开始的实际时间戳 + qint64 m_pauseStartTime = 0; // 暂停开始时间戳 + qint64 m_totalPausedTime = 0; // 总的暂停时间 + bool m_isPaused = false; // 是否处于暂停状态 }; #endif // DISKBADSECTORSDIALOG_H From f4fc2e3f489a1390fdaf58a446d82e703e5e5f79 Mon Sep 17 00:00:00 2001 From: xust Date: Thu, 7 Aug 2025 19:34:28 +0800 Subject: [PATCH 2/6] fix: Disable bad sector detection for SSD devices Changes: 1. Added a condition to disable the bad sector detection feature for SSD devices in the device list widget. Log: Improved user experience by preventing unnecessary checks on SSDs. Bug: https://pms.uniontech.com/bug-view-327485.html --- application/widgets/devicelistwidget.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/application/widgets/devicelistwidget.cpp b/application/widgets/devicelistwidget.cpp index 44af95e2..f7c832e5 100644 --- a/application/widgets/devicelistwidget.cpp +++ b/application/widgets/devicelistwidget.cpp @@ -134,6 +134,11 @@ void DeviceListWidget::treeMenu(const QPoint &pos) createPartitionTable->setDisabled(true); } + // 如果是SSD设备,禁用坏道检测功能 + if (info.m_mediaType == "SSD") { + actionVerifyRepair->setDisabled(true); + } + menu->exec(QCursor::pos()); //显示菜单 delete menu; } else if (m_curDiskInfoData.m_level == DMDbusHandler::PARTITION) { From 2cc27242feff905262c5c048d043ffc68388b90c Mon Sep 17 00:00:00 2001 From: xust Date: Fri, 10 Oct 2025 15:53:49 +0800 Subject: [PATCH 3/6] feat: hide specific version of UFS only shows USF and hide the versions. Log: as above. Task: https://pms.uniontech.com/task-view-382543.html --- service/diskoperation/DeviceStorage.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/service/diskoperation/DeviceStorage.cpp b/service/diskoperation/DeviceStorage.cpp index 4ca62cc2..915e3eee 100755 --- a/service/diskoperation/DeviceStorage.cpp +++ b/service/diskoperation/DeviceStorage.cpp @@ -749,12 +749,8 @@ void DeviceStorage::getDiskInfoInterface(const QString &devicePath, QString &int QString spec_version = Utils::readContent("/sys/block/sdd/device/spec_version").trimmed(); if (!spec_version.isEmpty()) { qDebug() << "spec_version is not empty"; - if (spec_version.contains("300")) { - interface = "UFS 3.0"; - } else if (spec_version.contains("310")) { - interface = "UFS 3.1"; - } else if (spec_version.contains("400")) { - interface = "UFS 4.0"; + if (spec_version.contains("300") || spec_version.contains("310") || spec_version.contains("400")) { + interface = "UFS"; } } } From 5c9967bbc93f5b97846927271ca55bd1679f9276 Mon Sep 17 00:00:00 2001 From: xust Date: Tue, 21 Oct 2025 16:20:43 +0800 Subject: [PATCH 4/6] feat: normalize disk size only for specific devices. Log: as above. Bug: https://pms.uniontech.com/bug-view-329231.html Task: https://pms.uniontech.com/task-view-368603.html --- service/diskoperation/DeviceStorage.cpp | 44 +++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/service/diskoperation/DeviceStorage.cpp b/service/diskoperation/DeviceStorage.cpp index 915e3eee..8328f58b 100755 --- a/service/diskoperation/DeviceStorage.cpp +++ b/service/diskoperation/DeviceStorage.cpp @@ -774,11 +774,11 @@ void DeviceStorage::getDiskInfoInterface(const QString &devicePath, QString &int return; } -void DeviceStorage::updateForHWDevice(const QString &devicePath) +void DeviceStorage::updateForHWDevice(const QString &/*devicePath*/) { qDebug() << "DeviceStorage::updateForHWDevice BEGIN"; - if (m_model != Utils::readContent("/proc/bootdevice/product_name").trimmed()) { - qDebug() << "m_model is not boot device, return"; + if (Utils::readContent("/proc/bootdevice/product_name").trimmed().isEmpty()) + qDebug() << "Fail to read the product_name file or the file is empty, return"; return; } @@ -794,6 +794,44 @@ void DeviceStorage::updateForHWDevice(const QString &devicePath) // hide model and vendor m_model = ""; m_vendor = ""; + + // Normalize disk size + if (!m_size.isEmpty()) { + // Convert size string to bytes + qint64 bytes = 0; + QString sizeStr = m_size.toLower(); + + if (sizeStr.contains("bytes")) { + sizeStr = sizeStr.split("bytes").first().trimmed(); + bytes = sizeStr.toLongLong(); + } else { + // Handle GB/TB directly + double value = sizeStr.split(" ").first().toDouble(); + if (sizeStr.contains("gb")) { + bytes = value * 1000 * 1000 * 1000; + } else if (sizeStr.contains("tb")) { + bytes = value * 1000 * 1000 * 1000 * 1000; + } + } + + // Convert to standardized format + if (bytes > 0) { + // Convert to GB and round to standard sizes + int gb = qRound(bytes / (1000.0 * 1000 * 1000)); + if (gb < 200) { + return; + } else if (gb <= 300) { + m_size = "256 GB"; + } else if (gb <= 600) { + m_size = "512 GB"; + } else if (gb <= 1200){ + m_size = "1 TB"; + } else if (gb <= 2200) { + m_size = "2 TB"; + } + } + } + qDebug() << "DeviceStorage::updateForHWDevice END"; } From ca2bac928a3e9c7d6308cdab810bdf43352dfc2f Mon Sep 17 00:00:00 2001 From: xust Date: Mon, 24 Nov 2025 13:11:08 +0800 Subject: [PATCH 5/6] fix: Remove hardcoded colors in disk health detection dialog for theme compatibility - Remove hardcoded DPalette definitions (palette1-6) in DiskHealthDetectionDialog - Remove all setPalette() calls that prevented theme color following - Use option.palette.color(QPalette::Text) in DiskHealthDetectionDelegate for dynamic theme color - Preserve semantic colors for health status indicators (good/damaged/unknown) Log: Fix disk health panel font color not following dark mode theme Bug: https://pms.uniontech.com/bug-view-341105.html --- .../widgets/diskhealthdetectiondelegate.cpp | 3 +-- .../widgets/diskhealthdetectiondialog.cpp | 23 ------------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/application/widgets/diskhealthdetectiondelegate.cpp b/application/widgets/diskhealthdetectiondelegate.cpp index 5dd6db4b..8f39d174 100644 --- a/application/widgets/diskhealthdetectiondelegate.cpp +++ b/application/widgets/diskhealthdetectiondelegate.cpp @@ -134,8 +134,7 @@ void DiskHealthDetectionDelegate::paint(QPainter *painter, const QStyleOptionVie // qDebug() << "Drawing UNKNOWN status icon"; painter->setPen(QColor("#777777")); } else { - // qDebug() << "Drawing UNKNOWN status icon"; - painter->setPen(m_color); + painter->setPen(option.palette.color(QPalette::Text)); } painter->drawText(paintRect.x() + 15, paintRect.y() + 20, text); diff --git a/application/widgets/diskhealthdetectiondialog.cpp b/application/widgets/diskhealthdetectiondialog.cpp index 8a0a28fa..805a3489 100644 --- a/application/widgets/diskhealthdetectiondialog.cpp +++ b/application/widgets/diskhealthdetectiondialog.cpp @@ -53,27 +53,11 @@ void DiskHealthDetectionDialog::initUI() DLabel *diskLabel = new DLabel; diskLabel->setPixmap(iconDisk.pixmap(85, 85)); - DPalette palette1; - palette1.setColor(DPalette::Text, "#666666"); - - // 状态提示字体颜色 - DPalette palette4; - palette4.setColor(DPalette::WindowText, QColor("#526A7F")); - - // 表格内容颜色 - DPalette palette5; - palette5.setColor(DPalette::Text, QColor("#001A2E")); - - // 表头字体颜色 - DPalette palette6; - palette6.setColor(DPalette::Text, QColor("#414D68")); - // 硬盘信息 HardDiskInfo hardDiskInfo = DMDbusHandler::instance()->getHardDiskInfo(m_devicePath); DLabel *serialNumberNameLabel = new DLabel(tr("Serial number")); // 序列号 DFontSizeManager::instance()->bind(serialNumberNameLabel, DFontSizeManager::T8, QFont::Medium); - serialNumberNameLabel->setPalette(palette1); m_serialNumberValue = new DLabel; m_serialNumberValue->setText(hardDiskInfo.m_serialNumber); @@ -82,7 +66,6 @@ void DiskHealthDetectionDialog::initUI() DLabel *userCapacityNameLabel = new DLabel(tr("Storage")); // 用户容量 DFontSizeManager::instance()->bind(userCapacityNameLabel, DFontSizeManager::T10, QFont::Medium); - userCapacityNameLabel->setPalette(palette1); m_userCapacityValue = new DLabel; m_userCapacityValue->setText(hardDiskInfo.m_size); @@ -104,7 +87,6 @@ void DiskHealthDetectionDialog::initUI() DLabel *healthStateLabel = new DLabel(tr("Health Status")); // 健康状态 DFontSizeManager::instance()->bind(healthStateLabel, DFontSizeManager::T6, QFont::Medium); - healthStateLabel->setPalette(palette1); QIcon iconHealth = Common::getIcon("good"); DLabel *iconHealthLabel = new DLabel; @@ -112,7 +94,6 @@ void DiskHealthDetectionDialog::initUI() DFontSizeManager::instance()->bind(m_healthStateValue, DFontSizeManager::T2, QFont::Medium); m_healthStateValue->setAccessibleName("healthState"); - // 状态颜色 DPalette paletteStateColor; if (0 == healthStateValue.compare("PASSED", Qt::CaseInsensitive) || 0 == healthStateValue.compare("OK", Qt::CaseInsensitive)) { @@ -154,7 +135,6 @@ void DiskHealthDetectionDialog::initUI() // 温度 DLabel *temperatureLabel = new DLabel(tr("Temperature")); // 温度 DFontSizeManager::instance()->bind(temperatureLabel, DFontSizeManager::T6, QFont::Medium); - temperatureLabel->setPalette(palette1); m_temperatureValue = new DLabel("-°C"); DFontSizeManager::instance()->bind(m_temperatureValue, DFontSizeManager::T2, QFont::Medium); @@ -192,14 +172,12 @@ void DiskHealthDetectionDialog::initUI() m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows); m_tableView->setSelectionMode(QAbstractItemView::NoSelection); m_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); - m_tableView->setPalette(palette5); m_diskHealthHeaderView = new DiskHealthHeaderView(Qt::Horizontal, this); m_tableView->setHorizontalHeader(m_diskHealthHeaderView); DFontSizeManager::instance()->bind(m_tableView->horizontalHeader(), DFontSizeManager::T6, QFont::Medium); m_tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignCenter); - m_tableView->horizontalHeader()->setPalette(palette6); m_diskHealthDetectionDelegate = new DiskHealthDetectionDelegate(this); @@ -332,7 +310,6 @@ void DiskHealthDetectionDialog::initUI() DLabel *stateTipsLabel = new DLabel; stateTipsLabel->setText(tr("Status: (G: Good | W: Warning | D: Damaged | U: Unknown)")); // 状态:(G: 良好 | W: 警告 | D: 损坏 | U: 未知) DFontSizeManager::instance()->bind(stateTipsLabel, DFontSizeManager::T8, QFont::Normal); - stateTipsLabel->setPalette(palette4); m_linkButton = new DCommandLinkButton(tr("Export", "button")); // 导出 DFontSizeManager::instance()->bind(m_linkButton, DFontSizeManager::T8, QFont::Medium); From 94f2865f36887d8e40caf1f06b1177930d3a8216 Mon Sep 17 00:00:00 2001 From: wangrong Date: Fri, 19 Dec 2025 15:57:25 +0800 Subject: [PATCH 6/6] fix: Fix compilation errors As title. Log: Merge from release/1071 Task: https://pms.uniontech.com/task-view-383523.html --- service/diskoperation/DeviceStorage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/diskoperation/DeviceStorage.cpp b/service/diskoperation/DeviceStorage.cpp index 8328f58b..2f04c897 100755 --- a/service/diskoperation/DeviceStorage.cpp +++ b/service/diskoperation/DeviceStorage.cpp @@ -777,7 +777,7 @@ void DeviceStorage::getDiskInfoInterface(const QString &devicePath, QString &int void DeviceStorage::updateForHWDevice(const QString &/*devicePath*/) { qDebug() << "DeviceStorage::updateForHWDevice BEGIN"; - if (Utils::readContent("/proc/bootdevice/product_name").trimmed().isEmpty()) + if (Utils::readContent("/proc/bootdevice/product_name").trimmed().isEmpty()) { qDebug() << "Fail to read the product_name file or the file is empty, return"; return; }