MUC chat states; closes #845

This commit is contained in:
Travis Shirk 2005-09-14 00:51:26 +00:00
parent 3836656737
commit 4bf0ac5703
3 changed files with 64 additions and 14 deletions

View File

@ -92,6 +92,10 @@ class Chat:
self.notebook.set_show_tabs(gajim.config.get('tabs_always_visible'))
self.notebook.set_show_border(gajim.config.get('tabs_border'))
# muc attention states (when we are mentioned in a muc)
# if the room jid is in the list, the room has mentioned us
self.muc_attentions = []
def update_font(self):
font = pango.FontDescription(gajim.config.get('conversation_font'))
for jid in self.tagIn:
@ -164,12 +168,6 @@ class Chat:
def redraw_tab(self, jid, chatstate = None):
'''redraw the label of the tab
if chatstate is given that means we have HE SENT US a chatstate'''
unread = ''
num_unread = self.nb_unread[jid]
if num_unread == 1 and not gajim.config.get('show_unread_tab_icon'):
unread = '* '
elif num_unread > 1:
unread = '[' + unicode(num_unread) + '] '
# Update status images
self.set_state_image(jid)
@ -179,6 +177,13 @@ class Chat:
nickname = hb.get_children()[1]
close_button = hb.get_children()[2]
unread = ''
num_unread = self.nb_unread[jid]
if num_unread == 1 and not gajim.config.get('show_unread_tab_icon'):
unread = '* '
elif num_unread > 1:
unread = '[' + unicode(num_unread) + '] '
# Draw tab label using chatstate
theme = gajim.config.get('roster_theme')
color = None
@ -227,6 +232,31 @@ class Chat:
nickname = hb.get_children()[0]
close_button = hb.get_children()[1]
unread = ''
has_focus = self.window.get_property('has-toplevel-focus')
current_tab = (self.notebook.page_num(child) == self.notebook.get_current_page())
color = None
theme = gajim.config.get('roster_theme')
if chatstate == 'attention' and (not has_focus or not current_tab):
if jid not in self.muc_attentions:
self.muc_attentions.append(jid)
color = gajim.config.get_per('themes', theme, 'state_muc_directed_msg')
elif chatstate:
if chatstate == 'active' or (current_tab and has_focus):
if jid in self.muc_attentions:
self.muc_attentions.remove(jid)
color = gajim.config.get_per('themes', theme, 'state_active_color')
elif chatstate == 'newmsg' and (not has_focus or not current_tab) and\
jid not in self.muc_attentions:
color = gajim.config.get_per('themes', theme, 'state_muc_msg')
if color:
color = gtk.gdk.colormap_get_system().alloc_color(color)
# The widget state depend on whether this tab is the "current" tab
if current_tab:
nickname.modify_fg(gtk.STATE_NORMAL, color)
else:
nickname.modify_fg(gtk.STATE_ACTIVE, color)
if gajim.config.get('tabs_close_button'):
close_button.show()
else:
@ -301,8 +331,11 @@ class Chat:
if widget.props.urgency_hint:
widget.props.urgency_hint = False
# Undo "unread" state display, etc.
# NOTE: we do not send any chatstate
self.redraw_tab(jid)
if self.widget_name == 'groupchat_window':
self.redraw_tab(jid, 'active')
else:
# NOTE: we do not send any chatstate to preserve inactive, gone, etc.
self.redraw_tab(jid)
def on_compact_view_menuitem_activate(self, widget):
isactive = widget.get_active()

View File

@ -228,6 +228,10 @@ class Config:
'state_composing_color': [ opt_color, 'green4' ],
'state_paused_color': [ opt_color, 'mediumblue' ],
'state_gone_color': [ opt_color, 'grey' ],
# MUC chat states
'state_muc_msg': [ opt_color, 'mediumblue' ],
'state_muc_directed_msg': [ opt_color, 'red2' ],
}, {}),
}

View File

@ -76,6 +76,7 @@ class GroupchatWindow(chat.Chat):
'on_groupchat_window_focus_in_event': self.on_groupchat_window_focus_in_event,
'on_groupchat_window_focus_out_event': self.on_groupchat_window_focus_out_event,
'on_chat_notebook_key_press_event': self.on_chat_notebook_key_press_event,
'on_chat_notebook_switch_page': self.on_chat_notebook_switch_page,
}
self.xml.signal_autoconnect(signal_dict)
@ -184,23 +185,32 @@ class GroupchatWindow(chat.Chat):
chat.Chat.on_chat_notebook_key_press_event(self, widget, event)
def on_chat_notebook_switch_page(self, notebook, page, page_num):
old_child = notebook.get_nth_page(notebook.get_current_page())
new_child = notebook.get_nth_page(page_num)
old_jid = ''
new_jid = ''
for room_jid in self.xmls:
if self.childs[room_jid] == new_child:
if self.childs[room_jid] == new_child:
new_jid = room_jid
break
subject = self.subjects[new_jid]
self.redraw_tab(new_jid, 'active')
elif self.childs[room_jid] == old_child:
old_jid = room_jid
self.redraw_tab(old_jid, 'active')
if old_jid != '' and new_jid != '': # we found both jids
break # so stop looping
subject = self.subjects[new_jid]
subject = gtkgui_helpers.escape_for_pango_markup(subject)
new_jid = gtkgui_helpers.escape_for_pango_markup(new_jid)
name_label = self.name_labels[new_jid]
name_label.set_markup('<span weight="heavy" size="x-large">%s</span>\n%s' % (new_jid, subject))
name_label.set_markup('<span weight="heavy" size="x-large">%s</span>\n%s' %\
(new_jid, subject))
event_box = name_label.get_parent()
if subject == '':
subject = _('This room has no subject')
self.subject_tooltip[new_jid].set_tip(event_box, subject)
chat.Chat.on_chat_notebook_switch_page(self, notebook, page, page_num)
def get_role_iter(self, room_jid, role):
@ -718,12 +728,15 @@ class GroupchatWindow(chat.Chat):
kind = 'outgoing'
else:
kind = 'incoming'
# muc-specific chatstate
self.redraw_tab(room_jid, 'newmsg')
else:
kind = 'status'
nick = self.nicks[room_jid]
if kind == 'incoming' and \
text.lower().find(nick.lower()) != -1:
if kind == 'incoming' and text.lower().find(nick.lower()) != -1:
# muc-specific chatstate
self.redraw_tab(room_jid, 'attention')
other_tags_for_name.append('bold')
other_tags_for_text.append('marked')