Moved sound category constants to the separate module sound
for importing from the sound theme plugins.
This commit is contained in:
parent
289a6c5bfa
commit
cd81718871
|
@ -84,6 +84,7 @@ import state
|
||||||
from statusbar import BMStatusBar
|
from statusbar import BMStatusBar
|
||||||
import throttle
|
import throttle
|
||||||
from version import softwareVersion
|
from version import softwareVersion
|
||||||
|
import sound
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from plugins.plugin import get_plugin, get_plugins
|
from plugins.plugin import get_plugin, get_plugins
|
||||||
|
@ -141,14 +142,6 @@ def change_translation(newlocale):
|
||||||
|
|
||||||
class MyForm(settingsmixin.SMainWindow):
|
class MyForm(settingsmixin.SMainWindow):
|
||||||
|
|
||||||
# sound type constants
|
|
||||||
SOUND_NONE = 0
|
|
||||||
SOUND_KNOWN = 1
|
|
||||||
SOUND_UNKNOWN = 2
|
|
||||||
SOUND_CONNECTED = 3
|
|
||||||
SOUND_DISCONNECTED = 4
|
|
||||||
SOUND_CONNECTION_GREEN = 5
|
|
||||||
|
|
||||||
# the last time that a message arrival sound was played
|
# the last time that a message arrival sound was played
|
||||||
lastSoundTime = datetime.now() - timedelta(days=1)
|
lastSoundTime = datetime.now() - timedelta(days=1)
|
||||||
|
|
||||||
|
@ -1362,15 +1355,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
# update the menu entries
|
# update the menu entries
|
||||||
self.ubuntuMessagingMenuUnread(drawAttention)
|
self.ubuntuMessagingMenuUnread(drawAttention)
|
||||||
|
|
||||||
# returns true if the given sound category is a connection sound
|
|
||||||
# rather than a received message sound
|
|
||||||
def isConnectionSound(self, category):
|
|
||||||
return category in (
|
|
||||||
self.SOUND_CONNECTED,
|
|
||||||
self.SOUND_DISCONNECTED,
|
|
||||||
self.SOUND_CONNECTION_GREEN
|
|
||||||
)
|
|
||||||
|
|
||||||
# play a sound
|
# play a sound
|
||||||
def playSound(self, category, label):
|
def playSound(self, category, label):
|
||||||
# filename of the sound to be played
|
# filename of the sound to be played
|
||||||
|
@ -1387,14 +1371,14 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
soundFilename = state.appdata + 'sounds/' + label
|
soundFilename = state.appdata + 'sounds/' + label
|
||||||
ext = _choose_ext(soundFilename)
|
ext = _choose_ext(soundFilename)
|
||||||
if not ext:
|
if not ext:
|
||||||
category = self.SOUND_KNOWN
|
category = sound.SOUND_KNOWN
|
||||||
soundFilename = None
|
soundFilename = None
|
||||||
|
|
||||||
if soundFilename is None:
|
if soundFilename is None:
|
||||||
# Avoid making sounds more frequently than the threshold.
|
# Avoid making sounds more frequently than the threshold.
|
||||||
# This suppresses playing sounds repeatedly when there
|
# This suppresses playing sounds repeatedly when there
|
||||||
# are many new messages
|
# are many new messages
|
||||||
if not self.isConnectionSound(category):
|
if not sound.is_connection_sound(category):
|
||||||
# elapsed time since the last sound was played
|
# elapsed time since the last sound was played
|
||||||
dt = datetime.now() - self.lastSoundTime
|
dt = datetime.now() - self.lastSoundTime
|
||||||
# suppress sounds which are more frequent than the threshold
|
# suppress sounds which are more frequent than the threshold
|
||||||
|
@ -1402,26 +1386,26 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
return
|
return
|
||||||
|
|
||||||
# the sound is for an address which exists in the address book
|
# the sound is for an address which exists in the address book
|
||||||
if category is self.SOUND_KNOWN:
|
if category is sound.SOUND_KNOWN:
|
||||||
soundFilename = state.appdata + 'sounds/known'
|
soundFilename = state.appdata + 'sounds/known'
|
||||||
# the sound is for an unknown address
|
# the sound is for an unknown address
|
||||||
elif category is self.SOUND_UNKNOWN:
|
elif category is sound.SOUND_UNKNOWN:
|
||||||
soundFilename = state.appdata + 'sounds/unknown'
|
soundFilename = state.appdata + 'sounds/unknown'
|
||||||
# initial connection sound
|
# initial connection sound
|
||||||
elif category is self.SOUND_CONNECTED:
|
elif category is sound.SOUND_CONNECTED:
|
||||||
soundFilename = state.appdata + 'sounds/connected'
|
soundFilename = state.appdata + 'sounds/connected'
|
||||||
# disconnected sound
|
# disconnected sound
|
||||||
elif category is self.SOUND_DISCONNECTED:
|
elif category is sound.SOUND_DISCONNECTED:
|
||||||
soundFilename = state.appdata + 'sounds/disconnected'
|
soundFilename = state.appdata + 'sounds/disconnected'
|
||||||
# sound when the connection status becomes green
|
# sound when the connection status becomes green
|
||||||
elif category is self.SOUND_CONNECTION_GREEN:
|
elif category is sound.SOUND_CONNECTION_GREEN:
|
||||||
soundFilename = state.appdata + 'sounds/green'
|
soundFilename = state.appdata + 'sounds/green'
|
||||||
|
|
||||||
if soundFilename is None:
|
if soundFilename is None:
|
||||||
logger.warning("Probably wrong category number in playSound()")
|
logger.warning("Probably wrong category number in playSound()")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.isConnectionSound(category):
|
if not sound.is_connection_sound(category):
|
||||||
# record the last time that a received message sound was played
|
# record the last time that a received message sound was played
|
||||||
self.lastSoundTime = datetime.now()
|
self.lastSoundTime = datetime.now()
|
||||||
|
|
||||||
|
@ -1664,7 +1648,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
self.notifierShow(
|
self.notifierShow(
|
||||||
'Bitmessage',
|
'Bitmessage',
|
||||||
_translate("MainWindow", "Connection lost"),
|
_translate("MainWindow", "Connection lost"),
|
||||||
self.SOUND_DISCONNECTED)
|
sound.SOUND_DISCONNECTED)
|
||||||
if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'upnp') and \
|
if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'upnp') and \
|
||||||
BMConfigParser().get('bitmessagesettings', 'socksproxytype') == "none":
|
BMConfigParser().get('bitmessagesettings', 'socksproxytype') == "none":
|
||||||
self.statusBar().showMessage(_translate(
|
self.statusBar().showMessage(_translate(
|
||||||
|
@ -1686,7 +1670,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
self.notifierShow(
|
self.notifierShow(
|
||||||
'Bitmessage',
|
'Bitmessage',
|
||||||
_translate("MainWindow", "Connected"),
|
_translate("MainWindow", "Connected"),
|
||||||
self.SOUND_CONNECTED)
|
sound.SOUND_CONNECTED)
|
||||||
self.connected = True
|
self.connected = True
|
||||||
|
|
||||||
if self.actionStatus is not None:
|
if self.actionStatus is not None:
|
||||||
|
@ -1703,7 +1687,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
self.notifierShow(
|
self.notifierShow(
|
||||||
'Bitmessage',
|
'Bitmessage',
|
||||||
_translate("MainWindow", "Connected"),
|
_translate("MainWindow", "Connected"),
|
||||||
self.SOUND_CONNECTION_GREEN)
|
sound.SOUND_CONNECTION_GREEN)
|
||||||
self.connected = True
|
self.connected = True
|
||||||
|
|
||||||
if self.actionStatus is not None:
|
if self.actionStatus is not None:
|
||||||
|
@ -2254,7 +2238,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
_translate("MainWindow", "New Message"),
|
_translate("MainWindow", "New Message"),
|
||||||
_translate("MainWindow", "From %1").arg(
|
_translate("MainWindow", "From %1").arg(
|
||||||
unicode(acct.fromLabel, 'utf-8')),
|
unicode(acct.fromLabel, 'utf-8')),
|
||||||
self.SOUND_UNKNOWN
|
sound.SOUND_UNKNOWN
|
||||||
)
|
)
|
||||||
if self.getCurrentAccount() is not None and ((self.getCurrentFolder(treeWidget) != "inbox" and self.getCurrentFolder(treeWidget) is not None) or self.getCurrentAccount(treeWidget) != acct.address):
|
if self.getCurrentAccount() is not None and ((self.getCurrentFolder(treeWidget) != "inbox" and self.getCurrentFolder(treeWidget) is not None) or self.getCurrentAccount(treeWidget) != acct.address):
|
||||||
# Ubuntu should notify of new message irespective of whether it's in current message list or not
|
# Ubuntu should notify of new message irespective of whether it's in current message list or not
|
||||||
|
|
19
src/bitmessageqt/sound.py
Normal file
19
src/bitmessageqt/sound.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# sound type constants
|
||||||
|
SOUND_NONE = 0
|
||||||
|
SOUND_KNOWN = 1
|
||||||
|
SOUND_UNKNOWN = 2
|
||||||
|
SOUND_CONNECTED = 3
|
||||||
|
SOUND_DISCONNECTED = 4
|
||||||
|
SOUND_CONNECTION_GREEN = 5
|
||||||
|
|
||||||
|
|
||||||
|
# returns true if the given sound category is a connection sound
|
||||||
|
# rather than a received message sound
|
||||||
|
def is_connection_sound(category):
|
||||||
|
return category in (
|
||||||
|
SOUND_CONNECTED,
|
||||||
|
SOUND_DISCONNECTED,
|
||||||
|
SOUND_CONNECTION_GREEN
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user