2016-04-01 16:13:01 +00:00
|
|
|
from PySide import QtGui, QtCore
|
2016-03-11 16:46:30 +00:00
|
|
|
from PySide.phonon import Phonon
|
2016-02-25 08:32:40 +00:00
|
|
|
from util import curr_directory
|
2016-04-02 11:41:06 +00:00
|
|
|
# TODO: rewrite sound notifications
|
2016-02-24 18:38:36 +00:00
|
|
|
|
|
|
|
|
2016-03-11 16:46:30 +00:00
|
|
|
SOUND_NOTIFICATION = {
|
|
|
|
'MESSAGE': 0,
|
|
|
|
'FRIEND_CONNECTION_STATUS': 1,
|
|
|
|
'FILE_TRANSFER': 2
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-01 16:13:01 +00:00
|
|
|
def tray_notification(title, text, tray, window):
|
|
|
|
"""
|
2016-04-02 18:31:59 +00:00
|
|
|
Show tray notification and activate window icon
|
|
|
|
NOTE: different behaviour on different OS
|
2016-04-01 16:13:01 +00:00
|
|
|
:param title: Name of user who sent message or file
|
|
|
|
:param text: text of message or file info
|
|
|
|
:param tray: ref to tray icon
|
|
|
|
:param window: main window
|
|
|
|
"""
|
2016-02-24 18:38:36 +00:00
|
|
|
if QtGui.QSystemTrayIcon.isSystemTrayAvailable():
|
2016-02-25 08:32:40 +00:00
|
|
|
if len(text) > 30:
|
2016-02-25 20:40:00 +00:00
|
|
|
text = text[:27] + '...'
|
2016-02-25 08:32:40 +00:00
|
|
|
tray.showMessage(title, text, QtGui.QSystemTrayIcon.NoIcon, 3000)
|
2016-04-02 18:31:59 +00:00
|
|
|
QtGui.QApplication.alert(window, 0)
|
2016-03-11 16:46:30 +00:00
|
|
|
|
2016-04-01 16:13:01 +00:00
|
|
|
def message_clicked():
|
|
|
|
window.setWindowState(window.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
|
|
|
|
window.activateWindow()
|
|
|
|
tray.connect(tray, QtCore.SIGNAL("messageClicked()"), message_clicked)
|
|
|
|
|
2016-03-11 16:46:30 +00:00
|
|
|
|
|
|
|
def sound_notification(t):
|
2016-04-02 18:31:59 +00:00
|
|
|
"""
|
|
|
|
Plays sound notification
|
|
|
|
:param t: type of notification
|
|
|
|
"""
|
2016-03-11 16:46:30 +00:00
|
|
|
if t == SOUND_NOTIFICATION['MESSAGE']:
|
|
|
|
f = curr_directory() + '/sounds/message.wav'
|
2016-03-18 13:50:32 +00:00
|
|
|
elif t == SOUND_NOTIFICATION['FILE_TRANSFER']:
|
|
|
|
f = curr_directory() + '/sounds/file.wav'
|
2016-03-11 16:46:30 +00:00
|
|
|
else:
|
2016-04-01 14:38:24 +00:00
|
|
|
f = curr_directory() + '/sounds/contact.wav'
|
2016-03-11 16:46:30 +00:00
|
|
|
m = Phonon.MediaSource(f)
|
|
|
|
player = Phonon.createPlayer(Phonon.MusicCategory, m)
|
|
|
|
player.play()
|