From 620acfaa5306e1a85f1e1730e8bdc0009b05796d Mon Sep 17 00:00:00 2001 From: Denis Fomin Date: Fri, 31 Dec 2010 13:28:14 +0300 Subject: [PATCH] GNOME SessionManager plugin --- gnome_session_manager/__init__.py | 1 + gnome_session_manager/manifest.ini | 7 +++ gnome_session_manager/plugin.py | 89 ++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 gnome_session_manager/__init__.py create mode 100644 gnome_session_manager/manifest.ini create mode 100644 gnome_session_manager/plugin.py diff --git a/gnome_session_manager/__init__.py b/gnome_session_manager/__init__.py new file mode 100644 index 0000000..4f4909c --- /dev/null +++ b/gnome_session_manager/__init__.py @@ -0,0 +1 @@ +from plugin import GnomeSessionManagerPlugin diff --git a/gnome_session_manager/manifest.ini b/gnome_session_manager/manifest.ini new file mode 100644 index 0000000..7f87975 --- /dev/null +++ b/gnome_session_manager/manifest.ini @@ -0,0 +1,7 @@ +[info] +name: GNOME SessionManager +short_name: gnome_session_manager +version: 0.1.1 +description: Set and react on GNOME Session presence settings +authors: Philippe Normand +homepage: http://base-art.net diff --git a/gnome_session_manager/plugin.py b/gnome_session_manager/plugin.py new file mode 100644 index 0000000..34f80e0 --- /dev/null +++ b/gnome_session_manager/plugin.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- + +## Copyright (C) 2010 Philippe Normand +## +## This file is part of Gajim. +## +## Gajim 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; version 3 only. +## +## Gajim 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 Gajim. If not, see . +## + +import dbus +from common import gajim +from common import ged +from common import dbus_support +import gui_interface +from plugins import GajimPlugin +from plugins.helpers import log_calls, log + +GNOME_STATUS = [u'online', u'invisible', u'dnd', u'idle'] +PRESENCE_INTERFACE = "org.gnome.SessionManager.Presence" + +class GnomeSessionManagerPlugin(GajimPlugin): + + @log_calls('GnomeSessionManagerPlugin') + def init(self): + self.config_dialog = None + self.events_handlers = {} + + @log_calls('GnomeSessionManagerPlugin') + def activate(self): + if not dbus_support.supported: + return + + self.bus = dbus_support.session_bus.SessionBus() + try: + self.session_presence = self.bus.get_object("org.gnome.SessionManager", + "/org/gnome/SessionManager/Presence") + except: + gajim.log.debug("GNOME SessionManager D-Bus service not found") + return + + self.active = True + gajim.ged.register_event_handler('our-show', ged.POSTGUI, + self.on_our_status) + self.bus.add_signal_receiver(self.gnome_presence_changed, + "StatusChanged", PRESENCE_INTERFACE) + + @log_calls('GnomeSessionManagerPlugin') + def deactivate(self): + if not dbus_support.supported or not self.active: + return + + self.active = False + self.bus.remove_signal_receiver(self.gnome_presence_changed, "StatusChanged", + dbus_interface=PRESENCE_INTERFACE) + ged.remove_event_handler('our-show', ged.POSTGUI, self.on_our_status) + + + def gnome_presence_changed(self, status, *args, **kw): + if not gajim.interface.remote_ctrl: + try: + import remote_control + gajim.interface.remote_ctrl = remote_control.Remote() + except: + return + remote_gajim = gajim.interface.remote_ctrl.signal_object + gajim_status = GNOME_STATUS[status] + accounts = remote_gajim.list_accounts() + for account in accounts: + message = remote_gajim.get_status_message(account) + remote_gajim.change_status(gajim_status, message, account) + + def on_our_status(self, network_event): + try: + gnome_status = GNOME_STATUS.index(network_event.show) + except ValueError: + print "GNOME SessionManager doesn't support %r status" % network_event.show + else: + self.session_presence.SetStatus(dbus.UInt32(gnome_status), + dbus_interface=PRESENCE_INTERFACE)