Blame SOURCES/kde-workspace-4.10.5-solid-bz#1109987.patch

511c81
commit 775a99e8bc1e9c5e277ff17a84a406227a5a32fb
511c81
Author: Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
511c81
Date:   Tue Jun 17 17:35:19 2014 +0200
511c81
511c81
    Consider additional batteries for power management (when the critical battery timer is running)
511c81
    
511c81
    After resuming from suspend, all batteries are added
511c81
    to powerdevil. When a battery, with charge lower or
511c81
    equal than the critical charge percentage is added, the
511c81
    critical battery timer will be started.
511c81
    
511c81
    In the current version the critical battery timeout can
511c81
    only be interrupted by plugging in AC.
511c81
    
511c81
    But if the system has more than one battery, the global
511c81
    charge percentage can be greater than the critical charge
511c81
    percentage and so the system shouldn't suspend. To achive
511c81
    this behaviour, we calculate the global charge percentage
511c81
    whenever a new battery was added and if the critical
511c81
    battery timer is running and the global charge is high
511c81
    enough, we stop the timer.
511c81
    
511c81
    Also we use the already calculated global charge percentage
511c81
    for the battery charge percentage notification instead of
511c81
    the charge of each individual battery.
511c81
    
511c81
    With this patch, the user can not only interrupt the critical
511c81
    timer by plugging in the AC but also by plugging in a new or
511c81
    additional battery (if the battery has enough charge).
511c81
    
511c81
    Note: The 30 sec timeout message will still popup.
511c81
    
511c81
    Tested with a Thinkpad T440s (two batteries)
511c81
    
511c81
    @Philipp Paris: Thanks for testing!
511c81
    
511c81
    BUG: 329537
511c81
    BUG: 325707
511c81
    FIXED-IN: 4.11.11
511c81
    REVIEW: 118801
511c81
511c81
diff --git a/powerdevil/daemon/powerdevilcore.cpp b/powerdevil/daemon/powerdevilcore.cpp
511c81
index 76e1b82..d096d74 100644
511c81
--- a/powerdevil/daemon/powerdevilcore.cpp
511c81
+++ b/powerdevil/daemon/powerdevilcore.cpp
511c81
@@ -456,8 +456,20 @@ void Core::onDeviceAdded(const QString& udi)
511c81
     }
511c81
     m_loadedBatteriesUdi.append(udi);
511c81
 
511c81
+    // Compute the current global percentage
511c81
+    int globalChargePercent = 0;
511c81
+    for (QHash<QString,int>::const_iterator i = m_batteriesPercent.constBegin(); i != m_batteriesPercent.constEnd(); ++i) {
511c81
+        globalChargePercent += i.value();
511c81
+    }
511c81
+
511c81
+    // If a new battery has been added, let's clear some pending suspend actions if the new global batteries percentage is
511c81
+    // higher than the battery low level. (See bug 329537)
511c81
+    if (m_criticalBatteryTimer->isActive() && globalChargePercent > PowerDevilSettings::batteryCriticalLevel()) {
511c81
+        m_criticalBatteryTimer->stop();
511c81
+    }
511c81
+
511c81
     // So we get a "Battery is low" notification directly on system startup if applicable
511c81
-    emitBatteryChargePercentNotification(b->chargePercent(), 100);
511c81
+    emitBatteryChargePercentNotification(globalChargePercent, 100);
511c81
 }
511c81
 
511c81
 void Core::onDeviceRemoved(const QString& udi)