#1005 preparation : Begin to move notifications to notify.py :
-moved popup and sound for contact in/out -added popup for status change (always disable for the moment, will be advanced only) Note : removed "if not gajim.awaiting_events[account].has_key(jid)" from condition for an in/out popup to be showed
This commit is contained in:
parent
7a8cdad04c
commit
af3500a225
|
@ -1114,6 +1114,8 @@ class PopupNotificationWindow:
|
|||
bg_color = 'yellowgreen'
|
||||
elif event_type == _('Groupchat Invitation'):
|
||||
bg_color = 'tan1'
|
||||
elif event_type == _('Contact Changed status'):
|
||||
bg_color = 'thistle2'
|
||||
else: # Unknown event ! Shouldn't happen but deal with it
|
||||
bg_color = 'white'
|
||||
popup_bg_color = gtk.gdk.color_parse(bg_color)
|
||||
|
|
73
src/gajim.py
73
src/gajim.py
|
@ -416,67 +416,18 @@ class Interface:
|
|||
account)
|
||||
# play sound
|
||||
if old_show < 2 and new_show > 1:
|
||||
if gajim.config.get_per('soundevents', 'contact_connected',
|
||||
'enabled') and not gajim.block_signed_in_notifications[account]:
|
||||
helpers.play_sound('contact_connected')
|
||||
if not gajim.awaiting_events[account].has_key(jid) and \
|
||||
gajim.config.get('notify_on_signin') and \
|
||||
not gajim.block_signed_in_notifications[account]:
|
||||
if helpers.allow_showing_notification(account):
|
||||
transport_name = gajim.get_transport_name_from_jid(jid)
|
||||
img = None
|
||||
if transport_name:
|
||||
img = os.path.join(gajim.DATA_DIR, 'iconsets',
|
||||
'transports', transport_name, '48x48',
|
||||
'online.png')
|
||||
if not img or not os.path.isfile(img):
|
||||
iconset = gajim.config.get('iconset')
|
||||
img = os.path.join(gajim.DATA_DIR, 'iconsets',
|
||||
iconset, '48x48', 'online.png')
|
||||
path = gtkgui_helpers.get_path_to_generic_or_avatar(img,
|
||||
jid = jid, suffix = '_notif_size_colored.png')
|
||||
title = _('%(nickname)s Signed In') % \
|
||||
{'nickname': gajim.get_name_from_jid(account, jid)}
|
||||
text = ''
|
||||
if status_message:
|
||||
text = status_message
|
||||
notify.notify(_('Contact Signed In'), jid, account,
|
||||
path_to_image = path, title = title, text = text)
|
||||
|
||||
notify.notify('contact_connected', jid, account, status_message)
|
||||
if self.remote_ctrl:
|
||||
self.remote_ctrl.raise_signal('ContactPresence',
|
||||
(account, array))
|
||||
|
||||
elif old_show > 1 and new_show < 2:
|
||||
if gajim.config.get_per('soundevents', 'contact_disconnected',
|
||||
'enabled'):
|
||||
helpers.play_sound('contact_disconnected')
|
||||
if not gajim.awaiting_events[account].has_key(jid) and \
|
||||
gajim.config.get('notify_on_signout'):
|
||||
if helpers.allow_showing_notification(account):
|
||||
transport_name = gajim.get_transport_name_from_jid(jid)
|
||||
img = None
|
||||
if transport_name:
|
||||
img = os.path.join(gajim.DATA_DIR, 'iconsets',
|
||||
'transports', transport_name, '48x48',
|
||||
'offline.png')
|
||||
if not img or not os.path.isfile(img):
|
||||
iconset = gajim.config.get('iconset')
|
||||
img = os.path.join(gajim.DATA_DIR, 'iconsets',
|
||||
iconset, '48x48', 'offline.png')
|
||||
path = gtkgui_helpers.get_path_to_generic_or_avatar(img,
|
||||
jid = jid, suffix = '_notif_size_bw.png')
|
||||
title = _('%(nickname)s Signed Out') % \
|
||||
{'nickname': gajim.get_name_from_jid(account, jid)}
|
||||
text = ''
|
||||
if status_message:
|
||||
text = status_message
|
||||
notify.notify(_('Contact Signed Out'), jid, account,
|
||||
path_to_image = path, title = title, text = text)
|
||||
|
||||
notify.notify('contact_disconnected', jid, account, status_message)
|
||||
if self.remote_ctrl:
|
||||
self.remote_ctrl.raise_signal('ContactAbsence', (account, array))
|
||||
# FIXME: stop non active file transfers
|
||||
elif new_show > 1: # Status change (not connected/disconnected or error (<1))
|
||||
notify.notify('status_change', jid, account, [new_show, status_message])
|
||||
else:
|
||||
# FIXME: Msn transport (CMSN1.2.1 and PyMSN0.10) doesn't follow the JEP
|
||||
# remove in 2007
|
||||
|
@ -583,7 +534,7 @@ class Interface:
|
|||
title = _('New Private Message from room %s') % room_name
|
||||
text = _('%(nickname)s: %(message)s') % {'nickname': nick,
|
||||
'message': message}
|
||||
notify.notify(_('New Private Message'), full_jid_with_resource,
|
||||
notify.popup(_('New Private Message'), full_jid_with_resource,
|
||||
account, 'pm', path_to_image = path, title = title,
|
||||
text = text)
|
||||
|
||||
|
@ -612,7 +563,7 @@ class Interface:
|
|||
title = _('New Message from %(nickname)s') % \
|
||||
{'nickname': gajim.get_name_from_jid(account, jid)}
|
||||
path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
|
||||
notify.notify(event_type, jid_of_control, account, msg_type,
|
||||
notify.popup(event_type, jid_of_control, account, msg_type,
|
||||
path_to_image = path, title = title, text = text)
|
||||
|
||||
# array: (jid, msg, time, encrypted, msg_type, subject)
|
||||
|
@ -968,7 +919,7 @@ class Interface:
|
|||
'gc_invitation.png')
|
||||
path = gtkgui_helpers.get_path_to_generic_or_avatar(path)
|
||||
event_type = _('Groupchat Invitation')
|
||||
notify.notify(event_type, jid, account, 'gc-invitation', path,
|
||||
notify.popup(event_type, jid, account, 'gc-invitation', path,
|
||||
event_type, room_jid)
|
||||
|
||||
def handle_event_bad_passphrase(self, account, array):
|
||||
|
@ -1070,7 +1021,7 @@ class Interface:
|
|||
img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 'ft_error.png')
|
||||
path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
|
||||
event_type = _('File Transfer Error')
|
||||
notify.notify(event_type, jid, account, 'file-send-error', path,
|
||||
notify.popup(event_type, jid, account, 'file-send-error', path,
|
||||
event_type, file_props['name'])
|
||||
|
||||
def handle_event_gmail_notify(self, account, array):
|
||||
|
@ -1083,7 +1034,7 @@ class Interface:
|
|||
{'gmail_mail_address': jid}
|
||||
text = i18n.ngettext('You have %d new E-mail message', 'You have %d new E-mail messages', gmail_new_messages, gmail_new_messages, gmail_new_messages)
|
||||
path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
|
||||
notify.notify(_('New E-mail'), jid, account, 'gmail',
|
||||
notify.popup(_('New E-mail'), jid, account, 'gmail',
|
||||
path_to_image = path, title = title, text = text)
|
||||
|
||||
def save_avatar_files(self, jid, photo_decoded, puny_nick = None):
|
||||
|
@ -1199,7 +1150,7 @@ class Interface:
|
|||
|
||||
path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
|
||||
event_type = _('File Transfer Error')
|
||||
notify.notify(event_type, jid, account, msg_type, path,
|
||||
notify.popup(event_type, jid, account, msg_type, path,
|
||||
title = event_type, text = file_props['name'])
|
||||
|
||||
def handle_event_file_request(self, account, array):
|
||||
|
@ -1222,7 +1173,7 @@ class Interface:
|
|||
txt = _('%s wants to send you a file.') % gajim.get_name_from_jid(account, jid)
|
||||
path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
|
||||
event_type = _('File Transfer Request')
|
||||
notify.notify(event_type, jid, account, 'file-request',
|
||||
notify.popup(event_type, jid, account, 'file-request',
|
||||
path_to_image = path, title = event_type, text = txt)
|
||||
|
||||
def handle_event_file_progress(self, account, file_props):
|
||||
|
@ -1313,7 +1264,7 @@ class Interface:
|
|||
gajim.connections[account].connected in (2, 3)):
|
||||
# we want to be notified and we are online/chat or we don't mind
|
||||
# bugged when away/na/busy
|
||||
notify.notify(event_type, jid, account, msg_type, path_to_image = path,
|
||||
notify.popup(event_type, jid, account, msg_type, path_to_image = path,
|
||||
title = event_type, text = txt)
|
||||
|
||||
def handle_event_stanza_arrived(self, account, stanza):
|
||||
|
|
|
@ -24,6 +24,7 @@ import gtkgui_helpers
|
|||
|
||||
from common import gajim
|
||||
from common import i18n
|
||||
from common import helpers
|
||||
i18n.init()
|
||||
_ = i18n._
|
||||
|
||||
|
@ -34,7 +35,90 @@ if dbus_support.supported:
|
|||
import dbus.glib
|
||||
import dbus.service
|
||||
|
||||
def notify(event_type, jid, account, msg_type = '', path_to_image = None,
|
||||
def notify(event, jid, account, parameters):
|
||||
'''Check what type of notifications we want, depending on basic configuration
|
||||
of notifications and advanced one and do these notifications'''
|
||||
# First, find what notifications we want
|
||||
do_popup = False
|
||||
do_sound = 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
|
||||
if gajim.config.get('notify_on_signin') and \
|
||||
not gajim.block_signed_in_notifications[account]\
|
||||
and helpers.allow_showing_notification(account):
|
||||
do_popup = True
|
||||
if gajim.config.get_per('soundevents', 'contact_connected',
|
||||
'enabled') and not gajim.block_signed_in_notifications[account]:
|
||||
do_sound = True
|
||||
elif (event == 'contact_disconnected'):
|
||||
status_message = parameters
|
||||
if gajim.config.get('notify_on_signout') \
|
||||
and helpers.allow_showing_notification(account):
|
||||
do_popup = True
|
||||
if gajim.config.get_per('soundevents', 'contact_disconnected',
|
||||
'enabled'):
|
||||
do_sound = True
|
||||
|
||||
# Do the wanted notifications
|
||||
if (do_popup):
|
||||
if (event == 'contact_connected' or event == 'contact_disconnected' or \
|
||||
event == 'status_change'): # Common code for popup for these 3 events
|
||||
if (event == 'contact_disconnected'):
|
||||
show_image = 'offline.png'
|
||||
suffix = '_notif_size_bw.png'
|
||||
else: #Status Change or Connected
|
||||
# TODO : 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.png'
|
||||
transport_name = gajim.get_transport_name_from_jid(jid)
|
||||
img = None
|
||||
if transport_name:
|
||||
img = os.path.join(gajim.DATA_DIR, 'iconsets',
|
||||
'transports', transport_name, '48x48', show_image)
|
||||
if not img or not os.path.isfile(img):
|
||||
iconset = gajim.config.get('iconset')
|
||||
img = os.path.join(gajim.DATA_DIR, 'iconsets',
|
||||
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)
|
||||
else:
|
||||
print 'Event not implemeted yet'
|
||||
if (do_sound):
|
||||
helpers.play_sound(event)
|
||||
|
||||
|
||||
def popup(event_type, jid, account, msg_type = '', path_to_image = None,
|
||||
title = None, text = None):
|
||||
'''Notifies 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
|
||||
|
@ -52,7 +136,8 @@ def notify(event_type, jid, account, msg_type = '', path_to_image = None,
|
|||
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)
|
||||
instance = dialogs.PopupNotificationWindow(event_type, jid, account, msg_type, \
|
||||
path_to_image, title, text)
|
||||
gajim.interface.roster.popup_notification_windows.append(instance)
|
||||
|
||||
class NotificationResponseManager:
|
||||
|
@ -144,6 +229,8 @@ class DesktopNotification:
|
|||
ntype = 'email.arrived'
|
||||
elif event_type == _('Groupchat Invitation'):
|
||||
ntype = 'im.invitation'
|
||||
elif event_type == _('Contact Changed status'):
|
||||
ntype = 'presence.status'
|
||||
else:
|
||||
# default failsafe values
|
||||
self.path_to_image = os.path.abspath(
|
||||
|
|
Loading…
Reference in New Issue