From 6934d48bb354710800bec3f7d9926f00346a9148 Mon Sep 17 00:00:00 2001 From: uncor3 Date: Wed, 8 Apr 2026 18:19:44 +0300 Subject: [PATCH] reuse updateChargingStatus --- src/deviceinfowidget.cpp | 43 +++++++++++++++++++++++++--------------- src/deviceinfowidget.h | 2 +- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/deviceinfowidget.cpp b/src/deviceinfowidget.cpp index 77cb1ac..5577cd4 100644 --- a/src/deviceinfowidget.cpp +++ b/src/deviceinfowidget.cpp @@ -140,7 +140,6 @@ DeviceInfoWidget::DeviceInfoWidget( m_lightningIconLabel = new ZIconLabel(QIcon(":/resources/icons/MdiLightningBolt.png"), " Charging", 1.0, this); - updateChargingStatusIcon(); m_batteryWidget = new BatteryWidget( qBound(1, device->deviceInfo.batteryInfo.currentBatteryLevel, 100), @@ -151,12 +150,9 @@ DeviceInfoWidget::DeviceInfoWidget( chargingLayout->addWidget(m_lightningIconLabel); chargingLayout->addWidget(m_batteryWidget); - m_chargingWattsWithCableTypeLabel = new QLabel( - QString::number(device->deviceInfo.batteryInfo.watts) + "W" + "/" + - (device->deviceInfo.batteryInfo.usbConnectionType == - BatteryInfo::ConnectionType::USB - ? "USB" - : "USB-C")); + m_chargingWattsWithCableTypeLabel = new QLabel(); + + updateChargingStatus(); headerLayout->addWidget(devProductType); headerLayout->addWidget(diskCapacityLabel); @@ -374,20 +370,35 @@ void DeviceInfoWidget::updateBatteryInfo(const QString &diagnostics) else parseDeviceBattery(xml_doc, d); /*UI*/ - updateChargingStatusIcon(); - m_chargingWattsWithCableTypeLabel->setText( - QString::number(d.batteryInfo.watts) + "W" + "/" + - (d.batteryInfo.usbConnectionType == BatteryInfo::ConnectionType::USB - ? "USB" - : "USB-C")); + updateChargingStatus(); +} + +void DeviceInfoWidget::updateChargingStatus() +{ + auto &d = m_device->deviceInfo; + int watts = d.batteryInfo.watts; + + auto setValues = [this, d]() { + m_chargingWattsWithCableTypeLabel->setText( + QString::number(d.batteryInfo.watts) + "W" + "/" + + (d.batteryInfo.usbConnectionType == BatteryInfo::ConnectionType::USB + ? "USB" + : "USB-C")); + }; + + // watts can be 0 device is not charging + if (watts) { + setValues(); + } else if (d.isWireless) { + m_chargingWattsWithCableTypeLabel->setText("Wireless"); + } else { + setValues(); + } m_batteryWidget->updateContext( d.batteryInfo.isCharging, qBound(1, d.batteryInfo.currentBatteryLevel, 100)); -} -void DeviceInfoWidget::updateChargingStatusIcon() -{ if (m_device->deviceInfo.batteryInfo.isCharging) { m_chargingStatusLabel->setText("Charging"); m_chargingStatusLabel->setStyleSheet( diff --git a/src/deviceinfowidget.h b/src/deviceinfowidget.h index 6a56c26..0851683 100644 --- a/src/deviceinfowidget.h +++ b/src/deviceinfowidget.h @@ -56,7 +56,7 @@ private slots: private: const std::shared_ptr m_device; void updateBatteryInfo(const QString &diagnostics); - void updateChargingStatusIcon(); + void updateChargingStatus(); QLabel *m_chargingStatusLabel; QLabel *m_chargingWattsWithCableTypeLabel; BatteryWidget *m_batteryWidget;