7 from dbus.mainloop.glib import DBusGMainLoop
10 class CallNotify(hildondesktop.StatusMenuItem):
12 hildondesktop.StatusMenuItem.__init__(self)
14 self.path = "/home/user/.rtcom-eventlogger/el.db"
16 # Prevent multiple timers to refresh the status icon
23 self.missed = self.getMissedCallsCount(False)
24 self.missedSMS = self.getMissedCallsCount(True)
25 self.missedLastCall = self.missed
26 self.missedLastSMS = self.missedSMS
27 gobject.timeout_add(5000, self.handleMissedCall)
29 # add d-bus listener for removing notification after viewing missed call
30 # Doing timeout_add with return False instead of explicitly raising a thread
31 gobject.timeout_add(500, self.startDbusListeners)
35 #self.pixbuf = gtk.gdk.pixbuf_new_from_file_at_size("/home/user/phone.png",18,18)
36 icon_theme = gtk.icon_theme_get_default()
37 self.callPicture = icon_theme.load_icon("general_call", 18, gtk.ICON_LOOKUP_NO_SVG)
38 self.smsPicture = gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/sms.png",18,18)
40 # Load 5 numbers and the "+5"
42 #self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/home/user/1.png",18,18))
43 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/1.png",18,18))
44 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/2.png",18,18))
45 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/3.png",18,18))
46 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/4.png",18,18))
47 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/5.png",18,18))
48 self.imgList.append(gtk.gdk.pixbuf_new_from_file_at_size("/usr/share/CallNotify/more.png",18,18))
50 # Method to define the way to add dbus signal receiver
51 def startDbusListeners(self):
52 DBusGMainLoop(set_as_default=True)
53 bus = dbus.SessionBus()
54 #bus.add_signal_receiver(self.stop_notification, "NotificationClosed", "org.freedesktop.Notifications", "org.freedesktop.Notifications", "/org/freedesktop/Notifications")
55 #bus.add_signal_receiver(self.handleMissedCall, "Notify", None, None, None)
56 #bus.add_signal_receiver(self.handleMissedCall, "MembersChanged", None, None, None)
57 bus.add_signal_receiver(self.smsReceived, "Received", "org.freedesktop.Telepathy.Channel.Type.Text", None, None)
58 bus.add_signal_receiver(self.smsRead, "NotificationClosed", "org.freedesktop.Notifications", None, "/org/freedesktop/Notifications")
59 gobject.MainLoop().run()
62 def smsReceived(self, a, b, c, d, e, f):
63 if self.missedLastSMS == self.getMissedCallsCount(True):
64 if self.msgType == "Call":
69 self.missedLastSMS = self.getMissedCallsCount(True)
72 self.stop_notification(a)
74 def handleMissedCall(self):
75 if self.missedLastCall != self.getMissedCallsCount(False):
76 if self.msgType == "SMS":
81 self.missedLastCall = self.getMissedCallsCount(False)
84 def stop_notification(self, a):
85 self.set_status_area_icon(None)
86 gobject.source_remove(self.tmr_ptr)
87 self.set_status_area_icon(None)
88 # Reset the notification (get recent missed call count)
89 self.missed = self.getMissedCallsCount(False)
90 self.missedSMS = self.getMissedCallsCount(True)
91 self.missedLastCall = self.missed
92 self.missedLastSMS = self.missedSMS
97 missedCalls = self.getMissedCallsCount(False)
98 if self.missedLastCall != missedCalls:
100 self.missedLastCall = missedCalls
103 def getMissedCallsCount(self, isSms):
107 conn = sqlite3.connect(self.path)
109 cur.execute("select count(id) from Events where event_type_id = " + str(eType))
110 return cur.fetchone()[0]
113 # blink the icon every 1 second
115 self.tmr_ptr = gobject.timeout_add(1000, self.blinkIcon)
121 img = self.callPicture
122 if self.msgType == "SMS":
123 img = self.smsPicture
124 self.set_status_area_icon(img)
127 img = self.smsPicture
129 counter = self.missed
130 if self.msgType == "SMS":
131 counter = self.missedSMS
133 index = self.getMissedCallsCount(isSMS) - counter - 1
138 if self.msgType != "Both":
139 img = self.imgList[index]
141 self.set_status_area_icon(img)
144 hd_plugin_type = CallNotify