summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/connection.py8
-rw-r--r--src/gui.py30
-rw-r--r--src/handler.py5
-rw-r--r--src/multiuserchat.py10
-rw-r--r--src/window.py4
5 files changed, 44 insertions, 13 deletions
diff --git a/src/connection.py b/src/connection.py
index 94167c75..ec5a2d9d 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -85,7 +85,7 @@ class Connection(Thread):
if fro == to: # own presence
self.online = 2
self.jid = to
- self.handler.emit('on-connected')
+ self.handler.emit('on-connected', jid=fro)
return
self.handler.emit('room-presence', stanza=presence)
@@ -93,12 +93,12 @@ class Connection(Thread):
self.handler.emit('room-message', stanza=message)
def handler_iq(self, connection, iq):
- pass
+ self.handler.emit('room-iq', stanza=iq)
def handler_error(self, connection, error):
- import sys
- print "TOUCHE FION"
+ print "fion"
sys.exit()
+# self.handler.emit('room-iq', stanza=iq)
def process(self, timeout=10):
if self.online:
diff --git a/src/gui.py b/src/gui.py
index 2e2a33e7..ddcd57d6 100644
--- a/src/gui.py
+++ b/src/gui.py
@@ -96,13 +96,23 @@ class Room(object):
user.change_nick(stanza.getNick())
return self.add_info('%s is now known as %s' % (nick, stanza.getNick()))
if kick:
+ self.users.remove(user)
reason = stanza.getReason().encode('utf-8') or ''
- by = stanza.getActor().encode('utf-8') or ''
+ try:
+ by = stanza.getActor().encode('utf-8')
+ except:
+ by = None
if nick == self.own_nick:
self.joined = False
- return self.add_info('You have been kicked by %s. Reason: %s' % (by, reason))
+ if by:
+ return self.add_info('You have been kicked by %s. Reason: %s' % (by, reason))
+ else:
+ return self.add_info('You have been kicked. Reason: %s' % (reason))
else:
- return self.add_info('%s has been kicked by %s. Reason: %s' % (nick, by, reason))
+ if by:
+ return self.add_info('%s has been kicked by %s. Reason: %s' % (nick, by, reason))
+ else:
+ return self.add_info('%s has been kicked. Reason: %s' % (nick, reason))
if status == 'offline' or role == 'none':
self.users.remove(user)
return self.add_info('%s has left the room' % (nick))
@@ -154,6 +164,7 @@ class Gui(object):
self.handler.connect('join-room', self.join_room)
self.handler.connect('room-presence', self.room_presence)
self.handler.connect('room-message', self.room_message)
+ self.handler.connect('room-iq', self.room_iq)
def main_loop(self, stdscr):
while 1:
@@ -211,8 +222,9 @@ class Gui(object):
curses.echo()
curses.endwin()
- def on_connected(self):
+ def on_connected(self, jid):
self.information("Welcome on Poezio \o/ !")
+ self.information("Your JID is %s" % jid)
pass
def join_room(self, room, nick):
@@ -229,6 +241,8 @@ class Gui(object):
self.window.refresh(self.current_room())
def room_message(self, stanza):
+ if len(sys.argv) > 1:
+ self.information(str(stanza))
if stanza.getType() != 'groupchat':
return # ignore all messages not comming from a MUC
room_from = stanza.getFrom().getStripped()
@@ -263,7 +277,7 @@ class Gui(object):
from_room = stanza.getFrom().getStripped()
room = self.get_room_by_name(from_room)
if not room:
- return logger.warning("presence received for a non-existing room: %s" % (name))
+ self.information("presence received for a non-existing room: %s" % (name))
msg = room.on_presence(stanza, from_nick)
if room == self.current_room():
self.window.text_win.add_line(room, (datetime.now(), msg))
@@ -271,6 +285,10 @@ class Gui(object):
self.window.user_win.refresh(room.users)
curses.doupdate()
+ def room_iq(self, iq):
+ if len(sys.argv) > 1:
+ self.information(str(iq))
+
def execute(self):
line = self.window.input.get_text()
self.window.input.clear_text()
@@ -301,6 +319,8 @@ class Gui(object):
info = room.add_info(msg)
if self.current_room() == room:
self.window.text_win.add_line(room, (datetime.now(), info))
+ self.window.text_win.refresh(room.name)
+ curses.doupdate()
def command_quit(self, args):
self.reset_curses()
diff --git a/src/handler.py b/src/handler.py
index 5d7831e7..8942ae7c 100644
--- a/src/handler.py
+++ b/src/handler.py
@@ -32,6 +32,7 @@ class Handler(Singleton):
'on-connected': list(),
# At the end of a successful connection process.
# emitted when presence confirmation is received
+ # Args: jid
'join-room': list(),
# Join a room.
@@ -45,6 +46,10 @@ class Handler(Singleton):
# A message is received
# Args: the stanza object
+ 'room-iq': list(),
+ # An iq is received
+ # Args: the stanza object
+
# 'xmpp-presence-handler': list(),
# # A presence is received
# # Args: the stanza object
diff --git a/src/multiuserchat.py b/src/multiuserchat.py
index 0d50b51d..5f5a1ffd 100644
--- a/src/multiuserchat.py
+++ b/src/multiuserchat.py
@@ -17,7 +17,7 @@
# Implementation of the XEP-0045: Multi-User Chat.
-from xmpp import NS_MUC_ADMIN
+from xmpp import NS_MUC_ADMIN, NS_MUC
from xmpp.protocol import Presence, Iq, Message, JID
from handler import Handler
@@ -41,11 +41,14 @@ class MultiUserChat(object):
self.rooms = []
self.rn = {}
+ self.own_jid = None
+
self.handler = Handler()
self.handler.connect('join-room', self.join_room)
self.handler.connect('on-connected', self.on_connected)
- def on_connected(self):
+ def on_connected(self, jid):
+ self.own_jid = jid
rooms = config.get('rooms', '')
if rooms == '':
return
@@ -67,6 +70,9 @@ class MultiUserChat(object):
self.rn[room] = nick
pres = Presence(to='%s/%s' % (room, nick))
+ pres.setFrom('%s'%self.own_jid)
+ pres.addChild(name='x', namespace=NS_MUC)
+ open('fion', 'w').write(str(pres))
self.connection.send(pres)
def quit_room(self, room, nick):
diff --git a/src/window.py b/src/window.py
index 5c4c1a32..b7965335 100644
--- a/src/window.py
+++ b/src/window.py
@@ -297,10 +297,10 @@ class Window(object):
Resize the whole tabe. i.e. all its sub-windows
"""
self.size = (self.height, self.width) = stdscr.getmaxyx()
- self.user_win.resize(self.height-3, self.width/7, 1, 6*(self.width/7), stdscr)
+ self.user_win.resize(self.height-3, self.width/9, 1, 11*(self.width/12), stdscr)
self.topic_win.resize(1, self.width, 0, 0, stdscr)
self.info_win.resize(1, self.width, self.height-2, 0, stdscr)
- self.text_win.resize(self.height-3, (self.width/7)*6, 1, 0, stdscr)
+ self.text_win.resize(self.height-3, (self.width/12)*11, 1, 0, stdscr)
self.input.resize(1, self.width, self.height-1, 0, stdscr)
def refresh(self, room):