Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ build
.qmake.stash
*.qm
.cache/*
.claude/*
.vscode

# AI
.cursor/
.cursorindexingignore
.specstory/
.claude/*

# debian output
debian/.debhelper/
Expand Down
5 changes: 5 additions & 0 deletions application/widgets/devicelistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
73 changes: 65 additions & 8 deletions application/widgets/diskbadsectorsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
#include <QVBoxLayout>
#include <QGridLayout>
#include <QDebug>
#include <QStackedWidget>

Check warning on line 22 in application/widgets/diskbadsectorsdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStackedWidget> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QSettings>

Check warning on line 23 in application/widgets/diskbadsectorsdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSettings> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFile>

Check warning on line 24 in application/widgets/diskbadsectorsdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFile> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDateTime>

Check warning on line 25 in application/widgets/diskbadsectorsdialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDateTime> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DiskBadSectorsDialog::DiskBadSectorsDialog(QWidget *parent) : DDialog(parent)
{
Expand Down Expand Up @@ -644,6 +645,11 @@
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";
Expand Down Expand Up @@ -798,18 +804,45 @@
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;
Expand Down Expand Up @@ -871,6 +904,10 @@
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();
Expand Down Expand Up @@ -910,6 +947,14 @@
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();
Expand Down Expand Up @@ -959,6 +1004,12 @@
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();
Expand Down Expand Up @@ -1015,6 +1066,12 @@
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");
Expand Down
6 changes: 6 additions & 0 deletions application/widgets/diskbadsectorsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions application/widgets/diskhealthdetectiondelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 0 additions & 23 deletions application/widgets/diskhealthdetectiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -104,15 +87,13 @@ 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;
m_healthStateValue = new DLabel;
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)) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
52 changes: 43 additions & 9 deletions service/diskoperation/DeviceStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,8 @@
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";
}
}
}
Expand All @@ -778,11 +774,11 @@
return;
}

void DeviceStorage::updateForHWDevice(const QString &devicePath)
void DeviceStorage::updateForHWDevice(const QString &/*devicePath*/)

Check warning on line 777 in service/diskoperation/DeviceStorage.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'updateForHWDevice' is never used.
{
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;
}

Expand All @@ -798,6 +794,44 @@
// 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";
}

Expand Down