Chatstate and tab redraw fixes

This commit is contained in:
Travis Shirk 2006-01-05 02:58:59 +00:00
parent 5464701cda
commit 715afc7113
4 changed files with 31 additions and 30 deletions

View File

@ -359,10 +359,8 @@ class ChatControlBase(MessageControl):
if gajim.interface.systray_enabled and\ if gajim.interface.systray_enabled and\
gajim.config.get('trayicon_notification_on_new_messages'): gajim.config.get('trayicon_notification_on_new_messages'):
gajim.interface.systray.add_jid(jid, self.account, self.type_id) gajim.interface.systray.add_jid(jid, self.account, self.type_id)
# FIXME: This is one hairy race condition self.parent_win.redraw_tab(self.contact)
if self.parent_win.get_active_control(): self.parent_win.show_title(urgent)
self.parent_win.redraw_tab(self.contact)
self.parent_win.show_title(urgent)
def toggle_emoticons(self): def toggle_emoticons(self):
'''hide show emoticons_button and make sure emoticons_menu is always there '''hide show emoticons_button and make sure emoticons_menu is always there
@ -935,12 +933,7 @@ class ChatControl(ChatControlBase):
ChatControlBase.print_conversation_line(self, text, kind, name, tim, ChatControlBase.print_conversation_line(self, text, kind, name, tim,
subject = subject) subject = subject)
def markup_tab_label(self, label_str, chatstate): def get_tab_label(self, chatstate):
'''Markup the label if necessary. Returns a tuple such as:
(new_label_str, color)
either of which can be None
if chatstate is given that means we have HE SENT US a chatstate'''
unread = '' unread = ''
num_unread = self.nb_unread num_unread = self.nb_unread
if num_unread == 1 and not gajim.config.get('show_unread_tab_icon'): if num_unread == 1 and not gajim.config.get('show_unread_tab_icon'):
@ -981,10 +974,24 @@ class ChatControl(ChatControlBase):
color.green = int((color.green * p) + (mask * (1 - p))) color.green = int((color.green * p) + (mask * (1 - p)))
color.blue = int((color.blue * p) + (mask * (1 - p))) color.blue = int((color.blue * p) + (mask * (1 - p)))
label_str = self.contact.name
if num_unread: # if unread, text in the label becomes bold if num_unread: # if unread, text in the label becomes bold
label_str = '<b>' + unread + label_str + '</b>' label_str = '<b>' + unread + label_str + '</b>'
return (label_str, color) return (label_str, color)
def get_tab_image(self):
num_unread = self.nb_unread
# Set tab image (always 16x16); unread messages show the 'message' image
img_16 = gajim.interface.roster.get_appropriate_state_images(self.contact.jid)
tab_img = None
if num_unread and gajim.config.get('show_unread_tab_icon'):
tab_img = img_16['message']
else:
tab_img = img_16[self.contact.show]
return tab_img
def remove_possible_switch_to_menuitems(self, menu): def remove_possible_switch_to_menuitems(self, menu):
''' remove duplicate 'Switch to' if they exist and return clean menu''' ''' remove duplicate 'Switch to' if they exist and return clean menu'''
@ -1114,19 +1121,17 @@ class ChatControl(ChatControlBase):
# prevent going paused if we we were not composing (JEP violation) # prevent going paused if we we were not composing (JEP violation)
if state == 'paused' and not contact.our_chatstate == 'composing': if state == 'paused' and not contact.our_chatstate == 'composing':
MessageControl.send_message(self, jid, None, None, MessageControl.send_message(self, None, chatstate = 'active') # go active before
chatstate = 'active') # go active before
contact.our_chatstate = 'active' contact.our_chatstate = 'active'
self.reset_kbd_mouse_timeout_vars() self.reset_kbd_mouse_timeout_vars()
# if we're inactive prevent composing (JEP violation) # if we're inactive prevent composing (JEP violation)
if contact.our_chatstate == 'inactive' and state == 'composing': if contact.our_chatstate == 'inactive' and state == 'composing':
MessageControl.send_message(self, jid, None, None, MessageControl.send_message(self, None, chatstate = 'active') # go active before
chatstate = 'active') # go active before
contact.our_chatstate = 'active' contact.our_chatstate = 'active'
self.reset_kbd_mouse_timeout_vars() self.reset_kbd_mouse_timeout_vars()
MessageControl.send_message(self, jid, None, None, chatstate = state) MessageControl.send_message(self, None, chatstate = state)
contact.our_chatstate = state contact.our_chatstate = state
if contact.our_chatstate == 'active': if contact.our_chatstate == 'active':
self.reset_kbd_mouse_timeout_vars() self.reset_kbd_mouse_timeout_vars()

View File

@ -88,10 +88,17 @@ class MessageControl:
gobject.source_remove(self.print_time_timeout_id) gobject.source_remove(self.print_time_timeout_id)
del self.print_time_timeout_id del self.print_time_timeout_id
return False return False
def markup_tab_label(self, label_str, chatstate): def get_tab_label(self, chatstate):
'''Return a suitable the tab label string. Returns a tuple such as:
(label_str, color) either of which can be None
if chatstate is given that means we have HE SENT US a chatstate and
we want it displayed'''
# NOTE: Derived classes SHOULD implement this # NOTE: Derived classes SHOULD implement this
# Reurn a markup'd label and optional gtk.Color # Reurn a markup'd label and optional gtk.Color
return (label_str, None) return (label_str, None)
def get_tab_image(self):
'''Return a suitable tab image for display. None clears any current label.'''
return None
def prepare_context_menu(self): def prepare_context_menu(self):
# NOTE: Derived classes SHOULD implement this # NOTE: Derived classes SHOULD implement this
return None return None

View File

@ -257,25 +257,13 @@ class MessageWindow:
# Update nick # Update nick
nick_label.set_max_width_chars(10) nick_label.set_max_width_chars(10)
(tab_label_str, tab_label_color) = ctl.markup_tab_label(contact.name, (tab_label_str, tab_label_color) = ctl.get_tab_label(chatstate)
chatstate)
nick_label.set_markup(tab_label_str) nick_label.set_markup(tab_label_str)
if tab_label_color: if tab_label_color:
nick_label.modify_fg(gtk.STATE_NORMAL, tab_label_color) nick_label.modify_fg(gtk.STATE_NORMAL, tab_label_color)
nick_label.modify_fg(gtk.STATE_ACTIVE, tab_label_color) nick_label.modify_fg(gtk.STATE_ACTIVE, tab_label_color)
num_unread = ctl.nb_unread tab_img = ctl.get_tab_image()
# Set tab image (always 16x16); unread messages show the 'message' image
img_16 = gajim.interface.roster.get_appropriate_state_images(contact.jid)
tab_img = None
if ctl.type_id == message_control.TYPE_CHAT:
if num_unread and gajim.config.get('show_unread_tab_icon'):
tab_img = img_16['message']
else:
tab_img = img_16[contact.show]
elif ctl.type_id == message_control.TYPE_GC:
# FIXME: muc_active muc_inactive
pass
if tab_img: if tab_img:
if tab_img.get_storage_type() == gtk.IMAGE_ANIMATION: if tab_img.get_storage_type() == gtk.IMAGE_ANIMATION:
status_img.set_from_animation(tab_img.get_animation()) status_img.set_from_animation(tab_img.get_animation())

View File

@ -722,6 +722,7 @@ class RosterWindow:
win = gajim.interface.msg_win_mgr.get_window(contact.jid) win = gajim.interface.msg_win_mgr.get_window(contact.jid)
ctl = win.get_control(jid) ctl = win.get_control(jid)
ctl.update_state() ctl.update_state()
win.redraw_tab(contact)
name = contact.name name = contact.name
if contact.resource != '': if contact.resource != '':