From e0f0871ea667e27fa49b5224b4b5419e215f6a4e Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sat, 4 Apr 2009 05:06:46 +0000 Subject: [PATCH] [ken.vandine] add indicator support. Fixes #4942 --- src/common/gajim.py | 6 ++++++ src/gajim.py | 4 ++++ src/notify.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/common/gajim.py b/src/common/gajim.py index d29ca4873..06e9e37ff 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -182,6 +182,12 @@ else: import latex HAVE_LATEX = latex.check_for_latex_support() +HAVE_INDICATOR = True +try: + import indicate +except ImportError: + HAVE_INDICATOR = False + gajim_identity = {'type': 'pc', 'category': 'client', 'name': 'Gajim'} gajim_common_features = [xmpp.NS_BYTESTREAM, xmpp.NS_SI, xmpp.NS_FILE, xmpp.NS_MUC, xmpp.NS_MUC_USER, xmpp.NS_MUC_ADMIN, xmpp.NS_MUC_OWNER, diff --git a/src/gajim.py b/src/gajim.py index 3abdd3819..ff75320ec 100644 --- a/src/gajim.py +++ b/src/gajim.py @@ -3448,6 +3448,10 @@ class Interface: if resolver.USE_LIBASYNCNS: gobject.timeout_add(200, gajim.resolver.process) + # setup the indicator + if gajim.HAVE_INDICATOR: + notify.setup_indicator_server() + def remote_init(): if gajim.config.get('remote_control'): try: diff --git a/src/notify.py b/src/notify.py index 117a0601f..548e33ad6 100644 --- a/src/notify.py +++ b/src/notify.py @@ -32,6 +32,7 @@ import time import dialogs import gobject import gtkgui_helpers +import gtk from common import gajim from common import helpers @@ -56,6 +57,21 @@ try: except Exception: USER_HAS_GROWL = False +def setup_indicator_server(): + server = indicate.indicate_server_ref_default() + server.set_type('message.im') + server.set_desktop_file('/usr/share/applications/gajim.desktop') + server.connect('server-display', server_display) + server.show() + +def display(indicator, account, jid, msg_type): + gajim.interface.handle_event(account, jid, msg_type) + indicator.hide() + +def server_display(server): + win = gajim.interface.roster.window + win.present() + def get_show_in_roster(event, account, contact, session=None): '''Return True if this event must be shown in roster, else False''' if event == 'gc_message_received': @@ -327,6 +343,18 @@ def popup(event_type, jid, account, msg_type='', path_to_image=None, os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'chat_msg_recv.png')) # img to display + if gajim.HAVE_INDICATOR and event_type in (_('New Message'), + _('New Single Message'), _('New Private Message')): + indicator = indicate.IndicatorMessage() + indicator.set_property('subtype', 'im') + indicator.set_property('sender', jid) + indicator.set_property('body', text) + indicator.set_property_time('time', time.time()) + pixbuf = gtk.gdk.pixbuf_new_from_file(path_to_image) + indicator.set_property_icon('icon', pixbuf) + indicator.connect('user-display', display, account, jid, msg_type) + indicator.show() + # Try Growl first, as we might have D-Bus and notification daemon running # on OS X for some reason. if USER_HAS_GROWL: