Ticket #1984: sound.2.diff
| File sound.2.diff, 10.3 kB (added by ressu@…, 3 years ago) |
|---|
-
src/config.py
39 39 from common import gajim 40 40 from common import connection 41 41 from common import i18n 42 from common import sound 42 43 43 44 _ = i18n._ 44 45 APP = i18n.APP … … 977 978 if not iter: 978 979 return 979 980 snd_event_config_name = model[iter][3] 980 helpers.play_sound(snd_event_config_name)981 sound.play_event(snd_event_config_name) 981 982 982 983 def on_open_advanced_editor_button_clicked(self, widget, data = None): 983 984 if gajim.interface.instances.has_key('advanced_config'): -
src/notify.py
25 25 from common import gajim 26 26 from common import i18n 27 27 from common import helpers 28 from common import sound 28 29 i18n.init() 29 30 _ = i18n._ 30 31 … … 115 116 else: 116 117 print 'Event not implemeted yet' 117 118 if (do_sound): 118 helpers.play_sound(event)119 sound.play_event(event) 119 120 120 121 121 122 def popup(event_type, jid, account, msg_type = '', path_to_image = None, -
src/gajim.py
39 39 40 40 from common import exceptions 41 41 from common import i18n 42 from common import sound 42 43 i18n.init() 43 44 _ = i18n._ 44 45 … … 515 516 516 517 if gajim.config.get_per('soundevents', 'first_message_received', 517 518 'enabled') and first: 518 helpers.play_sound('first_message_received')519 sound.play_event('first_message_received') 519 520 elif gajim.config.get_per('soundevents', 'next_message_received', 520 521 'enabled'): 521 helpers.play_sound('next_message_received')522 sound.play_event('next_message_received') 522 523 523 524 if pm: 524 525 room_jid = jid … … 617 618 msg = array[1] 618 619 # do not play sound when standalone chatstate message (eg no msg) 619 620 if msg and gajim.config.get_per('soundevents', 'message_sent', 'enabled'): 620 helpers.play_sound('message_sent')621 sound.play_event('message_sent') 621 622 622 623 def handle_event_subscribe(self, account, array): 623 624 #('SUBSCRIBE', account, (jid, text)) -
src/groupchat_control.py
36 36 37 37 from common import gajim 38 38 from common import helpers 39 from common import sound 39 40 40 41 from chat_control import ChatControl 41 42 from chat_control import ChatControlBase … … 535 536 536 537 if kind == 'incoming': # it's a message NOT from us 537 538 # highlighting and sounds 538 (highlight, sound ) = self.highlighting_for_message(text, tim)539 (highlight, sound_event) = self.highlighting_for_message(text, tim) 539 540 if highlight: 540 541 # muc-specific chatstate 541 542 self.parent_win.redraw_tab(self, 'attention') 542 543 other_tags_for_name.append('bold') 543 544 other_tags_for_text.append('marked') 544 if sound == 'received':545 helpers.play_sound('muc_message_received')546 elif sound == 'highlight':547 helpers.play_sound('muc_message_highlight')545 if sound_event == 'received': 546 sound.play_event('muc_message_received') 547 elif sound_event == 'highlight': 548 sound.play_event('muc_message_highlight') 548 549 549 550 self.check_and_possibly_add_focus_out_line() 550 551 … … 554 555 def highlighting_for_message(self, text, tim): 555 556 '''Returns a 2-Tuple. The first says whether or not to highlight the 556 557 text, the second, what sound to play.''' 557 highlight, sound = (None, None)558 highlight, sound_event = (None, None) 558 559 559 560 # Do we play a sound on every muc message? 560 561 if gajim.config.get_per('soundevents', 'muc_message_received', 'enabled'): 561 562 if gajim.config.get('notify_on_all_muc_messages'): 562 sound = 'received'563 sound_event = 'received' 563 564 564 565 # Are any of the defined highlighting words in the text? 565 566 if self.needs_visual_notification(text): 566 567 highlight = True 567 568 if gajim.config.get_per('soundevents', 'muc_message_highlight', 568 569 'enabled'): 569 sound = 'highlight'570 sound_event = 'highlight' 570 571 571 572 # Is it a history message? Don't want sound-floods when we join. 572 573 if tim != time.localtime(): 573 sound = None574 sound_event = None 574 575 575 return (highlight, sound )576 return (highlight, sound_event) 576 577 577 578 def check_and_possibly_add_focus_out_line(self): 578 579 '''checks and possibly adds focus out line for room_jid if it needs it -
src/common/sound.py
1 ## common/gst.py 2 ## 3 ## Contributors for this file: 4 ## - Sami Haahtinen <ressu@ressukka.net> 5 ## 6 ## Copyright (C) 2006 Sami Haahtinen <ressu@ressukka.net> 7 ## 8 ## This program is free software; you can redistribute it and/or modify 9 ## it under the terms of the GNU General Public License as published 10 ## by the Free Software Foundation; version 2 only. 11 ## 12 ## This program is distributed in the hope that it will be useful, 13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 ## GNU General Public License for more details. 16 17 import gajim 18 import os 19 20 class GajimPlayer: 21 player = None 22 23 def __init__(self): 24 # For now, lets default to GStreamer, winsound, and then try External player 25 # FIXME: This really needs elegance! 26 if not gajim.config.get('sounds_on'): 27 raise NoSound 28 29 try: 30 self.player = GajimGstPlayer() 31 except self.PlayerUnavailable: 32 try: 33 self.player = GajimWin32Player() 34 except self.PlayerUnavailable: 35 try: 36 self.player = GajimExtPlayer() 37 except self.PlayerUnavailable: 38 self.player = None # Make sure that player is still set to None 39 raise NoSound 40 41 class NoSound(Exception): 42 '''Notifies the system that we should be silent''' 43 44 class BeepOnly(Exception): 45 '''Notifies the system that we should just beep''' 46 47 class PlayerUnavailable(Exception): 48 '''Notifies that the player is unavailable''' 49 50 def event_to_soundfile(self, event): 51 '''Returns the full file path for sound file of an event''' 52 # Check if we should play sound at all 53 if self.player is None: 54 raise NoSound 55 56 # Get soundevent 57 path_to_soundfile = gajim.config.get_per('soundevents', event, 'path') 58 59 if path_to_soundfile is None or not os.path.exists(path_to_soundfile): 60 raise NoSound 61 62 return path_to_soundfile 63 64 def play(self, soundfile): 65 if soundfile == 'beep': 66 beep() 67 68 if self.player is None: 69 return 70 71 self.player.play_sound(soundfile) 72 73 def beep(self): 74 '''Play a single beep''' 75 # FIXME: There must be a better way 76 print "\a" 77 78 # FIXME: This class hasn't gotten any testing! 79 class GajimWin32Player: 80 '''User native Win32 layer to play sounds''' 81 82 def __init__(self): 83 try: 84 import winsound 85 except ImportError: 86 # gst module is not available... 87 raise GajimPlayer.PlayerUnavailable, "Winsound library not available" 88 89 def play_sound(self,soundfile): 90 try: 91 winsound.PlaySound(soundfile, winsound.SND_FILENAME|winsound.SND_ASYNC) 92 except: 93 pass 94 95 class GajimExtPlayer: 96 '''Use external application to play the sounds''' 97 98 def __init__(self): 99 self.player = gajim.config.get('soundplayer') 100 if self.player == '': 101 raise GajimPlayer.PlayerUnavailable, "External player not set" 102 # FIXME: We should check if the player exists! 103 104 def play_sound(self,soundfile): 105 soundfile = soundfile.replace('"', '\\"') 106 command = self.player + ' "' + soundfile + '" &' 107 os.system(command) 108 109 class GajimGstPlayer: 110 '''Player that plays sound events through the GStreamer framework''' 111 112 def __init__(self): 113 try: 114 import gst 115 except ImportError: 116 # gst module is not available... 117 raise GajimPlayer.PlayerUnavailable, "Python Gstreamer modules not available" 118 self.gst = gst 119 self.GstBin = self.gst.parse_launch("playbin") 120 121 # Create a sink for video, if someone decides to use a video file ;) 122 fakesink = self.gst.element_factory_make("fakesink") 123 self.GstBin.set_property("video-sink", fakesink) 124 125 def play_sound(self,soundfile): 126 self.GstBin.set_state(self.gst.STATE_NULL) 127 128 # since playbin takes input in URI format, add file:// prefix 129 sounduri = "file://" + os.path.abspath(soundfile) 130 self.GstBin.set_property('uri', sounduri) 131 132 self.GstBin.set_state(self.gst.STATE_PLAYING) 133 134 def play_event(event): 135 global Player 136 try: 137 try: 138 soundfile = Player.event_to_soundfile(event) 139 except NameError: 140 Player = GajimPlayer() 141 soundfile = Player.event_to_soundfile(event) 142 except GajimPlayer.NoSound: 143 # No sound. 144 return 145 146 # Ok, we should be clear to play the sound 147 Player.play(soundfile) -
src/common/helpers.py
30 30 from xmpp_stringprep import nodeprep, resourceprep, nameprep 31 31 32 32 try: 33 import winsound # windows-only built-in module for playing wav34 33 import win32api 35 34 import win32con 36 35 except: … … 417 416 except: 418 417 pass 419 418 420 def play_sound(event):421 if not gajim.config.get('sounds_on'):422 return423 path_to_soundfile = gajim.config.get_per('soundevents', event, 'path')424 if path_to_soundfile == 'beep':425 print '\a' # make a speaker beep426 return427 if path_to_soundfile is None or not os.path.exists(path_to_soundfile):428 return429 if os.name == 'nt':430 try:431 winsound.PlaySound(path_to_soundfile,432 winsound.SND_FILENAME|winsound.SND_ASYNC)433 except:434 pass435 elif os.name == 'posix':436 if gajim.config.get('soundplayer') == '':437 return438 player = gajim.config.get('soundplayer')439 # we add the path in "" so we have good parsing from shell440 path_to_soundfile = path_to_soundfile.replace('"', '\\"') # escape "441 command = player + ' "' + path_to_soundfile + '" &'442 #FIXME: when we require 2.4+ use subprocess module443 os.system(command)444 445 419 def get_file_path_from_dnd_dropped_uri(uri): 446 420 path = urllib.url2pathname(uri) # escape special chars 447 421 path = path.strip('\r\n\x00') # remove \r\n and NULL
