remote nickname is colored in ConversationTab

This commit is contained in:
louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 2010-12-31 10:52:15 +00:00
parent 9f4474be20
commit 3b2d28e6ee
9 changed files with 27 additions and 31 deletions

View file

@ -3,7 +3,7 @@ For more detailed changelog, see the roadmap:
http://codingteam.net/project/poezio/roadmap http://codingteam.net/project/poezio/roadmap
* Poezio 0.7 - dev * Poezio 0.7 - dev
"Roster" Codename ”Koshie & Mathieui”
- Introduce the roster - Introduce the roster
- One to one conversations - One to one conversations
- Roster search - Roster search
@ -15,8 +15,7 @@ http://codingteam.net/project/poezio/roadmap
- auto-rejoin when kicked from a MUC - auto-rejoin when kicked from a MUC
- The number of lines available to scroll down is displayed - The number of lines available to scroll down is displayed
- Possibility to use a modified nickname automatically when a nick is reserved - Possibility to use a modified nickname automatically when a nick is reserved
- A line separates the alread-read messages - A line separates the alread-read messages from the new messages
from the new messages in a conversation
- Information messages are more colored - Information messages are more colored
- bugfixes - bugfixes

3
README
View file

@ -79,12 +79,13 @@ the Creative Commons BY license (http://creativecommons.org/licenses/by/2.0/)
Thanks Thanks
======================= =======================
= People = = People =
Link Mauve - Code (a little) Link Mauve - Code
Gaëtan Ribémont (http://www.bonbref.com) - Logo design Gaëtan Ribémont (http://www.bonbref.com) - Logo design
Ovart - Testing Ovart - Testing
mathieui - Testing, Makefile, Documentation and Donation mathieui - Testing, Makefile, Documentation and Donation
Gapan - Makefile Gapan - Makefile
Koshie - Donation Koshie - Donation
FlashCode (weechat dev) - Useful advices on how to use ncurses efficiently FlashCode (weechat dev) - Useful advices on how to use ncurses efficiently
Pipo - Ronrons
= Project = = Project =
Gajim - send_vcard method and common.py Gajim - send_vcard method and common.py

View file

@ -49,7 +49,6 @@ from user import User
from room import Room from room import Room
from roster import Roster, RosterGroup, roster from roster import Roster, RosterGroup, roster
from contact import Contact, Resource from contact import Contact, Resource
from message import Message
from text_buffer import TextBuffer from text_buffer import TextBuffer
from keyboard import read_char from keyboard import read_char
@ -491,8 +490,7 @@ class Core(object):
if not conversation: if not conversation:
# We create the conversation with the bare Jid if nothing was found # We create the conversation with the bare Jid if nothing was found
conversation = self.open_conversation_window(jid.bare, False) conversation = self.open_conversation_window(jid.bare, False)
# room = self.open_conversation_window(jid, False) conversation.get_room().add_message(body, None, jid.full, False, curses.color_pair(theme.COLOR_REMOTE_USER))
self.add_message_to_text_buffer(conversation.get_room(), body, None, jid.full)
if self.current_tab() is not conversation: if self.current_tab() is not conversation:
conversation.set_color_state(theme.COLOR_TAB_PRIVATE) conversation.set_color_state(theme.COLOR_TAB_PRIVATE)
self.refresh_window() self.refresh_window()
@ -765,8 +763,7 @@ class Core(object):
""" """
open a new conversation tab and focus it if needed open a new conversation tab and focus it if needed
""" """
text_buffer = TextBuffer() new_tab = tabs.ConversationTab(self, jid)
new_tab = tabs.ConversationTab(self, text_buffer, jid)
# insert it in the rooms # insert it in the rooms
self.add_tab(new_tab, focus) self.add_tab(new_tab, focus)
self.refresh_window() self.refresh_window()
@ -841,9 +838,8 @@ class Core(object):
body = message['body'] body = message['body']
if body: if body:
date = date if delayed == True else None date = date if delayed == True else None
# if not delayed:
# logger.groupchat(room_from, nick_from, body)
self.add_message_to_text_buffer(room, body, date, nick_from) self.add_message_to_text_buffer(room, body, date, nick_from)
# TODO, only if we are focused on this MUC
self.refresh_window() self.refresh_window()
self.doupdate() self.doupdate()

View file

@ -26,28 +26,27 @@ class Message(object):
The color can be a single number OR a list of numbers, for The color can be a single number OR a list of numbers, for
specials cases like join or quit messages. specials cases like join or quit messages.
""" """
def __init__(self, txt, time=None, nickname=None, user=None, color=None, colorized=False): def __init__(self, txt, time=None, nickname=None, nick_color=None, color=None, colorized=False):
""" """
time is a datetime object, None means 'now'. time is a datetime object, None means 'now'.
If no nickname is specified, it's an information. If no nickname is specified, it's an information.
user is an User object (used for the color, etc)
""" """
self.txt = txt self.txt = txt
self.nickname = nickname self.nickname = nickname
self.time = time self.time = time
self.user = user self.nick_color = nick_color
self.color = color self.color = color
self.colorized = colorized self.colorized = colorized
def __repr__(self): def __repr__(self):
return "<Message txt=%s, nickname=%s, time=%s, user=%s, colorized=%s>" % (self.txt, self.nickname, str(self.time), str(self.user), self.colorized) return "<Message txt=%s, nickname=%s, time=%s, user=%s, colorized=%s>" % (self.txt, self.nickname, str(self.time), str(self.nick_color), self.colorized)
def __str__(self): def __str__(self):
return self.__repr__() return self.__repr__()
class Line(object): class Line(object):
""" """
A line, corresponding to ONE row of the text area. A line, corresponding to ONE row of a TextWin.
A message is composed of ONE line or MORE. A message is composed of ONE line or MORE.
The same particularity for colors in Message class applies The same particularity for colors in Message class applies
here too. here too.

View file

@ -88,7 +88,7 @@ class Room(TextBuffer):
""" """
self.color_state = color self.color_state = color
def add_message(self, txt, time=None, nickname=None, colorized=False, forced_user=None): def add_message(self, txt, time=None, nickname=None, colorized=False, forced_user=None, nick_color=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
@ -116,7 +116,7 @@ class Room(TextBuffer):
if time: # History messages are colored to be distinguished if time: # History messages are colored to be distinguished
color = theme.COLOR_INFORMATION_TEXT color = theme.COLOR_INFORMATION_TEXT
time = time if time is not None else datetime.now() time = time if time is not None else datetime.now()
message = Message(txt, time, nickname, user, color, colorized) message = Message(txt, time, nickname, nick_color or user.color, color, colorized)
while len(self.messages) > MESSAGE_NB_LIMIT: while len(self.messages) > MESSAGE_NB_LIMIT:
self.messages.pop(0) self.messages.pop(0)
self.messages.append(message) self.messages.append(message)

View file

@ -860,9 +860,10 @@ class RosterInfoTab(Tab):
class ConversationTab(ChatTab): class ConversationTab(ChatTab):
""" """
The tab containg a normal conversation (someone from our roster) The tab containg a normal conversation (not from a MUC)
""" """
def __init__(self, core, text_buffer, jid): def __init__(self, core, jid):
text_buffer = windows.TextBuffer()
ChatTab.__init__(self, core, text_buffer) ChatTab.__init__(self, core, text_buffer)
self.color_state = theme.COLOR_TAB_NORMAL self.color_state = theme.COLOR_TAB_NORMAL
self._name = jid # a conversation tab is linked to one specific full jid OR bare jid self._name = jid # a conversation tab is linked to one specific full jid OR bare jid
@ -890,9 +891,6 @@ class ConversationTab(ChatTab):
self.core.add_message_to_text_buffer(self.get_room(), line, None, self.core.own_nick) self.core.add_message_to_text_buffer(self.get_room(), line, None, self.core.own_nick)
def command_unquery(self, arg): def command_unquery(self, arg):
"""
/unquery
"""
self.core.close_tab() self.core.close_tab()
def resize(self): def resize(self):

View file

@ -25,13 +25,14 @@ from message import Message
from datetime import datetime from datetime import datetime
import theme import theme
MESSAGE_NB_LIMIT = 16384 MESSAGE_NB_LIMIT = 8192
class TextBuffer(object): class TextBuffer(object):
""" """
This class just keep trace of messages, in a list with various This class just keep trace of messages, in a list with various
informations and attributes. informations and attributes.
""" """
def __init__(self): def __init__(self):
self.messages = [] # Message objects self.messages = [] # Message objects
self.windows = [] # we keep track of one or more windows self.windows = [] # we keep track of one or more windows
@ -41,13 +42,11 @@ class TextBuffer(object):
def add_window(self, win): def add_window(self, win):
self.windows.append(win) self.windows.append(win)
def add_message(self, txt, time=None, nickname=None, colorized=False): def add_message(self, txt, time=None, nickname=None, colorized=False, nick_color=None):
color = theme.COLOR_NORMAL_TEXT color = theme.COLOR_NORMAL_TEXT
user = None nick_color = nick_color
time = time or datetime.now() time = time or datetime.now()
# if self.pos: # avoid scrolling of one line when one line is received msg = Message(txt, time, nickname, nick_color, color, colorized)
# self.pos += 1
msg = Message(txt, time, nickname, user, color, colorized)
self.messages.append(msg) self.messages.append(msg)
while len(self.messages) > MESSAGE_NB_LIMIT: while len(self.messages) > MESSAGE_NB_LIMIT:
self.messages.pop(0) self.messages.pop(0)
@ -56,3 +55,4 @@ class TextBuffer(object):
nb = window.build_new_message(msg) nb = window.build_new_message(msg)
if window.pos != 0: if window.pos != 0:
window.scroll_up(nb) window.scroll_up(nb)

View file

@ -40,6 +40,9 @@ COLOR_USER_PARTICIPANT = 4
COLOR_USER_NONE = 0 COLOR_USER_NONE = 0
COLOR_USER_MODERATOR = 1 COLOR_USER_MODERATOR = 1
# nickname colors
COLOR_REMOTE_USER = 23
# The character printed in color (COLOR_STATUS_*) before the nickname # The character printed in color (COLOR_STATUS_*) before the nickname
# in the user list # in the user list
CHAR_STATUS = ' ' CHAR_STATUS = ' '

View file

@ -467,7 +467,7 @@ class TextWin(Win):
else: else:
limit = self.width-offset-1 limit = self.width-offset-1
this_line_was_broken_by_space = False this_line_was_broken_by_space = False
color = message.user.color if message.user else None color = message.nick_color
if not first: if not first:
nick = None nick = None
time = None time = None