From f4cb713c711ec410eeb2c16b9270b994982936e8 Mon Sep 17 00:00:00 2001 From: Piyush Aggarwal Date: Tue, 18 May 2021 14:05:00 +0530 Subject: [PATCH] indicator: status-aware battery action icon --- indicator/systray_actions/battery_action.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/indicator/systray_actions/battery_action.cpp b/indicator/systray_actions/battery_action.cpp index b658f5445..81f7b77f7 100644 --- a/indicator/systray_actions/battery_action.cpp +++ b/indicator/systray_actions/battery_action.cpp @@ -19,8 +19,6 @@ BatteryAction::BatteryAction(DeviceDbusInterface* device) setCharging(m_batteryIface.isCharging()); }); - setIcon(QIcon::fromTheme(QStringLiteral("battery"))); - BatteryAction::update(); } @@ -32,6 +30,22 @@ void BatteryAction::update() setText(i18n("Battery: %1% (Charging)", m_charge)); else setText(i18n("Battery: %1%", m_charge)); + + // set icon name + QString iconName = QStringLiteral("battery"); + if (m_charge < 0) { + iconName += QStringLiteral("-missing"); + } else { + int val = int(m_charge / 10) * 10; + QString numberPaddedString = QStringLiteral("%1").arg(val, 3, 10, QLatin1Char('0')); + iconName += QStringLiteral("-") + numberPaddedString; + } + + if (m_charging) { + iconName += QStringLiteral("-charging"); + } + + setIcon(QIcon::fromTheme(iconName)); } void BatteryAction::setCharge(int charge)