Set a maximum frequency for playing sounds #355
|
@ -987,11 +987,24 @@ class MyForm(QtGui.QMainWindow):
|
|||
# update the menu entries
|
||||
self.ubuntuMessagingMenuUnread(drawAttention)
|
||||
|
||||
# returns true if the given sound category is a connection sound
|
||||
# rather than a received message sound
|
||||
def isConnectionSound(self, category):
|
||||
if (category is self.SOUND_CONNECTED or
|
||||
category is self.SOUND_DISCONNECTED or
|
||||
category is self.SOUND_CONNECTION_GREEN):
|
||||
return True
|
||||
return False
|
||||
|
||||
# play a sound
|
||||
def playSound(self, category, label):
|
||||
# filename of the sound to be played
|
||||
soundFilename = None
|
||||
|
||||
# whether to play a sound or not
|
||||
play = True
|
||||
|
||||
# if the address had a known label in the address book
|
||||
if label is not None:
|
||||
# Does a sound file exist for this particular contact?
|
||||
if (os.path.isfile(shared.appdata + 'sounds/' + label + '.wav') or
|
||||
|
@ -1002,27 +1015,33 @@ class MyForm(QtGui.QMainWindow):
|
|||
# This suppresses playing sounds repeatedly when there
|
||||
# are many new messages
|
||||
if (soundFilename is None and
|
||||
category is not self.SOUND_CONNECTED and
|
||||
category is not self.SOUND_DISCONNECTED and
|
||||
category is not self.SOUND_CONNECTION_GREEN):
|
||||
not self.isConnectionSound(category)):
|
||||
# elapsed time since the last sound was played
|
||||
dt = datetime.datetime.now() - self.lastSoundTime
|
||||
# suppress sounds which are more frequent than the threshold
|
||||
if dt.total_seconds() < self.maxSoundFrequencySec:
|
||||
play = False
|
||||
|
||||
if soundFilename is None:
|
||||
# the sound is for an address which exists in the address book
|
||||
if category is self.SOUND_KNOWN:
|
||||
soundFilename = shared.appdata + 'sounds/known'
|
||||
# the sound is for an unknown address
|
||||
elif category is self.SOUND_UNKNOWN:
|
||||
soundFilename = shared.appdata + 'sounds/unknown'
|
||||
# initial connection sound
|
||||
elif category is self.SOUND_CONNECTED:
|
||||
soundFilename = shared.appdata + 'sounds/connected'
|
||||
# disconnected sound
|
||||
elif category is self.SOUND_DISCONNECTED:
|
||||
soundFilename = shared.appdata + 'sounds/disconnected'
|
||||
# sound when the connection status becomes green
|
||||
elif category is self.SOUND_CONNECTION_GREEN:
|
||||
soundFilename = shared.appdata + 'sounds/green'
|
||||
|
||||
if soundFilename is not None and play is True:
|
||||
# record the last time that a sound was played
|
||||
if not self.isConnectionSound(category):
|
||||
# record the last time that a received message sound was played
|
||||
self.lastSoundTime = datetime.datetime.now()
|
||||
|
||||
# if not wav then try mp3 format
|
||||
|
|
Reference in New Issue
Block a user