[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-panel-devel
Subject: Re: Review Request: Add a tooltip to battery monitor applet
From: Sebastian =?iso-8859-15?q?K=FCgler?= <sebas () kde ! org>
Date: 2009-11-26 23:14:07
Message-ID: 200911270014.13058.sebas () kde ! org
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
On Thursday 26 November 2009 18:01:19 Aaron J. Seigo wrote:
> On November 26, 2009, Kåre Särs wrote:
> > I also thought about extragear/base/plasma/applets/, but that one is
> > empty (dead?).
>
> anything that you wish to package, ship and support can go into extragear
> (and yes, we do need to open a plasma module in extragear again). a forked
> version won't happen in addons, however. i mean, really, two battery
> monitors in the default packages?
>
> in this particular case, i'm ok with a hidden config option. usually i
> really dislike these things, but it's trivial, will get this issue off my
> back and will be a nice example later on for why hidden config options do
> or don't work.
Here's a patch that re-enables this option, with the hidden config option
"showRemainingTime=true". I've commented out the i18n for the label since we're in
string freeze.
It basically moves around a bit of code I had disabled temporarily when I reworked
the layout of the popup and adapts to the better alignment. No tooltip in there,
however.
Should I commit this one?
--
sebas
http://www.kde.org | http://vizZzion.org | GPG Key ID: 9119 0EF9
["battery-applet-showremainingtime.diff" (text/x-patch)]
diff --git a/workspace/plasma/generic/applets/battery/battery.cpp \
b/workspace/plasma/generic/applets/battery/battery.cpp index 232222c..538237b 100644
--- a/workspace/plasma/generic/applets/battery/battery.cpp
+++ b/workspace/plasma/generic/applets/battery/battery.cpp
@@ -390,6 +390,15 @@ void Battery::initExtenderItem(Plasma::ExtenderItem *item)
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<Battery*>(Plasma::Applet::load("battery")); int s = 64;
if (m_extenderApplet) {
@@ -536,58 +545,40 @@ void Battery::updateStatus()
if (m_numOfBattery && m_batteryLabelLabel) {
QHashIterator<QString, QHash<QString, QVariant > > \
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: <b>%1</b><br />", \
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("<br />");
- batteriesInfo.append("<br />");
- }
- batteriesLabel.append(i18nc("Placeholder is the battery ID", \
"<b>Battery %1:</b> ", 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("<br />");
+ batteriesInfo.append("<br />");
+ }
+ batteriesLabel.append(i18nc("Placeholder is the battery ID", \
"<b>Battery %1:</b> ", 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 @@ void Battery::updateStatus()
} 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("<b>Battery:</b> "));
m_batteryInfoLabel->setText(i18nc("Battery is not plugged in", "Not \
present")); @@ -856,8 +858,8 @@ void Battery::paintInterface(QPainter *p, const \
QStyleOptionGraphicsItem *option }
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");
diff --git a/workspace/plasma/generic/applets/battery/battery.h \
b/workspace/plasma/generic/applets/battery/battery.h index 8f44ded..08543ec 100644
--- a/workspace/plasma/generic/applets/battery/battery.h
+++ b/workspace/plasma/generic/applets/battery/battery.h
@@ -108,6 +108,8 @@ class Battery : public Plasma::PopupApplet
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;
["signature.asc" (application/pgp-signature)]
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic