From 11cd6d152c1486578d11ecc8977ded89c0cf679c Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Thu, 28 Sep 2006 00:31:59 +0000 Subject: [PATCH] Support for notify-python so if notification-daemon is not available, we still can show cool popups. FIXES #1901 --- Changelog | 5 ++--- README | 2 +- src/dialogs.py | 5 +++-- src/notify.py | 61 +++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/Changelog b/Changelog index f21490300..86b28f39e 100644 --- a/Changelog +++ b/Changelog @@ -1,7 +1,6 @@ Gajim 0.11 (XX October 2006) - * Put your stuff here [each dev put their own please; next time we do this everytime we commit sth major and not in the end] - + * Support for notify-python so if notification-daemon is not available, we still can show cool popups * We can now operate on more than one contact in one in time in roster (#1514) * Connection lost is now a non-intrusive popup * Try to get contact desired nick when we add him to roster aka User Nickname (JEP-0172) @@ -14,7 +13,7 @@ Gajim 0.11 (XX October 2006) * We can save avatar with right click on avatar in chat banner * Use differents colors for nickname colors of occupants in groupchats. * Ability to show only Join/Leave in groupchats instead of all status changes - * New possibilities to insert nickname of an occupant in groupchats conversations : Tab in an empty line now cycle through nicks, maj+right click->insert nickname, maj+click on name in gc-roster, /names command to show all users presents + * New possibilities to insert nickname of an occupant in groupchats conversations: Tab in an empty line now cycle through nicks, maj+right click->insert nickname, maj+click on name in gc-roster, /names command to show all users presents * Fixed bugs when removing or renaming an account with tabs open (#2369 and #2370) diff --git a/README b/README index 5e2ad7468..49fdbefff 100644 --- a/README +++ b/README @@ -25,7 +25,7 @@ Optionally: dnsutils (or whatever package provides the nslookup binary) for SRV support; if you don't know what that is, you don't need it gtkspell and aspell-LANG where lang is your locale eg. en, fr etc GnomePythonExtras 2.10 or above so you can avoid compiling trayicon and gtkspell -notification-daemon (and D-Bus) to get cooler popups +notification-daemon or notify-python (and D-Bus) to get cooler popups D-Bus to have gajim-remote working NOTE TO PACKAGERS: diff --git a/src/dialogs.py b/src/dialogs.py index 01d220afc..0f0f13266 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -1306,7 +1306,8 @@ class PopupNotificationWindow: # default image if not path_to_image: path_to_image = os.path.abspath( - os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'chat_msg_recv.png')) # img to display + os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', + 'chat_msg_recv.png')) # img to display if event_type == _('Contact Signed In'): bg_color = 'limegreen' @@ -1326,7 +1327,7 @@ class PopupNotificationWindow: bg_color = 'tan1' elif event_type == _('Contact Changed Status'): bg_color = 'thistle2' - else: # Unknown event ! Shouldn't happen but deal with it + else: # Unknown event! Shouldn't happen but deal with it bg_color = 'white' popup_bg_color = gtk.gdk.color_parse(bg_color) close_button.modify_bg(gtk.STATE_NORMAL, popup_bg_color) diff --git a/src/notify.py b/src/notify.py index d6d9e8303..0169dd2b7 100644 --- a/src/notify.py +++ b/src/notify.py @@ -31,6 +31,14 @@ if dbus_support.supported: import dbus.glib import dbus.service + +USER_HAS_PYNOTIFY = True # user has pynotify module +try: + import pynotify + pynotify.init('Gajim Notification') +except ImportError: + USER_HAS_PYNOTIFY = False + def get_show_in_roster(event, account, contact): '''Return True if this event must be shown in roster, else False''' num = get_advanced_notification(event, account, contact) @@ -271,20 +279,61 @@ def popup(event_type, jid, account, msg_type = '', path_to_image = None, the older style PopupNotificationWindow method.''' text = gtkgui_helpers.escape_for_pango_markup(text) title = gtkgui_helpers.escape_for_pango_markup(title) + if gajim.config.get('use_notif_daemon') and dbus_support.supported: try: DesktopNotification(event_type, jid, account, msg_type, path_to_image, title, text) - return + return # sucessfully did D-Bus Notification procedure! except dbus.dbus_bindings.DBusException, e: - # Connection to D-Bus failed, try popup + # Connection to D-Bus failed gajim.log.debug(str(e)) except TypeError, e: # This means that we sent the message incorrectly gajim.log.debug(str(e)) - instance = dialogs.PopupNotificationWindow(event_type, jid, account, - msg_type, path_to_image, title, text) - gajim.interface.roster.popup_notification_windows.append(instance) + # we failed to speak to notification daemon via D-Bus + if USER_HAS_PYNOTIFY: # try via libnotify + if not text: + text = gajim.get_name_from_jid(account, jid) # default value of text + if not title: + title = event_type + # default image + if not path_to_image: + path_to_image = os.path.abspath( + os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', + 'chat_msg_recv.png')) # img to display + + + notification = pynotify.Notification(title, text) + timeout = gajim.config.get('notification_timeout') * 1000 # make it ms + notification.set_timeout(timeout) + + notification.set_category(event_type) + notification.set_data('event_type', event_type) + notification.set_data('jid', jid) + notification.set_data('account', account) + notification.set_data('msg_type', event_type) + notification.set_data('path_to_image', path_to_image) + notification.add_action('default', 'Default Action', + on_pynotify_notification_clicked) + + notification.show() + + else: # go old style + instance = dialogs.PopupNotificationWindow(event_type, jid, + account, msg_type, path_to_image, title, text) + gajim.interface.roster.popup_notification_windows.append( + instance) + +def on_pynotify_notification_clicked(notification, action): + event_type = notification.get_data('event_type') + jid = notification.get_data('jid') + account = notification.get_data('account') + msg_type = notification.get_data('msg_type') + path_to_image = notification.get_data('path_to_image') + + notification.close() + gajim.interface.handle_event(account, jid, msg_type) class NotificationResponseManager: '''Collects references to pending DesktopNotifications and manages there @@ -337,7 +386,7 @@ class NotificationResponseManager: notification_response_manager = NotificationResponseManager() class DesktopNotification: - '''A DesktopNotification that interfaces with DBus via the Desktop + '''A DesktopNotification that interfaces with D-Bus via the Desktop Notification specification''' def __init__(self, event_type, jid, account, msg_type = '', path_to_image = None, title = None, text = None):