use better varname; put a comment or two; try to make it better understandable; rm two unneeded lines

This commit is contained in:
Nikos Kouremenos 2006-09-28 13:35:53 +00:00
parent 320698e497
commit b19b73d4cc
2 changed files with 18 additions and 16 deletions

View File

@ -747,20 +747,20 @@ def sanitize_filename(filename):
return filename
def allow_showing_notification(account, type = None, advanced_notif_num = None,
first = True):
def allow_showing_notification(account, type = None,
advanced_notif_num = None, is_first_message = True):
'''is it allowed to show nofication?
check OUR status and if we allow notifications for that status
type is the option that need to be True ex: notify_on_signing
first: set it to false when it's not the first message'''
if advanced_notif_num != None:
type is the option that need to be True e.g.: notify_on_signing
is_first_message: set it to false when it's not the first message'''
if advanced_notif_num is not None:
popup = gajim.config.get_per('notifications', str(advanced_notif_num),
'popup')
if popup == 'yes':
return True
if popup == 'no':
return False
if type and (not gajim.config.get(type) or not first):
if type and (not gajim.config.get(type) or not is_first_message):
return False
if gajim.config.get('autopopupaway'): # always show notification
return True
@ -785,7 +785,7 @@ def allow_popup_window(account, advanced_notif_num = None):
return False
def allow_sound_notification(sound_event, advanced_notif_num = None):
if advanced_notif_num != None:
if advanced_notif_num is not None:
sound = gajim.config.get_per('notifications', str(advanced_notif_num),
'sound')
if sound == 'yes':

View File

@ -64,7 +64,8 @@ def get_show_in_systray(event, account, contact):
return True
def get_advanced_notification(event, account, contact):
'''Returns the number of the first advanced notification or None'''
'''Returns the number of the first (top most)
advanced notification else None'''
num = 0
notif = gajim.config.get_per('notifications', str(num))
while notif:
@ -112,7 +113,8 @@ def get_advanced_notification(event, account, contact):
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'''
and the advanced configuration of notifications and do these notifications;
advanced_notif_num'''
# First, find what notifications we want
do_popup = False
do_sound = False
@ -146,16 +148,16 @@ def notify(event, jid, account, parameters, advanced_notif_num = None):
do_sound = True
elif event == 'new_message':
message_type = parameters[0]
first = parameters[1]
is_first_message = parameters[1]
nickname = parameters[2]
message = parameters[3]
if helpers.allow_showing_notification(account, 'notify_on_new_message',
advanced_notif_num, first):
advanced_notif_num, is_first_message):
do_popup = True
if first and helpers.allow_sound_notification('first_message_received',
advanced_notif_num):
if is_first_message and helpers.allow_sound_notification(
'first_message_received', advanced_notif_num):
do_sound = True
elif not first and helpers.allow_sound_notification(
elif not is_first_message and helpers.allow_sound_notification(
'next_message_received', advanced_notif_num):
do_sound = True
else:
@ -253,7 +255,7 @@ def notify(event, jid, account, parameters, advanced_notif_num = None):
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 first:
elif is_first_message:
snd_event = 'first_message_received'
else:
snd_event = 'next_message_received'