Changeset 6677
- Timestamp:
- 08/27/06 00:51:33 (2 years ago)
- Location:
- trunk/src
- Files:
-
- 5 modified
-
common/helpers.py (modified) (8 diffs)
-
gajim.py (modified) (4 diffs)
-
notify.py (modified) (6 diffs)
-
roster_window.py (modified) (3 diffs)
-
systray.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/common/helpers.py
r6553 r6677 19 19 import sre 20 20 import os 21 import subprocess 21 22 import urllib 22 23 import errno … … 361 362 return is_in_dir 362 363 364 def exec_command(command): 365 '''command is a string that contain arguments''' 366 # os.system(command) 367 subprocess.Popen(command.split()) 368 363 369 def launch_browser_mailer(kind, uri): 364 370 #kind = 'url' or 'mail' … … 384 390 if command == '': # if no app is configured 385 391 return 386 # we add the uri in "" so we have good parsing from shell 387 uri = uri.replace('"', '\\"') # escape " 388 command = command + ' "' + uri + '" &' 389 try: #FIXME: when we require python2.4+ use subprocess module 390 os.system(command) 392 command = command + ' ' + uri 393 try: 394 exec_command(command) 391 395 except: 392 396 pass … … 407 411 if command == '': # if no app is configured 408 412 return 409 # we add the path in "" so we have good parsing from shell 410 path_to_open = path_to_open.replace('"', '\\"') # escape " 411 command = command + ' "' + path_to_open + '" &' 412 try: #FIXME: when we require python2.4+ use subprocess module 413 os.system(command) 413 command = command + ' ' + path_to_open 414 try: 415 exec_command(command) 414 416 except: 415 417 pass … … 437 439 return 438 440 player = gajim.config.get('soundplayer') 439 # we add the path in "" so we have good parsing from shell 440 path_to_soundfile = path_to_soundfile.replace('"', '\\"') # escape " 441 command = player + ' "' + path_to_soundfile + '" &' 442 #FIXME: when we require 2.4+ use subprocess module 443 os.system(command) 441 command = player + ' ' + path_to_soundfile 442 exec_command(command) 444 443 445 444 def get_file_path_from_dnd_dropped_uri(uri): … … 728 727 return filename 729 728 730 def allow_showing_notification(account ):729 def allow_showing_notification(account, type = None, advanced_notif_num = None): 731 730 '''is it allowed to show nofication? 732 check OUR status and if we allow notifications for that status''' 731 check OUR status and if we allow notifications for that status 732 type is the option that need to be True ex: notify_on_signin''' 733 if advanced_notif_num != None: 734 popup = gajim.config.get_per('notifications', str(advanced_notif_num), 735 'popup') 736 if popup == 'yes': 737 return True 738 if popup == 'no': 739 return False 740 if type and not gajim.config.get(type): 741 return False 733 742 if gajim.config.get('autopopupaway'): # always show notification 734 743 return True … … 737 746 return False 738 747 739 def allow_popup_window(account ):748 def allow_popup_window(account, advanced_notif_num = None): 740 749 '''is it allowed to popup windows?''' 750 if advanced_notif_num != None: 751 popup = gajim.config.get_per('notifications', str(advanced_notif_num), 752 'auto_open') 753 if popup == 'yes': 754 return True 755 if popup == 'no': 756 return False 741 757 autopopup = gajim.config.get('autopopup') 742 758 autopopupaway = gajim.config.get('autopopupaway') … … 745 761 return True 746 762 return False 763 764 def allow_sound_notification(sound_event, advanced_notif_num = None): 765 if advanced_notif_num != None: 766 sound = gajim.config.get_per('notifications', str(advanced_notif_num), 767 'sound') 768 if sound == 'yes': 769 return True 770 if sound == 'no': 771 return False 772 if gajim.config.get_per('soundevents', sound_event, 'enabled'): 773 return True 774 return False -
trunk/src/gajim.py
r6660 r6677 558 558 return 559 559 560 advanced_notif_num = notify.get_advanced_notification('message_received', 561 account, contact) 562 560 563 # Is it a first or next message received ? 561 564 first = False … … 572 575 # array: (jid, msg, time, encrypted, msg_type, subject) 573 576 self.roster.on_message(jid, message, array[2], account, array[3], 574 msg_type, subject, resource, msg_id, array[9] )577 msg_type, subject, resource, msg_id, array[9], advanced_notif_num) 575 578 nickname = gajim.get_name_from_jid(account, jid) 576 579 # Check and do wanted notifications … … 579 582 msg = _('Subject: %s') % subject + '\n' + msg 580 583 notify.notify('new_message', jid, account, [msg_type, first, nickname, 581 msg] )584 msg], advanced_notif_num) 582 585 583 586 if self.remote_ctrl: … … 931 934 array[3])) 932 935 933 if gajim.config.get('notify_on_new_message') and \ 934 helpers.allow_showing_notification(account): 936 if helpers.allow_showing_notification(account, 'notify_on_new_message'): 935 937 path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', 936 938 'gc_invitation.png') -
trunk/src/notify.py
r6554 r6677 33 33 import dbus.service 34 34 35 def notify(event, jid, account, parameters): 35 def get_advanced_notification(event, account, contact): 36 num = 0 37 notif = gajim.config.get_per('notifications', str(num)) 38 while notif: 39 recipient_ok = False 40 status_ok = False 41 tab_opened_ok = False 42 # test event 43 if gajim.config.get_per('notifications', str(num), 'event') == event: 44 # test recipient 45 recipient_type = gajim.config.get_per('notifications', str(num), 46 'recipient_type') 47 recipients = gajim.config.get_per('notifications', str(num), 48 'recipients').split() 49 if recipient_type == 'all': 50 recipient_ok = True 51 elif recipient_type == 'contact' and contact.jid in recipients: 52 recipient_ok = True 53 elif recipient_type == 'group': 54 for group in contact.groups: 55 if group in contact.groups: 56 recipient_ok = True 57 break 58 if recipient_ok: 59 # test status 60 our_status = gajim.SHOW_LIST[gajim.connections[account].connected] 61 status = gajim.config.get_per('notifications', str(num), 'status') 62 if status == 'all' or our_status in status.split(): 63 status_ok = True 64 if status_ok: 65 # test window_opened 66 tab_opened = gajim.config.get_per('notifications', str(num), 67 'tab_opened') 68 if tab_opened == 'both': 69 tab_opened_ok = True 70 else: 71 chat_control = False 72 full_jid_with_resource = contact.jid 73 if contact.resource: 74 full_jid_with_resource += '/' + contact.resource 75 highest_contact = gajim.contacts.get_contact_with_highest_priority( 76 account, contact.jid) 77 # Look for a chat control that has the given resource, or default to 78 # one without resource 79 if gajim.interface.msg_win_mgr.get_control(full_jid_with_resource, 80 account): 81 chat_control = True 82 elif not highest_contact or not highest_contact.resource: 83 # unknow contact or offline message 84 if gajim.interface.msg_win_mgr.get_control(contact.jid, account): 85 chat_control = True 86 elif highest_contact and contact.resource != \ 87 highest_contact.resource: 88 chat_control = False 89 elif gajim.interface.msg_win_mgr.get_control(contact.jid, account): 90 chat_control = True 91 if (chat_control and tab_opened == 'yes') or (not chat_control and \ 92 tab_opened == 'no'): 93 tab_opened_ok = True 94 if tab_opened_ok: 95 return num 96 97 num += 1 98 notif = gajim.config.get_per('notifications', str(num)) 99 100 def notify(event, jid, account, parameters, advanced_notif_num = None): 36 101 '''Check what type of notifications we want, depending on basic configuration 37 102 of notifications and advanced one and do these notifications''' … … 39 104 do_popup = False 40 105 do_sound = False 106 do_cmd = False 41 107 if (event == 'status_change'): 42 108 new_show = parameters[0] … … 52 118 gajim.block_signed_in_notifications[account_server]: 53 119 block_transport = True 54 if gajim.config.get('notify_on_signin') and \ 55 not gajim.block_signed_in_notifications[account] and not block_transport \ 56 and helpers.allow_showing_notification(account): 120 if helpers.allow_showing_notification(account, 'notify_on_signin') and \ 121 not gajim.block_signed_in_notifications[account] and not block_transport: 57 122 do_popup = True 58 123 if gajim.config.get_per('soundevents', 'contact_connected', … … 62 127 elif (event == 'contact_disconnected'): 63 128 status_message = parameters 64 if gajim.config.get('notify_on_signout') \ 65 and helpers.allow_showing_notification(account): 129 if helpers.allow_showing_notification(account, 'notify_on_signout'): 66 130 do_popup = True 67 131 if gajim.config.get_per('soundevents', 'contact_disconnected', … … 73 137 nickname = parameters[2] 74 138 message = parameters[3] 75 if gajim.config.get('notify_on_new_message') and \76 helpers.allow_showing_notification(account) and first:139 if helpers.allow_showing_notification(account, 'notify_on_new_message', 140 advanced_notif_num) and first: 77 141 do_popup = True 78 if first and gajim.config.get_per('soundevents','first_message_received',79 'enabled'):142 if first and helpers.allow_sound_notification('first_message_received', 143 advanced_notif_num): 80 144 do_sound = True 81 elif not first and gajim.config.get_per('soundevents', 'next_message_received',82 'enabled'):145 elif not first and helpers.allow_sound_notification( 146 'next_message_received', advanced_notif_num): 83 147 do_sound = True 84 148 else: 85 149 print '*Event not implemeted yet*' 150 151 if advanced_notif_num != None and gajim.config.get_per('notifications', 152 str(advanced_notif_num), 'run_command'): 153 do_cmd = True 86 154 87 155 # Do the wanted notifications … … 162 230 163 231 if (do_sound): 232 snd_file = None 233 snd_event = None # If not snd_file, play the event 164 234 if (event == 'new_message'): 165 if first: 166 helpers.play_sound('first_message_received') 235 if advanced_notif_num != None and gajim.config.get_per('notifications', 236 str(advanced_notif_num), 'sound') == 'yes': 237 snd_file = gajim.config.get_per('notifications', 238 str(advanced_notif_num), 'sound_file') 239 elif advanced_notif_num != None and gajim.config.get_per( 240 'notifications', str(advanced_notif_num), 'sound') == 'no': 241 pass # do not set snd_event 242 elif first: 243 snd_event = 'first_message_received' 167 244 else: 168 helpers.play_sound('next_message_received')245 snd_event = 'next_message_received' 169 246 elif event in ('contact_connected', 'contact_disconnected'): 170 helpers.play_sound(event) 171 247 snd_event = event 248 if snd_file: 249 helpers.play_sound_file(snd_file) 250 if snd_event: 251 helpers.play_sound(snd_event) 252 253 if do_cmd: 254 command = gajim.config.get_per('notifications', str(advanced_notif_num), 255 'command') 256 try: 257 helpers.exec_command(command) 258 except: 259 pass 172 260 173 261 def popup(event_type, jid, account, msg_type = '', path_to_image = None, -
trunk/src/roster_window.py
r6676 r6677 2440 2440 def on_message(self, jid, msg, tim, account, encrypted = False, 2441 2441 msg_type = '', subject = None, resource = '', msg_id = None, 2442 user_nick = '' ):2442 user_nick = '', advanced_notif_num = None): 2443 2443 '''when we receive a message''' 2444 2444 contact = None … … 2497 2497 no_queue = False 2498 2498 2499 popup = helpers.allow_popup_window(account )2499 popup = helpers.allow_popup_window(account, advanced_notif_num) 2500 2500 2501 2501 if msg_type == 'normal' and popup: # it's single message to be autopopuped … … 2555 2555 self.tree.set_cursor(path) 2556 2556 if gajim.interface.systray_capabilities: 2557 gajim.interface.systray.add_jid(fjid, account, kind )2557 gajim.interface.systray.add_jid(fjid, account, kind, advanced_notif_num) 2558 2558 2559 2559 def on_preferences_menuitem_activate(self, widget): -
trunk/src/systray.py
r6612 r6677 59 59 self.popup_menus = [] 60 60 61 def set_img(self ):61 def set_img(self, advanced_notif_num = None): 62 62 if not gajim.interface.systray_enabled: 63 63 return 64 if advanced_notif_num: 65 if gajim.config.get_per('notifications', str(advanced_notif_num), 66 'systray') == 'no': 67 return 64 68 if len(self.jids) > 0: 65 69 state = 'message' … … 72 76 self.img_tray.set_from_pixbuf(image.get_pixbuf()) 73 77 74 def add_jid(self, jid, account, typ ):78 def add_jid(self, jid, account, typ, advanced_notif_num = None): 75 79 l = [account, jid, typ] 76 80 # We can keep several single message 'cause we open them one by one 77 81 if not l in self.jids or typ == 'normal': 78 82 self.jids.append(l) 79 self.set_img( )83 self.set_img(advanced_notif_num) 80 84 81 85 def remove_jid(self, jid, account, typ):
