Logo Search packages:      
Sourcecode: guidance-power-manager version File versions

def guidance-power-manager::PowerManager::poll (   self,
  notify = True 
)

Check for changes in plugged in status, battery status and laptop lid closed status. 

Definition at line 617 of file guidance-power-manager.py.

00617                               :
        """ Check for changes in plugged in status, battery status and laptop lid closed status. """
        debug( "------------ POLL ---------------")

        self.powermanager.checkHAL()
        # Battery stuff:
        # check for last state, and run plugged / unplugged message if the state changed.
        if self.powermanager.hasBattery:
            plugged_num = 0
            self.batt_state = "not present" # unknown yet
            self.batt_level = self.batt_remain = 0
            self.batt_rate = self.batt_charge = self.batt_full = 0
            for batt in self.powermanager.batteries:
                state, level, remain, rate, current, full = self.powermanager.getBatteryState(batt)
                self._updateBatteryWidget(batt, state, level, remain, rate)

                # notify plugged/unplugged batteries
                if state == "not present":
                    if self.powermanager.batteryIsPresent[batt]:
                        print "been removed"
                        self.notify(i18n("The battery has been removed."))
                        self.powermanager.batteryIsPresent[batt] = False
                else: # battery present
                    if not self.powermanager.batteryIsPresent[batt]:
                        print "inserted"
                        self.notify(i18n("The battery has been inserted."))
                        self.powermanager.batteryIsPresent[batt] = True

                    # get cumulative charge levels/rate
                    self.batt_rate += rate
                    self.batt_charge += current
                    self.batt_full += full

                    # calculate overall level (average of present batteries)
                    self.batt_remain += remain
                    self.batt_level += level
                    plugged_num += 1

                    # calculate overall state (charging/discharging/charged)
                    if state in ("charging","discharging"):
                        self.batt_state = state
                    elif not self.batt_state in ("charging, discharging"):
                        self.batt_state = state

            # if we know charge and full -> recalculate overall level
            if self.batt_full > 0 and self.batt_charge > 0:
                self.batt_level = 100 * self.batt_charge / self.batt_full
            else:
                # if more than one battery present, we need to calculate average level
                if plugged_num > 1:
                    self.batt_level /= plugged_num

            # if rate is reported, calculate remaining time on our own
            if self.batt_rate > 0:
                if self.batt_state == "charging":
                    self.batt_remain = 3600 * (float(self.batt_full - self.batt_charge) / self.batt_rate)
                if self.batt_state == "discharging":
                    self.batt_remain = 3600 * (float(self.batt_charge) / self.batt_rate)

            remain_h = self.batt_remain/3600
            remain_m = (self.batt_remain/60)%60

            blabel = i18n("<b>Battery:</b>")
            if self.batt_state == "charged":
                blabel += i18n(" fully charged")
            elif self.batt_state == "charging":
                blabel += ki18nc("hours:minutes", " %1:%2h to charge").subs(remain_h).subs(remain_m, 2).toString()
            elif self.batt_state == "discharging":
                blabel += ki18nc("hours:minutes", " %1:%2h remaining").subs(remain_h).subs(remain_m, 2).toString()
            self.BattMainLabel.setText(blabel)

            # update tray icon if needed
            self.setIcon()

            # check battery state
            self.checkBatteryCritical()

            # check Idletime
            self.checkIdletime()

        # CPU stuff
        self._updateCpuWidgets()

        if self.powermanager.hasBattery:
            on_battery = self.powermanager.onBattery()
            if self.powermanager.wasOnBattery != on_battery:
                self.powermanager.wasOnBattery = on_battery
                debug("poll: states differ")
                if not on_battery:
                    debug("poll: Now on AC")
                    if notify:
                        self.powerHasBeenPlugged()
                else:
                    debug("poll: Now on battery")
                    if notify:
                        self.powerHasBeenUnplugged()
            else:
                debug("poll: state is the same")

        # Lid stuff
        if self.powermanager.hasLid:
            if self.powermanager.getLidClosedState():
                if not self.powermanager.lidClosedState:
                    self.powermanager.lidClosedState = True

                    action = self._getRB(self.LaptopLidRadios, self.lid_act)
                    if not self.act_name.has_key(action):
                        action = self.act_name[self.lid_act_def]

                    if self.act_call[action] != None:
                        if action == "nothing":
                            note = i18n("Laptop lid is closed, hibernating now.")
                        elif action == "blank":
                            note = i18n("Laptop lid is closed, blanking screen now.")
                        elif action == "suspend":
                            note = i18n("Laptop lid is closed, suspending now.")
                        elif action == "hibernate":
                            note = i18n("Laptop lid is closed, hibernating now.")
                        elif action == "shutdown":
                            note = i18n("Laptop lid is closed, shutting down now.")
                        self.notify(note, self.act_icon[action])
                        QTimer.singleShot(2000, self.act_call[action])
            else:
                self.powermanager.lidClosedState = False

    def _addBatteryWidgets(self):


Generated by  Doxygen 1.6.0   Back to index