1
diff -Nur -x '*.orig' -x '*~' kde-guidance-0.8.0svn20080103/powermanager/gpmhelper.py kde-guidance-0.8.0svn20080103.new/powermanager/gpmhelper.py
2
--- kde-guidance-0.8.0svn20080103/powermanager/gpmhelper.py 1970-01-01 01:00:00.000000000 +0100
3
+++ kde-guidance-0.8.0svn20080103.new/powermanager/gpmhelper.py 2008-03-25 15:08:51.000000000 +0100
6
+# -*- coding: UTF-8 -*-
8
+Copyright 2008 Sebastian Kügler, Canonical Ltd, Luka Renko
11
+ Andreas Wenning <awen@awen.dk>
13
+This program is free software; you can redistribute it and/or modify
14
+it under the terms of the GNU General Public License as published by
15
+the Free Software Foundation; either version 2 of the License, or
16
+(at your option) any later version.
21
+A frontend to HAL's power features for KDE - Helper application
22
+This application listens for HAL signals and issues dcop-calls to the
23
+kde-power-manager that originally started it. To avoid the need for
24
+kde-power-manager to shut it's helper down, this application
25
+will automatically shut down if it's kde-power-manager isn't running.
28
+import dbus, sys, time
29
+from dbus.mainloop.glib import DBusGMainLoop
31
+from dcopext import DCOPClient, DCOPObj, DCOPApp
34
+ def mother_alive(self):
35
+ """Check that our mother is still alive"""
37
+ for name in self.dcop.registeredApplications():
39
+ if name == self.motherName:
42
+ """No mother; commit suicide"""
43
+ print "guidance-power-manager not alive; exiting"
46
+ """Called when signal is received"""
47
+ def signal_recv(self, *args):
48
+ if args[0] == "ButtonPressed":
49
+ if args[1] == "brightness-up":
51
+ ok, foo = self.mother.brightnessUp()
53
+ print "brightnessUp-call failed"
54
+ return self.mother_alive()
56
+ print "brightnessUp-call failed"
57
+ return self.mother_alive()
58
+ elif args[1] == "brightness-down":
60
+ ok, foo = self.mother.brightnessDown()
62
+ print "brightnessDown-call failed"
63
+ return self.mother_alive()
65
+ print "brightnessDown-call failed"
66
+ return self.mother_alive()
67
+ elif args[1] == "sleep":
68
+ if time.time()-1 <= self.last_sleep <= time.time():
69
+ """Most likely an extra sleep-call, discarding"""
70
+ print "Extra sleep-call discarded"
73
+ ok, foo = self.mother.suspend()
75
+ print "suspend-call failed"
76
+ return self.mother_alive()
77
+ self.last_sleep = time.time()
79
+ print "suspend-call failed"
80
+ return self.mother_alive()
81
+ elif args[1] == "hibernate":
83
+ ok, foo = self.mother.hibernate()
85
+ print "hibernate-call failed"
86
+ return self.mother_alive()
88
+ print "hibernate failed"
89
+ return self.mother_alive()
92
+ """Connect to HAL"""
93
+ self.dbus_loop = DBusGMainLoop(set_as_default=True)
94
+ self.bus = dbus.SystemBus(mainloop=self.dbus_loop)
95
+ hal_manager_obj = self.bus.get_object("org.freedesktop.Hal",u'/org/freedesktop/Hal/Manager')
96
+ self.hal_manager = dbus.Interface(hal_manager_obj, "org.freedesktop.Hal.Manager")
98
+ """Find button-devices and to connect to"""
99
+ button_devices = self.hal_manager.FindDeviceByCapability("button")
100
+ for device in button_devices:
101
+ self.bus.add_signal_receiver(self.signal_recv,
103
+ "org.freedesktop.Hal.Device",
104
+ "org.freedesktop.Hal",
106
+ """Let's find our mother"""
107
+ self.dcop = DCOPClient()
110
+ for name in self.dcop.registeredApplications():
112
+ if name.startswith('guidance-'):
113
+ self.motherName = name
115
+ self.mother = DCOPObj(name, self.dcop, 'power-manager')
118
+ """Do nothing, catched by found=False"""
121
+ """No mother; commit suicide"""
122
+ print "No guidance-power-manager is running"
125
+ """Some laptops issue double sleep-calls, we need to discard one in that case"""
126
+ self.last_sleep = 0
128
+if __name__ == "__main__":
130
+ loop = gobject.MainLoop()
132
diff -Nur -x '*.orig' -x '*~' kde-guidance-0.8.0svn20080103/powermanager/guidance-power-manager.py kde-guidance-0.8.0svn20080103.new/powermanager/guidance-power-manager.py
133
--- kde-guidance-0.8.0svn20080103/powermanager/guidance-power-manager.py 2008-03-25 15:07:56.000000000 +0100
134
+++ kde-guidance-0.8.0svn20080103.new/powermanager/guidance-power-manager.py 2008-03-25 15:07:57.000000000 +0100
135
@@ -1120,5 +1120,14 @@
136
mainWindow = PowermanagerApp(None, "main window")
138
dcop_iface = DcopIface(mainWindow.pmwidget)
139
+ """Start helper module / button listener"""
141
+ helperPid = os.spawnl(os.P_NOWAIT, os.path.dirname(__file__)+'/gpmhelper.py', 'gpmhelper.py')
143
+ """Non-fatal if this fails"""
144
+ print "Unable to start button-listener"
148
+ """Kill helper module / button listener"""
149
+ os.system('kill '+str(helperPid))
150
diff -Nur -x '*.orig' -x '*~' kde-guidance-0.8.0svn20080103/setup.py kde-guidance-0.8.0svn20080103.new/setup.py
151
--- kde-guidance-0.8.0svn20080103/setup.py 2008-03-21 12:24:40.000000000 +0100
152
+++ kde-guidance-0.8.0svn20080103.new/setup.py 2008-03-25 15:07:57.000000000 +0100
154
'wineconfig/drivedetect.py',
155
'powermanager/guidance-power-manager.py',
156
'powermanager/powermanage.py',
157
+ 'powermanager/gpmhelper.py',
158
'powermanager/guidance_power_manager_ui.ui',
159
'powermanager/powermanager_ui.ui',
160
'grubconfig/grubconfig.py'],