Add 'joined' tab state, and rewrite the function handling the priorities

This commit is contained in:
mathieui 2012-02-14 00:33:29 +01:00
parent af11058129
commit 560390793d
4 changed files with 23 additions and 32 deletions

View file

@ -1085,35 +1085,16 @@ class Core(object):
def go_to_important_room(self):
"""
Go to the next room with activity, in this order:
- A personal conversation with a new message
- A Muc with an highlight
- A Muc with any new message
Go to the next room with activity, in the order defined in the
dict tabs.STATE_PRIORITY
"""
for tab in self.tabs:
if tab.state == 'attention':
self.command_win('%s' % tab.nb)
return
for tab in self.tabs:
if tab.state == 'private':
self.command_win('%s' % tab.nb)
return
for tab in self.tabs:
if tab.state == 'highlight':
self.command_win('%s' % tab.nb)
return
for tab in self.tabs:
if tab.state == 'message':
self.command_win('%s' % tab.nb)
return
for tab in self.tabs:
if tab.state == 'disconnected':
self.command_win('%s' % tab.nb)
return
for tab in self.tabs:
if isinstance(tab, tabs.ChatTab) and not tab.input.is_empty():
self.command_win('%s' % tab.nb)
return
priority = tabs.STATE_PRIORITY
sorted_tabs = sorted(self.tabs, key=lambda tab: priority[tab.state],
reverse=True)
tab = sorted_tabs.pop(0) if sorted_tabs else None
if priority[tab.state] < 0 or not tab:
return
self.command_win('%s' % tab.nb)
def rotate_rooms_right(self, args=None):
"""

View file

@ -62,6 +62,7 @@ NS_MUC_USER = 'http://jabber.org/protocol/muc#user'
STATE_COLORS = {
'disconnected': lambda: get_theme().COLOR_TAB_DISCONNECTED,
'joined': lambda: get_theme().COLOR_TAB_JOINED,
'message': lambda: get_theme().COLOR_TAB_NEW_MESSAGE,
'highlight': lambda: get_theme().COLOR_TAB_HIGHLIGHT,
'private': lambda: get_theme().COLOR_TAB_PRIVATE,
@ -72,6 +73,7 @@ STATE_COLORS = {
VERTICAL_STATE_COLORS = {
'disconnected': lambda: get_theme().COLOR_VERTICAL_TAB_DISCONNECTED,
'joined': lambda: get_theme().COLOR_VERTICAL_TAB_JOINED,
'message': lambda: get_theme().COLOR_VERTICAL_TAB_NEW_MESSAGE,
'highlight': lambda: get_theme().COLOR_VERTICAL_TAB_HIGHLIGHT,
'private': lambda: get_theme().COLOR_VERTICAL_TAB_PRIVATE,
@ -84,10 +86,11 @@ VERTICAL_STATE_COLORS = {
STATE_PRIORITY = {
'normal': -1,
'current': -1,
'disconnected': 0,
'message': 1,
'joined': 1,
'highlight': 2,
'private': 2,
'disconnected': 3,
'attention': 3
}
@ -155,7 +158,7 @@ class Tab(object):
if not value in STATE_COLORS:
log.debug("Invalid value for tab state: %s", value)
elif STATE_PRIORITY[value] < STATE_PRIORITY[self._state] and \
value != 'current':
value != 'current' and value != 'joined':
log.debug("Did not set status because of lower priority, asked: %s, kept: %s", value, self._state)
else:
self._state = value
@ -1066,6 +1069,8 @@ class MucTab(ChatTab):
self.users.append(new_user)
if from_nick == self.own_nick:
self.joined = True
if self != self.core.current_tab():
self.state = 'joined'
if self.core.current_tab() == self and self.core.status.show not in ('xa', 'away'):
self.send_chat_state('active')
new_user.color = get_theme().COLOR_OWN_NICK
@ -1100,6 +1105,9 @@ class MucTab(ChatTab):
self.info_header.refresh(self, self.text_win)
self.input.refresh()
self.core.doupdate()
else:
self.core.current_tab().refresh_tab_win()
self.core.doupdate()
def on_user_join(self, from_nick, affiliation, show, status, role, jid):
"""

View file

@ -122,6 +122,7 @@ class Theme(object):
# Tabs
COLOR_TAB_NORMAL = (7, 4)
COLOR_TAB_JOINED = (82, 4)
COLOR_TAB_CURRENT = (7, 6)
COLOR_TAB_NEW_MESSAGE = (7, 5)
COLOR_TAB_HIGHLIGHT = (7, 3)
@ -130,6 +131,7 @@ class Theme(object):
COLOR_TAB_DISCONNECTED = (7, 8)
COLOR_VERTICAL_TAB_NORMAL = (4, -1)
COLOR_VERTICAL_TAB_JOINED = (82, -1)
COLOR_VERTICAL_TAB_CURRENT = (7, 4)
COLOR_VERTICAL_TAB_NEW_MESSAGE = (5, -1)
COLOR_VERTICAL_TAB_HIGHLIGHT = (3, -1)

View file

@ -310,7 +310,7 @@ class GlobalInfoBar(Win):
for tab in sorted_tabs:
color = tab.color
if config.get('show_inactive_tabs', 'true') == 'false' and\
color == get_theme().COLOR_TAB_NORMAL:
color is get_theme().COLOR_TAB_NORMAL:
continue
try:
self.addstr("%s" % str(tab.nb), to_curses_attr(color))
@ -342,7 +342,7 @@ class VerticalGlobalInfoBar(Win):
sorted_tabs = sorted(self.core.tabs, key=comp)
if config.get('show_inactive_tabs', 'true') == 'false':
sorted_tabs = [tab for tab in sorted_tabs if\
tab.vertical_color != get_theme().COLOR_VERTICAL_TAB_NORMAL]
tab.vertical_color is not get_theme().COLOR_VERTICAL_TAB_NORMAL]
nb_tabs = len(sorted_tabs)
if nb_tabs >= height:
for y, tab in enumerate(sorted_tabs):