home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / deskbar-applet / handlers / gdmactions.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-04-29  |  11.2 KB  |  269 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import dbus
  5. import dbus.glib as dbus
  6. from gettext import gettext as _
  7. import deskbar
  8. import deskbar.Indexer as deskbar
  9. import deskbar.Handler as deskbar
  10. import deskbar.Utils as deskbar
  11. from deskbar.defs import VERSION
  12. import gdmclient
  13. import gtk
  14. import gnome
  15. import gnome.ui as gnome
  16. HANDLERS = {
  17.     'GdmHandler': {
  18.         'name': _('Computer Actions'),
  19.         'description': _('Logoff, shutdown, restart, suspend and related actions.'),
  20.         'version': VERSION } }
  21.  
  22. class GpmMatch(deskbar.Match.Match):
  23.     
  24.     def __init__(self, backend, name = None, **args):
  25.         deskbar.Match.Match.__init__(self, backend, name = name, **args)
  26.         bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
  27.         obj = bus.get_object('org.gnome.PowerManager', '/org/gnome/PowerManager')
  28.         self._gpm = dbus.Interface(obj, 'org.gnome.PowerManager')
  29.  
  30.     
  31.     def get_category(self):
  32.         return 'actions'
  33.  
  34.  
  35.  
  36. class SuspendMatch(GpmMatch):
  37.     
  38.     def __init__(self, backend, name = None, **args):
  39.         GpmMatch.__init__(self, backend, name)
  40.         self._icon = deskbar.Utils.load_icon('gpm-suspend-to-ram.png')
  41.  
  42.     
  43.     def action(self, text = None):
  44.         
  45.         try:
  46.             self._gpm.Suspend()
  47.         except dbus.DBusException:
  48.             pass
  49.  
  50.  
  51.     
  52.     def get_category(self):
  53.         return 'actions'
  54.  
  55.     
  56.     def get_verb(self):
  57.         return _('Suspend the machine')
  58.  
  59.  
  60.  
  61. class HibernateMatch(GpmMatch):
  62.     
  63.     def __init__(self, backend, name = None, **args):
  64.         GpmMatch.__init__(self, backend, name)
  65.         self._icon = deskbar.Utils.load_icon('gpm-suspend-to-disk.png')
  66.  
  67.     
  68.     def action(self, text = None):
  69.         
  70.         try:
  71.             self._gpm.Hibernate()
  72.         except dbus.DBusException:
  73.             pass
  74.  
  75.  
  76.     
  77.     def get_verb(self):
  78.         return _('Hibernate the machine')
  79.  
  80.  
  81.  
  82. class ShutdownMatch(GpmMatch):
  83.     
  84.     def __init__(self, backend, name = None, **args):
  85.         GpmMatch.__init__(self, backend, name)
  86.         self._icon = deskbar.Utils.load_icon(gtk.STOCK_QUIT)
  87.  
  88.     
  89.     def action(self, text = None):
  90.         
  91.         try:
  92.             self._gpm.Shutdown()
  93.         except dbus.DBusException:
  94.             pass
  95.  
  96.  
  97.     
  98.     def get_verb(self):
  99.         return _('Shutdown the machine')
  100.  
  101.  
  102.  
  103. class LockScreenMatch(deskbar.Match.Match):
  104.     
  105.     def __init__(self, backend, name = None, **args):
  106.         deskbar.Match.Match.__init__(self, backend, name = name, **args)
  107.         self._icon = deskbar.Utils.load_icon(gtk.STOCK_FULLSCREEN)
  108.         bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
  109.         obj = bus.get_object('org.gnome.ScreenSaver', '/org/gnome/ScreenSaver')
  110.         self._scrsvr = dbus.Interface(obj, 'org.gnome.ScreenSaver')
  111.  
  112.     
  113.     def action(self, text = None):
  114.         
  115.         try:
  116.             self._scrsvr.Lock()
  117.         except dbus.DBusException:
  118.             pass
  119.  
  120.  
  121.     
  122.     def get_category(self):
  123.         return 'actions'
  124.  
  125.     
  126.     def get_verb(self):
  127.         return _('Lock the screen')
  128.  
  129.  
  130.  
  131. class GdmMatch(deskbar.Match.Match):
  132.     
  133.     def __init__(self, backend, name, **args):
  134.         deskbar.Match.Match.__init__(self, backend, name = name, **args)
  135.         self.logout_reentrance = 0
  136.  
  137.     
  138.     def get_category(self):
  139.         return 'actions'
  140.  
  141.     
  142.     def request_logout(self):
  143.         if self.logout_reentrance == 0:
  144.             self.logout_reentrance += 1
  145.             client = gnome.ui.master_client()
  146.             if client:
  147.                 client.request_save(gnome.ui.SAVE_GLOBAL, True, gnome.ui.INTERACT_ANY, True, True)
  148.                 self.logout_reentrance -= 1
  149.             
  150.         
  151.  
  152.  
  153.  
  154. class GdmShutdownMatch(GdmMatch):
  155.     
  156.     def __init__(self, backend, **args):
  157.         GdmMatch.__init__(self, backend, _('Shut Down'), **args)
  158.  
  159.     
  160.     def action(self, text = None):
  161.         gdmclient.set_logout_action(gdmclient.LOGOUT_ACTION_SHUTDOWN)
  162.         self.request_logout()
  163.  
  164.     
  165.     def get_verb(self):
  166.         return _('Turn off the computer')
  167.  
  168.  
  169.  
  170. class GdmLogoutMatch(GdmMatch):
  171.     
  172.     def __init__(self, backend, **args):
  173.         GdmMatch.__init__(self, backend, _('Log Out'), **args)
  174.  
  175.     
  176.     def action(self, text = None):
  177.         gdmclient.set_logout_action(gdmclient.LOGOUT_ACTION_NONE)
  178.         self.request_logout()
  179.  
  180.     
  181.     def get_verb(self):
  182.         return _('Log out')
  183.  
  184.  
  185.  
  186. class GdmRebootMatch(GdmMatch):
  187.     
  188.     def __init__(self, backend, **args):
  189.         GdmMatch.__init__(self, backend, _('Restart'), **args)
  190.  
  191.     
  192.     def action(self, text = None):
  193.         gdmclient.set_logout_action(gdmclient.LOGOUT_ACTION_REBOOT)
  194.         self.request_logout()
  195.  
  196.     
  197.     def get_verb(self):
  198.         return _('Restart the computer')
  199.  
  200.  
  201.  
  202. class GdmSwitchUserMatch(GdmMatch):
  203.     
  204.     def __init__(self, backend, **args):
  205.         GdmMatch.__init__(self, backend, _('Switch User'), **args)
  206.  
  207.     
  208.     def action(self, text = None):
  209.         gdmclient.new_login()
  210.  
  211.     
  212.     def get_verb(self):
  213.         return _('Switch User')
  214.  
  215.  
  216.  
  217. class GdmHandler(deskbar.Handler.Handler):
  218.     
  219.     def __init__(self):
  220.         deskbar.Handler.Handler.__init__(self, 'gpm-suspend-to-ram.png')
  221.         self.indexer = deskbar.Indexer.Indexer()
  222.  
  223.     
  224.     def initialize(self):
  225.         for klass in (GdmShutdownMatch, GdmSwitchUserMatch, GdmRebootMatch, GdmLogoutMatch):
  226.             match = klass(self)
  227.             self.indexer.add(match.get_verb(), match)
  228.         
  229.         self.init_gpm_matches()
  230.         self.init_screensaver_matches()
  231.  
  232.     
  233.     def init_screensaver_matches(self):
  234.         
  235.         try:
  236.             bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
  237.             obj = bus.get_object('org.gnome.ScreenSaver', '/org/gnome/ScreenSaver')
  238.             scrsvr = dbus.Interface(obj, 'org.gnome.ScreenSaver')
  239.             self.indexer.add(_('Lock'), LockScreenMatch(self))
  240.             return True
  241.         except dbus.DBusException:
  242.             return False
  243.  
  244.  
  245.     
  246.     def init_gpm_matches(self):
  247.         
  248.         try:
  249.             bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
  250.             obj = bus.get_object('org.gnome.PowerManager', '/org/gnome/PowerManager')
  251.             gpm = dbus.Interface(obj, 'org.gnome.PowerManager')
  252.             if gpm.AllowedSuspend():
  253.                 self.indexer.add(_('Suspend'), SuspendMatch(self))
  254.             
  255.             if gpm.AllowedHibernate():
  256.                 self.indexer.add(_('Hibernate'), HibernateMatch(self))
  257.             
  258.             if gpm.AllowedShutdown():
  259.                 self.indexer.add(_('Shutdown'), ShutdownMatch(self))
  260.         except dbus.DBusException:
  261.             return False
  262.  
  263.  
  264.     
  265.     def query(self, query):
  266.         return self.indexer.look_up(query)
  267.  
  268.  
  269.