~ubuntu-branches/ubuntu/hardy/kde-guidance/hardy-proposed

« back to all changes in this revision

Viewing changes to debian/patches/kubuntu_23_kde-powermanager_gpmhelper.patch

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman, Andreas Wenning, Scott Kitterman
  • Date: 2008-03-30 19:11:55 UTC
  • Revision ID: james.westby@ubuntu.com-20080330191155-bl8ex35pq52jh6sy
Tags: 0.8.0svn20080103-0ubuntu10
[ Andreas Wenning ]
* Added kubuntu_21_kde-powermanager_unique-check.patch:
  - Fixed guidance-power-managers check for being a unique app.
* Added kubuntu_23_kde-powermanager_gpmhelper.patch:
  - Added gpmhelper.py to listen for HAL button-events and issue
    dcop calls to guidance-power-manager.
  - guidance-power-manager will now start gpmhelper.py.
  - Patched setup.py to build/install gpmhelper.py
* Changed debian/rules and debian/kde-guidance-powermanager.install
  to install gpmhelper.py
* Added depends for kde-guidance-powermanager to python-gobject as
  this is the only mainloop to work with DBusGMainLoop.

[ Scott Kitterman ]
* In kubuntu_14_displayconfig_no_xorg_no_serverlayout.patch simplify fake
  xorg.conf invented if it's missing - match xorg.conf generatedy by
  Hardy's Bulletproof X
* Update kununtu_13_displayconfig_add_new_monitors.patch with new monitors

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
@@ -0,0 +1,127 @@
 
5
+#!/usr/bin/python
 
6
+# -*- coding: UTF-8 -*-
 
7
+"""
 
8
+Copyright 2008 Sebastian Kügler, Canonical Ltd, Luka Renko
 
9
+
 
10
+Authors: 
 
11
+    Andreas Wenning <awen@awen.dk>
 
12
+
 
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.
 
17
+
 
18
+"""
 
19
+
 
20
+"""
 
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.
 
26
+"""
 
27
+
 
28
+import dbus, sys, time
 
29
+from dbus.mainloop.glib import DBusGMainLoop
 
30
+import gobject
 
31
+from dcopext import DCOPClient, DCOPObj, DCOPApp
 
32
+
 
33
+class GPMHelper():
 
34
+    def mother_alive(self):
 
35
+        """Check that our mother is still alive"""
 
36
+        found = False
 
37
+        for name in self.dcop.registeredApplications():
 
38
+            name = str(name)
 
39
+            if name == self.motherName:
 
40
+                found = True
 
41
+        if not found:
 
42
+            """No mother; commit suicide"""
 
43
+            print "guidance-power-manager not alive; exiting"
 
44
+            loop.quit()
 
45
+
 
46
+    """Called when signal is received"""
 
47
+    def signal_recv(self, *args):
 
48
+        if args[0] == "ButtonPressed":
 
49
+            if args[1] == "brightness-up":
 
50
+                try:
 
51
+                    ok, foo = self.mother.brightnessUp()
 
52
+                    if not ok:
 
53
+                        print "brightnessUp-call failed"
 
54
+                        return self.mother_alive()
 
55
+                except:
 
56
+                    print "brightnessUp-call failed"
 
57
+                    return self.mother_alive()
 
58
+            elif args[1] == "brightness-down":
 
59
+                try:
 
60
+                    ok, foo = self.mother.brightnessDown()
 
61
+                    if not ok:
 
62
+                        print "brightnessDown-call failed"
 
63
+                        return self.mother_alive()
 
64
+                except:
 
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"
 
71
+                    return
 
72
+                try:
 
73
+                    ok, foo = self.mother.suspend()
 
74
+                    if not ok:
 
75
+                        print "suspend-call failed"
 
76
+                        return self.mother_alive()
 
77
+                    self.last_sleep = time.time()
 
78
+                except:
 
79
+                    print "suspend-call failed"
 
80
+                    return self.mother_alive()
 
81
+            elif args[1] == "hibernate":
 
82
+                try:
 
83
+                    ok, foo = self.mother.hibernate()
 
84
+                    if not ok:
 
85
+                        print "hibernate-call failed"
 
86
+                        return self.mother_alive()
 
87
+                except:
 
88
+                    print "hibernate failed"
 
89
+                    return self.mother_alive()
 
90
+
 
91
+    def __init__(self):
 
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")
 
97
+
 
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,
 
102
+                                        "Condition",
 
103
+                                        "org.freedesktop.Hal.Device",
 
104
+                                        "org.freedesktop.Hal",
 
105
+                                        device)
 
106
+        """Let's find our mother"""
 
107
+        self.dcop = DCOPClient()
 
108
+        self.dcop.attach()
 
109
+        found = False
 
110
+        for name in self.dcop.registeredApplications():
 
111
+            name = str(name)
 
112
+            if name.startswith('guidance-'):
 
113
+                self.motherName = name
 
114
+                try:
 
115
+                    self.mother = DCOPObj(name, self.dcop, 'power-manager')
 
116
+                    found = True
 
117
+                except:
 
118
+                    """Do nothing, catched by found=False"""
 
119
+                break
 
120
+        if not found:
 
121
+            """No mother; commit suicide"""
 
122
+            print "No guidance-power-manager is running"
 
123
+            sys.exit()
 
124
+
 
125
+        """Some laptops issue double sleep-calls, we need to discard one in that case"""
 
126
+        self.last_sleep = 0
 
127
+
 
128
+if __name__ == "__main__":
 
129
+    gpmh = GPMHelper()
 
130
+    loop = gobject.MainLoop()
 
131
+    loop.run()
 
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")
 
137
     doDcop(kapp)
 
138
     dcop_iface = DcopIface(mainWindow.pmwidget)
 
139
+    """Start helper module / button listener"""
 
140
+    try:
 
141
+        helperPid = os.spawnl(os.P_NOWAIT, os.path.dirname(__file__)+'/gpmhelper.py', 'gpmhelper.py')
 
142
+    except:
 
143
+        """Non-fatal if this fails"""
 
144
+        print "Unable to start button-listener"
 
145
 
 
146
     kapp.exec_loop()
 
147
+
 
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
 
153
@@ -183,6 +183,7 @@
 
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'],