make notify.py pythonic
This commit is contained in:
parent
ac1b317f62
commit
37667a99e2
|
@ -4,7 +4,7 @@
|
||||||
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com>
|
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com>
|
||||||
## Copyright (C) 2005-2006 Andrew Sayman <lorien420@myrealbox.com>
|
## Copyright (C) 2005-2006 Andrew Sayman <lorien420@myrealbox.com>
|
||||||
##
|
##
|
||||||
## DBUS/libnotify connection code:
|
## Notification daemon connection via D-Bus code:
|
||||||
## Copyright (C) 2005 by Sebastian Estienne
|
## Copyright (C) 2005 by Sebastian Estienne
|
||||||
##
|
##
|
||||||
## This program is free software; you can redistribute it and/or modify
|
## This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -109,11 +109,11 @@ def notify(event, jid, account, parameters, advanced_notif_num = None):
|
||||||
do_popup = False
|
do_popup = False
|
||||||
do_sound = False
|
do_sound = False
|
||||||
do_cmd = False
|
do_cmd = False
|
||||||
if (event == 'status_change'):
|
if event == 'status_change':
|
||||||
new_show = parameters[0]
|
new_show = parameters[0]
|
||||||
status_message = parameters[1]
|
status_message = parameters[1]
|
||||||
# Default : No popup for status change
|
# Default: No popup for status change
|
||||||
elif (event == 'contact_connected'):
|
elif event == 'contact_connected':
|
||||||
status_message = parameters
|
status_message = parameters
|
||||||
j = gajim.get_jid_without_resource(jid)
|
j = gajim.get_jid_without_resource(jid)
|
||||||
server = gajim.get_server_from_jid(j)
|
server = gajim.get_server_from_jid(j)
|
||||||
|
@ -129,14 +129,14 @@ def notify(event, jid, account, parameters, advanced_notif_num = None):
|
||||||
'enabled') and not gajim.block_signed_in_notifications[account] and \
|
'enabled') and not gajim.block_signed_in_notifications[account] and \
|
||||||
not block_transport:
|
not block_transport:
|
||||||
do_sound = True
|
do_sound = True
|
||||||
elif (event == 'contact_disconnected'):
|
elif event == 'contact_disconnected':
|
||||||
status_message = parameters
|
status_message = parameters
|
||||||
if helpers.allow_showing_notification(account, 'notify_on_signout'):
|
if helpers.allow_showing_notification(account, 'notify_on_signout'):
|
||||||
do_popup = True
|
do_popup = True
|
||||||
if gajim.config.get_per('soundevents', 'contact_disconnected',
|
if gajim.config.get_per('soundevents', 'contact_disconnected',
|
||||||
'enabled'):
|
'enabled'):
|
||||||
do_sound = True
|
do_sound = True
|
||||||
elif (event == 'new_message'):
|
elif event == 'new_message':
|
||||||
message_type = parameters[0]
|
message_type = parameters[0]
|
||||||
first = parameters[1]
|
first = parameters[1]
|
||||||
nickname = parameters[2]
|
nickname = parameters[2]
|
||||||
|
@ -153,19 +153,20 @@ def notify(event, jid, account, parameters, advanced_notif_num = None):
|
||||||
else:
|
else:
|
||||||
print '*Event not implemeted yet*'
|
print '*Event not implemeted yet*'
|
||||||
|
|
||||||
if advanced_notif_num != None and gajim.config.get_per('notifications',
|
if advanced_notif_num is not None and gajim.config.get_per('notifications',
|
||||||
str(advanced_notif_num), 'run_command'):
|
str(advanced_notif_num), 'run_command'):
|
||||||
do_cmd = True
|
do_cmd = True
|
||||||
|
|
||||||
# Do the wanted notifications
|
# Do the wanted notifications
|
||||||
if (do_popup):
|
if do_popup:
|
||||||
if (event == 'contact_connected' or event == 'contact_disconnected' or \
|
if event in ('contact_connected', 'contact_disconnected',
|
||||||
event == 'status_change'): # Common code for popup for these 3 events
|
'status_change'): # Common code for popup for these three events
|
||||||
if (event == 'contact_disconnected'):
|
if event == 'contact_disconnected':
|
||||||
show_image = 'offline.png'
|
show_image = 'offline.png'
|
||||||
suffix = '_notif_size_bw.png'
|
suffix = '_notif_size_bw.png'
|
||||||
else: #Status Change or Connected
|
else: #Status Change or Connected
|
||||||
# TODO : for status change, we don't always 'online.png', but we
|
# FIXME: for status change,
|
||||||
|
# we don't always 'online.png', but we
|
||||||
# first need 48x48 for all status
|
# first need 48x48 for all status
|
||||||
show_image = 'online.png'
|
show_image = 'online.png'
|
||||||
suffix = '_notif_size_colored.png'
|
suffix = '_notif_size_colored.png'
|
||||||
|
@ -180,7 +181,7 @@ def notify(event, jid, account, parameters, advanced_notif_num = None):
|
||||||
iconset, '48x48', show_image)
|
iconset, '48x48', show_image)
|
||||||
path = gtkgui_helpers.get_path_to_generic_or_avatar(img,
|
path = gtkgui_helpers.get_path_to_generic_or_avatar(img,
|
||||||
jid = jid, suffix = suffix)
|
jid = jid, suffix = suffix)
|
||||||
if (event == 'status_change'):
|
if event == 'status_change':
|
||||||
title = _('%(nick)s Changed Status') % \
|
title = _('%(nick)s Changed Status') % \
|
||||||
{'nick': gajim.get_name_from_jid(account, jid)}
|
{'nick': gajim.get_name_from_jid(account, jid)}
|
||||||
text = _('%(nick)s is now %(status)s') % \
|
text = _('%(nick)s is now %(status)s') % \
|
||||||
|
@ -190,7 +191,7 @@ def notify(event, jid, account, parameters, advanced_notif_num = None):
|
||||||
text = text + " : " + status_message
|
text = text + " : " + status_message
|
||||||
popup(_('Contact Changed Status'), jid, account,
|
popup(_('Contact Changed Status'), jid, account,
|
||||||
path_to_image = path, title = title, text = text)
|
path_to_image = path, title = title, text = text)
|
||||||
elif (event == 'contact_connected'):
|
elif event == 'contact_connected':
|
||||||
title = _('%(nickname)s Signed In') % \
|
title = _('%(nickname)s Signed In') % \
|
||||||
{'nickname': gajim.get_name_from_jid(account, jid)}
|
{'nickname': gajim.get_name_from_jid(account, jid)}
|
||||||
text = ''
|
text = ''
|
||||||
|
@ -198,7 +199,7 @@ def notify(event, jid, account, parameters, advanced_notif_num = None):
|
||||||
text = status_message
|
text = status_message
|
||||||
popup(_('Contact Signed In'), jid, account,
|
popup(_('Contact Signed In'), jid, account,
|
||||||
path_to_image = path, title = title, text = text)
|
path_to_image = path, title = title, text = text)
|
||||||
elif (event == 'contact_disconnected'):
|
elif event == 'contact_disconnected':
|
||||||
title = _('%(nickname)s Signed Out') % \
|
title = _('%(nickname)s Signed Out') % \
|
||||||
{'nickname': gajim.get_name_from_jid(account, jid)}
|
{'nickname': gajim.get_name_from_jid(account, jid)}
|
||||||
text = ''
|
text = ''
|
||||||
|
@ -206,7 +207,7 @@ def notify(event, jid, account, parameters, advanced_notif_num = None):
|
||||||
text = status_message
|
text = status_message
|
||||||
popup(_('Contact Signed Out'), jid, account,
|
popup(_('Contact Signed Out'), jid, account,
|
||||||
path_to_image = path, title = title, text = text)
|
path_to_image = path, title = title, text = text)
|
||||||
elif (event == 'new_message'):
|
elif event == 'new_message':
|
||||||
if message_type == 'normal': # single message
|
if message_type == 'normal': # single message
|
||||||
event_type = _('New Single Message')
|
event_type = _('New Single Message')
|
||||||
img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
|
img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
|
||||||
|
@ -233,15 +234,15 @@ def notify(event, jid, account, parameters, advanced_notif_num = None):
|
||||||
popup(event_type, jid, account, message_type,
|
popup(event_type, jid, account, message_type,
|
||||||
path_to_image = path, title = title, text = text)
|
path_to_image = path, title = title, text = text)
|
||||||
|
|
||||||
if (do_sound):
|
if do_sound:
|
||||||
snd_file = None
|
snd_file = None
|
||||||
snd_event = None # If not snd_file, play the event
|
snd_event = None # If not snd_file, play the event
|
||||||
if (event == 'new_message'):
|
if event == 'new_message':
|
||||||
if advanced_notif_num != None and gajim.config.get_per('notifications',
|
if advanced_notif_num is not None and gajim.config.get_per(
|
||||||
str(advanced_notif_num), 'sound') == 'yes':
|
'notifications', str(advanced_notif_num), 'sound') == 'yes':
|
||||||
snd_file = gajim.config.get_per('notifications',
|
snd_file = gajim.config.get_per('notifications',
|
||||||
str(advanced_notif_num), 'sound_file')
|
str(advanced_notif_num), 'sound_file')
|
||||||
elif advanced_notif_num != None and gajim.config.get_per(
|
elif advanced_notif_num is not None and gajim.config.get_per(
|
||||||
'notifications', str(advanced_notif_num), 'sound') == 'no':
|
'notifications', str(advanced_notif_num), 'sound') == 'no':
|
||||||
pass # do not set snd_event
|
pass # do not set snd_event
|
||||||
elif first:
|
elif first:
|
||||||
|
@ -272,8 +273,8 @@ def popup(event_type, jid, account, msg_type = '', path_to_image = None,
|
||||||
title = gtkgui_helpers.escape_for_pango_markup(title)
|
title = gtkgui_helpers.escape_for_pango_markup(title)
|
||||||
if gajim.config.get('use_notif_daemon') and dbus_support.supported:
|
if gajim.config.get('use_notif_daemon') and dbus_support.supported:
|
||||||
try:
|
try:
|
||||||
DesktopNotification(event_type, jid, account, msg_type, path_to_image,
|
DesktopNotification(event_type, jid, account, msg_type,
|
||||||
title, text)
|
path_to_image, title, text)
|
||||||
return
|
return
|
||||||
except dbus.dbus_bindings.DBusException, e:
|
except dbus.dbus_bindings.DBusException, e:
|
||||||
# Connection to D-Bus failed, try popup
|
# Connection to D-Bus failed, try popup
|
||||||
|
@ -281,8 +282,8 @@ def popup(event_type, jid, account, msg_type = '', path_to_image = None,
|
||||||
except TypeError, e:
|
except TypeError, e:
|
||||||
# This means that we sent the message incorrectly
|
# This means that we sent the message incorrectly
|
||||||
gajim.log.debug(str(e))
|
gajim.log.debug(str(e))
|
||||||
instance = dialogs.PopupNotificationWindow(event_type, jid, account, msg_type, \
|
instance = dialogs.PopupNotificationWindow(event_type, jid, account,
|
||||||
path_to_image, title, text)
|
msg_type, path_to_image, title, text)
|
||||||
gajim.interface.roster.popup_notification_windows.append(instance)
|
gajim.interface.roster.popup_notification_windows.append(instance)
|
||||||
|
|
||||||
class NotificationResponseManager:
|
class NotificationResponseManager:
|
||||||
|
|
Loading…
Reference in New Issue