SVN commit 1054869 by sebas: Re-enable the hidden config option to show the remaining time in the battery applet You can enable showing the remaining time in your plasma-desktop-appletsrc (or plasma-netbook-appletsrc), locate the section for the "battery" plugin and add "showRemainingTime=true" on a new line. Make sure you're not editing the section for the battery's extenderitem, but the battery itself.) In my config, this looks like: [Containments][3][Applets][7][Configuration][Applets][30] geometry=140,2.5,30,24 immutability=1 plugin=battery zvalue=0 [Containments][3][Applets][7][Configuration][Applets][30][Configuration] Share=false showBatteryString=false showRemainingTime=true (Obviously, the last line is relevant.) We're not offering this as an option in the GUI since this information is, for a lot of users not reliable enough. The label for the time remaining option is disabled for now since I couldn't re-use the existing string. Should be uncommented once 4.5 opens. I hope we can all be happy now :) CCMAIL:plasma-devel@kde.org M +48 -46 battery.cpp M +2 -0 battery.h --- trunk/KDE/kdebase/workspace/plasma/generic/applets/battery/battery.cpp #1054868:1054869 @@ -390,6 +390,15 @@ m_controlsLayout->addItem(m_acInfoLabel, row, 1); row++; + m_remainingTimeLabel = new Plasma::Label(controls); + m_remainingTimeLabel->setAlignment(Qt::AlignRight); + //m_remainingTimeLabel->setText(i18nc("Label for remaining time", "Time Remaining:")); + m_remainingInfoLabel = new Plasma::Label(controls); + m_remainingInfoLabel->nativeWidget()->setWordWrap(false); + m_controlsLayout->addItem(m_remainingTimeLabel, row, 0); + m_controlsLayout->addItem(m_remainingInfoLabel, row, 1); + row++; + Battery *m_extenderApplet = static_cast(Plasma::Applet::load("battery")); int s = 64; if (m_extenderApplet) { @@ -536,58 +545,40 @@ if (m_numOfBattery && m_batteryLabelLabel) { QHashIterator > battery_data(m_batteries_data); int bnum = 0; + QString state; while (battery_data.hasNext()) { bnum++; battery_data.next(); - QString state = battery_data.value()["State"].toString(); - m_remainingMSecs = battery_data.value()["Remaining msec"].toInt(); - //kDebug() << "time left:" << m_remainingMSecs; - /* - if (state == "Discharging" && m_remainingMSecs > 0 && m_showRemainingTime) { - - // FIXME: Somehow, m_extenderApplet is null here, so the label never becomes visible - if (m_extenderApplet) { - m_extenderApplet->showBatteryLabel(true); - } - // we don't have too much accuracy so only give hours and minutes - batteryLabelText.append(i18n("Time remaining: %1
", KGlobal::locale()->prettyFormatDuration(m_remainingMSecs))); - } else { - */ - //if (m_extenderApplet) { - // m_extenderApplet->showBatteryLabel(false); - //} - if (m_numOfBattery == 0) { - //kDebug() << "zero batteries ..."; - } else if (m_numOfBattery == 1) { - m_batteryLabelLabel->setText(i18n("Battery:")); - if (battery_data.value()["Plugged in"].toBool()) { - if (state == "NoCharge") { - m_batteryInfoLabel->setText(i18n("%1% (charged)", battery_data.value()["Percent"].toString())); - } else if (state == "Discharging") { - m_batteryInfoLabel->setText(i18nc("Shown when a time estimate is not available", "%1% (discharging)\n", battery_data.value()["Percent"].toString())); - } else { - m_batteryInfoLabel->setText(i18n("%1% (charging)", battery_data.value()["Percent"].toString())); - } - } else { - m_batteryInfoLabel->setText(i18nc("Battery is not plugged in", "Not present")); - } - } else { - //kDebug() << "More batteries ..."; - // FIXME: we're overwriting the text - if (bnum > 1) { - batteriesLabel.append("
"); - batteriesInfo.append("
"); - } - batteriesLabel.append(i18nc("Placeholder is the battery ID", "Battery %1: ", bnum)); + state = battery_data.value()["State"].toString(); + if (m_numOfBattery == 1) { + m_batteryLabelLabel->setText(i18n("Battery:")); + if (battery_data.value()["Plugged in"].toBool()) { if (state == "NoCharge") { - batteriesInfo.append(i18n("%1% (charged)", battery_data.value()["Percent"].toString())); + m_batteryInfoLabel->setText(i18n("%1% (charged)", battery_data.value()["Percent"].toString())); } else if (state == "Discharging") { - batteriesInfo.append(i18n("%2% (discharging)", bnum, battery_data.value()["Percent"].toString())); + m_batteryInfoLabel->setText(i18nc("Shown when a time estimate is not available", "%1% (discharging)", battery_data.value()["Percent"].toString())); } else { - batteriesInfo.append(i18n("%2% (charging)", bnum, battery_data.value()["Percent"].toString())); + m_batteryInfoLabel->setText(i18n("%1% (charging)", battery_data.value()["Percent"].toString())); } + } else { + m_batteryInfoLabel->setText(i18nc("Battery is not plugged in", "Not present")); } - //} + } else { + //kDebug() << "More batteries ..."; + // FIXME: we're overwriting the text + if (bnum > 1) { + batteriesLabel.append("
"); + batteriesInfo.append("
"); + } + batteriesLabel.append(i18nc("Placeholder is the battery ID", "Battery %1: ", bnum)); + if (state == "NoCharge") { + batteriesInfo.append(i18n("%1% (charged)", battery_data.value()["Percent"].toString())); + } else if (state == "Discharging") { + batteriesInfo.append(i18n("%2% (discharging)", bnum, battery_data.value()["Percent"].toString())); + } else { + batteriesInfo.append(i18n("%2% (charging)", bnum, battery_data.value()["Percent"].toString())); + } + } } m_acLabelLabel->setText(i18n("AC Adapter:")); // ouch ... if (m_acAdapterPlugged) { @@ -595,6 +586,17 @@ } else { m_acInfoLabel->setText(i18n("Not plugged in")); } + m_remainingMSecs = battery_data.value()["Remaining msec"].toInt(); + //kDebug() << "time left:" << m_remainingMSecs; + if ((state == "Discharging" || state == "Charging") && m_remainingMSecs > 0 && m_showRemainingTime) { + m_remainingTimeLabel->show(); + m_remainingInfoLabel->show(); + // we don't have too much accuracy so only give hours and minutes + m_remainingInfoLabel->setText(KGlobal::locale()->prettyFormatDuration(m_remainingMSecs)); + } else { + m_remainingTimeLabel->hide(); + m_remainingInfoLabel->hide(); + } } else { m_batteryLabelLabel->setText(i18n("Battery: ")); m_batteryInfoLabel->setText(i18nc("Battery is not plugged in", "Not present")); @@ -856,8 +858,8 @@ } QString state = battery_data.value()["State"].toString(); - if (m_showRemainingTime && (state=="Charging" || state=="Discharging" )) { - m_remainingMSecs = battery_data.value()["Remaining msec"].toInt(); + m_remainingMSecs = battery_data.value()["Remaining msec"].toInt(); + if (m_remainingMSecs > 0 && (m_showRemainingTime && (state=="Charging" || state=="Discharging"))) { QTime t = QTime(m_hours, m_minutes); KLocale tmpLocale(*KGlobal::locale()); tmpLocale.setTimeFormat("%k:%M"); --- trunk/KDE/kdebase/workspace/plasma/generic/applets/battery/battery.h #1054868:1054869 @@ -108,6 +108,8 @@ Plasma::Label *m_batteryInfoLabel; Plasma::Label *m_acLabelLabel; Plasma::Label *m_acInfoLabel; + Plasma::Label *m_remainingTimeLabel; + Plasma::Label *m_remainingInfoLabel; //QGraphicsGridLayout *m_brightnessLayout; Plasma::Label *m_statusLabel; //Plasma::Label *m_batteryLabel; _______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel