From 63c890da2b5ed2779b9362fe05e280896510de24 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sat, 24 Sep 2005 09:42:10 +0000 Subject: [PATCH] systray.add_jid and systray.remove_jid now have another argument: the typ of message: ('gc' or 'chat' or 'single_chat' or 'pm') systary now can handle pm messages --- src/chat.py | 23 ++++++++++++++------ src/groupchat_window.py | 3 ++- src/roster_window.py | 2 +- src/systray.py | 45 ++++++++++++++++++++++++++------------- src/systraywin32.py | 8 +++---- src/tabbed_chat_window.py | 4 +++- 6 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/chat.py b/src/chat.py index e06f087de..1907beace 100644 --- a/src/chat.py +++ b/src/chat.py @@ -264,6 +264,12 @@ class Chat: nickname.set_max_width_chars(10) nickname.set_text(unread + self.names[jid]) + def get_type(self, jid): + if self.widget_name == 'groupchat_window': + return 'gc' + if gajim.contacts[self.account].has_key(jid): + return 'chat' + return 'pm' def on_window_destroy(self, widget, kind): #kind is 'chats' or 'gc' '''clean self.plugin.windows[self.account][kind]''' @@ -275,7 +281,8 @@ class Chat: gobject.source_remove(self.possible_paused_timeout_id[jid]) gobject.source_remove(self.possible_inactive_timeout_id[jid]) if self.plugin.systray_enabled and self.nb_unread[jid] > 0: - self.plugin.systray.remove_jid(jid, self.account) + self.plugin.systray.remove_jid(jid, self.account, + self.get_type(jid)) del windows[jid] if self.print_time_timeout_id.has_key(jid): gobject.source_remove(self.print_time_timeout_id[jid]) @@ -321,7 +328,8 @@ class Chat: self.nb_unread[jid] = 0 + self.get_specific_unread(jid) self.show_title() if self.plugin.systray_enabled: - self.plugin.systray.remove_jid(jid, self.account) + self.plugin.systray.remove_jid(jid, self.account, + self.get_type(jid)) '''TC/GC window received focus, so if we had urgency REMOVE IT NOTE: we do not have to read the message (it maybe in a bg tab) @@ -485,7 +493,8 @@ class Chat: self.redraw_tab(new_jid) self.show_title() if self.plugin.systray_enabled: - self.plugin.systray.remove_jid(new_jid, self.account) + self.plugin.systray.remove_jid(new_jid, self.account, + self.get_type(new_jid)) conversation_textview.grab_focus() @@ -521,7 +530,8 @@ class Chat: if self.nb_unread[jid] > 0: self.nb_unread[jid] = 0 if self.plugin.systray_enabled: - self.plugin.systray.remove_jid(jid, self.account) + self.plugin.systray.remove_jid(jid, self.account, + self.get_type(jid)) if self.print_time_timeout_id.has_key(jid): gobject.source_remove(self.print_time_timeout_id[jid]) del self.print_time_timeout_id[jid] @@ -840,7 +850,8 @@ class Chat: self.redraw_tab(jid) self.show_title() if self.plugin.systray_enabled: - self.plugin.systray.remove_jid(jid, self.account) + self.plugin.systray.remove_jid(jid, self.account, + self.get_type(jid)) def on_conversation_textview_motion_notify_event(self, widget, event): '''change the cursor to a hand when we are over a mail or an url''' @@ -1307,7 +1318,7 @@ class Chat: self.nb_unread[jid] += 1 if self.plugin.systray_enabled and gajim.config.get( 'trayicon_notification_on_new_messages'): - self.plugin.systray.add_jid(jid, self.account) + self.plugin.systray.add_jid(jid, self.account, self.get_type(jid)) self.redraw_tab(jid) self.show_title(urgent) diff --git a/src/groupchat_window.py b/src/groupchat_window.py index 8c17edb2a..7329940cb 100644 --- a/src/groupchat_window.py +++ b/src/groupchat_window.py @@ -1259,7 +1259,6 @@ current room topic.') % command, room_jid) qs[fjid] = [] qs[fjid].append((msg, 'incoming', tim, False)) # False is for encrypted self.nb_unread[room_jid] += 1 - #FIXME: when we scroll to end we set nb_unread to 0 autopopup = gajim.config.get('autopopup') autopopupaway = gajim.config.get('autopopupaway') @@ -1272,6 +1271,8 @@ current room topic.') % command, room_jid) state_images = self.plugin.roster.get_appropriate_state_images(room_jid) image = state_images['message'] model[iter][C_IMG] = image + if self.plugin.systray_enabled: + self.plugin.systray.add_jid(fjid, self.account, 'pm') self.show_title() else: show = gajim.gc_contacts[self.account][room_jid][nick].show diff --git a/src/roster_window.py b/src/roster_window.py index f75fbd9ec..6e63a4e36 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1540,7 +1540,7 @@ _('If "%s" accepts this request you will know his status.') %jid) model = self.tree.get_model() self.draw_contact(jid, account) if self.plugin.systray_enabled: - self.plugin.systray.add_jid(jid, account) + self.plugin.systray.add_jid(jid, account, 'chat') self.show_title() # we show the * or [n] if not path: self.add_contact_to_roster(jid, account) diff --git a/src/systray.py b/src/systray.py index 564be0987..d9c2ae059 100644 --- a/src/systray.py +++ b/src/systray.py @@ -26,6 +26,7 @@ import os import tooltips +from gajim import Contact from common import gajim from common import helpers from common import i18n @@ -53,7 +54,7 @@ class Systray: def __init__(self, plugin): self.plugin = plugin - self.jids = [] + self.jids = [] # Contain things like [account, jid, type_of_msg] self.new_message_handler_id = None self.t = None self.img_tray = gtk.Image() @@ -73,8 +74,8 @@ class Systray: elif image.get_storage_type() == gtk.IMAGE_PIXBUF: self.img_tray.set_from_pixbuf(image.get_pixbuf()) - def add_jid(self, jid, account): - l = [account, jid] + def add_jid(self, jid, account, typ): + l = [account, jid, typ] if not l in self.jids: self.jids.append(l) self.set_img() @@ -88,8 +89,8 @@ class Systray: if jid != 'tabbed': nb += jids[jid].nb_unread[jid] - def remove_jid(self, jid, account): - l = [account, jid] + def remove_jid(self, jid, account, typ): + l = [account, jid, typ] if l in self.jids: self.jids.remove(l) self.set_img() @@ -260,17 +261,31 @@ class Systray: else: account = self.jids[0][0] jid = self.jids[0][1] - acc = self.plugin.windows[account] + typ = self.jids[0][2] + wins = self.plugin.windows[account] w = None - if acc['gc'].has_key(jid): - w = acc['gc'][jid] - elif acc['chats'].has_key(jid): - w = acc['chats'][jid] - else: - self.plugin.roster.new_chat( - gajim.contacts[account][jid][0], account) - acc['chats'][jid].set_active_tab(jid) - acc['chats'][jid].window.present() + if typ == 'gc': + if wins['gc'].has_key(jid): + w = wins['gc'][jid] + elif typ == 'chat': + if wins['chats'].has_key(jid): + w = wins['chats'][jid] + else: + self.plugin.roster.new_chat( + gajim.contacts[account][jid][0], account) + w = wins['chats'][jid] + elif typ == 'single_chat': + pass + elif typ == 'pm': + if wins['chats'].has_key(jid): + w = wins['chats'][jid] + else: + room_jid, nick = jid.split('/', 1) + show = gajim.gc_contacts[account][room_jid][nick].show + c = Contact(jid = jid, name = nick, groups = ['none'], + show = show, ask = 'none') + self.plugin.roster.new_chat(c, account) + w = wins['chats'][jid] if w: w.set_active_tab(jid) w.window.present() diff --git a/src/systraywin32.py b/src/systraywin32.py index d298ade5d..4a7edc164 100644 --- a/src/systraywin32.py +++ b/src/systraywin32.py @@ -250,8 +250,8 @@ class SystrayWin32(systray.Systray): elif lparam == win32con.WM_LBUTTONUP: # Left click self.on_left_click() - def add_jid(self, jid, account): - l = [account, jid] + def add_jid(self, jid, account, typ): + l = [account, jid, typ] if not l in self.jids: self.jids.append(l) self.set_img() @@ -272,8 +272,8 @@ class SystrayWin32(systray.Systray): self.systray_winapi.notify_icon.set_tooltip(text) - def remove_jid(self, jid, account): - l = [account, jid] + def remove_jid(self, jid, account, typ): + l = [account, jid, typ] if l in self.jids: self.jids.remove(l) self.set_img() diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index db2331b7c..7c415c431 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -722,15 +722,17 @@ timestamp, contact): else: self.plugin.roster.show_title() del gajim.awaiting_messages[self.account][jid] + typ = 'chat' # Is it a normal chat or a pm ? # reset to status image in gc if it is a pm room_jid = jid.split('/', 1)[0] gcs = self.plugin.windows[self.account]['gc'] if gcs.has_key(room_jid): gcs[room_jid].update_state_images() + typ = 'pm' self.plugin.roster.draw_contact(jid, self.account) if self.plugin.systray_enabled: - self.plugin.systray.remove_jid(jid, self.account) + self.plugin.systray.remove_jid(jid, self.account, typ) showOffline = gajim.config.get('showoffline') if (user.show == 'offline' or user.show == 'error') and \ not showOffline: