source: trunk/debathena/config/gdm-config/debian/debathena-nologin-monitor @ 24822

Revision 24822, 3.6 KB checked in by jdreed, 14 years ago (diff)
In gdm-config: * Add an applet to monitor /etc/nologin on new-GDM
  • Property svn:executable set to *
Line 
1#!/usr/bin/python
2#
3# An applet to monitor /etc/nologin
4
5import gio
6import dbus
7import dbus.mainloop.glib
8import gtk
9import gobject
10import sys
11import os
12
13SM_DBUS_NAME = "org.gnome.SessionManager"
14SM_DBUS_PATH = "/org/gnome/SessionManager"
15SM_DBUS_INTERFACE = "org.gnome.SessionManager"
16SM_CLIENT_DBUS_INTERFACE = "org.gnome.SessionManager.ClientPrivate"
17APP_ID = "debathena-nologin-monitor"
18
19class GDMSucks:
20    def __init__(self):
21        self.sessionEnding = False
22        self.sessionBus = dbus.SessionBus()
23        try:
24            self.register_with_sm()
25            self.init_sm_client()
26        except:
27            print "Warning: Cannot register with session manager."
28       
29        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
30        self.label = gtk.Label()
31        self.label.set_markup('<span font_desc="Sans Bold 24">This workstation is temporarily unavailable.  Please use another workstation.</span>')
32        self.window.add(self.label)
33        self.window.set_decorated(False)
34        self.window.set_position(gtk.WIN_POS_CENTER)
35        self.window.hide()
36        self.gfile = gio.File("/etc/nologin")
37        self.monitor = self.gfile.monitor_file(gio.FILE_MONITOR_NONE, None)
38        self.monitor.connect("changed", self.directory_changed)
39
40    def directory_changed(self, monitor, file1, file2, evt_type):
41        # type(evt_type) is <class 'gio._gio.FileMonitorEvent'>
42        # Value is something like:
43        #     <enum G_FILE_MONITOR_EVENT_CREATED of type GFileMonitorEvent>
44        # However, those constants aren't available in Python, unless I'm missing something
45        # So, we do this the stupid way:
46        if str(evt_type) == "<enum G_FILE_MONITOR_EVENT_CREATED of type GFileMonitorEvent>":
47            self.window.show_all()
48        if str(evt_type) == "<enum G_FILE_MONITOR_EVENT_DELETED of type GFileMonitorEvent>":
49            self.window.hide()
50
51   # Connect to the session manager, and register our client.
52    def register_with_sm(self):
53        proxy = self.sessionBus.get_object(SM_DBUS_NAME, SM_DBUS_PATH)
54        sm = dbus.Interface(proxy, SM_DBUS_INTERFACE)
55        autostart_id = os.getenv("DESKTOP_AUTOSTART_ID", default="")
56        self.smClientId = sm.RegisterClient(APP_ID, autostart_id)
57
58    # Set up to handle signals from the session manager.
59    def init_sm_client(self):
60        proxy = self.sessionBus.get_object(SM_DBUS_NAME, self.smClientId)
61        self.smClient = dbus.Interface(proxy, SM_CLIENT_DBUS_INTERFACE)
62        self.smClient.connect_to_signal("QueryEndSession",
63                                         self.sm_on_QueryEndSession)
64        self.smClient.connect_to_signal("EndSession", self.sm_on_EndSession)
65        self.smClient.connect_to_signal("CancelEndSession",
66                                         self.sm_on_CancelEndSession)
67        self.smClient.connect_to_signal("Stop", self.sm_on_Stop)
68
69     # Here on a QueryEndSession signal from the session manager.
70    def sm_on_QueryEndSession(self, flags):
71        self.sessionEnding = True
72        # Response args: is_ok, reason.
73        self.smClient.EndSessionResponse(True, "")
74
75    # Here on an EndSession signal from the session manager.
76    def sm_on_EndSession(self, flags):
77        self.sessionEnding = True
78        # Response args: is_ok, reason.
79        self.smClient.EndSessionResponse(True, "")
80
81    # Here on a CancelEndSession signal from the session manager.
82    def sm_on_CancelEndSession(self):
83        self.sessionEnding = False
84
85    # Here on a Stop signal from the session manager.
86    def sm_on_Stop(self):
87        gtk.main_quit()
88
89def main():
90    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
91    GDMSucks()
92    gtk.main()
93
94if __name__ == '__main__':
95    main()
Note: See TracBrowser for help on using the repository browser.