summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-07-24 15:19:26 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-07-24 15:19:26 +0200
commitc166e79a896eba0299f16f6f727febd225e62100 (patch)
treef4c7bd971cbe3598cc270d8b32b1e491cf20c3b7
parent9c3fece96bee3c381cf0d7bd7022b46c858c6e1b (diff)
downloadpoezio-c166e79a896eba0299f16f6f727febd225e62100.tar.gz
poezio-c166e79a896eba0299f16f6f727febd225e62100.tar.bz2
poezio-c166e79a896eba0299f16f6f727febd225e62100.tar.xz
poezio-c166e79a896eba0299f16f6f727febd225e62100.zip
First adaptation to slixmpp
-rw-r--r--src/connection.py18
-rw-r--r--src/core/commands.py1
-rw-r--r--src/core/core.py67
-rw-r--r--src/core/handlers.py5
-rw-r--r--src/poezio.py1
5 files changed, 45 insertions, 47 deletions
diff --git a/src/connection.py b/src/connection.py
index be55a90f..fafbff69 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -133,6 +133,7 @@ class Connection(slixmpp.ClientXMPP):
self.register_plugin('xep_0280')
self.register_plugin('xep_0297')
self.register_plugin('xep_0308')
+ self.init_plugins()
def set_keepalive_values(self, option=None, value=None):
"""
@@ -158,32 +159,25 @@ class Connection(slixmpp.ClientXMPP):
def start(self):
"""
Connect and process events.
-
- TODO: try multiple servers with anon auth.
"""
custom_host = config.get('custom_host', '')
custom_port = config.get('custom_port', 5222)
if custom_port == -1:
custom_port = 5222
if custom_host:
- res = self.connect((custom_host, custom_port), reattempt=True)
+ self.connect((custom_host, custom_port))
elif custom_port != 5222 and custom_port != -1:
- res = self.connect((self.boundjid.host, custom_port),
- reattempt=True)
+ self.connect((self.boundjid.host, custom_port))
else:
- res = self.connect(reattempt=True)
- if not res:
- return False
- self.process(threaded=True)
- return True
+ self.connect()
- def send_raw(self, data, now=False, reconnect=None):
+ def send_raw(self, data):
"""
Overrides XMLStream.send_raw, with an event added
"""
if self.core:
self.core.outgoing_stanza(data)
- slixmpp.ClientXMPP.send_raw(self, data, now, reconnect)
+ slixmpp.ClientXMPP.send_raw(self, data)
class MatchAll(slixmpp.xmlstream.matcher.base.MatcherBase):
"""
diff --git a/src/core/commands.py b/src/core/commands.py
index 82d2d6da..1713c0f1 100644
--- a/src/core/commands.py
+++ b/src/core/commands.py
@@ -822,7 +822,6 @@ def command_quit(self, arg=''):
self.disconnect(msg)
self.running = False
self.reset_curses()
- sys.exit()
def command_destroy_room(self, arg=''):
"""
diff --git a/src/core/core.py b/src/core/core.py
index 00d7c364..42d8df31 100644
--- a/src/core/core.py
+++ b/src/core/core.py
@@ -468,6 +468,7 @@ class Core(object):
' ask for help or tell us how great it is.'),
_('Help'))
self.refresh_window()
+ self.xmpp.plugin['xep_0012'].begin_idle(jid=self.xmpp.boundjid)
def on_exception(self, typ, value, trace):
"""
@@ -480,7 +481,7 @@ class Core(object):
pass
sys.__excepthook__(typ, value, trace)
- def main_loop(self):
+ def on_input_readable(self):
"""
main loop waiting for the user to press a key
"""
@@ -527,39 +528,41 @@ class Core(object):
res.append(current)
return res
- while self.running:
- self.xmpp.plugin['xep_0012'].begin_idle(jid=self.xmpp.boundjid)
- big_char_list = [replace_key_with_bound(key)\
- for key in self.read_keyboard()]
- # whether to refresh after ALL keys have been handled
- for char_list in separate_chars_from_bindings(big_char_list):
- if self.paused:
- self.current_tab().input.do_command(char_list[0])
- self.current_tab().input.prompt()
- self.event.set()
- continue
- # Special case for M-x where x is a number
- if len(char_list) == 1:
- char = char_list[0]
- if char.startswith('M-') and len(char) == 3:
- try:
- nb = int(char[2])
- except ValueError:
- pass
- else:
- if self.current_tab().nb == nb:
- self.go_to_previous_tab()
- else:
- self.command_win('%d' % nb)
- # search for keyboard shortcut
- func = self.key_func.get(char, None)
- if func:
- func()
+ log.debug("Input is readable.")
+ big_char_list = [replace_key_with_bound(key)\
+ for key in self.read_keyboard()]
+ log.debug("Got from keyboard: %s", (big_char_list,))
+
+ # whether to refresh after ALL keys have been handled
+ for char_list in separate_chars_from_bindings(big_char_list):
+ if self.paused:
+ self.current_tab().input.do_command(char_list[0])
+ self.current_tab().input.prompt()
+ self.event.set()
+ continue
+ # Special case for M-x where x is a number
+ if len(char_list) == 1:
+ char = char_list[0]
+ if char.startswith('M-') and len(char) == 3:
+ try:
+ nb = int(char[2])
+ except ValueError:
+ pass
else:
- self.do_command(replace_line_breaks(char), False)
+ if self.current_tab().nb == nb:
+ self.go_to_previous_tab()
+ else:
+ self.command_win('%d' % nb)
+ # search for keyboard shortcut
+ func = self.key_func.get(char, None)
+ if func:
+ func()
else:
- self.do_command(''.join(char_list), True)
- self.doupdate()
+ self.do_command(replace_line_breaks(char), False)
+ else:
+ self.do_command(''.join(char_list), True)
+ self.doupdate()
+ self.xmpp.plugin['xep_0012'].begin_idle(jid=self.xmpp.boundjid)
def save_config(self):
"""
diff --git a/src/core/handlers.py b/src/core/handlers.py
index e9e1c892..654ce376 100644
--- a/src/core/handlers.py
+++ b/src/core/handlers.py
@@ -170,7 +170,8 @@ def on_message(self, message):
def on_normal_message(self, message):
"""
- When receiving "normal" messages (from someone in our roster)
+ When receiving "normal" messages (not a private message from a
+ muc participant)
"""
if message['type'] == 'error':
return self.information(self.get_error_message(message, deprecated=True), 'Error')
@@ -889,7 +890,7 @@ def on_session_start(self, event):
show=self.status.show)
if config.get('enable_user_nick', True):
- self.xmpp.plugin['xep_0172'].publish_nick(nick=self.own_nick, callback=dumb_callback, block=False)
+ self.xmpp.plugin['xep_0172'].publish_nick(nick=self.own_nick, callback=dumb_callback)
self.xmpp.plugin['xep_0115'].update_caps()
### Other handlers ###
diff --git a/src/poezio.py b/src/poezio.py
index 1baf10eb..4c687b41 100644
--- a/src/poezio.py
+++ b/src/poezio.py
@@ -12,6 +12,7 @@ Starting point of poezio. Launches both the Connection and Gui
import sys
import os
+import asyncio
import signal
import logging