summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-03-24 16:44:55 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-03-24 16:44:55 +0000
commit899a33ae477df3dec4541cb86d65783677d37211 (patch)
tree270ae36f397c6fef2cdc281290df86b71a305c65
parent42fbbddbd4e751e7d13c76cff46b1bc66fc790d9 (diff)
downloadpoezio-899a33ae477df3dec4541cb86d65783677d37211.tar.gz
poezio-899a33ae477df3dec4541cb86d65783677d37211.tar.bz2
poezio-899a33ae477df3dec4541cb86d65783677d37211.tar.xz
poezio-899a33ae477df3dec4541cb86d65783677d37211.zip
fixed #1235 (affiche un message si la connexion echoue)
-rw-r--r--src/connection.py21
-rw-r--r--src/gui.py13
-rw-r--r--src/handler.py6
-rw-r--r--src/room.py1
4 files changed, 32 insertions, 9 deletions
diff --git a/src/connection.py b/src/connection.py
index 9b047da9..c514d964 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -17,6 +17,16 @@
# You should have received a copy of the GNU General Public License
# along with Poezio. If not, see <http://www.gnu.org/licenses/>.
+from gettext import (bindtextdomain, textdomain, bind_textdomain_codeset,
+ gettext as _)
+
+
+bindtextdomain('poezio')
+textdomain('poezio')
+bind_textdomain_codeset('poezio', 'utf-8')
+import locale
+locale.setlocale(locale.LC_ALL, '')
+
import sys
import xmpp
@@ -50,10 +60,10 @@ class Connection(threading.Thread):
"""
sys.excepthook = exception_handler
if not self.connect_to_server(self.server, self.port):
- logger.error('Could not connect to server')
+ self.handler.emit('error', msg='Could not connect to server')
sys.exit(-1)
if not self.authenticate():
- logger.error('Could not authenticate to server')
+ self.handler.emit('error', msg='Could not authenticate to server')
sys.exit(-1)
self.client.sendInitPresence(requestRoster=0)
self.online = 1 # 2 when confirmation of auth is received
@@ -74,7 +84,12 @@ class Connection(threading.Thread):
def authenticate(self, anon=True):
if anon:
- return self.client.auth(None, "", self.resource)
+ try:
+ self.client.auth(None, "", self.resource)
+ return True
+ except TypeError:
+ self.handler.emit('error', msg=_('Error: Could not authenticate. Please make sure the server you chose (%s) supports anonymous authentication' % (config.get('server', '')))) # TODO msg
+ return None
else:
log.error('Non-anonymous connections not handled currently')
return None
diff --git a/src/gui.py b/src/gui.py
index b9a02703..3253561f 100644
--- a/src/gui.py
+++ b/src/gui.py
@@ -106,6 +106,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('error', self.information)
def main_loop(self, stdscr):
while 1:
@@ -260,7 +261,7 @@ class Gui(object):
from_room = stanza.getFrom().getStripped()
room = self.get_room_by_name(from_room)
if not room:
- self.information(_("presence received for a non-existing room: %s") % (from_room))
+ return
if stanza.getType() == 'error':
msg = _("Error: %s") % stanza.getError()
else:
@@ -294,7 +295,10 @@ class Gui(object):
# kick
elif kick:
room.users.remove(user)
- reason = stanza.getReason().encode('utf-8') or ''
+ try:
+ reason = stanza.getReason().encode('utf-8')
+ except:
+ reason = ''
try:
by = stanza.getActor().encode('utf-8')
except:
@@ -444,8 +448,10 @@ class Gui(object):
self.information(_("already in room [%s]") % room)
return
self.muc.join_room(room, nick)
- if not r: # if the room window exists, we don't recreate it.
+ if not r: # if the room window exists, we don't recreate it.
self.join_room(room, nick)
+ else:
+ r.users = []
def command_bookmark(self, args):
nick = None
@@ -562,7 +568,6 @@ class Gui(object):
def information(self, msg):
room = self.get_room_by_name("Info")
- info = room.add_info(msg)
self.add_info(room, msg)
def command_quit(self, args):
diff --git a/src/handler.py b/src/handler.py
index 1911d7fa..d651b336 100644
--- a/src/handler.py
+++ b/src/handler.py
@@ -54,7 +54,11 @@ class Handler(Singleton):
# We send our version
# Args: the stanza we reply to
- 'send-time': list()
+ 'send-time': list(),
+ # We send our time
+ # Args: the stanza we reply to
+
+ 'error': list()
# We send our time
# Args: the stanza we reply to
}
diff --git a/src/room.py b/src/room.py
index 87a78107..100b2fe5 100644
--- a/src/room.py
+++ b/src/room.py
@@ -37,7 +37,6 @@ class Room(object):
def disconnect(self):
self.joined = False
- self.users = []
def add_message(self, nick, msg, date=None):
if not date: