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 __init__(self,audio=True,vibra=True): _d = NotifierDebug(); self._d = _d.d; self.manager = MNotificationManager('wazappnotify','WazappNotify'); self.vibra = vibra self.personalRingtone = WAConstants.DEFAULT_SOUND_NOTIFICATION; self.personalVibrate = True; self.groupRingtone = WAConstants.DEFAULT_SOUND_NOTIFICATION; self.groupVibrate = True; QCoreApplication.setApplicationName("Wazapp"); self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, None) self.mediaObject = Phonon.MediaObject(None) Phonon.createPath(self.mediaObject, self.audioOutput) self.profileChanged(0, 0, self.getCurrentProfile(), 0) bus = dbus.SessionBus() mybus = bus.get_object('com.nokia.profiled', '/com/nokia/profiled') self.nface = dbus.Interface(mybus, 'com.nokia.profiled') self.nface.connect_to_signal("profile_changed", self.profileChanged) #prof = self.getCurrentProfile() #reply = self.nface.get_value(prof,"ringing.alert.volume"); #self.currentProfile = prof #self.currentVolume = "1.0" if reply=="100" else "0." + reply #self._d("Checking current profile: " + prof + " - Volume: " + self.currentVolume) #self.audioOutput.setVolume(float(self.currentVolume)) #self.newMessageSound = WAConstants.DEFAULT_SOUND_NOTIFICATION #fetch from settings self.devInfo = QSystemDeviceInfo(); #self.devInfo.currentProfileChanged.connect(self.profileChanged); self.audio = True '''if audio: self.audio = QMediaPlayer(None,QMediaPlayer.LowLatency); self.audio.setVolume(100); else: self.audio = False''' self.enabled = True self.notifications = {} # vibration comes too early here, now handled by ui.py when the message is already added in QML # well, the truth is that sound comes too late... :D #>> Any notification should be handler by the notifier, not UI :P I don't feel it's too early though, # but if necessary connect to a signal and vibrate from here. if self.vibra: self.vibra = QFeedbackHapticsEffect(); self.vibra.setIntensity(1.0); self.vibra.setDuration(200);
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);
class Notifier(): def __init__(self,audio=True,vibra=True): _d = NotifierDebug(); self._d = _d.d; self.manager = MNotificationManager('wazappnotify','WazappNotify'); self.vibra = vibra self.personalRingtone = WAConstants.DEFAULT_SOUND_NOTIFICATION; self.personalVibrate = True; self.groupRingtone = WAConstants.DEFAULT_SOUND_NOTIFICATION; self.groupVibrate = True; QCoreApplication.setApplicationName("Wazapp"); self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, None) self.mediaObject = Phonon.MediaObject(None) Phonon.createPath(self.mediaObject, self.audioOutput) self.profileChanged(0, 0, self.getCurrentProfile(), 0) bus = dbus.SessionBus() mybus = bus.get_object('com.nokia.profiled', '/com/nokia/profiled') self.nface = dbus.Interface(mybus, 'com.nokia.profiled') self.nface.connect_to_signal("profile_changed", self.profileChanged) #prof = self.getCurrentProfile() #reply = self.nface.get_value(prof,"ringing.alert.volume"); #self.currentProfile = prof #self.currentVolume = "1.0" if reply=="100" else "0." + reply #self._d("Checking current profile: " + prof + " - Volume: " + self.currentVolume) #self.audioOutput.setVolume(float(self.currentVolume)) #self.newMessageSound = WAConstants.DEFAULT_SOUND_NOTIFICATION #fetch from settings self.devInfo = QSystemDeviceInfo(); #self.devInfo.currentProfileChanged.connect(self.profileChanged); self.audio = True '''if audio: self.audio = QMediaPlayer(None,QMediaPlayer.LowLatency); self.audio.setVolume(100); else: self.audio = False''' self.enabled = True self.notifications = {} # vibration comes too early here, now handled by ui.py when the message is already added in QML # well, the truth is that sound comes too late... :D #>> Any notification should be handler by the notifier, not UI :P I don't feel it's too early though, # but if necessary connect to a signal and vibrate from here. if self.vibra: self.vibra = QFeedbackHapticsEffect(); self.vibra.setIntensity(1.0); self.vibra.setDuration(200); def getCurrentProfile(self): bus = dbus.SessionBus() notifierbus = bus.get_object('com.nokia.profiled', '/com/nokia/profiled') nface = dbus.Interface(notifierbus, 'com.nokia.profiled') reply = nface.get_profile(); return reply; def profileChanged(self,arg1,arg2,profile,arg4): self._d("Profile changed"); nbus = dbus.SessionBus() mynbus = nbus.get_object('com.nokia.profiled', '/com/nokia/profiled') nface = dbus.Interface(mynbus, 'com.nokia.profiled') reply = nface.get_value(profile,"ringing.alert.volume"); self.currentProfile = profile volume = int(reply) / 100.0 self.currentVolume = str(volume) self._d("Checking current profile: " + profile + " - Volume: " + self.currentVolume) self.audioOutput.setVolume(volume) def enable(self): self.enabled = True def disable(self): self.enabled = False def saveNotification(self,jid,data): self.notifications[jid] = data; def getCurrentSoundPath(self,ringtone): #activeProfile = self.devInfo.currentProfile(); if self.currentProfile == "general": return ringtone elif self.currentProfile == "meeting": return WAConstants.FOCUSED_SOUND_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); self.mediaObject.clear() 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 stopSound(self): self.mediaObject.clear() def playSound(self,soundfile): self.mediaObject.clear() self.mediaObject.setCurrentSource(Phonon.MediaSource(soundfile)) self.mediaObject.play() def newGroupMessage(self,jid,contactName,message,picture=None,callback=False): self.newMessage(jid,contactName,message,self.groupRingtone, self.groupVibrate, picture, callback) def newSingleMessage(self,jid,contactName,message,picture=None,callback=False): self.newMessage(jid,contactName,message,self.personalRingtone, self.personalVibrate, picture, callback) def newMessage(self,jid,contactName,message,ringtone,vibration,picture=None,callback=False): message = message.replace("<br />", "\n").replace("<", "<").replace(">", ">").replace(""", "\"").replace("&", "&") self._d("NEW NOTIFICATION! Ringtone: " + ringtone + " - Vibrate: " + str(vibration)) activeConvJId = self.ui.getActiveConversation() max_len = min(len(message),20) if self.enabled: if(activeConvJId == jid or activeConvJId == ""): if self.audio and ringtone!= WAConstants.NO_SOUND: soundPath = WAConstants.DEFAULT_BEEP_NOTIFICATION; self._d(soundPath) self.playSound(soundPath) if self.vibra and vibration: self.vibra.start() return if self.audio and ringtone!=WAConstants.NO_SOUND: soundPath = self.getCurrentSoundPath(ringtone); self._d(soundPath) self.playSound(soundPath) 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 and vibration: self.vibra.start()
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();