diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2008-06-06 17:41:41 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2008-06-06 17:41:41 (GMT) |
commit | 1500384cd1f427a209712c95b671ee6e8252ac8c (patch) | |
tree | cc126f871a09a585c5bd49a481753fef4b68e42b /src/session.py | |
parent | 006058be744c61b4a93bb00e418e6205f0ce9af5 (diff) |
First go at session management implementation.
Diffstat (limited to 'src/session.py')
-rw-r--r-- | src/session.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/session.py b/src/session.py new file mode 100644 index 0000000..4157370 --- /dev/null +++ b/src/session.py @@ -0,0 +1,79 @@ +# 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 +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import gtk +import dbus + +from sugar import session +from sugar import env + +from hardware import hardwaremanager + +_session = None + +class Session(session.Session): + MODE_LOGOUT = 0 + MODE_SHUTDOWN = 1 + MODE_REBOOT = 2 + + def __init__(self): + session.Session.__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() + + def reboot(self): + self._logout_mode = self.MODE_REBOOT + self.initiate_shutdown() + + def shutdown_completed(self): + hw_manager = hardwaremanager.get_manager() + hw_manager.shutdown() + + bus = dbus.SystemBus() + proxy = bus.get_object('org.freedesktop.Hal', + '/org/freedesktop/Hal/devices/computer') + pm = dbus.Interface(proxy, \ + 'org.freedesktop.Hal.Device.SystemPowerManagement') + + if env.is_emulator(): + pass + #self._close_emulator() + else: + if self._logout_mode == self.MODE_LOGOUT: + gtk.main_quit() + elif self._logout_mode == self.MODE_SHUTDOWN: + pm.Shutdown() + elif self._logout_mode == self.MODE_REBOOT: + pm.Reboot() + + def _close_emulator(self): + if os.environ.has_key('SUGAR_EMULATOR_PID'): + pid = int(os.environ['SUGAR_EMULATOR_PID']) + os.kill(pid, signal.SIGTERM) + +def get_session(): + global _session + + if _session == None: + _session = Session() + return _session |