fix ctrl+x, automatic-completion. Add auto-rejoin (fixed #1662)
This commit is contained in:
parent
1c73778040
commit
ba08dd43da
4 changed files with 97 additions and 61 deletions
|
@ -48,6 +48,12 @@ import time
|
||||||
|
|
||||||
import xmpp
|
import xmpp
|
||||||
|
|
||||||
|
ROOM_STATE_NONE = 11
|
||||||
|
ROOM_STATE_CURRENT = 10
|
||||||
|
ROOM_STATE_PRIVATE = 15
|
||||||
|
ROOM_STATE_MESSAGE = 12
|
||||||
|
ROOM_STATE_HL = 13
|
||||||
|
|
||||||
def debug(string):
|
def debug(string):
|
||||||
"""
|
"""
|
||||||
Print a string in a file.
|
Print a string in a file.
|
||||||
|
|
59
src/gui.py
59
src/gui.py
|
@ -215,6 +215,13 @@ class Gui(object):
|
||||||
self.information(_("Welcome on Poezio \o/!"))
|
self.information(_("Welcome on Poezio \o/!"))
|
||||||
self.information(_("Your JID is %s") % jid)
|
self.information(_("Your JID is %s") % jid)
|
||||||
|
|
||||||
|
def refresh_window(self):
|
||||||
|
"""
|
||||||
|
Refresh everything
|
||||||
|
"""
|
||||||
|
self.current_room().set_color_state(common.ROOM_STATE_CURRENT)
|
||||||
|
self.window.refresh(self.rooms)
|
||||||
|
|
||||||
def join_room(self, room, nick):
|
def join_room(self, room, nick):
|
||||||
"""
|
"""
|
||||||
join the specified room (muc), using the specified nick
|
join the specified room (muc), using the specified nick
|
||||||
|
@ -228,9 +235,8 @@ class Gui(object):
|
||||||
if ro.nb == 0:
|
if ro.nb == 0:
|
||||||
self.rooms.insert(self.rooms.index(ro), r)
|
self.rooms.insert(self.rooms.index(ro), r)
|
||||||
break
|
break
|
||||||
while self.current_room().nb != r.nb:
|
self.command_win("%s" % r.nb)
|
||||||
self.rooms.insert(0, self.rooms.pop())
|
self.refresh_window()
|
||||||
self.window.refresh(self.rooms)
|
|
||||||
|
|
||||||
def completion(self):
|
def completion(self):
|
||||||
"""
|
"""
|
||||||
|
@ -247,6 +253,7 @@ class Gui(object):
|
||||||
return 1
|
return 1
|
||||||
if len(self.window.input.text) == 0:
|
if len(self.window.input.text) == 0:
|
||||||
self.last_talked_completion()
|
self.last_talked_completion()
|
||||||
|
else:
|
||||||
self.window.input.auto_completion([user.nick for user in sorted(self.current_room().users, compare_users)])
|
self.window.input.auto_completion([user.nick for user in sorted(self.current_room().users, compare_users)])
|
||||||
|
|
||||||
def last_talked_completion(self):
|
def last_talked_completion(self):
|
||||||
|
@ -258,6 +265,7 @@ class Gui(object):
|
||||||
if msg.nickname is not None and msg.nickname != self.current_room().own_nick:
|
if msg.nickname is not None and msg.nickname != self.current_room().own_nick:
|
||||||
self.window.input.text = msg.nickname+config.get('after_completion', ',')+" "
|
self.window.input.text = msg.nickname+config.get('after_completion', ',')+" "
|
||||||
self.window.input.key_end()
|
self.window.input.key_end()
|
||||||
|
return
|
||||||
|
|
||||||
def last_words_completion(self):
|
def last_words_completion(self):
|
||||||
"""
|
"""
|
||||||
|
@ -283,39 +291,42 @@ class Gui(object):
|
||||||
"""
|
"""
|
||||||
for room in self.rooms:
|
for room in self.rooms:
|
||||||
if room.color_state == 15:
|
if room.color_state == 15:
|
||||||
self.command_win([room.nb])
|
self.command_win('%s' % room.nb)
|
||||||
return
|
return
|
||||||
for room in self.rooms:
|
for room in self.rooms:
|
||||||
if room.color_state == 13:
|
if room.color_state == 13:
|
||||||
self.command_win([room.nb])
|
self.command_win('%s' % room.nb)
|
||||||
return
|
return
|
||||||
for room in self.rooms:
|
for room in self.rooms:
|
||||||
if room.color_state == 12:
|
if room.color_state == 12:
|
||||||
self.command_win([room.nb])
|
self.command_win('%s' % room.nb)
|
||||||
|
return
|
||||||
|
|
||||||
def rotate_rooms_right(self, args=None):
|
def rotate_rooms_right(self, args=None):
|
||||||
"""
|
"""
|
||||||
rotate the rooms list to the right
|
rotate the rooms list to the right
|
||||||
"""
|
"""
|
||||||
self.current_room().set_color_state(11)
|
self.current_room().set_color_state(common.ROOM_STATE_NONE)
|
||||||
self.rooms.append(self.rooms.pop(0))
|
self.rooms.append(self.rooms.pop(0))
|
||||||
self.window.refresh(self.rooms)
|
self.current_room().set_color_state(common.ROOM_STATE_CURRENT)
|
||||||
|
self.refresh_window()
|
||||||
|
|
||||||
def rotate_rooms_left(self, args=None):
|
def rotate_rooms_left(self, args=None):
|
||||||
"""
|
"""
|
||||||
rotate the rooms list to the right
|
rotate the rooms list to the right
|
||||||
"""
|
"""
|
||||||
self.current_room().set_color_state(11)
|
self.current_room().set_color_state(common.ROOM_STATE_NONE)
|
||||||
self.rooms.insert(0, self.rooms.pop())
|
self.rooms.insert(0, self.rooms.pop())
|
||||||
self.window.refresh(self.rooms)
|
self.current_room().set_color_state(common.ROOM_STATE_CURRENT)
|
||||||
|
self.refresh_window()
|
||||||
|
|
||||||
def scroll_page_down(self, args=None):
|
def scroll_page_down(self, args=None):
|
||||||
self.current_room().scroll_down()
|
self.current_room().scroll_down()
|
||||||
self.window.refresh(self.rooms)
|
self.refresh_window()
|
||||||
|
|
||||||
def scroll_page_up(self, args=None):
|
def scroll_page_up(self, args=None):
|
||||||
self.current_room().scroll_up(self.window.size)
|
self.current_room().scroll_up(self.window.size)
|
||||||
self.window.refresh(self.rooms)
|
self.refresh_window()
|
||||||
|
|
||||||
def room_error(self, room, error, msg):
|
def room_error(self, room, error, msg):
|
||||||
"""
|
"""
|
||||||
|
@ -334,7 +345,7 @@ class Gui(object):
|
||||||
{'msg':msg, 'code':code, 'body':body}))
|
{'msg':msg, 'code':code, 'body':body}))
|
||||||
if code == '401':
|
if code == '401':
|
||||||
room.add(_('To provide a password in order to join the room, type "/join / password" (replace "password" by the real password)'))
|
room.add(_('To provide a password in order to join the room, type "/join / password" (replace "password" by the real password)'))
|
||||||
self.window.refresh(self.rooms)
|
self.refresh_window()
|
||||||
|
|
||||||
def private_message(self, stanza):
|
def private_message(self, stanza):
|
||||||
"""
|
"""
|
||||||
|
@ -358,7 +369,7 @@ class Gui(object):
|
||||||
for room in self.rooms: # if the room exists, focus it and return
|
for room in self.rooms: # if the room exists, focus it and return
|
||||||
if room.jid:
|
if room.jid:
|
||||||
if room.jid == complete_jid:
|
if room.jid == complete_jid:
|
||||||
self.command_win(str(room.nb))
|
self.command_win('%s' % room.nb)
|
||||||
return
|
return
|
||||||
# create the new tab
|
# create the new tab
|
||||||
room = self.get_room_by_name(room_name)
|
room = self.get_room_by_name(room_name)
|
||||||
|
@ -378,7 +389,7 @@ class Gui(object):
|
||||||
while self.current_room().nb != r.nb:
|
while self.current_room().nb != r.nb:
|
||||||
self.rooms.insert(0, self.rooms.pop())
|
self.rooms.insert(0, self.rooms.pop())
|
||||||
# self.window.new_room(r)
|
# self.window.new_room(r)
|
||||||
self.window.refresh(self.rooms)
|
self.refresh_window()
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def room_message(self, stanza, date=None):
|
def room_message(self, stanza, date=None):
|
||||||
|
@ -424,7 +435,7 @@ class Gui(object):
|
||||||
else:
|
else:
|
||||||
date = date if delayed == True else None
|
date = date if delayed == True else None
|
||||||
self.add_message_to_room(room, body, date, nick_from)
|
self.add_message_to_room(room, body, date, nick_from)
|
||||||
self.window.refresh(self.rooms)
|
self.refresh_window()
|
||||||
doupdate()
|
doupdate()
|
||||||
|
|
||||||
def room_presence(self, stanza):
|
def room_presence(self, stanza):
|
||||||
|
@ -497,6 +508,9 @@ class Gui(object):
|
||||||
self.add_message_to_room(room, _("You have been kicked by %(by)s. Reason: %(reason)s") % {'by':by, 'reason':reason})
|
self.add_message_to_room(room, _("You have been kicked by %(by)s. Reason: %(reason)s") % {'by':by, 'reason':reason})
|
||||||
else:
|
else:
|
||||||
self.add_message_to_room(room, _("You have been kicked. Reason: %s") % (reason))
|
self.add_message_to_room(room, _("You have been kicked. Reason: %s") % (reason))
|
||||||
|
# try to auto-rejoin
|
||||||
|
if config.get('autorejoin', 'false') == 'true':
|
||||||
|
self.muc.join_room(room.name, room.own_nick)
|
||||||
else:
|
else:
|
||||||
if by:
|
if by:
|
||||||
self.add_message_to_room(room, _("%(nick)s has been kicked by %(by)s. Reason: %(reason)s") % {'nick':from_nick, 'by':by, 'reason':reason})
|
self.add_message_to_room(room, _("%(nick)s has been kicked by %(by)s. Reason: %(reason)s") % {'nick':from_nick, 'by':by, 'reason':reason})
|
||||||
|
@ -618,16 +632,17 @@ class Gui(object):
|
||||||
return
|
return
|
||||||
if self.current_room().nb == nb:
|
if self.current_room().nb == nb:
|
||||||
return
|
return
|
||||||
self.current_room().set_color_state(11)
|
self.current_room().set_color_state(common.ROOM_STATE_NONE)
|
||||||
start = self.current_room()
|
start = self.current_room()
|
||||||
self.rooms.append(self.rooms.pop(0))
|
self.rooms.append(self.rooms.pop(0))
|
||||||
while self.current_room().nb != nb:
|
while self.current_room().nb != nb:
|
||||||
self.rooms.append(self.rooms.pop(0))
|
self.rooms.append(self.rooms.pop(0))
|
||||||
if self.current_room() == start:
|
if self.current_room() == start:
|
||||||
self.window.refresh(self.rooms)
|
self.current_room().set_color_state(common.ROOM_STATE_CURRENT)
|
||||||
|
self.refresh_window()
|
||||||
return
|
return
|
||||||
self.window.refresh(self.rooms)
|
self.current_room().set_color_state(common.ROOM_STATE_CURRENT)
|
||||||
self.current_room().set_color_state(11)
|
self.refresh_window()
|
||||||
|
|
||||||
def command_kick(self, arg):
|
def command_kick(self, arg):
|
||||||
"""
|
"""
|
||||||
|
@ -858,7 +873,7 @@ class Gui(object):
|
||||||
if room.joined:
|
if room.joined:
|
||||||
self.muc.quit_room(room.name, room.own_nick, msg)
|
self.muc.quit_room(room.name, room.own_nick, msg)
|
||||||
self.rooms.remove(self.current_room())
|
self.rooms.remove(self.current_room())
|
||||||
self.window.refresh(self.rooms)
|
self.refresh_window()
|
||||||
|
|
||||||
def command_unquery(self, arg):
|
def command_unquery(self, arg):
|
||||||
"""
|
"""
|
||||||
|
@ -867,7 +882,7 @@ class Gui(object):
|
||||||
room = self.current_room()
|
room = self.current_room()
|
||||||
if room.jid is not None:
|
if room.jid is not None:
|
||||||
self.rooms.remove(room)
|
self.rooms.remove(room)
|
||||||
self.window.refresh(self.rooms)
|
self.refresh_window()
|
||||||
|
|
||||||
def command_query(self, arg):
|
def command_query(self, arg):
|
||||||
"""
|
"""
|
||||||
|
|
80
src/room.py
80
src/room.py
|
@ -22,6 +22,8 @@ from config import config
|
||||||
from logging import logger
|
from logging import logger
|
||||||
from message import Message
|
from message import Message
|
||||||
|
|
||||||
|
import common
|
||||||
|
|
||||||
class Room(object):
|
class Room(object):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
@ -30,7 +32,7 @@ class Room(object):
|
||||||
self.jid = jid # used for a private chat. None if it's a MUC
|
self.jid = jid # used for a private chat. None if it's a MUC
|
||||||
self.name = name
|
self.name = name
|
||||||
self.own_nick = nick
|
self.own_nick = nick
|
||||||
self.color_state = 11 # color used in RoomInfo
|
self.color_state = common.ROOM_STATE_NONE # color used in RoomInfo
|
||||||
self.nb = Room.number # number used in RoomInfo
|
self.nb = Room.number # number used in RoomInfo
|
||||||
Room.number += 1
|
Room.number += 1
|
||||||
self.joined = False # false until self presence is received
|
self.joined = False # false until self presence is received
|
||||||
|
@ -40,60 +42,77 @@ class Room(object):
|
||||||
self.window = window
|
self.window = window
|
||||||
self.pos = 0 # offset
|
self.pos = 0 # offset
|
||||||
|
|
||||||
def scroll_up(self, y_x):
|
def scroll_up(self, y_x, dist=14):
|
||||||
y, x = y_x
|
y, x = y_x
|
||||||
if len(self.messages) <= y:
|
if len(self.messages) <= y:
|
||||||
return
|
return
|
||||||
self.pos += 14
|
self.pos += dist
|
||||||
if self.pos + y >= len(self.messages):
|
if self.pos + y >= len(self.messages):
|
||||||
self.pos = len(self.messages) - y+3
|
self.pos = len(self.messages) - y+3
|
||||||
|
|
||||||
def scroll_down(self):
|
def scroll_down(self, dist=14):
|
||||||
self.pos -= 14
|
self.pos -= dist
|
||||||
if self.pos <= 0:
|
if self.pos <= 0:
|
||||||
self.pos = 0
|
self.pos = 0
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
self.joined = False
|
self.joined = False
|
||||||
|
|
||||||
|
def log_message(self, txt, time, nickname):
|
||||||
|
"""
|
||||||
|
Log the messages in the archives, if it needs
|
||||||
|
to be
|
||||||
|
"""
|
||||||
|
if time == None and self.joined: # don't log the history messages
|
||||||
|
logger.message(self.name, nickname, txt)
|
||||||
|
|
||||||
|
def do_highlight(self, txt, time, nickname):
|
||||||
|
"""
|
||||||
|
Set the tab color and returns the txt color
|
||||||
|
"""
|
||||||
|
color = None
|
||||||
|
if not time and nickname != self.own_nick and self.joined and nickname is not None: # do the highlight
|
||||||
|
try:
|
||||||
|
if self.own_nick.encode('utf-8') in txt:
|
||||||
|
self.set_color_state(13)
|
||||||
|
color = 2
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
try:
|
||||||
|
if self.own_nick in txt:
|
||||||
|
self.set_color_state(13)
|
||||||
|
color = 2
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
highlight_words = config.get('highlight_on', '').split(':')
|
||||||
|
for word in highlight_words:
|
||||||
|
if word.lower() in txt.lower() and word != '':
|
||||||
|
self.set_color_state(common.ROOM_STATE_HL)
|
||||||
|
color = 2
|
||||||
|
break
|
||||||
|
return color
|
||||||
|
|
||||||
def add_message(self, txt, time=None, nickname=None):
|
def add_message(self, txt, time=None, nickname=None):
|
||||||
"""
|
"""
|
||||||
Note that user can be None even if nickname is not None. It happens
|
Note that user can be None even if nickname is not None. It happens
|
||||||
when we receive an history message said by someone who is not
|
when we receive an history message said by someone who is not
|
||||||
in the room anymore
|
in the room anymore
|
||||||
"""
|
"""
|
||||||
if time == None and self.joined: # don't log the history messages
|
self.log_message(txt, time, nickname)
|
||||||
logger.message(self.name, nickname, txt)
|
|
||||||
user = self.get_user_by_name(nickname) if nickname is not None else None
|
user = self.get_user_by_name(nickname) if nickname is not None else None
|
||||||
if user:
|
if user:
|
||||||
user.set_last_talked(datetime.now())
|
user.set_last_talked(datetime.now())
|
||||||
color = None
|
color = None
|
||||||
if not time and nickname is not None:
|
if not time and nickname is not None and\
|
||||||
|
nickname != self.own_nick and\
|
||||||
|
self.color_state != common.ROOM_STATE_CURRENT:
|
||||||
if not self.jid:
|
if not self.jid:
|
||||||
self.set_color_state(12)
|
self.set_color_state(common.ROOM_STATE_MESSAGE)
|
||||||
else:
|
|
||||||
self.set_color_state(15)
|
|
||||||
else:
|
else:
|
||||||
|
self.set_color_state(common.ROOM_STATE_PRIVATE)
|
||||||
|
color = self.do_highlight(txt, time, nickname)
|
||||||
|
if time: # History messages are colored to be distinguished
|
||||||
color = 8
|
color = 8
|
||||||
if not time and nickname != self.own_nick and self.joined and nickname is not None: # do the highlight
|
|
||||||
try:
|
|
||||||
if self.own_nick.encode('utf-8') in txt:
|
|
||||||
self.set_color_state(13)
|
|
||||||
color = 3
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
try:
|
|
||||||
if self.own_nick in txt:
|
|
||||||
self.set_color_state(13)
|
|
||||||
color = 3
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
highlight_words = config.get('highlight_on', '').split(':')
|
|
||||||
for word in highlight_words:
|
|
||||||
if word.lower() in txt.lower() and word != '':
|
|
||||||
self.set_color_state(13)
|
|
||||||
color = 2
|
|
||||||
break
|
|
||||||
time = time if time is not None else datetime.now()
|
time = time if time is not None else datetime.now()
|
||||||
self.messages.append(Message(txt, time, nickname, user, color))
|
self.messages.append(Message(txt, time, nickname, user, color))
|
||||||
|
|
||||||
|
@ -108,5 +127,4 @@ class Room(object):
|
||||||
Set the color that will be used to display the room's
|
Set the color that will be used to display the room's
|
||||||
number in the RoomInfo window
|
number in the RoomInfo window
|
||||||
"""
|
"""
|
||||||
if self.color_state < color or color == 11:
|
|
||||||
self.color_state = color
|
self.color_state = color
|
||||||
|
|
|
@ -160,13 +160,10 @@ class RoomInfo(Win):
|
||||||
,curses.color_pair(1))
|
,curses.color_pair(1))
|
||||||
sorted_rooms = sorted(rooms, compare_room)
|
sorted_rooms = sorted(rooms, compare_room)
|
||||||
for room in sorted_rooms:
|
for room in sorted_rooms:
|
||||||
if current == room:
|
|
||||||
color = 10
|
|
||||||
else:
|
|
||||||
color = room.color_state
|
color = room.color_state
|
||||||
try:
|
try:
|
||||||
self.win.addstr(str(room.nb), curses.color_pair(color))
|
self.win.addstr("%s" % str(room.nb), curses.color_pair(color))
|
||||||
self.win.addstr(",", curses.color_pair(1))
|
self.win.addstr(u"|".encode('utf-8'), curses.color_pair(1))
|
||||||
except: # end of line
|
except: # end of line
|
||||||
break
|
break
|
||||||
(y, x) = self.win.getyx()
|
(y, x) = self.win.getyx()
|
||||||
|
|
Loading…
Reference in a new issue