minimal audio notifications (using phonon)
This commit is contained in:
parent
05bf4cd97f
commit
6c2da5e767
@ -83,9 +83,8 @@ def friend_name(window):
|
|||||||
return wrapped
|
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
|
:return: function for callback friend_status_message. It updates friend's status message
|
||||||
and calls window repaint
|
and calls window repaint
|
||||||
"""
|
"""
|
||||||
@ -113,6 +112,8 @@ def friend_message(window):
|
|||||||
friend = profile.get_friend_by_number(friend_number)
|
friend = profile.get_friend_by_number(friend_number)
|
||||||
if settings['notifications']:
|
if settings['notifications']:
|
||||||
invoke_in_main_thread(tray_notification, friend.name, message.decode('utf8'))
|
invoke_in_main_thread(tray_notification, friend.name, message.decode('utf8'))
|
||||||
|
if settings['sound_notifications']:
|
||||||
|
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
@ -136,5 +137,5 @@ def init_callbacks(tox, window):
|
|||||||
tox.callback_self_connection_status(self_connection_status(tox), 0)
|
tox.callback_self_connection_status(self_connection_status(tox), 0)
|
||||||
tox.callback_friend_connection_status(friend_connection_status, 0)
|
tox.callback_friend_connection_status(friend_connection_status, 0)
|
||||||
tox.callback_friend_name(friend_name(window), 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)
|
tox.callback_friend_request(friend_request, 0)
|
||||||
|
@ -295,8 +295,8 @@ class NotificationsSettings(CenteredWidget):
|
|||||||
def retranslateUi(self):
|
def retranslateUi(self):
|
||||||
self.setWindowTitle(QtGui.QApplication.translate("notificationsForm", "Notification settings", None, QtGui.QApplication.UnicodeUTF8))
|
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.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 call\'s sound", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
self.callsSound.setText(QtGui.QApplication.translate("notificationsForm", "Enable sound notifications", None, QtGui.QApplication.UnicodeUTF8))
|
self.soundNotifications.setText(QtGui.QApplication.translate("notificationsForm", "Enable sound notifications", None, QtGui.QApplication.UnicodeUTF8))
|
||||||
|
|
||||||
def closeEvent(self, *args, **kwargs):
|
def closeEvent(self, *args, **kwargs):
|
||||||
settings = Settings.get_instance()
|
settings = Settings.get_instance()
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
from PySide import QtGui
|
from PySide import QtGui
|
||||||
|
from PySide.phonon import Phonon
|
||||||
from util import curr_directory
|
from util import curr_directory
|
||||||
# TODO: add sound notifications
|
|
||||||
# TODO: make app icon active
|
# TODO: make app icon active
|
||||||
|
|
||||||
|
|
||||||
|
SOUND_NOTIFICATION = {
|
||||||
|
'MESSAGE': 0,
|
||||||
|
'FRIEND_CONNECTION_STATUS': 1,
|
||||||
|
'FILE_TRANSFER': 2
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def tray_notification(title, text):
|
def tray_notification(title, text):
|
||||||
if QtGui.QSystemTrayIcon.isSystemTrayAvailable():
|
if QtGui.QSystemTrayIcon.isSystemTrayAvailable():
|
||||||
tray = QtGui.QSystemTrayIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
|
tray = QtGui.QSystemTrayIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
|
||||||
@ -12,3 +19,14 @@ def tray_notification(title, text):
|
|||||||
if len(text) > 30:
|
if len(text) > 30:
|
||||||
text = text[:27] + '...'
|
text = text[:27] + '...'
|
||||||
tray.showMessage(title, text, QtGui.QSystemTrayIcon.NoIcon, 3000)
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user