8 from dbus.mainloop.glib import DBusGMainLoop
11 class CallNotify(hildondesktop.StatusMenuItem):
13 hildondesktop.StatusMenuItem.__init__(self)
15 self.path = "/home/user/.rtcom-eventlogger/el.db"
17 # Prevent multiple timers to refresh the status icon
24 self.missed = self.getMissedCallsCount(False)
25 self.missedSMS = self.getMissedCallsCount(True)
26 self.missedLastCall = self.missed
27 self.missedLastSMS = self.missedSMS
29 # Register to handle screen off/on events
30 osso_c = osso.Context("osso_test_device_on", "0.0.1", False)
31 device = osso.DeviceState(osso_c)
32 device.set_display_event_cb(self.state_cb)
34 self.tmr_main = gobject.timeout_add(5000, self.handleMissedCall)
36 # add d-bus listener for removing notification after viewing missed call
37 # Doing timeout_add with return False instead of explicitly raising a thread
38 gobject.timeout_add(500, self.startDbusListeners)
42 #self.pixbuf = gtk.gdk.pixbuf_new_from_file_at_size("/home/user/phone.png",18,18)
43 icon_theme = gtk.icon_theme_get_default()
44 self.callPicture = icon_theme.load_icon("general_call", 18, gtk.ICON_LOOKUP_NO_SVG)
45 self.smsPicture = gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/sms.png",18,18)
47 # Load 5 numbers and the "+5"
49 #self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/home/user/1.png",18,18))
50 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/1.png",18,18))
51 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/2.png",18,18))
52 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/3.png",18,18))
53 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/4.png",18,18))
54 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/5.png",18,18))
55 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/more.png",18,18))
57 # Screen off event-handler
58 def state_cb(self, state):
59 if state == osso.device_state.OSSO_DISPLAY_OFF:
60 gobject.source_remove(self.tmr_main)
61 gobject.source_remove(self.tmr_ptr)
62 elif state == osso.device_state.OSSO_DISPLAY_ON:
63 self.tmr_main = gobject.timeout_add(5000, self.handleMissedCall)
67 # Method to define the way to add dbus signal receiver
68 def startDbusListeners(self):
69 DBusGMainLoop(set_as_default=True)
70 bus = dbus.SessionBus()
71 #bus.add_signal_receiver(self.stop_notification, "NotificationClosed", "org.freedesktop.Notifications", "org.freedesktop.Notifications", "/org/freedesktop/Notifications")
72 #bus.add_signal_receiver(self.handleMissedCall, "Notify", None, None, None)
73 #bus.add_signal_receiver(self.handleMissedCall, "MembersChanged", None, None, None)
74 bus.add_signal_receiver(self.smsReceived, "MessageReceived", None, None, None)
75 bus.add_signal_receiver(self.smsRead, "NotificationClosed", "org.freedesktop.Notifications", None, "/org/freedesktop/Notifications")
76 gobject.MainLoop().run()
79 def smsReceived(self, a):
80 if a[0].has_key('message-type'):
81 if self.missedLastSMS == self.getMissedCallsCount(True):
82 if self.msgType == "Call":
87 self.missedLastSMS = self.getMissedCallsCount(True)
90 self.stop_notification(a)
92 def handleMissedCall(self):
93 if self.missedLastCall != self.getMissedCallsCount(False):
94 if self.msgType == "SMS":
99 self.missedLastCall = self.getMissedCallsCount(False)
102 def stop_notification(self, a):
103 self.set_status_area_icon(None)
104 gobject.source_remove(self.tmr_ptr)
105 self.set_status_area_icon(None)
106 # Reset the notification (get recent missed call count)
107 self.missed = self.getMissedCallsCount(False)
108 self.missedSMS = self.getMissedCallsCount(True)
109 self.missedLastCall = self.missed
110 self.missedLastSMS = self.missedSMS
115 missedCalls = self.getMissedCallsCount(False)
116 if self.missedLastCall != missedCalls:
118 self.missedLastCall = missedCalls
121 def getMissedCallsCount(self, isSms):
125 conn = sqlite3.connect(self.path)
127 cur.execute("select count(id) from Events where event_type_id = " + str(eType))
128 return cur.fetchone()[0]
131 # blink the icon every 1 second
133 self.tmr_ptr = gobject.timeout_add(1000, self.blinkIcon)
139 img = self.callPicture
140 if self.msgType == "SMS":
141 img = self.smsPicture
142 self.set_status_area_icon(img)
145 img = self.smsPicture
147 counter = self.missed
148 if self.msgType == "SMS":
149 counter = self.missedSMS
151 index = self.getMissedCallsCount(isSMS) - counter - 1
156 if self.msgType != "Both":
157 img = self.imgList[index]
159 self.set_status_area_icon(img)
162 hd_plugin_type = CallNotify