fixes some crashes, and stuff

parent cdcfddcb
...@@ -35,8 +35,7 @@ import theme ...@@ -35,8 +35,7 @@ import theme
import multiuserchat as muc import multiuserchat as muc
from handler import Handler from handler import Handler
from config import config from config import config
from tab import MucTab, InfoTab, PrivateTab from tab import MucTab, InfoTab, PrivateTab, RosterInfoTab
from window import Window
from user import User from user import User
from room import Room from room import Room
from message import Message from message import Message
...@@ -74,7 +73,9 @@ class Gui(object): ...@@ -74,7 +73,9 @@ class Gui(object):
self.stdscr = curses.initscr() self.stdscr = curses.initscr()
self.init_curses(self.stdscr) self.init_curses(self.stdscr)
self.xmpp = xmpp self.xmpp = xmpp
self.tabs = [InfoTab(self.stdscr, "lol info")] default_tab = InfoTab(self.stdscr, "Info") if self.xmpp.anon\
else RosterInfoTab(self.stdscr, "Roster")
self.tabs = [default_tab]
# a unique buffer used to store global informations # a unique buffer used to store global informations
# that are displayed in almost all tabs, in an # that are displayed in almost all tabs, in an
# information window. # information window.
......
...@@ -355,3 +355,67 @@ class PrivateTab(Tab): ...@@ -355,3 +355,67 @@ class PrivateTab(Tab):
def get_room(self): def get_room(self):
return self._room return self._room
class RosterInfoTab(Tab):
"""
A tab, splitted in two, containg the roster and infos
"""
def __init__(self, stdscr, roster):
Tab.__init__(self, stdscr)
self.name = "Roster"
self.roster = roster
roster_width = self.width//2
info_width = self.width-roster_width-1
self.v_separator = window.VerticalSeparator(self.height-2, 1, 0, roster_width, stdscr, self.visible)
self.tab_win = window.GlobalInfoBar(1, self.width, self.height-2, 0, stdscr, self.visible)
self.info_win = window.TextWin(self.height-2, info_width, 0, roster_width+1, stdscr, self.visible)
self.roster_win = window.RosterWin(self.height-2, roster_width, 0, 0, stdscr, self.visible)
self.input = window.Input(1, self.width, self.height-1, 0, stdscr, self.visible)
self.set_color_state(theme.COLOR_TAB_NORMAL)
def resize(self, stdscr):
Tab.resize(self, stdscr)
roster_width = self.width//2
info_width = self.width-roster_width-1
self.v_separator.resize(self.height-2, 1, 0, roster_width, stdscr, self.visible)
self.tab_win.resize(1, self.width, self.height-2, 0, stdscr, self.visible)
self.info_win.resize(self.height-2, info_width, 0, roster_width+1, stdscr, self.visible)
self.roster_win.resize(self.height-2, roster_width, 0, 0, stdscr, self.visible)
self.input.resize(1, self.width, self.height-1, 0, stdscr, self.visible)
def refresh(self, tabs, informations):
self.v_separator.refresh()
self.roster_win.refresh(self.roster)
self.info_win.refresh(informations)
self.tab_win.refresh(tabs, tabs[0])
self.input.refresh()
def get_name(self):
return self.name
def get_color_state(self):
return self._color_state
def set_color_state(self, color):
self._color_state = color
def on_input(self, key):
return self.input.do_command(key)
def on_lose_focus(self):
self._color_state = theme.COLOR_TAB_NORMAL
def on_gain_focus(self):
self._color_state = theme.COLOR_TAB_CURRENT
def add_message(self):
return False
def on_scroll_down(self):
debug('TODO DOWN')
def on_scroll_up(self):
debug('TODO UP')
def on_info_win_size_changed(self):
return
...@@ -39,7 +39,7 @@ class Win(object): ...@@ -39,7 +39,7 @@ class Win(object):
def _resize(self, height, width, y, x, parent_win): def _resize(self, height, width, y, x, parent_win):
self.height, self.width, self.x, self.y = height, width, x, y self.height, self.width, self.x, self.y = height, width, x, y
try: try:
self.win = parent_win.subwin(height, width, y, x) self.win = curses.newwin(height, width, y, x)
except: except:
from common import debug from common import debug
debug('%s %s %s %s %s\n' % (height, width, y, x, parent_win)) debug('%s %s %s %s %s\n' % (height, width, y, x, parent_win))
...@@ -312,14 +312,8 @@ class TextWin(Win): ...@@ -312,14 +312,8 @@ class TextWin(Win):
on each change. (thanks weechat :o) on each change. (thanks weechat :o)
""" """
def __init__(self, height, width, y, x, parent_win, visible): def __init__(self, height, width, y, x, parent_win, visible):
self.visible = visible
self.height = height
self.width = width
self.y = y
self.x = x
self.parent_win = parent_win
Win.__init__(self, height, width, y, x, parent_win) Win.__init__(self, height, width, y, x, parent_win)
self.win.scrollok(1) self.visible = visible
def build_lines_from_messages(self, messages): def build_lines_from_messages(self, messages):
""" """
...@@ -445,7 +439,7 @@ class TextWin(Win): ...@@ -445,7 +439,7 @@ class TextWin(Win):
try: try:
splitted = shlex.split(txt) splitted = shlex.split(txt)
except ValueError: except ValueError:
txt += '"' txt = txt.replace('"', '')
splitted = shlex.split(txt) splitted = shlex.split(txt)
for word in splitted: for word in splitted:
if word in list(special_words.keys()): if word in list(special_words.keys()):
...@@ -882,20 +876,21 @@ class Input(Win): ...@@ -882,20 +876,21 @@ class Input(Win):
def clear_text(self): def clear_text(self):
self.win.erase() self.win.erase()
class Window(object): # class RosterWin(Win):
""" # def __init__(self, height, width, y, x, parent_win, visible):
The whole "screen" that can be seen at once in the terminal. # Win.__init__(self, height, width, y, x, parent_win)
It contains an userlist, an input zone, a topic zone and a chat zone # self.visible = visible
"""
# def resize(self, height, width, y, x, stdscr, visible):
# self._resize(height, width, y, x, stdscr)
# self.visible = visible
# TODO JidWindow # def refresh(self, roster):
# elif jid: # g_lock.acquire()
# room = jid.split('/')[0] # self.win.erase()
# nick = '/'.join(jid.split('/')[1:]) # self.addnstr('teub', 4)
# topic = _('%(nick)s from room %(room)s' % {'nick': nick, 'room':room}) # self.win.refresh()
# self.addnstr(0, 0, topic + " "*(self.width-len(topic)), self.width-1 # g_lock.release()
# , curses.color_pair(theme.COLOR_PRIVATE_ROOM_BAR))
class VerticalSeparator(Win): class VerticalSeparator(Win):
""" """
...@@ -922,3 +917,71 @@ class VerticalSeparator(Win): ...@@ -922,3 +917,71 @@ class VerticalSeparator(Win):
if not self.visible: if not self.visible:
return return
self.rewrite_line() self.rewrite_line()
class RosterWin(Win):
"""
"""
def __init__(self, height, width, y, x, parent_win, visible):
self.visible = visible
Win.__init__(self, height, width, y, x, parent_win)
self.pos = 0 # position in the contact list
def resize(self, height, width, y, x, stdscr, visible):
self._resize(height, width, y, x, stdscr)
def refresh(self, roster=None):
"""
We get the roster object
"""
if not self.visible or not roster:
return
g_lock.acquire()
self.win.erase()
# TODO, two ways of scrolling
# currently: always centered
if self.pos > self.height//2 and\
self.pos + self.height//2 < len(roster.getContacts()):
# We are centered
begin = True
end = True
pos = self.height//2
contacts = roster.getContacts()[self.pos-pos:self.pos+pos+1]
elif self.pos <= self.height//2:
# we are at the beginning of the list
pos = self.pos
contacts = roster.getContacts()[:self.height]
begin = False
if self.height < len(roster.getContacts()):
end = True
else:
end = False
else:
# we are at the end of the list
pos = self.height - (len(roster.getContacts()) - self.pos)
contacts = roster.getContacts()[-self.height:]
begin = True
end = False
cpt = 0 # ipair ou chais plus quoi
for contact in contacts:
if cpt == pos:
self.draw_contact_line(contact, cpt, 0, 3)
else:
self.draw_contact_line(contact, cpt, 0)
cpt += 1
if end:
self.win.addstr(self.height-1, 0, '++++')
if begin:
self.win.addstr(0, 0, '++++')
self.win.refresh()
g_lock.release()
def draw_contact_line(self, contact, x, y, color=None):
"""
Draw on a line all informations about one contact
Use 'color' to draw the jid/display_name to show what is
is currently selected contact in the list
"""
if color:
self.win.addstr(x, y, contact.getJid().full, curses.color_pair(color))
else:
self.win.addstr(x, y, contact.getJid().full)
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