hi,

I am using kde 4.3.>5 from 
"svn://anonsvn.kde.org/home/kde/branches/KDE/4.3/"
on my laptop.

I was not able to see the remaining time, when my laptop is on battery.
So I "fixed" that.

I hope that you, or the person, who is responsible for that, will take the 
"fix" over to "svn://anonsvn.kde.org/home/kde/branches/KDE/4.3/", so that 
everyone can enjoy that.

The "fix" is in the email attachment.

thanks
Timo Welter
from Germany, UNI Mainz

Attachment: kde_4-3-x_fix_battery.tar.gz
Description: application/compressed-tar

diff -u --recursive /daten/kde4src/4.3.4_branches/KDE/kdebase/workspace/plasma/applets/battery/batteryConfig.ui ./batteryConfig.ui
--- /daten/kde4src/4.3.4_branches/KDE/kdebase/workspace/plasma/applets/battery/batteryConfig.ui	2010-02-13 12:43:10.448971603 +0100
+++ ./batteryConfig.ui	2010-02-13 12:42:25.438098713 +0100
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>247</width>
-    <height>73</height>
+    <width>293</width>
+    <height>116</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -35,6 +35,16 @@
     </widget>
    </item>
    <item>
+    <widget class="QCheckBox" name="showRemainingTimeCheckBox">
+     <property name="toolTip">
+      <string/>
+     </property>
+     <property name="text">
+      <string>Show remaining time</string>
+     </property>
+    </widget>
+   </item>
+   <item>
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
diff -u --recursive /daten/kde4src/4.3.4_branches/KDE/kdebase/workspace/plasma/applets/battery/battery.cpp ./battery.cpp
--- /daten/kde4src/4.3.4_branches/KDE/kdebase/workspace/plasma/applets/battery/battery.cpp	2010-02-13 12:43:10.446973514 +0100
+++ ./battery.cpp	2010-02-13 12:42:25.438098713 +0100
@@ -246,6 +246,7 @@
     connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
     ui.showBatteryStringCheckBox->setChecked(m_showBatteryString ? Qt::Checked : Qt::Unchecked);
     ui.showMultipleBatteriesCheckBox->setChecked(m_showMultipleBatteries ? Qt::Checked : Qt::Unchecked);
+    ui.showRemainingTimeCheckBox->setChecked(m_showRemainingTime ? Qt::Checked : Qt::Unchecked);
 }
 
 void Battery::configAccepted()
@@ -265,6 +266,12 @@
         emit sizeHintChanged(Qt::PreferredSize);
     }
 
+    if (m_showRemainingTime != ui.showRemainingTimeCheckBox->isChecked()) {
+        m_showRemainingTime = !m_showRemainingTime;
+        cg.writeEntry("showRemainingTime", m_showRemainingTime);
+        emit sizeHintChanged(Qt::PreferredSize);
+    }
+
     emit configNeedsSaving();
 }
 
@@ -346,7 +353,7 @@
     // as the battery applet is also embedded into the battery's extender.
     if (!m_isEmbedded && item->name() == "powermanagement") {
         int row = 0;
-        int rowHeight = 20;
+        int rowHeight = 30;
         int columnWidth = 120;
 
         QGraphicsWidget *controls = new QGraphicsWidget(item);
@@ -366,7 +373,7 @@
         m_batteryLayout->setColumnPreferredWidth(1, columnWidth);
         //m_batteryLayout->setRowPreferredHeight(row, 60);
         m_batteryLabel = new Plasma::Label(controls);
-        m_batteryLabel->setMinimumSize(200, 80);
+        m_batteryLabel->setMinimumSize(250, 80);
         m_batteryLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
         //m_batteryLabel->nativeWidget()->setWordWrap(false);
@@ -374,7 +381,7 @@
         // FIXME: larger fonts screw up this label
         m_batteryLayout->addItem(m_batteryLabel, 0, 0, 1, 1, Qt::AlignLeft);
 
-        Battery *m_extenderApplet = static_cast<Battery*>(Plasma::Applet::load("battery"));
+        m_extenderApplet = static_cast<Battery*>(Plasma::Applet::load("battery"));
         if (m_extenderApplet) {
             m_extenderApplet->setParent(this);
             m_extenderApplet->setAcceptsHoverEvents(false);
@@ -530,7 +537,7 @@
             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) {
+            if (state == "Discharging" && m_remainingMSecs > 0) { // && m_showRemainingTime) {
 
                 // FIXME: Somehow, m_extenderApplet is null here, so the label never becomes visible
                 if (m_extenderApplet) {
@@ -918,7 +925,7 @@
                     }
                     QString state = battery_data.value()["State"].toString();
 
-                    if (m_showRemainingTime && (state=="Charging" || state=="Discharging" )) {
+                    if (m_showRemainingTime && (state=="Discharging" )) {
                         m_remainingMSecs = battery_data.value()["Remaining msec"].toInt();
                         QTime t = QTime(m_hours, m_minutes);
                         KLocale tmpLocale(*KGlobal::locale());
@@ -937,6 +944,8 @@
         // paint only one battery and show cumulative charge level
         int battery_num = 0;
         int battery_charge = 0;
+        int sumRemainingMSecs = 0;
+        bool is_discharging = false;
         bool has_battery = false;
         QHashIterator<QString, QHash<QString, QVariant > > battery_data(m_batteries_data);
         while (battery_data.hasNext()) {
@@ -944,6 +953,14 @@
             if (battery_data.value()["Plugged in"].toBool()) {
                 battery_charge += battery_data.value()["Percent"].toInt();
                 has_battery = true;
+                if (m_showRemainingTime) {
+                    m_remainingMSecs = battery_data.value()["Remaining msec"].toInt();
+                    sumRemainingMSecs += m_remainingMSecs;
+                    QString state = battery_data.value()["State"].toString();
+                    if (state=="Discharging" ) {
+                        is_discharging=true;
+                    }
+                }
                 ++battery_num;
             }
         }
@@ -956,8 +973,22 @@
             // Show the charge percentage with a box on top of the battery
             QString batteryLabel;
             if (has_battery) {
-                batteryLabel = QString::number(battery_charge);
-                batteryLabel.append("%");
+                if (m_showRemainingTime && is_discharging) {
+                    //kDebug() << "bla1:" << sumRemainingMSecs;
+                    int hours = sumRemainingMSecs/1000/3600;
+                    int minutes = qRound(sumRemainingMSecs/60000) % 60;
+                    if (!(minutes==0 && hours==0)) {
+                        m_minutes= minutes;
+                        m_hours= hours;
+                    }
+                    QTime t = QTime(m_hours, m_minutes);
+                    KLocale tmpLocale(*KGlobal::locale());
+                    tmpLocale.setTimeFormat("%k:%M");
+                    batteryLabel = tmpLocale.formatTime(t, false, true); // minutes, hours as duration
+                } else {
+                    batteryLabel = QString::number(battery_charge);
+                    batteryLabel.append("%");
+                }
                 paintLabel(p, contentsRect, batteryLabel);
             }
         }
Nur in .: patch_kde_4-3-x_fix_battery.
Nur in /daten/kde4src/4.3.4_branches/KDE/kdebase/workspace/plasma/applets/battery: .svn.
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to