Imported Upstream version 0.0.2
[callnotify] / src / usr / lib / hildon-desktop / CallNotify.py
index d05e5d6..1722673 100644 (file)
@@ -4,6 +4,7 @@ import hildondesktop
 import sqlite3
 import time
 import dbus
+import osso
 from dbus.mainloop.glib import DBusGMainLoop
 
 
@@ -24,7 +25,13 @@ class CallNotify(hildondesktop.StatusMenuItem):
                self.missedSMS = self.getMissedCallsCount(True)
                self.missedLastCall = self.missed
                self.missedLastSMS = self.missedSMS
-               gobject.timeout_add(5000, self.handleMissedCall) 
+               
+               # Register to handle screen off/on events
+               osso_c = osso.Context("osso_test_device_on", "0.0.1", False)
+               device = osso.DeviceState(osso_c)
+               device.set_display_event_cb(self.state_cb)
+
+               self.tmr_main = gobject.timeout_add(5000, self.handleMissedCall) 
                
                # add d-bus listener for removing notification after viewing missed call
                # Doing timeout_add with return False instead of explicitly raising a thread
@@ -47,6 +54,16 @@ class CallNotify(hildondesktop.StatusMenuItem):
                self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/5.png",18,18))
                self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/more.png",18,18))
                
+       # Screen off event-handler
+    def state_cb(self, state):
+       if state == osso.device_state.OSSO_DISPLAY_OFF:
+               gobject.source_remove(self.tmr_main)
+               gobject.source_remove(self.tmr_ptr)
+       elif state == osso.device_state.OSSO_DISPLAY_ON:
+               self.tmr_main = gobject.timeout_add(5000, self.handleMissedCall)
+               self.show()
+       return False
+               
        # Method to define the way to add dbus signal receiver
     def startDbusListeners(self):
                DBusGMainLoop(set_as_default=True)                             
@@ -54,19 +71,20 @@ class CallNotify(hildondesktop.StatusMenuItem):
                 #bus.add_signal_receiver(self.stop_notification, "NotificationClosed", "org.freedesktop.Notifications", "org.freedesktop.Notifications", "/org/freedesktop/Notifications") 
                #bus.add_signal_receiver(self.handleMissedCall, "Notify", None, None, None)
                #bus.add_signal_receiver(self.handleMissedCall, "MembersChanged", None, None, None)
-               bus.add_signal_receiver(self.smsReceived, "Received", "org.freedesktop.Telepathy.Channel.Type.Text", None, None)
+               bus.add_signal_receiver(self.smsReceived, "MessageReceived", None, None, None)
                bus.add_signal_receiver(self.smsRead, "NotificationClosed", "org.freedesktop.Notifications", None, "/org/freedesktop/Notifications")
                 gobject.MainLoop().run()                                       
                return False
     
-    def smsReceived(self, a, b, c, d, e, f):
-       if self.missedLastSMS == self.getMissedCallsCount(True):
-               if self.msgType == "Call":
-                       self.msgType = "Both"
-               else:
-                       self.msgType = "SMS"
-               self.show()
-       self.missedLastSMS = self.getMissedCallsCount(True)
+    def smsReceived(self, a):
+       if a[0].has_key('message-type'):
+               if self.missedLastSMS == self.getMissedCallsCount(True):
+                       if self.msgType == "Call":
+                               self.msgType = "Both"
+                       else:
+                               self.msgType = "SMS"
+                       self.show()
+               self.missedLastSMS = self.getMissedCallsCount(True)
        
     def smsRead(self, a):
        self.stop_notification(a)
@@ -133,7 +151,7 @@ class CallNotify(hildondesktop.StatusMenuItem):
                        index = self.getMissedCallsCount(isSMS) - counter - 1
                        if index >= 5:
                                index = 5
-                               if index < 0
+                               if index < 0:
                                        index = 0
                        if self.msgType != "Both":
                                img = self.imgList[index]