class AudioTest(QMainWindow): def __init__(self, filename): QMainWindow.__init__(self) self.playButton = QPushButton('Play!') self.source = QUrl.fromLocalFile(filename) self.player = QMediaPlayer() self.player.setMedia(self.source) self.playButton.clicked.connect(self.play) self.setCentralWidget(self.playButton) self.playButton.show() def play(self): self.player.play()
class Notifier(): def __init__(self,audio=False,vibra=False): _d = NotifierDebug(); self._d = _d.d; self.manager = MNotificationManager('wazappnotify','WazappNotify'); self.vibra = vibra self.newMessageSound = WAConstants.DEFAULT_SOUND_NOTIFICATION #fetch from settings self.devInfo = QSystemDeviceInfo(); self.devInfo.currentProfileChanged.connect(self.profileChanged); if audio: self.audio = QMediaPlayer(); self.audio.setVolume(100); else: self.audio = False self.enabled = True self.notifications = {} if self.vibra: self.vibra = QFeedbackHapticsEffect(); self.vibra.setIntensity(1.0); self.vibra.setDuration(200); def profileChanged(self): self._d("Profile changed"); def enable(self): self.enabled = True def disable(self): self.enabled = False def saveNotification(self,jid,data): self.notifications[jid] = data; def getCurrentSoundPath(self): activeProfile = self.devInfo.currentProfile(); if activeProfile in (QSystemDeviceInfo.Profile.NormalProfile,QSystemDeviceInfo.Profile.LoudProfile): if self.enabled: return self.newMessageSound; else: return WAConstants.FOCUSED_SOUND_NOTIFICATION elif activeProfile == QSystemDeviceInfo.Profile.BeepProfile: return WAConstants.DEFAULT_BEEP_NOTIFICATION else: return WAConstants.NO_SOUND def hideNotification(self,jid): if self.notifications.has_key(jid): #jid = jids[0] nId = self.notifications[jid]["id"]; del self.notifications[jid] self._d("DELETING NOTIFICATION BY ID "+str(nId)); self.manager.removeNotification(nId); def notificationCallback(self,jid): #nId = 0 #jids = [key for key,value in self.notifications.iteritems() if value["id"]==nId] #if len(jids): if self.notifications.has_key(jid): #jid = jids[0] nId = self.notifications[jid]["id"]; self.notifications[jid]["callback"](jid); del self.notifications[jid] #self.manager.removeNotification(nId); def newMessage(self,jid,contactName,message,picture=None,callback=False): activeConvJId = self.ui.getActiveConversation() max_len = min(len(message),20) if self.enabled: if(activeConvJId == jid or activeConvJId == ""): if self.vibra: self.vibra.start() return n = MNotification("wazapp.message.new",contactName, message); n.image = picture n.manager = self.manager; action = lambda: self.notificationCallback(jid) n.setAction(action); notifications = n.notifications(); if self.notifications.has_key(jid): nId = self.notifications[jid]['id']; for notify in notifications: if int(notify[0]) == nId: n.id = nId break if n.id != nId: del self.notifications[jid] if(n.publish()): nId = n.id; self.saveNotification(jid,{"id":nId,"callback":callback}); #if self.vibra: # self.vibra.start() if self.audio: soundPath = self.getCurrentSoundPath(); self._d(soundPath) self.audio.setMedia(QUrl.fromLocalFile(soundPath)); self.audio.play();
class Notifier(): def __init__(self,audio=False,vibra=True): self.manager = MNotificationManager('wazappnotify','WazappNotify'); self.vibra = vibra self.newMessageSound = WAConstants.DEFAULT_SOUND_NOTIFICATION #fetch from settings self.devInfo = QSystemDeviceInfo(); self.devInfo.currentProfileChanged.connect(self.profileChanged); if audio: self.audio = QMediaPlayer(); self.audio.setVolume(100); else: self.audio = False self.enabled = True self.notifications = {} if self.vibra: self.vibra = QFeedbackHapticsEffect(); self.vibra.setIntensity(1.0); self.vibra.setDuration(200); def profileChanged(self): print "Profile changed"; def enable(self): #print "enabling notif" self.enabled = True def disable(self): #print "disabling notif" self.enabled = False def saveNotification(self,jid,data): self.notifications[jid] = data; def getCurrentSoundPath(self): activeProfile = self.devInfo.currentProfile(); if activeProfile in (QSystemDeviceInfo.Profile.NormalProfile,QSystemDeviceInfo.Profile.LoudProfile): if self.enabled: return self.newMessageSound; else: return WAConstants.FOCUSED_SOUND_NOTIFICATION elif activeProfile == QSystemDeviceInfo.Profile.BeepProfile: return WAConstants.DEFAULT_BEEP_NOTIFICATION else: return WAConstants.NO_SOUND def hideNotification(self,jid): if self.notifications.has_key(jid): #jid = jids[0] nId = self.notifications[jid]["id"]; del self.notifications[jid] print "DELETING NOTIFICATION BY ID "+str(nId); self.manager.removeNotification(nId); def notificationCallback(self,jid): #nId = 0 #jids = [key for key,value in self.notifications.iteritems() if value["id"]==nId] #if len(jids): if self.notifications.has_key(jid): #jid = jids[0] nId = self.notifications[jid]["id"]; self.notifications[jid]["callback"](jid); del self.notifications[jid] #self.manager.removeNotification(nId); def newMessage(self,jid,contactName,message,picture=None,callback=False): activeConvJId = self.ui.getActiveConversation() max_len = min(len(message),20) if self.enabled: if(activeConvJId == jid or activeConvJId == ""): if self.vibra: self.vibra.start() return n = MNotification("wazapp.message.new",contactName, message); n.image = picture n.manager = self.manager; action = lambda: self.notificationCallback(jid) n.setAction(action); notifications = n.notifications(); if self.notifications.has_key(jid): nId = self.notifications[jid]['id']; for notify in notifications: if int(notify[0]) == nId: n.id = nId break if n.id != nId: del self.notifications[jid] if(n.publish()): nId = n.id; self.saveNotification(jid,{"id":nId,"callback":callback}); #if self.vibra: # self.vibra.start() if self.audio: soundPath = self.getCurrentSoundPath(); print soundPath self.audio.setMedia(QUrl.fromLocalFile(soundPath)); self.audio.play();