diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client.py | 9 | ||||
-rw-r--r-- | src/config.py | 16 | ||||
-rw-r--r-- | src/connection.py | 5 | ||||
-rw-r--r-- | src/gui.py | 90 | ||||
-rw-r--r-- | src/handler.py | 86 | ||||
-rw-r--r-- | src/multiuserchat.py | 3 | ||||
-rw-r--r-- | src/poezio.cfg | 8 | ||||
-rw-r--r-- | src/window.py | 15 |
8 files changed, 66 insertions, 166 deletions
diff --git a/src/client.py b/src/client.py index 47a87071..263ed08f 100644 --- a/src/client.py +++ b/src/client.py @@ -17,6 +17,13 @@ # 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 sys from connection import Connection from multiuserchat import MultiUserChat @@ -25,10 +32,10 @@ from handler import Handler from gui import Gui from curses import wrapper, initscr -# sys.stderr = open('logs', 'a') if len(sys.argv) == 1: # not debug, so hide any error message and disable C-c import signal signal.signal(signal.SIGINT, signal.SIG_IGN) + sys.stderr = open('/dev/null', 'w') class Client(object): """ diff --git a/src/config.py b/src/config.py index 302716f6..4a507522 100644 --- a/src/config.py +++ b/src/config.py @@ -19,7 +19,8 @@ # along with Poezio. If not, see <http://www.gnu.org/licenses/>. from ConfigParser import RawConfigParser, NoOptionError -# from logging import logger +from os import environ, makedirs +from shutil import copy2 class Config(RawConfigParser): """ @@ -78,4 +79,15 @@ class Config(RawConfigParser): self.set(option, value) self.save() -config = Config('poezio.cfg') +CONFIG_HOME = environ.get("XDG_CONFIG_HOME") +if not CONFIG_HOME: + CONFIG_HOME = environ.get('HOME')+'/.config/' +CONFIG_PATH = CONFIG_HOME + 'poezio/' + +try: + makedirs(CONFIG_PATH) + copy2('../data/default_config.cfg', CONFIG_PATH+'poezio.cfg') +except: + pass + +config = Config(CONFIG_PATH+'poezio.cfg') diff --git a/src/connection.py b/src/connection.py index 0dae9cc7..c55c292c 100644 --- a/src/connection.py +++ b/src/connection.py @@ -96,14 +96,13 @@ class Connection(Thread): self.handler.emit('room-iq', stanza=iq) def handler_error(self, connection, error): - print "fion" - sys.exit() + pass def process(self, timeout=10): if self.online: try:self.client.Process(timeout) except: - pass + pass # FIXME else: log.warning('disconnecting...') sys.exit() @@ -17,25 +17,21 @@ # You should have received a copy of the GNU General Public License # along with Poezio. If not, see <http://www.gnu.org/licenses/>. -from handler import Handler -import curses -from curses import textpad +from gettext import (bindtextdomain, textdomain, bind_textdomain_codeset, + gettext as _) import locale +locale.setlocale(locale.LC_ALL, '') +import sys + +import curses +from curses import textpad from datetime import datetime +from handler import Handler from logging import logger - from random import randrange - from config import config - -locale.setlocale(locale.LC_ALL, '') -code = locale.getpreferredencoding() - -import sys - -from connection import * from window import Window class User(object): @@ -99,23 +95,21 @@ class Room(object): self.users.append(User(nick, affiliation, show, status, role)) if nick.encode('utf-8') == self.own_nick: self.joined = True - return self.add_info("Your nickname is %s" % (nick)) - return self.add_info("%s is in the room" % (nick)) + return self.add_info(_("Your nickname is %s") % (nick)) + return self.add_info(_("%s is in the room") % (nick)) change_nick = stanza.getStatusCode() == '303' kick = stanza.getStatusCode() == '307' user = self.get_user_by_name(nick) - if change_nick and not user: - return self.add_info('WTF: change nick for %s but user unknown'% nick) # New user if not user: self.users.append(User(nick, affiliation, show, status, role)) - return self.add_info('%s joined the room %s' % (nick, self.name)) + return self.add_info(_('%(nick)s joined the room %(roomname)s') % {'nick':nick, 'roomname': self.name}) # nick change if change_nick: if user.nick == self.own_nick: self.own_nick = stanza.getNick().encode('utf-8') user.change_nick(stanza.getNick()) - return self.add_info('%s is now known as %s' % (nick, stanza.getNick())) + return self.add_info(_('%(old_nick)s is now known as %(new_nick)s') % {'old_nick':nick, 'new_nick':stanza.getNick()}) # kick if kick: self.users.remove(user) @@ -127,21 +121,21 @@ class Room(object): if nick == self.own_nick: self.disconnect() if by: - return self.add_info('You have been kicked by %s. Reason: %s' % (by, reason)) + return self.add_info(_('You have been kicked by %(by)s. Reason: %(reason)s') % {'by':by, 'reason':reason}) else: - return self.add_info('You have been kicked. Reason: %s' % (reason)) + return self.add_info(_('You have been kicked. Reason: %s') % (reason)) else: if by: - return self.add_info('%s has been kicked by %s. Reason: %s' % (nick, by, reason)) + return self.add_info(_('%(nick)s has been kicked by %(by)s. Reason: %(reason)s') % {'nick':nick, 'by':by, 'reason':reason}) else: - return self.add_info('%s has been kicked. Reason: %s' % (nick, reason)) + return self.add_info(_('%(nick)s has been kicked. Reason: %(reason)s') % {'nick':nick, 'reason':reason}) # user quit if status == 'offline' or role == 'none': self.users.remove(user) - return self.add_info('%s has left the room' % (nick)) + return self.add_info(_('%s has left the room') % (nick)) # status change user.update(affiliation, show, status, role) - return self.add_info('%s, status : %s, %s, %s, %s' % (nick, affiliation, role, show, status)) + return self.add_info(_('%(nick)s changed his/her status : %(a)s, %(b)s, %(c)s, %(d)s') % {'nick':nick, 'b':affiliation, 'b':role, 'c':show, 'd':status}) class Gui(object): @@ -161,20 +155,20 @@ class Gui(object): self.muc = muc self.commands = { - 'help': (self.command_help, 'OLOL, this is SOOO recursive'), - 'join': (self.command_join, 'Usage: /join [room_name][/nick]\nJoin: Join the specified room. You can specify a nickname after a slash (/). If no nickname is specified, you will use the default_nick in the configuration file. You can omit the room name: you will then join the room you\'re looking at (useful if you were kicked). Examples:\n/join room@server.tld\n/join room@server.tld/John\n/join /me_again\n/join'), - 'quit': (self.command_quit, 'Usage: /quit\nQuit: Just disconnect from the server and exit poezio.'), - 'exit': (self.command_quit, 'Usage: /exit\nExit: Just disconnect from the server and exit poezio.'), - 'next': (self.rotate_rooms_left, 'Usage: /next\nNext: Go to the next room.'), - 'prev': (self.rotate_rooms_right, 'Usage: /prev\nPrev: Go to the previous room.'), - 'part': (self.command_part, 'Usage: /part [message]\nPart: disconnect from a room. You can specify an optionnal message.'), - 'show': (self.command_show, 'Usage: /show <availability> [status]\nShow: Change your availability and (optionnaly) your status. The <availability> argument is one of "avail, available, ok, here, chat, away, afk, dnd, busy, xa" and the optional [message] argument will be your status message'), - 'away': (self.command_away, 'Usage: /away [message]\nAway: Sets your availability to away and (optional) sets your status message. This is equivalent do "/show away [message]"'), - 'busy': (self.command_busy, 'Usage: /busy [message]\nBusy: Sets your availability to busy and (optional) sets your status message. This is equivalent do "/show busy [message]"'), - 'avail': (self.command_avail, 'Usage: /avail [message]\nAvail: Sets your availability to available and (optional) sets your status message. This is equivalent do "/show available [message]"'), - 'available': (self.command_avail, 'Usage: /available [message]\nAvailable: Sets your availability to available and (optional) sets your status message. This is equivalent do "/show available [message]"'), - 'bookmark': (self.command_bookmark, 'Usage: /bookmark [roomname][/nick]\nBookmark: Bookmark the specified room (you will then auto-join it on each poezio start). This commands uses the same syntaxe as /nick. Type /help nick for syntaxe examples. Note that when typing "/bookmark" on its own, the room will be bookmarked with the nickname you\'re currently using in this room (instead of default_nick)'), - 'nick': (self.command_nick, 'Usage: /nick <nickname>\nNick: Change your nickname in the current room') + 'help': (self.command_help, _('OLOL, this is SOOO recursive')), + 'join': (self.command_join, _('Usage: /join [room_name][/nick]\nJoin: Join the specified room. You can specify a nickname after a slash (/). If no nickname is specified, you will use the default_nick in the configuration file. You can omit the room name: you will then join the room you\'re looking at (useful if you were kicked). Examples:\n/join room@server.tld\n/join room@server.tld/John\n/join /me_again\n/join')), + 'quit': (self.command_quit, _('Usage: /quit\nQuit: Just disconnect from the server and exit poezio.')), + 'exit': (self.command_quit, _('Usage: /exit\nExit: Just disconnect from the server and exit poezio.')), + 'next': (self.rotate_rooms_left, _('Usage: /next\nNext: Go to the next room.')), + 'prev': (self.rotate_rooms_right, _('Usage: /prev\nPrev: Go to the previous room.')), + 'part': (self.command_part, _('Usage: /part [message]\nPart: disconnect from a room. You can specify an optional message.')), + 'show': (self.command_show, _('Usage: /show <availability> [status]\nShow: Change your availability and (optionaly) your status. The <availability> argument is one of "avail, available, ok, here, chat, away, afk, dnd, busy, xa" and the optional [message] argument will be your status message')), + 'away': (self.command_away, _('Usage: /away [message]\nAway: Sets your availability to away and (optional) sets your status message. This is equivalent to "/show away [message]"')), + 'busy': (self.command_busy, _('Usage: /busy [message]\nBusy: Sets your availability to busy and (optional) sets your status message. This is equivalent to "/show busy [message]"')), + 'avail': (self.command_avail, _('Usage: /avail [message]\nAvail: Sets your availability to available and (optional) sets your status message. This is equivalent to "/show available [message]"')), + 'available': (self.command_avail, _('Usage: /available [message]\nAvailable: Sets your availability to available and (optional) sets your status message. This is equivalent to "/show available [message]"')), + 'bookmark': (self.command_bookmark, _('Usage: /bookmark [roomname][/nick]\nBookmark: Bookmark the specified room (you will then auto-join it on each poezio start). This commands uses the same syntaxe as /nick. Type /help nick for syntaxe examples. Note that when typing "/bookmark" on its own, the room will be bookmarked with the nickname you\'re currently using in this room (instead of default_nick)')), + 'nick': (self.command_nick, _('Usage: /nick <nickname>\nNick: Change your nickname in the current room')) } self.key_func = { @@ -261,8 +255,8 @@ class Gui(object): curses.endwin() def on_connected(self, jid): - self.information("Welcome on Poezio \o/!") - self.information("Your JID is %s" % jid) + self.information(_("Welcome on Poezio \o/!")) + self.information(_("Your JID is %s") % jid) def join_room(self, room, nick): self.window.text_win.new_win(room) @@ -288,12 +282,12 @@ class Gui(object): nick_from = '' room = self.get_room_by_name(room_from) if not room: - self.information("message received for a non-existing room: %s" % (name)) + self.information(_("message received for a non-existing room: %s") % (name)) return body = stanza.getBody() if not body: body = stanza.getSubject() - info = room.add_info("%s changed the subject to: %s" % (nick_from, stanza.getSubject())) + info = room.add_info(_("%(nick)s changed the subject to: %(subject)s") % {'nick':nick_from, 'subject':stanza.getSubject()}) self.window.text_win.add_line(room, (datetime.now(), info)) room.topic = stanza.getSubject().encode('utf-8').replace('\n', '|') if room == self.current_room(): @@ -314,9 +308,9 @@ 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" % (name)) + self.information(_("presence received for a non-existing room: %s") % (name)) if stanza.getType() == 'error': - msg = "Error: %s" % stanza.getError() + msg = _("Error: %s") % stanza.getError() else: msg = room.on_presence(stanza, from_nick) if room == self.current_room(): @@ -351,15 +345,15 @@ class Gui(object): def command_help(self, args): room = self.current_room() if len(args) == 0: - msg = 'Available commands are:' + msg = _('Available commands are:') for command in self.commands.keys(): msg += "%s " % command - msg += "\nType /help <command_name> to know what each command does" + msg += _("\nType /help <command_name> to know what each command does") if len(args) == 1: if args[0] in self.commands.keys(): msg = self.commands[args[0]][1] else: - msg = 'Unknown command : %s' % args[0] + msg = _('Unknown command: %s') % args[0] room.add_info(msg) self.window.text_win.add_line(room, (datetime.now(), msg)) self.window.text_win.refresh(room.name) @@ -387,7 +381,7 @@ class Gui(object): room = info[0] r = self.get_room_by_name(room) if r and r.joined: # if we are already in the room - self.information("already in room [%s]" % room) + 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. diff --git a/src/handler.py b/src/handler.py index 8942ae7c..681af6d7 100644 --- a/src/handler.py +++ b/src/handler.py @@ -49,101 +49,15 @@ class Handler(Singleton): 'room-iq': list(), # An iq is received # Args: the stanza object - - # 'xmpp-presence-handler': list(), - # # A presence is received - # # Args: the stanza object - - # 'xmpp-iq-handler': list(), - # # An iq is received - # # Args: the stanza object - - # 'xmpp-message-handler': list(), - # # A message is received - # # Args: the stanza object - - # # - GUI event - - # 'on-quit': list(), - # # When the user wants to quit. - - # # - Roster and presence - - # 'on-disconnected': list(), - # # When the user is disconnected from the server. - - # 'on-message-received': list(), - # # When a message is received. - # # Args: jid, msg, subject, typ - - # 'send-message': list(), - # # Send a message to someone. - # # Args: jid, msg, subj, typ - - # # - vCard (XEP-0054) - - # 'vcard-request': list(), - # # Request a vcard. - # # Args: jid - - # 'on-vcard-received': list(), - # # When a vcard is received. - # # Args: jid, vcard - - # # - Multi-User Chat (XEP-0045) - - # 'gui-join-room': list(), - # # Join a room inside the GUI (call `join-room`). - # # Args: room, nickname - - # 'quit-room': list(), - # # Quit a room. - # # Args: room, nick - - # 'on-muc-message-received': list(), - # # When a message is received. - # # Args: jid, msg, subject, typ, stanza - - # 'on-muc-presence-changed': list(), - # # When someone in the roster changes his presence. - # # Args: jid, priority, show, status, stanza - - # 'on-muc-error': list(), - # # When the MUC composant sends an error - # # Args: room, code, msg - - # 'eject-user': list(), - # # When the user try to eject another one. - # # Args: room, action, nick, reason - - # 'change-user-role': list(), - # # When the user try to change the role of someone. - # # Args: room, nick, role - - # 'change-user-affiliation': list(), - # # When the user try to change the affiliation of someone. - # # Args: room, jid, aff - - # 'change-subject': list(), - # # When the user try to change the topic. - # # Args: room, subject - - # 'change-nick': list() - # # When the user try to change his nick. - # # Args: room, nick } def connect(self, signal, func): """Connect a function to a signal.""" if func not in self.__signals__[signal]: self.__signals__[signal].append(func) - else: - print "signal %s doesn't exist." % signal def emit(self, signal, **kwargs): """Emit a signal.""" if self.__signals__.has_key(signal): for func in self.__signals__[signal]: func(**kwargs) - else: - print "signal %s doesn't exist." % signal diff --git a/src/multiuserchat.py b/src/multiuserchat.py index e0f202c1..5101b708 100644 --- a/src/multiuserchat.py +++ b/src/multiuserchat.py @@ -73,9 +73,6 @@ class MultiUserChat(object): def join_room(self, room, nick, password=None): """Join a new room""" - # self.rooms.append(room) - # self.rn[room] = nick - pres = Presence(to='%s/%s' % (room, nick)) pres.setFrom('%s'%self.own_jid) if password: diff --git a/src/poezio.cfg b/src/poezio.cfg deleted file mode 100644 index 7bd02ac5..00000000 --- a/src/poezio.cfg +++ /dev/null @@ -1,8 +0,0 @@ -[Poezio] -resource = poezio -default_nick = louiz_on_poezio -server = louiz.org -rooms = test@chat.jabberfr.org:discussion@kikoo.louiz.org -logfile = logs -port = 5222 - diff --git a/src/window.py b/src/window.py index 27ba0ff4..2e51552a 100644 --- a/src/window.py +++ b/src/window.py @@ -20,21 +20,6 @@ import curses from logging import logger -def get_next_line(str, length): - pos = str.rfind(' ', 0, length) - if pos == -1: - return str[:length], str[length:] - else: - return str[:pos], str[pos+1:] - -def cut_line(str, length): - tab = [] - while len(str) > length: - cut, str = get_next_line(str, length) - tab.append(cut) - tab.append(str) - return tab - class Win(object): def __init__(self, height, width, y, x, parent_win): self._resize(height, width, y, x, parent_win) |