def on_event_added(self, event): account = event.account jid = event.jid when = time.localtime() contact = "" key = (account, jid) if event.type_ == "chat" or \ event.type_ == "printed_chat" or \ event.type_ == "normal" or \ event.type_ == "printed_normal" or \ event.type_ == "file-request" or \ event.type_ == "jingle-incoming": contact = gajim.contacts.get_contact_from_full_jid(account, jid) if contact: contact = contact.get_shown_name() else: contact = jid elif event.type_ == "pm" or event.type_ == "printed_pm": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) + \ "/" + gajim.get_room_and_nick_from_fjid(jid)[1] elif event.type_ == "printed_marked_gc_msg": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) else: return #print account, jid, when, contact event.time = when if key not in self.events: icon = None if gajim.config.get("show_avatars_in_roster"): pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid) if pixbuf not in (None, "ask"): icon = gtk.Image() icon.set_from_pixbuf(pixbuf) else: file_path = gtkgui_helpers.get_path_to_generic_or_avatar(jid) if os.path.isfile(file_path): fd = fopen(file_path, 'rb') data = fd.read() icon = gtk.Image() icon.set_from_pixbuf(gtkgui_helpers.get_pixbuf_from_data(data)) item = gtk.ImageMenuItem(contact + " (1)") if icon: item.set_image(icon) item.set_always_show_image(True) item.connect("activate", self.event_raise, event) item.show() self.menu.insert(item, self.menuEventInsertIndex) self.event_separator.show() self.events[key] = {} self.events[key]['item'] = item self.events[key]['contact'] = contact self.events[key]['events'] = [event] else: self.events[key]['events'].append(event) item = self.events[key]['item'] item.set_label(self.events[key]['contact'] + " (" + str(len(self.events[key]['events'])) + ")") self.indicator.set_status(appindicator.STATUS_ATTENTION)
def on_event_added(self, event): account = event.account jid = event.jid when = time.time() contact = "" key = (account, jid) if event.type_ == "chat" or \ event.type_ == "printed_chat" or \ event.type_ == "normal" or \ event.type_ == "printed_normal" or \ event.type_ == "file-request" or \ event.type_ == "jingle-incoming": contact = gajim.contacts.get_contact_from_full_jid(account, jid) if contact: contact = contact.get_shown_name() else: contact = jid elif event.type_ == "pm" or event.type_ == "printed_pm": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) + \ "/" + gajim.get_room_and_nick_from_fjid(jid)[1] elif event.type_ == "printed_marked_gc_msg": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) else: return #print account, jid, when, contact event.time = when if key not in self.events: icon = None if gajim.config.get("show_avatars_in_roster"): pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid) if pixbuf not in (None, "ask"): icon = gtk.Image() icon.set_from_pixbuf(pixbuf) else: file_path = gtkgui_helpers.get_path_to_generic_or_avatar(jid) if os.path.isfile(file_path): fd = fopen(file_path, 'rb') data = fd.read() icon = gtk.Image() icon.set_from_pixbuf(gtkgui_helpers.get_pixbuf_from_data(data)) item = gtk.ImageMenuItem(contact + " (1)") if icon: item.set_image(icon) item.set_always_show_image(True) item.connect("activate", self.event_raise, event) item.show() self.menu.insert(item, self.menuEventInsertIndex) self.event_separator.show() self.events[key] = {} self.events[key]['item'] = item self.events[key]['contact'] = contact self.events[key]['events'] = [event] else: self.events[key]['events'].append(event) item = self.events[key]['item'] item.set_label(self.events[key]['contact'] + " (" + str(len(self.events[key]['events'])) + ")") self.indicator.set_status(appindicator.STATUS_ATTENTION)
def on_event_added(self, event): """ Adds "Nickname Time" to the Messaging menu. """ print "----", event.type_ # Basic variables account = event.account jid = event.jid when = time.time() contact = "" # Check if the event is valid and modify the variables if event.type_ == "chat" or \ event.type_ == "printed_chat" or \ event.type_ == "normal" or \ event.type_ == "printed_normal" or \ event.type_ == "file-request" or \ event.type_ == "jingle-incoming": contact = gajim.contacts.get_contact_from_full_jid(account, jid) if contact: contact = contact.get_shown_name() else: contact = jid elif event.type_ == "pm" or event.type_ == "printed_pm": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) \ + "/" + gajim.get_room_and_nick_from_fjid(jid)[1] elif event.type_ == "printed_marked_gc_msg": contact = gajim.get_nick_from_jid(gajim.get_room_from_fjid(jid)) else: print "ignored" return print account, jid, when, contact # Add a new indicator if necessary key = (account, jid) if not key in self.events: indicator = indicate.Indicator() indicator.set_property("name", contact) indicator.set_property_time("time", when) indicator.set_property_bool("draw-attention", True) indicator.connect("user-display", self.on_indicator_activate) indicator.show() indicator.key = key self.events[key] = (indicator, []) # Prepare the event and save it event.time = when self.events[key][1].append(event)