62
62
uic.loadUi("guidance-power-manager.ui", self)
64
##KGlobal.iconLoader().addAppDir("guidance")
66
64
# The systray icon should show and hide the KDialogBase, not only this widget,
67
65
# therefore, it gets our parent as parent.
68
66
self.systray = SystemTrayIcon(parent)
69
67
self.icon = "battery-charging-100"
70
68
self.systray.setIcon(QIcon(UserIcon(self.icon)))
71
#self.connect(self.systray, SIGNAL("quitSelected()"), self.quit)
73
# Configuration filename
74
##self.config = KConfig("power-managerrc")
75
##config = KConfig("power-managerrc")
76
##self.config = config.group("General")
77
71
app = KApplication.kApplication()
78
72
config = KGlobal.config()
79
73
self.config = config.group("power-manager")
431
425
self.config.sync()
427
#FIXME add global key bindings for these
428
#def showBrightnessPopup(self):
429
# if self.powermanager.onBattery():
430
# value=self.BatteryBrightnessSlider.value()*100/self.BatteryBrightnessSlider.maxValue()
432
# value=self.PoweredBrightnessSlider.value()*100/self.PoweredBrightnessSlider.maxValue()
433
# self.brightnessPopup = KPassivePopup.message('<b>Brightness:</b> '+str(value)+'%', self.systray)
434
# """pop.setTimeout(3000)"""
435
# self.brightnessPopup.show()
437
#def setBrightnessUp(self):
438
# """Increments slider value by 10%"""
439
# if self.powermanager.onBattery():
440
# #self.BatteryBrightnessSlider.setValue(float(self.BatteryBrightnessSlider.value())+max(float(self.BatteryBrightnessSlider.maxValue())/float(10),1))
442
# self.PoweredBrightnessSlider.setValue(float(self.PoweredBrightnessSlider.value())+max(float(self.PoweredBrightnessSlider.maxValue())/float(10),1))
443
# self.showBrightnessPopup()
445
#def setBrightnessDown(self):
446
# """Decrements slider value by 10%"""
447
# if self.powermanager.onBattery():
448
# self.BatteryBrightnessSlider.setValue(float(self.BatteryBrightnessSlider.value())-max(float(self.BatteryBrightnessSlider.maxValue())/float(10),1))
450
# self.PoweredBrightnessSlider.setValue(float(self.PoweredBrightnessSlider.value())-max(float(self.PoweredBrightnessSlider.maxValue())/float(10),1))
451
# self.showBrightnessPopup()
453
#def getBrightness(self):
454
# """Work with percentages - it's a bit nicer"""
455
# if self.powermanager.onBattery():
456
# value=self.BatteryBrightnessSlider.value()*100/self.BatteryBrightnessSlider.maxValue()
458
# value=self.PoweredBrightnessSlider.value()*100/self.PoweredBrightnessSlider.maxValue()
459
# return QString(str(value))
436
461
def lockScreen(self):
437
462
""" locks the screen using kdesktop """
593
618
state, level, remain, rate, current, full = self.powermanager.getBatteryState(batt)
594
619
self._updateBatteryWidget(batt, state, level, remain, rate)
596
## notify plugged/unplugged batteries
597
print "poll, batt chck"
621
# notify plugged/unplugged batteries
598
622
if state == "not present":
599
623
if self.powermanager.batteryIsPresent[batt]:
600
624
print "been removed"
606
630
self.notify(i18n("The battery has been inserted."))
607
631
self.powermanager.batteryIsPresent[batt] = True
609
## get cumulative charge levels/rate
633
# get cumulative charge levels/rate
610
634
self.batt_rate += rate
611
635
self.batt_charge += current
612
636
self.batt_full += full
614
## calculate overall level (average of present batteries)
638
# calculate overall level (average of present batteries)
615
639
self.batt_remain += remain
616
640
self.batt_level += level
619
## calculate overall state (charging/discharging/charged)
643
# calculate overall state (charging/discharging/charged)
620
644
if state in ("charging","discharging"):
621
645
self.batt_state = state
622
646
elif not self.batt_state in ("charging, discharging"):
727
751
self.tooltip.layout().addLayout(self.BattLayout[batt])
754
def _updateBatteryWidget(self, batt, state, level, remain, rate):
755
""" Retrieve battery information and update the related widgets accordingly. """
756
self.BattProgress[batt].setEnabled(True)
757
self.BattProgress[batt].setMaximum(100)
758
self.BattProgress[batt].setValue(level)
759
if state == "not present":
760
self.BattProgress[batt].setFormat(i18n("not present"))
761
elif state == "charging":
762
self.BattProgress[batt].setFormat(i18n("Charging (%p%)"))
763
elif state == "discharging":
766
self.BattProgress[batt].setFormat(i18n("Discharging (%p%)") + " - %.d W" % showrate)
768
self.BattProgress[batt].setFormat(i18n("Discharging (%p%)"))
770
self.BattProgress[batt].setFormat("%p%")
730
772
def _addCpuWidgets(self):
731
773
""" Adds progressbars to show CPU frequencies to the tooltip."""
732
774
if not SHOW_CPUFREQ:
783
825
index = self.BatteryCriticalCombo.currentIndex()
784
826
self.CriticalRemainTime.setEnabled(index != 0)
786
def _updateBatteryWidget(self, batt, state, level, remain, rate):
787
""" Retrieve battery information and update the related widgets accordingly. """
788
self.BattProgress[batt].setEnabled(True)
789
self.BattProgress[batt].setMaximum(100)
790
self.BattProgress[batt].setValue(level)
791
if state == "not present":
792
self.BattProgress[batt].setFormat(i18n("not present"))
793
elif state == "charging":
794
self.BattProgress[batt].setFormat(i18n("Charging (%p%)"))
795
elif state == "discharging":
798
self.BattProgress[batt].setFormat(i18n("Discharging (%p%)") + " - %.d W" % showrate)
800
self.BattProgress[batt].setFormat(i18n("Discharging (%p%)"))
802
self.BattProgress[batt].setFormat("%p%")
804
828
def _updateCpuWidgets(self):
805
829
""" Retrieve CPU freq information and update the related widgets accordingly. """
806
830
if not SHOW_CPUFREQ:
1019
1043
def slotUser1(self):
1020
1044
self.aboutus.show()
1022
# This class needed because we can't use a widget for a tooltip in Qt 4 (only text)
1023
# Also we can't use a KPassivePopup because KSystemTrayIcon is not a QWidget
1024
1046
class SystemTrayIcon(KSystemTrayIcon):
1047
"""This class needed because we can't use a widget for a tooltip in Qt 4 (only text)
1048
Also we can't use a KPassivePopup because KSystemTrayIcon is not a QWidget """
1026
1050
def setToolTip(self, toolTip):
1051
""" set the toolTip widget """
1027
1052
self.toolTip = toolTip
1028
1053
self.toolTip.setWindowFlags(Qt.ToolTip)
1030
1055
def event(self, event):
1056
""" overloaded to pick up tooltip events and show our widget
1057
would be nice to hide it when the mouse leaves but systemtrayicons
1058
don't get that event so use a timer """
1031
1059
if event.type() == QEvent.ToolTip:
1032
1060
self.toolTip.show()
1033
1061
x = self.geometry().x() - self.toolTip.width()