diff options
Diffstat (limited to 'src/jarabe/model/session.py')
-rw-r--r-- | src/jarabe/model/session.py | 81 |
1 files changed, 23 insertions, 58 deletions
diff --git a/src/jarabe/model/session.py b/src/jarabe/model/session.py index 9b277ff..bab155c 100644 --- a/src/jarabe/model/session.py +++ b/src/jarabe/model/session.py @@ -1,5 +1,3 @@ -# Copyright (C) 2008, Red Hat, Inc. -# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -21,72 +19,39 @@ import signal import sys import logging -from sugar import session from sugar import env -_session_manager = None - - -class SessionManager(session.SessionManager): - MODE_LOGOUT = 0 - MODE_SHUTDOWN = 1 - MODE_REBOOT = 2 - - def __init__(self): - session.SessionManager.__init__(self) - self._logout_mode = None - - def logout(self): - self._logout_mode = self.MODE_LOGOUT - self.initiate_shutdown() - - def shutdown(self): - self._logout_mode = self.MODE_SHUTDOWN - self.initiate_shutdown() +GNOME_SESSION_DBUS_SERVICE = 'org.gnome.SessionManager' +GNOME_SESSION_DBUS_INTERFACE = 'org.gnome.SessionManager' +GNOME_SESSION_DBUS_PATH = '/org/gnome/SessionManager' - def reboot(self): - self._logout_mode = self.MODE_REBOOT - self.initiate_shutdown() - def shutdown_completed(self): - if env.is_emulator(): - self._close_emulator() - elif self._logout_mode != self.MODE_LOGOUT: - try: - bus = dbus.SystemBus() - proxy = bus.get_object('org.freedesktop.ConsoleKit', - '/org/freedesktop/ConsoleKit/Manager') - pm = dbus.Interface(proxy, - 'org.freedesktop.ConsoleKit.Manager') +def logout(): + _end_session('logout') - if self._logout_mode == self.MODE_SHUTDOWN: - pm.Stop() - elif self._logout_mode == self.MODE_REBOOT: - pm.Restart() - except: - logging.exception('Can not stop sugar') - self.session.cancel_shutdown() - return - session.SessionManager.shutdown_completed(self) - gtk.main_quit() +def shutdown(): + _end_session('shutdown') - def _close_emulator(self): - gtk.main_quit() - if 'SUGAR_EMULATOR_PID' in os.environ: - pid = int(os.environ['SUGAR_EMULATOR_PID']) - os.kill(pid, signal.SIGTERM) +def reboot(): + _end_session('reboot') - # Need to call this ASAP so the atexit handlers get called before we - # get killed by the X (dis)connection - sys.exit() +def _end_session(mode): + if env.is_emulator(): + mode = 'logout' -def get_session_manager(): - global _session_manager + bus = dbus.SessionBus() + obj = bus.get_object(GNOME_SESSION_DBUS_SERVICE, GNOME_SESSION_DBUS_PATH) + session_manager = dbus.Interface(obj, GNOME_SESSION_DBUS_INTERFACE) - if _session_manager == None: - _session_manager = SessionManager() - return _session_manager + if mode in ['shutdown', 'reboot']: + # FIXME: There's no way to trigger a reboot. + # FIXME: The Shutdown dialog only has a Cancel button, so the user + # needs to wait 50 seconds. + session_manager.Shutdown() + elif mode == 'logout': + # 1 = Don't show confirmation UI + session_manager.Logout(1) |