diff options
-rw-r--r-- | src/contact.py | 8 | ||||
-rw-r--r-- | src/gui.py | 37 | ||||
-rw-r--r-- | src/roster.py | 18 | ||||
-rw-r--r-- | src/tab.py | 11 | ||||
-rw-r--r-- | src/window.py | 36 |
5 files changed, 56 insertions, 54 deletions
diff --git a/src/contact.py b/src/contact.py index 510e208a..39ec9715 100644 --- a/src/contact.py +++ b/src/contact.py @@ -22,7 +22,7 @@ class Contact(object): """ def __init__(self, jid): self._jid = JID(jid) # a SleekXMPP jid object - self._display_name = '' + self._display_name = None self._subscription = 'none' self._ask = None self._status = '' @@ -51,3 +51,9 @@ class Contact(object): def get_presence(self): 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 from tab import MucTab, InfoTab, PrivateTab, RosterInfoTab, ConversationTab from user import User from room import Room -from roster import Roster +from roster import Roster, RosterGroup from contact import Contact from message import Message from text_buffer import TextBuffer @@ -427,6 +427,11 @@ class Gui(object): self.refresh_window() 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): """ When receiving "normal" messages (from someone in our roster) @@ -469,6 +474,10 @@ class Gui(object): contact.set_ask(item.attrib['ask']) else: contact.set_ask(None) + if 'name' in item.attrib: + contact.set_name(item.attrib['name']) + else: + contact.set_name(None) if item.attrib['subscription']: contact.set_subscription(item.attrib['subscription']) groups = item.findall('{jabber:iq:roster}group') @@ -925,10 +934,9 @@ class Gui(object): r = self.get_room_by_name(room) if len(args) == 2: # a password is provided password = args[1] - # TODO - # if r and r.joined: # if we are already in the room - # self.command_win('%s' % (r.nb)) - # return + if r and r.joined: # if we are already in the room + self.focus_tab_named(r.name) + return room = room.lower() if r and not r.joined: self.xmpp.plugin['xep_0045'].joinMUC(room, nick, password) @@ -1262,7 +1270,7 @@ class Gui(object): return if key in ('^J', '\n') and isinstance(res, str): self.execute(res) - else: + else : # we did "enter" with an empty input in the roster self.on_roster_enter_key(res) @@ -1271,18 +1279,13 @@ class Gui(object): when enter is pressed on the roster window """ if isinstance(roster_row, Contact): - r = Room(roster_row.get_jid().full, self.xmpp.fulljid) - new_tab = ConversationTab(self.stdscr, r, self.information_win_size) - debug('%s\n'% new_tab) - # insert it in the tabs - if self.current_tab().nb == 0: - self.tabs.append(new_tab) + if not self.get_conversation_by_jid(roster_row.get_jid().bare): + self.open_conversation_window(roster_row.get_jid().bare) else: - for ta in self.tabs: - if ta.nb == 0: - self.tabs.insert(self.tabs.index(ta), new_tab) - break - self.refresh_window() + self.focus_tab_named(roster_row.get_jid().bare) + elif isinstance(roster_row, RosterGroup): + roster_row.folded = not roster_row.folded + self.refresh_window() def execute(self,line): """ diff --git a/src/roster.py b/src/roster.py index e739d81d..209f7134 100644 --- a/src/roster.py +++ b/src/roster.py @@ -84,24 +84,6 @@ class Roster(object): self._roster_groups.append(new_group) 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): return self._roster_groups @@ -27,6 +27,7 @@ MIN_HEIGHT = 16 import window import theme +from roster import RosterGroup from common import debug @@ -422,8 +423,8 @@ class RosterInfoTab(Tab): pass def on_enter(self): - debug('%s\n' % (self.roster_win.get_selected_row())) - return self.roster_win.get_selected_row() + selected_row = self.roster_win.get_selected_row() + return selected_row 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.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.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.tab_win.refresh(tabs, tabs[0]) self.input.refresh() @@ -485,7 +486,7 @@ class ConversationTab(Tab): def on_info_win_size_changed(self, size, stdscr): 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_win.resize(self.info_win_size, (self.width//10)*9, self.height-2-self.info_win_size, 0, stdscr, self.visible) diff --git a/src/window.py b/src/window.py index 6e0ec174..bef3bc9c 100644 --- a/src/window.py +++ b/src/window.py @@ -254,21 +254,19 @@ class ConversationInfoWin(InfoWin): def resize(self, 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: return g_lock.acquire() self.win.erase() - self.write_room_name(room) + self.write_room_name(contact) self.print_scroll_position(room) self.finish_line(theme.COLOR_INFORMATION_BAR) self.win.refresh() g_lock.release() - def write_room_name(self, room): - # (room_name, nick) = room.name.split('/', 1) - # self.addnstr(nick, len(nick), curses.color_pair(13)) - txt = '%s' % room.name + def write_room_name(self, contact): + txt = '%s' % contact.get_jid().bare self.addnstr(txt, len(txt), curses.color_pair(theme.COLOR_INFORMATION_BAR)) class MucInfoWin(InfoWin): @@ -951,7 +949,7 @@ class RosterWin(Win): 'chat':theme.COLOR_STATUS_CHAT, 'unavailable': theme.COLOR_STATUS_UNAVAILABLE } - + # subscription_char = {'both': ' def __init__(self, height, width, y, x, parent_win, visible): self.visible = visible Win.__init__(self, height, width, y, x, parent_win) @@ -1000,6 +998,8 @@ class RosterWin(Win): if y >= self.start_pos: self.draw_group(y-self.start_pos+1, group, y-1==self.pos) y += 1 + if group.folded: + continue for contact in group.get_contacts(): if y-1 == self.pos: self.selected_row = contact @@ -1022,7 +1022,7 @@ class RosterWin(Win): Draw the indicator that shows that 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): """ @@ -1035,9 +1035,14 @@ class RosterWin(Win): Draw a groupname on a line """ 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: - 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): """ @@ -1046,11 +1051,16 @@ class RosterWin(Win): is currently selected contact in the list """ 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: - 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: - self.win.addstr(y, 2, contact.get_jid().bare) + self.win.addstr(y, 4, display_name) def get_selected_row(self): return self.selected_row |