minimal audio notifications (using phonon)

This commit is contained in:
ingvar1995 2016-03-11 19:46:30 +03:00
parent 05bf4cd97f
commit 6c2da5e767
3 changed files with 25 additions and 6 deletions

View File

@ -83,9 +83,8 @@ def friend_name(window):
return wrapped
def friend_status_message(window):
def friend_status_message():
"""
:param window: main window
:return: function for callback friend_status_message. It updates friend's status message
and calls window repaint
"""
@ -113,6 +112,8 @@ def friend_message(window):
friend = profile.get_friend_by_number(friend_number)
if settings['notifications']:
invoke_in_main_thread(tray_notification, friend.name, message.decode('utf8'))
if settings['sound_notifications']:
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
return wrapped
@ -136,5 +137,5 @@ def init_callbacks(tox, window):
tox.callback_self_connection_status(self_connection_status(tox), 0)
tox.callback_friend_connection_status(friend_connection_status, 0)
tox.callback_friend_name(friend_name(window), 0)
tox.callback_friend_status_message(friend_status_message(window), 0)
tox.callback_friend_status_message(friend_status_message(), 0)
tox.callback_friend_request(friend_request, 0)

View File

@ -295,8 +295,8 @@ class NotificationsSettings(CenteredWidget):
def retranslateUi(self):
self.setWindowTitle(QtGui.QApplication.translate("notificationsForm", "Notification settings", None, QtGui.QApplication.UnicodeUTF8))
self.enableNotifications.setText(QtGui.QApplication.translate("notificationsForm", "Enable notifications", None, QtGui.QApplication.UnicodeUTF8))
self.soundNotifications.setText(QtGui.QApplication.translate("notificationsForm", "Enable call\'s sound", None, QtGui.QApplication.UnicodeUTF8))
self.callsSound.setText(QtGui.QApplication.translate("notificationsForm", "Enable sound notifications", None, QtGui.QApplication.UnicodeUTF8))
self.callsSound.setText(QtGui.QApplication.translate("notificationsForm", "Enable call\'s sound", None, QtGui.QApplication.UnicodeUTF8))
self.soundNotifications.setText(QtGui.QApplication.translate("notificationsForm", "Enable sound notifications", None, QtGui.QApplication.UnicodeUTF8))
def closeEvent(self, *args, **kwargs):
settings = Settings.get_instance()

View File

@ -1,9 +1,16 @@
from PySide import QtGui
from PySide.phonon import Phonon
from util import curr_directory
# TODO: add sound notifications
# TODO: make app icon active
SOUND_NOTIFICATION = {
'MESSAGE': 0,
'FRIEND_CONNECTION_STATUS': 1,
'FILE_TRANSFER': 2
}
def tray_notification(title, text):
if QtGui.QSystemTrayIcon.isSystemTrayAvailable():
tray = QtGui.QSystemTrayIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
@ -12,3 +19,14 @@ def tray_notification(title, text):
if len(text) > 30:
text = text[:27] + '...'
tray.showMessage(title, text, QtGui.QSystemTrayIcon.NoIcon, 3000)
def sound_notification(t):
# TODO: add other sound notifications
if t == SOUND_NOTIFICATION['MESSAGE']:
f = curr_directory() + '/sounds/message.wav'
else:
return
m = Phonon.MediaSource(f)
player = Phonon.createPlayer(Phonon.MusicCategory, m)
player.play()