void BatteryAction::update()
{
if (m_charge < 0)
setText(i18n("No Battery"));
else if (m_charging)
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));
}
Sets the text and icon name by reading the battery value. It first sets the text and icon name, and adds a number of 10% argument to the battery icon.