[kde-doc-english] KDE/kdebase/workspace/plasma/applets/battery

Marcos David Dione mdione at grulic.org.ar
Thu Jan 22 15:41:43 CET 2009


SVN commit 915184 by mdione:

Battery applet now can show remaining time until depletion/fully charged 
(depending on AC adaptor state) instead of charge percentage.

GUI: new options in battery/batteryConfig.ui.



 M  +41 -19    battery.cpp  
 M  +2 -0      battery.h  
 M  +95 -3     batteryConfig.ui  


--- trunk/KDE/kdebase/workspace/plasma/applets/battery/battery.cpp #915183:915184
@@ -108,6 +108,7 @@
 {
     KConfigGroup cg = config();
     m_showBatteryString = cg.readEntry("showBatteryString", false);
+    m_showRemainingTime = cg.readEntry("showRemainingTime", false);
     m_showMultipleBatteries = cg.readEntry("showMultipleBatteries", !m_isEmbedded);
 
     showBattery(false);
@@ -157,22 +158,26 @@
     } else {
         setAspectRatioMode(Plasma::KeepAspectRatio);
     }
+    int minWidth;
+    int minHeight;
 
     if (constraints & (Plasma::FormFactorConstraint | Plasma::SizeConstraint)) {
         if (formFactor() == Plasma::Vertical) {
             if (!m_showMultipleBatteries) {
-                setMinimumHeight(qMax(m_textRect.height(), size().width()));
+                minHeight = qMax(m_textRect.height(), size().width());
             } else {
-                setMinimumHeight(qMax(m_textRect.height(), size().width()*m_numOfBattery));
+                minHeight = qMax(m_textRect.height(), size().width()*m_numOfBattery);
             }
             setMinimumWidth(0);
+            setMinimumHeight(minHeight);
             //kDebug() << "Vertical FormFactor";
         } else if (formFactor() == Plasma::Horizontal) {
             if (!m_showMultipleBatteries) {
-                setMinimumWidth(qMax(m_textRect.width(), size().height()));
+                minWidth = qMax(m_textRect.width(), size().height());
             } else {
-                setMinimumWidth(qMax(m_textRect.width(), size().height()*m_numOfBattery));
+                minWidth = qMax(m_textRect.width(), size().height()*m_numOfBattery);
             }
+            setMinimumWidth(minWidth);
             setMinimumHeight(0);
             //kDebug() << "Horizontal FormFactor" << m_textRect.width() << contentsRect().height();
         } else {
@@ -218,6 +223,11 @@
     connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
     connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
     ui.showBatteryStringCheckBox->setChecked(m_showBatteryString ? Qt::Checked : Qt::Unchecked);
+    if (m_showRemainingTime) {
+        ui.showTimeRadioButton->setChecked(Qt::Checked);
+    } else {
+        ui.showPercentageRadioButton->setChecked(Qt::Checked);
+    }
     ui.showMultipleBatteriesCheckBox->setChecked(m_showMultipleBatteries ? Qt::Checked : Qt::Unchecked);
 }
 
@@ -225,6 +235,16 @@
 {
     KConfigGroup cg = config();
 
+    if (m_showRemainingTime != ui.showTimeRadioButton->isChecked()) {
+        // kDebug() << "config changed";
+        m_showRemainingTime = !m_showRemainingTime;
+        cg.writeEntry("showRemainingTime", m_showRemainingTime);
+        // kDebug() << m_showRemainingTime;
+        if (m_showBatteryString && m_showBatteryString == ui.showBatteryStringCheckBox->isChecked()) {
+            showLabel(m_showBatteryString);
+        }
+    }
+
     if (m_showBatteryString != ui.showBatteryStringCheckBox->isChecked()) {
         m_showBatteryString = !m_showBatteryString;
         cg.writeEntry("showBatteryString", m_showBatteryString);
@@ -492,13 +512,13 @@
     if (m_numOfBattery && m_batteryLabel) {
         QHashIterator<QString, QHash<QString, QVariant > > battery_data(m_batteries_data);
         int bnum = 0;
-        int hours = m_remainingMSecs/1000/3600;
-        int minutes = qRound(m_remainingMSecs/60000) % 60;
 
         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) {
 
                 // FIXME: Somehow, m_extenderApplet is null here, so the label never becomes visible
@@ -507,17 +527,7 @@
                 }
 
                 // we don't have too much accuracy so only give hours and minutes
-                int msecs = hours * 1000 * 3600 + minutes * 60000;
-                batteryLabelText.append(i18n("Time remaining: <b>%1</b><br />", KGlobal::locale()->prettyFormatDuration(msecs)));
-                kDebug() << "hours:" << hours << "minutes:" << minutes;
-                /* might be useful for the tooltip
-                kDebug() << "hours:" << hours << "minutes:" << minutes;
-                QTime t = QTime(hours, minutes);
-                kDebug() << t;
-                KLocale tmpLocale(*KGlobal::locale());
-                tmpLocale.setTimeFormat("%k:h %Mm remaining");
-                kDebug() << tmpLocale.formatTime(t, false, true); // minutes, hours as duration
-                */
+                batteryLabelText.append(i18n("Time remaining: <b>%1</b><br />", KGlobal::locale()->prettyFormatDuration(m_remainingMSecs)));
             } else {
                 if (m_extenderApplet) {
                     m_extenderApplet->showBatteryLabel(false);
@@ -871,8 +881,20 @@
                 // Show the charge percentage with a box on top of the battery
                 QString batteryLabel;
                 if (battery_data.value()["Plugged in"].toBool()) {
-                    batteryLabel = battery_data.value()["Percent"].toString();
-                    batteryLabel.append("%");
+                    // kDebug() << m_showRemainingTime;
+                    if (!m_showRemainingTime || m_remainingMSecs==0) {
+                        batteryLabel = battery_data.value()["Percent"].toString();
+                        batteryLabel.append("%");
+                    } else {
+                        m_remainingMSecs = battery_data.value()["Remaining msec"].toInt();
+                        int hours = m_remainingMSecs/1000/3600;
+                        int minutes = qRound(m_remainingMSecs/60000) % 60;
+                        QTime t = QTime(hours, minutes);
+                        KLocale tmpLocale(*KGlobal::locale());
+                        tmpLocale.setTimeFormat("%k:%M");
+                        batteryLabel = tmpLocale.formatTime(t, false, true); // minutes, hours as duration
+                    }
+                    // kDebug() << batteryLabel;
                     paintLabel(p, corect, batteryLabel);
                 }
             }
--- trunk/KDE/kdebase/workspace/plasma/applets/battery/battery.h #915183:915184
@@ -120,6 +120,8 @@
         bool m_showMultipleBatteries;
         /* Should the battery charge information be shown on top? */
         bool m_showBatteryString;
+        /* Should that info be percentage (false) or time (true)? */
+        bool m_showRemainingTime;
         QSizeF m_size;
         int m_pixelSize;
         Plasma::Svg* m_theme;
--- trunk/KDE/kdebase/workspace/plasma/applets/battery/batteryConfig.ui #915183:915184
@@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>363</width>
-    <height>80</height>
+    <height>270</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -22,11 +22,70 @@
       <string/>
      </property>
      <property name="text" >
-      <string>Show the percentage of &amp;charge on the battery</string>
+      <string>Show charge &amp;information</string>
      </property>
     </widget>
    </item>
    <item>
+    <layout class="QGridLayout" name="gridLayout" >
+     <item row="0" column="1" >
+      <widget class="QRadioButton" name="showPercentageRadioButton" >
+       <property name="enabled" >
+        <bool>false</bool>
+       </property>
+       <property name="text" >
+        <string>Show &amp;percentage</string>
+       </property>
+       <property name="checked" >
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="0" >
+      <spacer name="horizontalSpacer" >
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType" >
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
+       <property name="sizeHint" stdset="0" >
+        <size>
+         <width>20</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item row="1" column="0" >
+      <spacer name="horizontalSpacer_2" >
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType" >
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
+       <property name="sizeHint" stdset="0" >
+        <size>
+         <width>20</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item row="1" column="1" >
+      <widget class="QRadioButton" name="showTimeRadioButton" >
+       <property name="enabled" >
+        <bool>false</bool>
+       </property>
+       <property name="text" >
+        <string>Show remaining &amp;time</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
     <widget class="QCheckBox" name="showMultipleBatteriesCheckBox" >
      <property name="toolTip" >
       <string/>
@@ -52,5 +111,38 @@
   </layout>
  </widget>
  <resources/>
- <connections/>
+ <connections>
+  <connection>
+   <sender>showBatteryStringCheckBox</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>showPercentageRadioButton</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>181</x>
+     <y>20</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>195</x>
+     <y>52</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>showBatteryStringCheckBox</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>showTimeRadioButton</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>181</x>
+     <y>20</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>195</x>
+     <y>83</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
 </ui>



More information about the kde-doc-english mailing list