fold groups, display-name, focus the tab if user tries to open an already...

fold groups, display-name, focus the tab if user tries to open an already opened conversation (on /join too !), and nicer roster
parent 27938ecf
...@@ -22,7 +22,7 @@ class Contact(object): ...@@ -22,7 +22,7 @@ class Contact(object):
""" """
def __init__(self, jid): def __init__(self, jid):
self._jid = JID(jid) # a SleekXMPP jid object self._jid = JID(jid) # a SleekXMPP jid object
self._display_name = '' self._display_name = None
self._subscription = 'none' self._subscription = 'none'
self._ask = None self._ask = None
self._status = '' self._status = ''
...@@ -51,3 +51,9 @@ class Contact(object): ...@@ -51,3 +51,9 @@ class Contact(object):
def get_presence(self): def get_presence(self):
return self._presence return self._presence
def set_name(self, name):
self._display_name = name
def get_name(self):
return self._display_name
...@@ -38,7 +38,7 @@ from config import config ...@@ -38,7 +38,7 @@ from config import config
from tab import MucTab, InfoTab, PrivateTab, RosterInfoTab, ConversationTab from tab import MucTab, InfoTab, PrivateTab, RosterInfoTab, ConversationTab
from user import User from user import User
from room import Room from room import Room
from roster import Roster from roster import Roster, RosterGroup
from contact import Contact from contact import Contact
from message import Message from message import Message
from text_buffer import TextBuffer from text_buffer import TextBuffer
...@@ -427,6 +427,11 @@ class Gui(object): ...@@ -427,6 +427,11 @@ class Gui(object):
self.refresh_window() self.refresh_window()
doupdate() doupdate()
def focus_tab_named(self, tab_name):
for tab in self.tabs:
if tab.get_name() == tab_name:
self.command_win('%s' % (tab.nb,))
def on_normal_message(self, message): def on_normal_message(self, message):
""" """
When receiving "normal" messages (from someone in our roster) When receiving "normal" messages (from someone in our roster)
...@@ -469,6 +474,10 @@ class Gui(object): ...@@ -469,6 +474,10 @@ class Gui(object):
contact.set_ask(item.attrib['ask']) contact.set_ask(item.attrib['ask'])
else: else:
contact.set_ask(None) contact.set_ask(None)
if 'name' in item.attrib:
contact.set_name(item.attrib['name'])
else:
contact.set_name(None)
if item.attrib['subscription']: if item.attrib['subscription']:
contact.set_subscription(item.attrib['subscription']) contact.set_subscription(item.attrib['subscription'])
groups = item.findall('{jabber:iq:roster}group') groups = item.findall('{jabber:iq:roster}group')
...@@ -925,10 +934,9 @@ class Gui(object): ...@@ -925,10 +934,9 @@ class Gui(object):
r = self.get_room_by_name(room) r = self.get_room_by_name(room)
if len(args) == 2: # a password is provided if len(args) == 2: # a password is provided
password = args[1] password = args[1]
# TODO if r and r.joined: # if we are already in the room
# if r and r.joined: # if we are already in the room self.focus_tab_named(r.name)
# self.command_win('%s' % (r.nb)) return
# return
room = room.lower() room = room.lower()
if r and not r.joined: if r and not r.joined:
self.xmpp.plugin['xep_0045'].joinMUC(room, nick, password) self.xmpp.plugin['xep_0045'].joinMUC(room, nick, password)
...@@ -1262,7 +1270,7 @@ class Gui(object): ...@@ -1262,7 +1270,7 @@ class Gui(object):
return return
if key in ('^J', '\n') and isinstance(res, str): if key in ('^J', '\n') and isinstance(res, str):
self.execute(res) self.execute(res)
else: else :
# we did "enter" with an empty input in the roster # we did "enter" with an empty input in the roster
self.on_roster_enter_key(res) self.on_roster_enter_key(res)
...@@ -1271,18 +1279,13 @@ class Gui(object): ...@@ -1271,18 +1279,13 @@ class Gui(object):
when enter is pressed on the roster window when enter is pressed on the roster window
""" """
if isinstance(roster_row, Contact): if isinstance(roster_row, Contact):
r = Room(roster_row.get_jid().full, self.xmpp.fulljid) if not self.get_conversation_by_jid(roster_row.get_jid().bare):
new_tab = ConversationTab(self.stdscr, r, self.information_win_size) self.open_conversation_window(roster_row.get_jid().bare)
debug('%s\n'% new_tab)
# insert it in the tabs
if self.current_tab().nb == 0:
self.tabs.append(new_tab)
else: else:
for ta in self.tabs: self.focus_tab_named(roster_row.get_jid().bare)
if ta.nb == 0: elif isinstance(roster_row, RosterGroup):
self.tabs.insert(self.tabs.index(ta), new_tab) roster_row.folded = not roster_row.folded
break self.refresh_window()
self.refresh_window()
def execute(self,line): def execute(self,line):
""" """
......
...@@ -84,24 +84,6 @@ class Roster(object): ...@@ -84,24 +84,6 @@ class Roster(object):
self._roster_groups.append(new_group) self._roster_groups.append(new_group)
new_group.add_contact(contact) new_group.add_contact(contact)
# def ordered_by_group(self, dic_roster, order):
# # ordered by contact
# for jid in dic_roster:
# if not dic_roster[jid]['in_roster']:
# continue
# self.contact_number += 1
# groups=dic_roster[jid]['groups']
# if not groups:
# groups = ['(none)']
# new_contact = Contact(jid, name=dic_roster[jid]['name'],
# groups=groups,
# subscription=dic_roster[jid]['subscription'],
# presence=dic_roster[jid]['presence'])
# for group in groups:
# self.add_contact_to_group(group, new_contact)
# # debug('Jid:%s, (%s)\n' % (jid, dic_roster[jid]))
# debug('\n')
def get_groups(self): def get_groups(self):
return self._roster_groups return self._roster_groups
......
...@@ -27,6 +27,7 @@ MIN_HEIGHT = 16 ...@@ -27,6 +27,7 @@ MIN_HEIGHT = 16
import window import window
import theme import theme
from roster import RosterGroup
from common import debug from common import debug
...@@ -422,8 +423,8 @@ class RosterInfoTab(Tab): ...@@ -422,8 +423,8 @@ class RosterInfoTab(Tab):
pass pass
def on_enter(self): def on_enter(self):
debug('%s\n' % (self.roster_win.get_selected_row())) selected_row = self.roster_win.get_selected_row()
return self.roster_win.get_selected_row() return selected_row
class ConversationTab(Tab): class ConversationTab(Tab):
""" """
...@@ -447,9 +448,9 @@ class ConversationTab(Tab): ...@@ -447,9 +448,9 @@ class ConversationTab(Tab):
self.tab_win.resize(1, self.width, self.height-2, 0, stdscr, self.visible) self.tab_win.resize(1, self.width, self.height-2, 0, stdscr, self.visible)
self.input.resize(1, self.width, self.height-1, 0, stdscr, self.visible) self.input.resize(1, self.width, self.height-1, 0, stdscr, self.visible)
def refresh(self, tabs, informations, _): def refresh(self, tabs, informations, roster):
self.text_win.refresh(self._room) self.text_win.refresh(self._room)
self.info_header.refresh(self._room) self.info_header.refresh(self._room, roster.get_contact_by_jid(self._room.name))
self.info_win.refresh(informations) self.info_win.refresh(informations)
self.tab_win.refresh(tabs, tabs[0]) self.tab_win.refresh(tabs, tabs[0])
self.input.refresh() self.input.refresh()
...@@ -485,7 +486,7 @@ class ConversationTab(Tab): ...@@ -485,7 +486,7 @@ class ConversationTab(Tab):
def on_info_win_size_changed(self, size, stdscr): def on_info_win_size_changed(self, size, stdscr):
self.info_win_size = size self.info_win_size = size
self.text_win.resize(self.height-2, self.width, 0, 0, stdscr, self.visible) self.text_win.resize(self.height-2-self.info_win_size, self.width, 0, 0, stdscr, self.visible)
self.info_header.resize(1, self.width, self.height-3-self.info_win_size, 0, stdscr, self.visible) self.info_header.resize(1, self.width, self.height-3-self.info_win_size, 0, stdscr, self.visible)
self.info_win.resize(self.info_win_size, (self.width//10)*9, self.height-2-self.info_win_size, 0, stdscr, self.visible) self.info_win.resize(self.info_win_size, (self.width//10)*9, self.height-2-self.info_win_size, 0, stdscr, self.visible)
......
...@@ -254,21 +254,19 @@ class ConversationInfoWin(InfoWin): ...@@ -254,21 +254,19 @@ class ConversationInfoWin(InfoWin):
def resize(self, height, width, y, x, stdscr, visible): def resize(self, height, width, y, x, stdscr, visible):
self._resize(height, width, y, x, stdscr, visible) self._resize(height, width, y, x, stdscr, visible)
def refresh(self, room): def refresh(self, room, contact):
if not self.visible: if not self.visible:
return return
g_lock.acquire() g_lock.acquire()
self.win.erase() self.win.erase()
self.write_room_name(room) self.write_room_name(contact)
self.print_scroll_position(room) self.print_scroll_position(room)
self.finish_line(theme.COLOR_INFORMATION_BAR) self.finish_line(theme.COLOR_INFORMATION_BAR)
self.win.refresh() self.win.refresh()
g_lock.release() g_lock.release()
def write_room_name(self, room): def write_room_name(self, contact):
# (room_name, nick) = room.name.split('/', 1) txt = '%s' % contact.get_jid().bare
# self.addnstr(nick, len(nick), curses.color_pair(13))
txt = '%s' % room.name
self.addnstr(txt, len(txt), curses.color_pair(theme.COLOR_INFORMATION_BAR)) self.addnstr(txt, len(txt), curses.color_pair(theme.COLOR_INFORMATION_BAR))
class MucInfoWin(InfoWin): class MucInfoWin(InfoWin):
...@@ -951,7 +949,7 @@ class RosterWin(Win): ...@@ -951,7 +949,7 @@ class RosterWin(Win):
'chat':theme.COLOR_STATUS_CHAT, 'chat':theme.COLOR_STATUS_CHAT,
'unavailable': theme.COLOR_STATUS_UNAVAILABLE 'unavailable': theme.COLOR_STATUS_UNAVAILABLE
} }
# subscription_char = {'both': '
def __init__(self, height, width, y, x, parent_win, visible): def __init__(self, height, width, y, x, parent_win, visible):
self.visible = visible self.visible = visible
Win.__init__(self, height, width, y, x, parent_win) Win.__init__(self, height, width, y, x, parent_win)
...@@ -1000,6 +998,8 @@ class RosterWin(Win): ...@@ -1000,6 +998,8 @@ class RosterWin(Win):
if y >= self.start_pos: if y >= self.start_pos:
self.draw_group(y-self.start_pos+1, group, y-1==self.pos) self.draw_group(y-self.start_pos+1, group, y-1==self.pos)
y += 1 y += 1
if group.folded:
continue
for contact in group.get_contacts(): for contact in group.get_contacts():
if y-1 == self.pos: if y-1 == self.pos:
self.selected_row = contact self.selected_row = contact
...@@ -1022,7 +1022,7 @@ class RosterWin(Win): ...@@ -1022,7 +1022,7 @@ class RosterWin(Win):
Draw the indicator that shows that Draw the indicator that shows that
the list is longer that what is displayed the list is longer that what is displayed
""" """
self.win.addstr(y, self.width-4, '+++', curses.color_pair(42)) self.win.addstr(y, self.width-5, '++++', curses.color_pair(42))
def draw_roster_information(self, roster): def draw_roster_information(self, roster):
""" """
...@@ -1035,9 +1035,14 @@ class RosterWin(Win): ...@@ -1035,9 +1035,14 @@ class RosterWin(Win):
Draw a groupname on a line Draw a groupname on a line
""" """
if colored: if colored:
self.addstr(y, 0, group.name, curses.color_pair(34)) self.win.attron(curses.color_pair(14))
if group.folded:
self.addstr(y, 0, '[+] ')
else: else:
self.addstr(y, 0, group.name) self.addstr(y, 0, '[-] ')
self.addstr(y, 4, group.name)
if colored:
self.win.attroff(curses.color_pair(14))
def draw_contact_line(self, y, contact, colored): def draw_contact_line(self, y, contact, colored):
""" """
...@@ -1046,11 +1051,16 @@ class RosterWin(Win): ...@@ -1046,11 +1051,16 @@ class RosterWin(Win):
is currently selected contact in the list is currently selected contact in the list
""" """
color = RosterWin.color_show[contact.get_presence()] color = RosterWin.color_show[contact.get_presence()]
self.win.addstr(y, 1, "!", curses.color_pair(color)) if contact.get_name():
display_name = '%s (%s)' % (contact.get_name(),
contact.get_jid().bare)
else:
display_name = '%s' % (contact.get_jid().bare,)
self.win.addstr(y, 1, " ", curses.color_pair(color))
if colored: if colored:
self.win.addstr(y, 2, contact.get_jid().bare, curses.color_pair(34)) self.win.addstr(y, 4, display_name, curses.color_pair(14))
else: else:
self.win.addstr(y, 2, contact.get_jid().bare) self.win.addstr(y, 4, display_name)
def get_selected_row(self): def get_selected_row(self):
return self.selected_row return self.selected_row
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment