fix 80 char width

This commit is contained in:
Yann Leboulanger 2010-03-14 00:05:30 +01:00
parent 86acbd398c
commit 6b36b6729d
1 changed files with 101 additions and 94 deletions

View File

@ -115,9 +115,9 @@ def get_advanced_notification(event, account, contact):
if gajim.config.get_per('notifications', str(num), 'event') == event: if gajim.config.get_per('notifications', str(num), 'event') == event:
# test recipient # test recipient
recipient_type = gajim.config.get_per('notifications', str(num), recipient_type = gajim.config.get_per('notifications', str(num),
'recipient_type') 'recipient_type')
recipients = gajim.config.get_per('notifications', str(num), recipients = gajim.config.get_per('notifications', str(num),
'recipients').split() 'recipients').split()
if recipient_type == 'all': if recipient_type == 'all':
recipient_ok = True recipient_ok = True
elif recipient_type == 'contact' and contact.jid in recipients: elif recipient_type == 'contact' and contact.jid in recipients:
@ -136,13 +136,13 @@ def get_advanced_notification(event, account, contact):
if status_ok: if status_ok:
# test window_opened # test window_opened
tab_opened = gajim.config.get_per('notifications', str(num), tab_opened = gajim.config.get_per('notifications', str(num),
'tab_opened') 'tab_opened')
if tab_opened == 'both': if tab_opened == 'both':
tab_opened_ok = True tab_opened_ok = True
else: else:
chat_control = helpers.get_chat_control(account, contact) chat_control = helpers.get_chat_control(account, contact)
if (chat_control and tab_opened == 'yes') or (not chat_control and \ if (chat_control and tab_opened == 'yes') or (not chat_control \
tab_opened == 'no'): and tab_opened == 'no'):
tab_opened_ok = True tab_opened_ok = True
if tab_opened_ok: if tab_opened_ok:
return num return num
@ -152,9 +152,10 @@ def get_advanced_notification(event, account, contact):
def notify(event, jid, account, parameters, advanced_notif_num=None): def notify(event, jid, account, parameters, advanced_notif_num=None):
""" """
Check what type of notifications we want, depending on basic and the advanced Check what type of notifications we want, depending on basic and the
configuration of notifications and do these notifications; advanced_notif_num advanced configuration of notifications and do these notifications;
holds the number of the first (top most) advanced notification advanced_notif_num holds the number of the first (top most) advanced
notification
""" """
# First, find what notifications we want # First, find what notifications we want
do_popup = False do_popup = False
@ -174,7 +175,8 @@ def notify(event, jid, account, parameters, advanced_notif_num=None):
gajim.block_signed_in_notifications[account_server]: gajim.block_signed_in_notifications[account_server]:
block_transport = True block_transport = True
if helpers.allow_showing_notification(account, 'notify_on_signin') and \ if helpers.allow_showing_notification(account, 'notify_on_signin') and \
not gajim.block_signed_in_notifications[account] and not block_transport: not gajim.block_signed_in_notifications[account] and \
not block_transport:
do_popup = True do_popup = True
if gajim.config.get_per('soundevents', 'contact_connected', if gajim.config.get_per('soundevents', 'contact_connected',
'enabled') and not gajim.block_signed_in_notifications[account] and \ 'enabled') and not gajim.block_signed_in_notifications[account] and \
@ -185,7 +187,7 @@ def notify(event, jid, account, parameters, advanced_notif_num=None):
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]
@ -206,8 +208,8 @@ def notify(event, jid, account, parameters, advanced_notif_num=None):
'first_message_received', advanced_notif_num): 'first_message_received', advanced_notif_num):
do_sound = True do_sound = True
elif not is_first_message and focused and \ elif not is_first_message and focused and \
helpers.allow_sound_notification(account, 'next_message_received_focused', helpers.allow_sound_notification(account,
advanced_notif_num): 'next_message_received_focused', advanced_notif_num):
do_sound = True do_sound = True
elif not is_first_message and not focused and \ elif not is_first_message and not focused and \
helpers.allow_sound_notification(account, helpers.allow_sound_notification(account,
@ -227,7 +229,7 @@ def notify(event, jid, account, parameters, advanced_notif_num=None):
if event == 'contact_disconnected': if event == 'contact_disconnected':
show_image = 'offline.png' show_image = 'offline.png'
suffix = '_notif_size_bw' suffix = '_notif_size_bw'
else: #Status Change or Connected else: # Status Change or Connected
# FIXME: for status change, # FIXME: for status change,
# we don't always 'online.png', but we # we don't always 'online.png', but we
# first need 48x48 for all status # first need 48x48 for all status
@ -236,46 +238,46 @@ def notify(event, jid, account, parameters, advanced_notif_num=None):
transport_name = gajim.get_transport_name_from_jid(jid) transport_name = gajim.get_transport_name_from_jid(jid)
img_path = None img_path = None
if transport_name: if transport_name:
img_path = os.path.join(helpers.get_transport_path(transport_name), img_path = os.path.join(helpers.get_transport_path(
'48x48', show_image) transport_name), '48x48', show_image)
if not img_path or not os.path.isfile(img_path): if not img_path or not os.path.isfile(img_path):
iconset = gajim.config.get('iconset') iconset = gajim.config.get('iconset')
img_path = os.path.join(helpers.get_iconset_path(iconset), '48x48', img_path = os.path.join(helpers.get_iconset_path(iconset),
show_image) '48x48', show_image)
path = gtkgui_helpers.get_path_to_generic_or_avatar(img_path, jid=jid, path = gtkgui_helpers.get_path_to_generic_or_avatar(img_path,
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') % \
{'nick': gajim.get_name_from_jid(account, jid),\ {'nick': gajim.get_name_from_jid(account, jid),\
'status': helpers.get_uf_show(gajim.SHOW_LIST[new_show])} 'status': helpers.get_uf_show(gajim.SHOW_LIST[new_show])}
if status_message: if status_message:
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 = ''
if status_message: if status_message:
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 = ''
if status_message: if status_message:
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_name = 'gajim-single_msg_recv' img_name = 'gajim-single_msg_recv'
title = _('New Single Message from %(nickname)s') % \ title = _('New Single Message from %(nickname)s') % \
{'nickname': nickname} {'nickname': nickname}
text = message text = message
elif message_type == 'pm': # private message elif message_type == 'pm': # private message
event_type = _('New Private Message') event_type = _('New Private Message')
@ -283,20 +285,21 @@ def notify(event, jid, account, parameters, advanced_notif_num=None):
img_name = 'gajim-priv_msg_recv' img_name = 'gajim-priv_msg_recv'
title = _('New Private Message from group chat %s') % room_name title = _('New Private Message from group chat %s') % room_name
if message: if message:
text = _('%(nickname)s: %(message)s') % {'nickname': nickname, text = _('%(nickname)s: %(message)s') % \
'message': message} {'nickname': nickname, 'message': message}
else: else:
text = _('Messaged by %(nickname)s') % {'nickname': nickname} text = _('Messaged by %(nickname)s') % \
{'nickname': nickname}
else: # chat message else: # chat message
event_type = _('New Message') event_type = _('New Message')
img_name = 'gajim-chat_msg_recv' img_name = 'gajim-chat_msg_recv'
title = _('New Message from %(nickname)s') % \ title = _('New Message from %(nickname)s') % \
{'nickname': nickname} {'nickname': nickname}
text = message text = message
img_path = gtkgui_helpers.get_icon_path(img_name, 48) img_path = gtkgui_helpers.get_icon_path(img_name, 48)
popup(event_type, jid, account, message_type, popup(event_type, jid, account, message_type,
path_to_image=img_path, title=title, text=text) path_to_image=img_path, title=title, text=text)
if do_sound: if do_sound:
snd_file = None snd_file = None
@ -305,7 +308,7 @@ def notify(event, jid, account, parameters, advanced_notif_num=None):
if advanced_notif_num is not None and gajim.config.get_per( if advanced_notif_num is not None and gajim.config.get_per(
'notifications', 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 is not 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
@ -324,14 +327,14 @@ def notify(event, jid, account, parameters, advanced_notif_num=None):
if do_cmd: if do_cmd:
command = gajim.config.get_per('notifications', str(advanced_notif_num), command = gajim.config.get_per('notifications', str(advanced_notif_num),
'command') 'command')
try: try:
helpers.exec_command(command) helpers.exec_command(command)
except Exception: except Exception:
pass pass
def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None, def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None,
text=None): text=None):
""" """
Notify a user of an event. It first tries to a valid implementation of 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 Desktop Notification Specification. If that fails, then we fall back to
@ -357,7 +360,7 @@ def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None,
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, DesktopNotification(event_type, jid, account, msg_type,
path_to_image, title, gobject.markup_escape_text(text)) path_to_image, title, gobject.markup_escape_text(text))
return # sucessfully did D-Bus Notification procedure! return # sucessfully did D-Bus Notification procedure!
except dbus.DBusException, e: except dbus.DBusException, e:
# Connection to D-Bus failed # Connection to D-Bus failed
@ -372,7 +375,7 @@ def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None,
# empty text for new_message means do_preview = False # empty text for new_message means do_preview = False
# -> default value for text # -> default value for text
_text = gobject.markup_escape_text( _text = gobject.markup_escape_text(
gajim.get_name_from_jid(account, jid)) gajim.get_name_from_jid(account, jid))
else: else:
_text = gobject.markup_escape_text(text) _text = gobject.markup_escape_text(text)
@ -404,7 +407,7 @@ def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None,
# Either nothing succeeded or the user wants old-style notifications # Either nothing succeeded or the user wants old-style notifications
instance = dialogs.PopupNotificationWindow(event_type, jid, account, instance = dialogs.PopupNotificationWindow(event_type, jid, account,
msg_type, 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)
def on_pynotify_notification_clicked(notification, action): def on_pynotify_notification_clicked(notification, action):
@ -431,7 +434,8 @@ class NotificationResponseManager:
if self.interface is not None: if self.interface is not None:
return return
self.interface = dbus_support.get_notifications_interface() self.interface = dbus_support.get_notifications_interface()
self.interface.connect_to_signal('ActionInvoked', self.on_action_invoked) self.interface.connect_to_signal('ActionInvoked',
self.on_action_invoked)
self.interface.connect_to_signal('NotificationClosed', self.on_closed) self.interface.connect_to_signal('NotificationClosed', self.on_closed)
def on_action_invoked(self, id_, reason): def on_action_invoked(self, id_, reason):
@ -470,12 +474,12 @@ notification_response_manager = NotificationResponseManager()
class DesktopNotification: class DesktopNotification:
""" """
A DesktopNotification that interfaces with D-Bus via the Desktop Notification A DesktopNotification that interfaces with D-Bus via the Desktop
specification Notification Specification
""" """
def __init__(self, event_type, jid, account, msg_type='', def __init__(self, event_type, jid, account, msg_type='',
path_to_image=None, title=None, text=None): path_to_image=None, title=None, text=None):
self.path_to_image = path_to_image self.path_to_image = path_to_image
self.event_type = event_type self.event_type = event_type
self.title = title self.title = title
@ -501,7 +505,7 @@ class DesktopNotification:
elif event_type == _('Contact Signed Out'): elif event_type == _('Contact Signed Out'):
ntype = 'presence.offline' ntype = 'presence.offline'
elif event_type in (_('New Message'), _('New Single Message'), elif event_type in (_('New Message'), _('New Single Message'),
_('New Private Message')): _('New Private Message')):
ntype = 'im.received' ntype = 'im.received'
elif event_type == _('File Transfer Request'): elif event_type == _('File Transfer Request'):
ntype = 'transfer' ntype = 'transfer'
@ -525,7 +529,7 @@ class DesktopNotification:
else: else:
# default failsafe values # default failsafe values
self.path_to_image = gtkgui_helpers.get_icon_path( self.path_to_image = gtkgui_helpers.get_icon_path(
'gajim-chat_msg_recv', 48) 'gajim-chat_msg_recv', 48)
ntype = 'im' # Notification Type ntype = 'im' # Notification Type
self.notif = dbus_support.get_notifications_interface(self) self.notif = dbus_support.get_notifications_interface(self)
@ -546,21 +550,21 @@ class DesktopNotification:
ntype = self.ntype ntype = self.ntype
if self.kde_notifications: if self.kde_notifications:
notification_text = ('<html><img src="%(image)s" align=left />' \ notification_text = ('<html><img src="%(image)s" align=left />' \
'%(title)s<br/>%(text)s</html>') % {'title': self.title, '%(title)s<br/>%(text)s</html>') % {'title': self.title,
'text': self.text, 'image': self.path_to_image} 'text': self.text, 'image': self.path_to_image}
gajim_icon = gtkgui_helpers.get_icon_path('gajim', 48) gajim_icon = gtkgui_helpers.get_icon_path('gajim', 48)
self.notif.Notify( self.notif.Notify(
dbus.String(_('Gajim')), # app_name (string) dbus.String(_('Gajim')), # app_name (string)
dbus.UInt32(0), # replaces_id (uint) dbus.UInt32(0), # replaces_id (uint)
ntype, # event_id (string) ntype, # event_id (string)
dbus.String(gajim_icon), # app_icon (string) dbus.String(gajim_icon), # app_icon (string)
dbus.String(''), # summary (string) dbus.String(''), # summary (string)
dbus.String(notification_text), # body (string) dbus.String(notification_text), # body (string)
# actions (stringlist) # actions (stringlist)
(dbus.String('default'), dbus.String(self.event_type), (dbus.String('default'), dbus.String(self.event_type),
dbus.String('ignore'), dbus.String(_('Ignore'))), dbus.String('ignore'), dbus.String(_('Ignore'))),
[], # hints (not used in KDE yet) [], # hints (not used in KDE yet)
dbus.UInt32(timeout*1000), # timeout (int), in ms dbus.UInt32(timeout*1000), # timeout (int), in ms
reply_handler=self.attach_by_id, reply_handler=self.attach_by_id,
error_handler=self.notify_another_way) error_handler=self.notify_another_way)
return return
@ -571,22 +575,23 @@ class DesktopNotification:
actions = {'default': 0} actions = {'default': 0}
try: try:
self.notif.Notify( self.notif.Notify(
dbus.String(_('Gajim')), dbus.String(_('Gajim')),
dbus.String(self.path_to_image), dbus.String(self.path_to_image),
dbus.UInt32(0), dbus.UInt32(0),
ntype, ntype,
dbus.Byte(0), dbus.Byte(0),
dbus.String(self.title), dbus.String(self.title),
dbus.String(self.text), dbus.String(self.text),
[dbus.String(self.path_to_image)], [dbus.String(self.path_to_image)],
actions, actions,
[''], [''],
True, True,
dbus.UInt32(timeout), dbus.UInt32(timeout),
reply_handler=self.attach_by_id, reply_handler=self.attach_by_id,
error_handler=self.notify_another_way) error_handler=self.notify_another_way)
except AttributeError: except AttributeError:
version = [0, 3, 1] # we're actually dealing with the newer version # we're actually dealing with the newer version
version = [0, 3, 1]
if version > [0, 3]: if version > [0, 3]:
if gajim.interface.systray_enabled and \ if gajim.interface.systray_enabled and \
gajim.config.get('attach_notifications_to_systray'): gajim.config.get('attach_notifications_to_systray'):
@ -607,30 +612,31 @@ class DesktopNotification:
text = ' ' text = ' '
actions = () actions = ()
if 'actions' in self.capabilities: if 'actions' in self.capabilities:
actions = (dbus.String('default'), dbus.String(self.event_type)) actions = (dbus.String('default'), dbus.String(
self.event_type))
self.notif.Notify( self.notif.Notify(
dbus.String(_('Gajim')), dbus.String(_('Gajim')),
dbus.UInt32(0), # this notification does not replace other dbus.UInt32(0), # this notification does not replace other
dbus.String(self.path_to_image), dbus.String(self.path_to_image),
dbus.String(self.title), dbus.String(self.title),
dbus.String(text), dbus.String(text),
actions, actions,
hints, hints,
dbus.UInt32(timeout*1000), dbus.UInt32(timeout*1000),
reply_handler=self.attach_by_id, reply_handler=self.attach_by_id,
error_handler=self.notify_another_way) error_handler=self.notify_another_way)
else: else:
self.notif.Notify( self.notif.Notify(
dbus.String(_('Gajim')), dbus.String(_('Gajim')),
dbus.String(self.path_to_image), dbus.String(self.path_to_image),
dbus.UInt32(0), dbus.UInt32(0),
dbus.String(self.title), dbus.String(self.title),
dbus.String(self.text), dbus.String(self.text),
dbus.String(''), dbus.String(''),
hints, hints,
dbus.UInt32(timeout*1000), dbus.UInt32(timeout*1000),
reply_handler=self.attach_by_id, reply_handler=self.attach_by_id,
error_handler=self.notify_another_way) error_handler=self.notify_another_way)
def attach_by_id(self, id_): def attach_by_id(self, id_):
self.id = id_ self.id = id_
@ -668,12 +674,13 @@ class DesktopNotification:
def get_version(self): def get_version(self):
self.notif.GetServerInfo( self.notif.GetServerInfo(
reply_handler=self.version_reply_handler, reply_handler=self.version_reply_handler,
error_handler=self.version_error_handler_2_x_try) error_handler=self.version_error_handler_2_x_try)
def version_error_handler_2_x_try(self, e): def version_error_handler_2_x_try(self, e):
self.notif.GetServerInformation(reply_handler=self.version_reply_handler, self.notif.GetServerInformation(
error_handler=self.version_error_handler_3_x_try) reply_handler=self.version_reply_handler,
error_handler=self.version_error_handler_3_x_try)
def version_error_handler_3_x_try(self, e): def version_error_handler_3_x_try(self, e):
self.version = self.default_version self.version = self.default_version