From 78eac624de7046102fe02e80bd27beada98375a5 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 24 Apr 2006 22:22:18 -0400 Subject: [PATCH] Use some icons for chat notifications --- chat/bubble.png | Bin 0 -> 255 bytes chat/bubbleOutline.png | Bin 0 -> 284 bytes chat/chat.py | 92 +++++++++++++++++++++++++++++------------ 3 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 chat/bubble.png create mode 100644 chat/bubbleOutline.png diff --git a/chat/bubble.png b/chat/bubble.png new file mode 100644 index 0000000000000000000000000000000000000000..3d1503df9fc5f20088310f03fc2f9e51fc0b5daf GIT binary patch literal 255 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4v7|ftIx;X^yK%)o!U)KhEOCt} z3C>R|DNig)WpGT%PfAtr%uP&B4N6T+sVqF1Y6Da>(bL5-q~cc6pa1{uog*Sz_?VfS z#!&D>MGH231{cSa~tMZDQrtWz{kf_C@eg|;}|?${an^LB{Ts5!d_GL literal 0 HcmV?d00001 diff --git a/chat/bubbleOutline.png b/chat/bubbleOutline.png new file mode 100644 index 0000000000000000000000000000000000000000..334ddca9c66b0af994decf500b6cf10ead4bb19d GIT binary patch literal 284 zcmeAS@N?(olHy`uVBq!ia0vp^AT}2V8<6ZZI=>f4v7|ftIx;X^yK%)o!U)KhEOCt} z3C>R|DNig)WpGT%PfAtr%uP&B4N6T+sVqF1Y6DcX&eO#)q~cc6pa1{uog*Sz_?VfS z#!&D>MGH231{cSa~tMZDcEsM-N6yMg8ym;?-5@e2PM{ybf!|> zbO+Yo4iXvBDjvMT6F#s#TFbM8(c|1~&SM7_3*-o#cxCBeBbedJaN$>h!dadt+zWP3 z6g+ud!CZ>*W9bT~koabiCWe5IRtihmk4$ywy!zssvEoMW#vjaPt_ciAf^Ch7tJ=@F dA7fx-W7sPYl5)yI@gC6S44$rjF6*2UngDbLVUhp< literal 0 HcmV?d00001 diff --git a/chat/chat.py b/chat/chat.py index 436a1b5b..c48ade15 100755 --- a/chat/chat.py +++ b/chat/chat.py @@ -38,6 +38,7 @@ class Chat(object): def recv_message(self, buddy, msg): self._insert_rich_message(buddy.nick(), msg) + self._parent.notify_new_message(self, buddy) def _insert_rich_message(self, nick, msg): aniter = self._buffer.get_end_iter() @@ -97,6 +98,10 @@ class GroupChat(Chat): self._gc_controller.send_msg(text) self._local_message(True, text) + def recv_message(self, buddy, msg): + self._insert_rich_message(buddy.nick(), msg) + self._parent.notify_new_message(self, None) + def _recv_group_message(self, msg): buddy = self._parent.find_buddy_by_address(msg['addr']) if buddy: @@ -121,9 +126,15 @@ class ChatRequestHandler(object): return True class ChatActivity(activity.Activity): + + _MODEL_COL_NICK = 0 + _MODEL_COL_ICON = 1 + _MODEL_COL_BUDDY = 2 + def __init__(self): activity.Activity.__init__(self) self._act_name = "Chat" + self._active_chat_buddy = None self._pannounce = presence.PresenceAnnounce() (self._nick, self._realname) = self._get_name() @@ -172,7 +183,10 @@ class ChatActivity(activity.Activity): vbox.pack_start(label, False) label.show() - self._buddy_list_model = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT) + self._buddy_list_model = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT) + + self._pixbuf_active_chat = gtk.gdk.pixbuf_new_from_file("bubbleOutline.png") + self._pixbuf_new_message = gtk.gdk.pixbuf_new_from_file("bubble.png") sw = gtk.ScrolledWindow() sw.set_shadow_type(gtk.SHADOW_IN) @@ -187,8 +201,14 @@ class ChatActivity(activity.Activity): sw.add(self._buddy_list_view) self._buddy_list_view.show() + renderer = gtk.CellRendererPixbuf() + column = gtk.TreeViewColumn("", renderer, pixbuf=self._MODEL_COL_ICON) + column.set_resizable(False) + column.set_expand(False); + self._buddy_list_view.append_column(column) + renderer = gtk.CellRendererText() - column = gtk.TreeViewColumn("", renderer, text=0) + column = gtk.TreeViewColumn("", renderer, text=self._MODEL_COL_NICK) column.set_resizable(True) column.set_sizing("GTK_TREE_VIEW_COLUMN_GROW_ONLY"); column.set_expand(True); @@ -232,8 +252,9 @@ class ChatActivity(activity.Activity): self._group_chat = GroupChat(self, self._chat_view, self._chat_label) aniter = self._buddy_list_model.append(None) - self._buddy_list_model.set(aniter, 0, "Group", 1, None) - self._group_chat.activate() + self._buddy_list_model.set(aniter, self._MODEL_COL_NICK, "Group", + self._MODEL_COL_ICON, self._pixbuf_active_chat, self._MODEL_COL_BUDDY, None) + self._activate_chat(None) plug.add(vbox) vbox.show() @@ -241,7 +262,7 @@ class ChatActivity(activity.Activity): def __key_press_event_cb(self, text_view, event): if event.keyval == gtk.keysyms.Return: buf = text_view.get_buffer() - chat = self._get_current_chat() + chat = self._get_active_chat() serializer = richtext.RichTextSerializer() text = serializer.serialize(buf) @@ -298,14 +319,14 @@ class ChatActivity(activity.Activity): def _on_buddyList_buddy_selected(self, widget, *args): (model, aniter) = widget.get_selection().get_selected() - name = self._buddy_list_model.get(aniter,0) + name = self._buddy_list_model.get(aniter, self._MODEL_COL_NICK) print "Selected %s" % name def _on_buddyList_buddy_double_clicked(self, widget, *args): """ Select the chat for this buddy or group """ (model, aniter) = widget.get_selection().get_selected() chat = None - buddy = self._buddy_list_model.get_value(aniter, 1) + buddy = self._buddy_list_model.get_value(aniter, self._MODEL_COL_BUDDY) if not buddy: chat = self._group_chat else: @@ -313,21 +334,30 @@ class ChatActivity(activity.Activity): if not chat: chat = BuddyChat(self, buddy, self._chat_view, self._chat_label) buddy.set_chat(chat) - - chat.activate() + self._activate_chat(chat) def _on_buddy_presence_event(self, action, buddy): if action == BuddyList.ACTION_BUDDY_ADDED: aniter = self._buddy_list_model.append(None) - self._buddy_list_model.set(aniter, 0, buddy.nick(), 1, buddy) + self._buddy_list_model.set(aniter, self._MODEL_COL_NICK, buddy.nick(), + self._MODEL_COL_ICON, None, self._MODEL_COL_BUDDY, buddy) elif action == BuddyList.ACTION_BUDDY_REMOVED: - aniter = self._buddy_list_model.get_iter_first() - while aniter: - list_buddy = self._buddy_list_model.get_value(aniter, 1) - if buddy == list_buddy: - self._buddy_list_model.remove(aniter) - break - aniter = self._buddy_list_model.iter_next(aniter) + aniter = self._get_iter_for_buddy(buddy) + if aniter: + self._buddy_list_model.remove(aniter) + + def _get_iter_for_buddy(self, buddy): + aniter = self._buddy_list_model.get_iter_first() + while aniter: + list_buddy = self._buddy_list_model.get_value(aniter, self._MODEL_COL_BUDDY) + if buddy == list_buddy: + return aniter + aniter = self._buddy_list_model.iter_next(aniter) + + def notify_new_message(self, chat, buddy): + if chat != self._get_active_chat(): + aniter = self._get_iter_for_buddy(buddy) + self._buddy_list_model.set(aniter, self._MODEL_COL_ICON, self._pixbuf_new_message) def find_buddy_by_address(self, address): return self._buddy_list.find_buddy_by_address(address) @@ -335,18 +365,28 @@ class ChatActivity(activity.Activity): def local_name(self): return (self._nick, self._realname) + def _activate_chat(self, buddy): + self._active_chat_buddy = buddy + + # Clear the "new message" icon when the user activates the chat + aniter = self._get_iter_for_buddy(buddy) + icon = self._buddy_list_model.get_value(aniter, self._MODEL_COL_ICON) + if icon == self._pixbuf_new_message: + self._buddy_list_model.set_value(aniter, self._MODEL_COL_ICON, self._pixbuf_active_chat) + + # Actually activate the chat + chat = self._group_chat + if buddy: + chat = buddy.chat() + chat.activate() + def _on_main_window_delete(self, widget, *args): self.quit() - def _get_current_chat(self): - selection = self._buddy_list_view.get_selection() - (model, aniter) = selection.get_selected() - buddy = None - if aniter: - buddy = model.get_value(aniter, 1) - if not buddy: - return self._group_chat - return buddy.chat() + def _get_active_chat(self): + chat = self._group_chat + if self._active_chat_buddy: + chat = self._active_chat_buddy.chat() def run(self): try: