def __init__(self, event_type, jid, account, msg_type='', path_to_image=None, title=None, text=None): self.path_to_image = path_to_image self.event_type = event_type self.title = title self.text = text '''0.3.1 is the only version of notification daemon that has no way to determine which version it is. If no method exists, it means they're using that one.''' self.default_version = [0, 3, 1] self.account = account self.jid = jid self.msg_type = msg_type # default value of text if not text and event_type == 'new_message': # empty text for new_message means do_preview = False self.text = gajim.get_name_from_jid(account, jid) if not title: self.title = event_type # default value if event_type == _('Contact Signed In'): ntype = 'presence.online' elif event_type == _('Contact Signed Out'): ntype = 'presence.offline' elif event_type in (_('New Message'), _('New Single Message'), _('New Private Message')): ntype = 'im.received' elif event_type == _('File Transfer Request'): ntype = 'transfer' elif event_type == _('File Transfer Error'): ntype = 'transfer.error' elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')): ntype = 'transfer.complete' elif event_type == _('New E-mail'): ntype = 'email.arrived' elif event_type == _('Groupchat Invitation'): ntype = 'im.invitation' elif event_type == _('Contact Changed Status'): ntype = 'presence.status' elif event_type == _('Connection Failed'): ntype = 'connection.failed' else: # default failsafe values self.path_to_image = os.path.abspath( os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'chat_msg_recv.png')) # img to display ntype = 'im' # Notification Type self.notif = dbus_support.get_notifications_interface() if self.notif is None: raise dbus.DBusException('unable to get notifications interface') self.ntype = ntype self.get_version()
def notify(event_type, jid, account, msg_type, path_to_image, title, text): global notifications if not event_type in notifications: event_type = GENERIC_NOTIF if not text: text = gajim.get_name_from_jid(account, jid) # default value of text text = filterString(text) if not title: title = event_type title = filterString(title) 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 icon = open(path_to_image, "r") context = [account, jid, msg_type] growler.notify(event_type, title, text, icon.read(), False, None, context) return
def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None, text=None, timeout=-1): """ Notify a user of an event. It first tries to a valid implementation of the Desktop Notification Specification. If that fails, then we fall back to the older style PopupNotificationWindow method """ # default image if not path_to_image: path_to_image = gtkgui_helpers.get_icon_path('gajim-chat_msg_recv', 48) if timeout < 0: timeout = gajim.config.get('notification_timeout') # Try to show our popup via D-Bus and notification daemon if gajim.config.get('use_notif_daemon') and dbus_support.supported: try: DesktopNotification(event_type, jid, account, msg_type, path_to_image, title, GLib.markup_escape_text(text), timeout) return # sucessfully did D-Bus Notification procedure! except dbus.DBusException as e: # Connection to D-Bus failed gajim.log.debug(str(e)) except TypeError as e: # This means that we sent the message incorrectly gajim.log.debug(str(e)) # Ok, that failed. Let's try pynotify, which also uses notification daemon if gajim.config.get('use_notif_daemon') and USER_HAS_PYNOTIFY: if not text and event_type == 'new_message': # empty text for new_message means do_preview = False # -> default value for text _text = GLib.markup_escape_text(gajim.get_name_from_jid(account, jid)) else: _text = GLib.markup_escape_text(text) if not title: _title = '' else: _title = title notification = Notify.Notification(_title, _text) notification.set_timeout(timeout*1000) 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', msg_type) notification.set_property('icon-name', path_to_image) if 'actions' in Notify.get_server_caps(): notification.add_action('default', 'Default Action', on_pynotify_notification_clicked) try: notification.show() return except GObject.GError as e: # Connection to notification-daemon failed, see #2893 gajim.log.debug(str(e)) # Either nothing succeeded or the user wants old-style notifications instance = PopupNotificationWindow(event_type, jid, account, msg_type, path_to_image, title, text, timeout) gajim.interface.roster.popup_notification_windows.append(instance)
def __init__(self, event_type, jid, account, msg_type='', path_to_image=None, title=None, text=None, timeout=-1): self.path_to_image = os.path.abspath(path_to_image) self.event_type = event_type self.title = title self.text = text self.timeout = timeout # 0.3.1 is the only version of notification daemon that has no way # to determine which version it is. If no method exists, it means # they're using that one. self.default_version = [0, 3, 1] self.account = account self.jid = jid self.msg_type = msg_type # default value of text if not text and event_type == 'new_message': # empty text for new_message means do_preview = False self.text = gajim.get_name_from_jid(account, jid) if not title: self.title = event_type # default value if event_type == _('Contact Signed In'): ntype = 'presence.online' elif event_type == _('Contact Signed Out'): ntype = 'presence.offline' elif event_type in (_('New Message'), _('New Single Message'), _('New Private Message')): ntype = 'im.received' elif event_type == _('File Transfer Request'): ntype = 'transfer' elif event_type == _('File Transfer Error'): ntype = 'transfer.error' elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')): ntype = 'transfer.complete' elif event_type == _('New E-mail'): ntype = 'email.arrived' elif event_type == _('Groupchat Invitation'): ntype = 'im.invitation' elif event_type == _('Contact Changed Status'): ntype = 'presence.status' elif event_type == _('Connection Failed'): ntype = 'connection.failed' elif event_type == _('Subscription request'): ntype = 'subscription.request' elif event_type == _('Unsubscribed'): ntype = 'unsubscribed' else: # default failsafe values self.path_to_image = gtkgui_helpers.get_icon_path( 'gajim-chat_msg_recv', 48) ntype = 'im' # Notification Type self.notif = dbus_support.get_notifications_interface(self) if self.notif is None: raise dbus.DBusException('unable to get notifications interface') self.ntype = ntype if self.kde_notifications: self.attempt_notify() else: self.capabilities = self.notif.GetCapabilities() if self.capabilities is None: self.capabilities = ['actions'] self.get_version()
def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None, text=None, timeout=-1): """ Notify a user of an event. It first tries to a valid implementation of the Desktop Notification Specification. If that fails, then we fall back to the older style PopupNotificationWindow method """ # default image if not path_to_image: path_to_image = gtkgui_helpers.get_icon_path('gajim-chat_msg_recv', 48) if timeout < 0: timeout = gajim.config.get('notification_timeout') # Try to show our popup via D-Bus and notification daemon if gajim.config.get('use_notif_daemon') and dbus_support.supported: try: DesktopNotification(event_type, jid, account, msg_type, path_to_image, title, GLib.markup_escape_text(text), timeout) return # sucessfully did D-Bus Notification procedure! except dbus.DBusException as e: # Connection to D-Bus failed gajim.log.debug(str(e)) except TypeError as e: # This means that we sent the message incorrectly gajim.log.debug(str(e)) # Ok, that failed. Let's try pynotify, which also uses notification daemon if gajim.config.get('use_notif_daemon') and USER_HAS_PYNOTIFY: if not text and event_type == 'new_message': # empty text for new_message means do_preview = False # -> default value for text _text = GLib.markup_escape_text( gajim.get_name_from_jid(account, jid)) else: _text = GLib.markup_escape_text(text) if not title: _title = '' else: _title = title notification = Notify.Notification.new(_title, _text) notification.set_timeout(timeout * 1000) notification.set_category(event_type) notification._data = {} notification._data["event_type"] = event_type notification._data["jid"] = jid notification._data["account"] = account notification._data["msg_type"] = msg_type notification.set_property('icon-name', path_to_image) if 'actions' in Notify.get_server_caps(): notification.add_action('default', 'Default Action', on_pynotify_notification_clicked) try: notification.show() return except GObject.GError as e: # Connection to notification-daemon failed, see #2893 gajim.log.debug(str(e)) # Either nothing succeeded or the user wants old-style notifications instance = PopupNotificationWindow(event_type, jid, account, msg_type, path_to_image, title, text, timeout) gajim.interface.roster.popup_notification_windows.append(instance)
class ChatControlSession(stanza_session.EncryptedStanzaSession): def __init__(self, conn, jid, thread_id, type_='chat'): stanza_session.EncryptedStanzaSession.__init__(self, conn, jid, thread_id, type_='chat') self.control = None def acknowledge_termination(self): if self.control: self.control.set_session(None) stanza_session.EncryptedStanzaSession.acknowledge_termination(self) def terminate(self): stanza_session.EncryptedStanzaSession.terminate(self) if self.control: self.control.set_session(None) # extracts chatstate from a <message/> stanza def get_chatstate(self, msg, msgtxt): composing_xep = None chatstate = None # chatstates - look for chatstate tags in a message if not delayed delayed = msg.getTag('x', namespace=common.xmpp.NS_DELAY) is not None if not delayed: composing_xep = False children = msg.getChildren() for child in children: if child.getNamespace( ) == 'http://jabber.org/protocol/chatstates': chatstate = child.getName() composing_xep = 'XEP-0085' break # No XEP-0085 support, fallback to XEP-0022 if not chatstate: chatstate_child = msg.getTag('x', namespace=common.xmpp.NS_EVENT) if chatstate_child: chatstate = 'active' composing_xep = 'XEP-0022' if not msgtxt and chatstate_child.getTag('composing'): chatstate = 'composing' return (composing_xep, chatstate) # dispatch a received <message> stanza def received(self, full_jid_with_resource, msgtxt, tim, encrypted, msg): msg_type = msg.getType() subject = msg.getSubject() if not msg_type or msg_type not in ('chat', 'groupchat', 'error'): msg_type = 'normal' msg_id = None # XEP-0172 User Nickname user_nick = msg.getTagData('nick') if not user_nick: user_nick = '' form_node = None for xtag in msg.getTags('x'): if xtag.getNamespace() == common.xmpp.NS_DATA: form_node = xtag break composing_xep, chatstate = self.get_chatstate(msg, msgtxt) xhtml = msg.getXHTML() if msg_type == 'chat': if not msg.getTag('body') and chatstate is None: return log_type = 'chat_msg_recv' else: log_type = 'single_msg_recv' if self.is_loggable() and msgtxt: try: msg_id = gajim.logger.write(log_type, full_jid_with_resource, msgtxt, tim=tim, subject=subject) except exceptions.PysqliteOperationalError, e: self.conn.dispatch('ERROR', (_('Disk WriteError'), str(e))) treat_as = gajim.config.get('treat_incoming_messages') if treat_as: msg_type = treat_as jid = gajim.get_jid_without_resource(full_jid_with_resource) resource = gajim.get_resource_from_jid(full_jid_with_resource) if gajim.config.get('ignore_incoming_xhtml'): xhtml = None if gajim.jid_is_transport(jid): jid = jid.replace('@', '') groupchat_control = gajim.interface.msg_win_mgr.get_gc_control( jid, self.conn.name) if not groupchat_control and \ jid in gajim.interface.minimized_controls[self.conn.name]: groupchat_control = gajim.interface.minimized_controls[self.conn.name]\ [jid] pm = False if groupchat_control and groupchat_control.type_id == \ message_control.TYPE_GC: # It's a Private message pm = True msg_type = 'pm' highest_contact = gajim.contacts.get_contact_with_highest_priority( self.conn.name, jid) # does this resource have the highest priority of any available? is_highest = not highest_contact or not highest_contact.resource or \ resource == highest_contact.resource or highest_contact.show == \ 'offline' # Handle chat states contact = gajim.contacts.get_contact(self.conn.name, jid, resource) if contact: if contact.composing_xep != 'XEP-0085': # We cache xep85 support contact.composing_xep = composing_xep if self.control and self.control.type_id == message_control.TYPE_CHAT: if chatstate is not None: # other peer sent us reply, so he supports jep85 or jep22 contact.chatstate = chatstate if contact.our_chatstate == 'ask': # we were jep85 disco? contact.our_chatstate = 'active' # no more self.control.handle_incoming_chatstate() elif contact.chatstate != 'active': # got no valid jep85 answer, peer does not support it contact.chatstate = False elif chatstate == 'active': # Brand new message, incoming. contact.our_chatstate = chatstate contact.chatstate = chatstate if msg_id: # Do not overwrite an existing msg_id with None contact.msg_id = msg_id # THIS MUST BE AFTER chatstates handling # AND BEFORE playsound (else we ear sounding on chatstates!) if not msgtxt: # empty message text return if gajim.config.get('ignore_unknown_contacts') and \ not gajim.contacts.get_contacts(self.conn.name, jid) and not pm: return if not contact: # contact is not in the roster, create a fake one to display # notification contact = contacts.Contact(jid=jid, resource=resource) advanced_notif_num = notify.get_advanced_notification( 'message_received', self.conn.name, contact) if not pm and is_highest: jid_of_control = jid else: jid_of_control = full_jid_with_resource if not self.control: ctrl = gajim.interface.msg_win_mgr.get_control( jid_of_control, self.conn.name) if ctrl: self.control = ctrl self.control.set_session(self) # Is it a first or next message received ? first = False if not self.control and not gajim.events.get_events(self.conn.name, \ jid_of_control, [msg_type]): first = True if pm: nickname = resource if self.control: # print if a control is open self.control.print_conversation(msgtxt, tim=tim, xhtml=xhtml, encrypted=encrypted) else: # otherwise pass it off to the control to be queued groupchat_control.on_private_message(nickname, msgtxt, tim, xhtml, self, msg_id=msg_id, encrypted=encrypted) else: self.roster_message(jid, msgtxt, tim, encrypted, msg_type, subject, resource, msg_id, user_nick, advanced_notif_num, xhtml=xhtml, form_node=form_node) nickname = gajim.get_name_from_jid(self.conn.name, jid) # Check and do wanted notifications msg = msgtxt if subject: msg = _('Subject: %s') % subject + '\n' + msg focused = False if self.control: parent_win = self.control.parent_win if self.control == parent_win.get_active_control() and \ parent_win.window.has_focus: focused = True notify.notify('new_message', jid_of_control, self.conn.name, [msg_type, first, nickname, msg, focused], advanced_notif_num) if gajim.interface.remote_ctrl: gajim.interface.remote_ctrl.raise_signal( 'NewMessage', (self.conn.name, [ full_jid_with_resource, msgtxt, tim, encrypted, msg_type, subject, chatstate, msg_id, composing_xep, user_nick, xhtml, form_node ]))
def notify(event, jid, account, parameters, advanced_notif_num=None): '''Check what type of notifications we want, depending on basic and the advanced configuration of notifications and do these notifications; advanced_notif_num holds the number of the first (top most) advanced notification''' # First, find what notifications we want do_popup = False do_sound = False do_cmd = False if event == 'status_change': new_show = parameters[0] status_message = parameters[1] # Default: No popup for status change elif event == 'contact_connected': status_message = parameters j = gajim.get_jid_without_resource(jid) server = gajim.get_server_from_jid(j) account_server = account + '/' + server block_transport = False if account_server in gajim.block_signed_in_notifications and \ gajim.block_signed_in_notifications[account_server]: block_transport = True if helpers.allow_showing_notification(account, 'notify_on_signin') and \ not gajim.block_signed_in_notifications[account] and not block_transport: do_popup = True if gajim.config.get_per('soundevents', 'contact_connected', 'enabled') and not gajim.block_signed_in_notifications[account] and \ not block_transport: do_sound = True elif event == 'contact_disconnected': status_message = parameters if helpers.allow_showing_notification(account, 'notify_on_signout'): do_popup = True if gajim.config.get_per('soundevents', 'contact_disconnected', 'enabled'): do_sound = True elif event == 'new_message': message_type = parameters[0] is_first_message = parameters[1] nickname = parameters[2] if gajim.config.get('notification_preview_message'): message = parameters[3] if message.startswith('/me ') or message.startswith('/me\n'): message = '* ' + nickname + message[3:] else: # We don't want message preview, do_preview = False message = '' focused = parameters[4] if helpers.allow_showing_notification(account, 'notify_on_new_message', advanced_notif_num, is_first_message): do_popup = True if is_first_message and helpers.allow_sound_notification( 'first_message_received', advanced_notif_num): do_sound = True elif not is_first_message and focused and \ helpers.allow_sound_notification('next_message_received_focused', advanced_notif_num): do_sound = True elif not is_first_message and not focused and \ helpers.allow_sound_notification('next_message_received_unfocused', advanced_notif_num): do_sound = True else: print '*Event not implemeted yet*' if advanced_notif_num is not None and gajim.config.get_per('notifications', str(advanced_notif_num), 'run_command'): do_cmd = True # Do the wanted notifications if do_popup: if event in ('contact_connected', 'contact_disconnected', 'status_change'): # Common code for popup for these three events if event == 'contact_disconnected': show_image = 'offline.png' suffix = '_notif_size_bw' else: #Status Change or Connected # FIXME: for status change, # we don't always 'online.png', but we # first need 48x48 for all status show_image = 'online.png' suffix = '_notif_size_colored' transport_name = gajim.get_transport_name_from_jid(jid) img = None if transport_name: img = os.path.join(helpers.get_transport_path(transport_name), '48x48', show_image) if not img or not os.path.isfile(img): iconset = gajim.config.get('iconset') img = os.path.join(helpers.get_iconset_path(iconset), '48x48', show_image) path = gtkgui_helpers.get_path_to_generic_or_avatar(img, jid = jid, suffix = suffix) if event == 'status_change': title = _('%(nick)s Changed Status') % \ {'nick': gajim.get_name_from_jid(account, jid)} text = _('%(nick)s is now %(status)s') % \ {'nick': gajim.get_name_from_jid(account, jid),\ 'status': helpers.get_uf_show(gajim.SHOW_LIST[new_show])} if status_message: text = text + " : " + status_message popup(_('Contact Changed Status'), jid, account, path_to_image=path, title=title, text=text) elif event == 'contact_connected': title = _('%(nickname)s Signed In') % \ {'nickname': gajim.get_name_from_jid(account, jid)} text = '' if status_message: text = status_message popup(_('Contact Signed In'), jid, account, path_to_image=path, title=title, text=text) elif event == 'contact_disconnected': title = _('%(nickname)s Signed Out') % \ {'nickname': gajim.get_name_from_jid(account, jid)} text = '' if status_message: text = status_message popup(_('Contact Signed Out'), jid, account, path_to_image=path, title=title, text=text) elif event == 'new_message': if message_type == 'normal': # single message event_type = _('New Single Message') img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'single_msg_recv.png') title = _('New Single Message from %(nickname)s') % \ {'nickname': nickname} text = message elif message_type == 'pm': # private message event_type = _('New Private Message') room_name = gajim.get_nick_from_jid(jid) img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'priv_msg_recv.png') title = _('New Private Message from group chat %s') % room_name if message: text = _('%(nickname)s: %(message)s') % {'nickname': nickname, 'message': message} else: text = _('Messaged by %(nickname)s') % {'nickname': nickname} else: # chat message event_type = _('New Message') img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'chat_msg_recv.png') title = _('New Message from %(nickname)s') % \ {'nickname': nickname} text = message path = gtkgui_helpers.get_path_to_generic_or_avatar(img) popup(event_type, jid, account, message_type, path_to_image=path, title=title, text=text) if do_sound: snd_file = None snd_event = None # If not snd_file, play the event if event == 'new_message': if advanced_notif_num is not None and gajim.config.get_per( 'notifications', str(advanced_notif_num), 'sound') == 'yes': snd_file = gajim.config.get_per('notifications', str(advanced_notif_num), 'sound_file') elif advanced_notif_num is not None and gajim.config.get_per( 'notifications', str(advanced_notif_num), 'sound') == 'no': pass # do not set snd_event elif is_first_message: snd_event = 'first_message_received' elif focused: snd_event = 'next_message_received_focused' else: snd_event = 'next_message_received_unfocused' elif event in ('contact_connected', 'contact_disconnected'): snd_event = event if snd_file: helpers.play_sound_file(snd_file) if snd_event: helpers.play_sound(snd_event) if do_cmd: command = gajim.config.get_per('notifications', str(advanced_notif_num), 'command') try: helpers.exec_command(command) except Exception: pass
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 # sucessfully did D-Bus Notification procedure! except dbus.DBusException, e: # 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)) # we failed to speak to notification daemon via D-Bus if USER_HAS_PYNOTIFY: # try via libnotify if not text and event_type == 'new_message': # empty text for new_message means do_preview = False 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)
path_to_image, title, gobject.markup_escape_text(text), timeout) return # sucessfully did D-Bus Notification procedure! except dbus.DBusException, e: # 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)) # Ok, that failed. Let's try pynotify, which also uses notification daemon if gajim.config.get('use_notif_daemon') and USER_HAS_PYNOTIFY: if not text and event_type == 'new_message': # empty text for new_message means do_preview = False # -> default value for text _text = gobject.markup_escape_text( gajim.get_name_from_jid(account, jid)) else: _text = gobject.markup_escape_text(text) if not title: _title = '' else: _title = title notification = pynotify.Notification(_title, _text) notification.set_timeout(timeout*1000) notification.set_category(event_type) notification.set_data('event_type', event_type) notification.set_data('jid', jid) notification.set_data('account', account)
def notify(event, jid, account, parameters, advanced_notif_num=None): '''Check what type of notifications we want, depending on basic and the advanced configuration of notifications and do these notifications; advanced_notif_num holds the number of the first (top most) advanced notification''' # First, find what notifications we want do_popup = False do_sound = False do_cmd = False if event == 'status_change': new_show = parameters[0] status_message = parameters[1] # Default: No popup for status change elif event == 'contact_connected': status_message = parameters j = gajim.get_jid_without_resource(jid) server = gajim.get_server_from_jid(j) account_server = account + '/' + server block_transport = False if account_server in gajim.block_signed_in_notifications and \ gajim.block_signed_in_notifications[account_server]: block_transport = True if helpers.allow_showing_notification(account, 'notify_on_signin') and \ not gajim.block_signed_in_notifications[account] and not block_transport: do_popup = True if gajim.config.get_per('soundevents', 'contact_connected', 'enabled') and not gajim.block_signed_in_notifications[account] and \ not block_transport: do_sound = True elif event == 'contact_disconnected': status_message = parameters if helpers.allow_showing_notification(account, 'notify_on_signout'): do_popup = True if gajim.config.get_per('soundevents', 'contact_disconnected', 'enabled'): do_sound = True elif event == 'new_message': message_type = parameters[0] is_first_message = parameters[1] nickname = parameters[2] if gajim.config.get('notification_preview_message'): message = parameters[3] if message.startswith('/me ') or message.startswith('/me\n'): message = '* ' + nickname + message[3:] else: # We don't want message preview, do_preview = False message = '' focused = parameters[4] if helpers.allow_showing_notification(account, 'notify_on_new_message', advanced_notif_num, is_first_message): do_popup = True if is_first_message and helpers.allow_sound_notification( 'first_message_received', advanced_notif_num): do_sound = True elif not is_first_message and focused and \ helpers.allow_sound_notification('next_message_received_focused', advanced_notif_num): do_sound = True elif not is_first_message and not focused and \ helpers.allow_sound_notification('next_message_received_unfocused', advanced_notif_num): do_sound = True else: print '*Event not implemeted yet*' if advanced_notif_num is not None and gajim.config.get_per( 'notifications', str(advanced_notif_num), 'run_command'): do_cmd = True # Do the wanted notifications if do_popup: if event in ('contact_connected', 'contact_disconnected', 'status_change' ): # Common code for popup for these three events if event == 'contact_disconnected': show_image = 'offline.png' suffix = '_notif_size_bw' else: #Status Change or Connected # FIXME: for status change, # we don't always 'online.png', but we # first need 48x48 for all status show_image = 'online.png' suffix = '_notif_size_colored' transport_name = gajim.get_transport_name_from_jid(jid) img = None if transport_name: img = os.path.join(helpers.get_transport_path(transport_name), '48x48', show_image) if not img or not os.path.isfile(img): iconset = gajim.config.get('iconset') img = os.path.join(helpers.get_iconset_path(iconset), '48x48', show_image) path = gtkgui_helpers.get_path_to_generic_or_avatar(img, jid=jid, suffix=suffix) if event == 'status_change': title = _('%(nick)s Changed Status') % \ {'nick': gajim.get_name_from_jid(account, jid)} text = _('%(nick)s is now %(status)s') % \ {'nick': gajim.get_name_from_jid(account, jid),\ 'status': helpers.get_uf_show(gajim.SHOW_LIST[new_show])} if status_message: text = text + " : " + status_message popup(_('Contact Changed Status'), jid, account, path_to_image=path, title=title, text=text) elif event == 'contact_connected': title = _('%(nickname)s Signed In') % \ {'nickname': gajim.get_name_from_jid(account, jid)} text = '' if status_message: text = status_message popup(_('Contact Signed In'), jid, account, path_to_image=path, title=title, text=text) elif event == 'contact_disconnected': title = _('%(nickname)s Signed Out') % \ {'nickname': gajim.get_name_from_jid(account, jid)} text = '' if status_message: text = status_message popup(_('Contact Signed Out'), jid, account, path_to_image=path, title=title, text=text) elif event == 'new_message': if message_type == 'normal': # single message event_type = _('New Single Message') img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'single_msg_recv.png') title = _('New Single Message from %(nickname)s') % \ {'nickname': nickname} text = message elif message_type == 'pm': # private message event_type = _('New Private Message') room_name = gajim.get_nick_from_jid(jid) img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'priv_msg_recv.png') title = _('New Private Message from group chat %s') % room_name if message: text = _('%(nickname)s: %(message)s') % { 'nickname': nickname, 'message': message } else: text = _('Messaged by %(nickname)s') % { 'nickname': nickname } else: # chat message event_type = _('New Message') img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'chat_msg_recv.png') title = _('New Message from %(nickname)s') % \ {'nickname': nickname} text = message path = gtkgui_helpers.get_path_to_generic_or_avatar(img) popup(event_type, jid, account, message_type, path_to_image=path, title=title, text=text) if do_sound: snd_file = None snd_event = None # If not snd_file, play the event if event == 'new_message': if advanced_notif_num is not None and gajim.config.get_per( 'notifications', str(advanced_notif_num), 'sound') == 'yes': snd_file = gajim.config.get_per('notifications', str(advanced_notif_num), 'sound_file') elif advanced_notif_num is not None and gajim.config.get_per( 'notifications', str(advanced_notif_num), 'sound') == 'no': pass # do not set snd_event elif is_first_message: snd_event = 'first_message_received' elif focused: snd_event = 'next_message_received_focused' else: snd_event = 'next_message_received_unfocused' elif event in ('contact_connected', 'contact_disconnected'): snd_event = event if snd_file: helpers.play_sound_file(snd_file) if snd_event: helpers.play_sound(snd_event) if do_cmd: command = gajim.config.get_per('notifications', str(advanced_notif_num), 'command') try: helpers.exec_command(command) except Exception: pass
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 # sucessfully did D-Bus Notification procedure! except dbus.DBusException, e: # 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)) # we failed to speak to notification daemon via D-Bus if USER_HAS_PYNOTIFY: # try via libnotify if not text and event_type == 'new_message': # empty text for new_message means do_preview = False 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)