summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common.py6
-rw-r--r--src/gui.py61
-rw-r--r--src/room.py66
-rw-r--r--src/window.py9
4 files changed, 89 insertions, 53 deletions
diff --git a/src/common.py b/src/common.py
index 6cd83248..c0bb97e7 100644
--- a/src/common.py
+++ b/src/common.py
@@ -48,6 +48,12 @@ import time
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):
"""
Print a string in a file.
diff --git a/src/gui.py b/src/gui.py
index 0cf27d7b..0363026e 100644
--- a/src/gui.py
+++ b/src/gui.py
@@ -215,6 +215,13 @@ class Gui(object):
self.information(_("Welcome on Poezio \o/!"))
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):
"""
join the specified room (muc), using the specified nick
@@ -228,9 +235,8 @@ class Gui(object):
if ro.nb == 0:
self.rooms.insert(self.rooms.index(ro), r)
break
- while self.current_room().nb != r.nb:
- self.rooms.insert(0, self.rooms.pop())
- self.window.refresh(self.rooms)
+ self.command_win("%s" % r.nb)
+ self.refresh_window()
def completion(self):
"""
@@ -247,7 +253,8 @@ class Gui(object):
return 1
if len(self.window.input.text) == 0:
self.last_talked_completion()
- self.window.input.auto_completion([user.nick for user in sorted(self.current_room().users, compare_users)])
+ else:
+ self.window.input.auto_completion([user.nick for user in sorted(self.current_room().users, compare_users)])
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:
self.window.input.text = msg.nickname+config.get('after_completion', ',')+" "
self.window.input.key_end()
+ return
def last_words_completion(self):
"""
@@ -283,39 +291,42 @@ class Gui(object):
"""
for room in self.rooms:
if room.color_state == 15:
- self.command_win([room.nb])
+ self.command_win('%s' % room.nb)
return
for room in self.rooms:
if room.color_state == 13:
- self.command_win([room.nb])
+ self.command_win('%s' % room.nb)
return
for room in self.rooms:
if room.color_state == 12:
- self.command_win([room.nb])
+ self.command_win('%s' % room.nb)
+ return
def rotate_rooms_right(self, args=None):
"""
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.window.refresh(self.rooms)
+ self.current_room().set_color_state(common.ROOM_STATE_CURRENT)
+ self.refresh_window()
def rotate_rooms_left(self, args=None):
"""
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.window.refresh(self.rooms)
+ self.current_room().set_color_state(common.ROOM_STATE_CURRENT)
+ self.refresh_window()
def scroll_page_down(self, args=None):
self.current_room().scroll_down()
- self.window.refresh(self.rooms)
+ self.refresh_window()
def scroll_page_up(self, args=None):
self.current_room().scroll_up(self.window.size)
- self.window.refresh(self.rooms)
+ self.refresh_window()
def room_error(self, room, error, msg):
"""
@@ -334,7 +345,7 @@ class Gui(object):
{'msg':msg, 'code':code, 'body':body}))
if code == '401':
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):
"""
@@ -358,7 +369,7 @@ class Gui(object):
for room in self.rooms: # if the room exists, focus it and return
if room.jid:
if room.jid == complete_jid:
- self.command_win(str(room.nb))
+ self.command_win('%s' % room.nb)
return
# create the new tab
room = self.get_room_by_name(room_name)
@@ -378,7 +389,7 @@ class Gui(object):
while self.current_room().nb != r.nb:
self.rooms.insert(0, self.rooms.pop())
# self.window.new_room(r)
- self.window.refresh(self.rooms)
+ self.refresh_window()
return r
def room_message(self, stanza, date=None):
@@ -424,7 +435,7 @@ class Gui(object):
else:
date = date if delayed == True else None
self.add_message_to_room(room, body, date, nick_from)
- self.window.refresh(self.rooms)
+ self.refresh_window()
doupdate()
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})
else:
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:
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})
@@ -618,16 +632,17 @@ class Gui(object):
return
if self.current_room().nb == nb:
return
- self.current_room().set_color_state(11)
+ self.current_room().set_color_state(common.ROOM_STATE_NONE)
start = self.current_room()
self.rooms.append(self.rooms.pop(0))
while self.current_room().nb != nb:
self.rooms.append(self.rooms.pop(0))
if self.current_room() == start:
- self.window.refresh(self.rooms)
+ self.current_room().set_color_state(common.ROOM_STATE_CURRENT)
+ self.refresh_window()
return
- self.window.refresh(self.rooms)
- self.current_room().set_color_state(11)
+ self.current_room().set_color_state(common.ROOM_STATE_CURRENT)
+ self.refresh_window()
def command_kick(self, arg):
"""
@@ -858,7 +873,7 @@ class Gui(object):
if room.joined:
self.muc.quit_room(room.name, room.own_nick, msg)
self.rooms.remove(self.current_room())
- self.window.refresh(self.rooms)
+ self.refresh_window()
def command_unquery(self, arg):
"""
@@ -867,7 +882,7 @@ class Gui(object):
room = self.current_room()
if room.jid is not None:
self.rooms.remove(room)
- self.window.refresh(self.rooms)
+ self.refresh_window()
def command_query(self, arg):
"""
diff --git a/src/room.py b/src/room.py
index a5134122..b7cb8ed3 100644
--- a/src/room.py
+++ b/src/room.py
@@ -22,6 +22,8 @@ from config import config
from logging import logger
from message import Message
+import common
+
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.name = name
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
Room.number += 1
self.joined = False # false until self presence is received
@@ -40,60 +42,77 @@ class Room(object):
self.window = window
self.pos = 0 # offset
- def scroll_up(self, y_x):
+ def scroll_up(self, y_x, dist=14):
y, x = y_x
if len(self.messages) <= y:
return
- self.pos += 14
+ self.pos += dist
if self.pos + y >= len(self.messages):
self.pos = len(self.messages) - y+3
- def scroll_down(self):
- self.pos -= 14
+ def scroll_down(self, dist=14):
+ self.pos -= dist
if self.pos <= 0:
self.pos = 0
def disconnect(self):
self.joined = False
- def add_message(self, txt, time=None, nickname=None):
+ def log_message(self, txt, time, nickname):
"""
- 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
- in the room anymore
+ 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)
- user = self.get_user_by_name(nickname) if nickname is not None else None
- if user:
- user.set_last_talked(datetime.now())
+
+ def do_highlight(self, txt, time, nickname):
+ """
+ Set the tab color and returns the txt color
+ """
color = None
- if not time and nickname is not None:
- if not self.jid:
- self.set_color_state(12)
- else:
- self.set_color_state(15)
- else:
- 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
+ color = 2
except UnicodeDecodeError:
try:
if self.own_nick in txt:
self.set_color_state(13)
- color = 3
+ 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(13)
+ self.set_color_state(common.ROOM_STATE_HL)
color = 2
break
+ return color
+
+ def add_message(self, txt, time=None, nickname=None):
+ """
+ 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
+ in the room anymore
+ """
+ self.log_message(txt, time, nickname)
+ user = self.get_user_by_name(nickname) if nickname is not None else None
+ if user:
+ user.set_last_talked(datetime.now())
+ color = 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:
+ self.set_color_state(common.ROOM_STATE_MESSAGE)
+ 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
time = time if time is not None else datetime.now()
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
number in the RoomInfo window
"""
- if self.color_state < color or color == 11:
- self.color_state = color
+ self.color_state = color
diff --git a/src/window.py b/src/window.py
index a3c35b2e..f50d8c08 100644
--- a/src/window.py
+++ b/src/window.py
@@ -160,13 +160,10 @@ class RoomInfo(Win):
,curses.color_pair(1))
sorted_rooms = sorted(rooms, compare_room)
for room in sorted_rooms:
- if current == room:
- color = 10
- else:
- color = room.color_state
+ color = room.color_state
try:
- self.win.addstr(str(room.nb), curses.color_pair(color))
- self.win.addstr(",", curses.color_pair(1))
+ self.win.addstr("%s" % str(room.nb), curses.color_pair(color))
+ self.win.addstr(u"|".encode('utf-8'), curses.color_pair(1))
except: # end of line
break
(y, x) = self.win.getyx()