From 26df9683434fc37619119c643f2b0fbfcf6e903c Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Thu, 14 Apr 2005 11:06:58 +0000 Subject: [PATCH] correct some typos, process connections every 50ms --- src/common/config.py | 18 +++---- src/common/connection.py | 102 ++++++++++++++++++++------------------- src/config.py | 1 + src/gtkgui.py | 9 +++- src/roster_window.py | 8 +-- 5 files changed, 74 insertions(+), 64 deletions(-) diff --git a/src/common/config.py b/src/common/config.py index cbef22172..e66ff2770 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -185,14 +185,14 @@ class Config: def get(self, optname): if not self.exist(optname): return None - val = self.__options[optname][OPT_VAL] - if val == 'True': return True - if val == 'False': return False - try: - val = int(val) - except ValueError: - pass - return val + opt = self.__options[optname] + if opt[OPT_TYPE] == opt_bool: + if opt[OPT_VAL] == 'False': return False + return True + elif opt[OPT_TYPE] == opt_int: + return int(opt[OPT_VAL]) + else: + return opt[OPT_VAL] def add_per(self, typename, name): if not self.__options_per_key.has_key(typename): @@ -240,7 +240,7 @@ class Config: return obj if not obj.has_key(subname): return None - return obj[subname] + return obj[subname][OPT_VAL] def exist(self, optname): return self.__options.has_key(optname) diff --git a/src/common/connection.py b/src/common/connection.py index 83db9b05b..1da45930f 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -99,7 +99,7 @@ class connection: self.connection = None # Jabber.py instance self.gpg = None self.myVCardID = [] - self.password = gajim.config.get_per('accounts', name, 'hostname') + self.password = gajim.config.get_per('accounts', name, 'password') if USE_GPG: self.gpg = GnuPG.GnuPG() gajim.config.set('usegpg', True) @@ -369,71 +369,73 @@ class connection: def connect(self): """Connect and authentificate to the Jabber server""" self.connected = 1 + name = gajim.config.get_per('accounts', self.name, 'name') hostname = gajim.config.get_per('accounts', self.name, 'hostname') resource = gajim.config.get_per('accounts', self.name, 'resource') #create connexion if it doesn't already existe - if not self.connection: - if gajim.config.get_per('accounts', self.name, 'use_proxy'): - proxy = {'host': gajim.config.get_per('accounts', self.name, \ - 'proxyhost')} - proxy['port'] = gajim.config.get_per('accounts', self.name, \ - 'proxyport') - else: - proxy = None - if gajim.log: - self.connection = common.jabber.Client(host = hostname, debug = [],\ - log = sys.stderr, connection=common.xmlstream.TCP, port=5222, \ - proxy = proxy) - else: - con = common.jabber.Client(host = hostname, debug = [], log = None,\ - connection=common.xmlstream.TCP, port=5222, proxy = proxy) - #debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, \ - #connection=common.xmlstream.TCP_SSL, port=5223, proxy = proxy) - self.connection.setDisconnectHandler(self.disconnectedCB) - self.connection.registerHandler('message', self.messageCB) - self.connection.registerHandler('presence', self.presenceCB) - self.connection.registerHandler('iq',self.vCardCB,'result') - self.connection.registerHandler('iq',self.rosterSetCB,'set', \ - common.jabber.NS_ROSTER) - self.connection.registerHandler('iq',self.BrowseResultCB,'result', \ - common.jabber.NS_BROWSE) - self.connection.registerHandler('iq',self.DiscoverItemsCB,'result', \ - common.jabber.NS_P_DISC_ITEMS) - self.connection.registerHandler('iq',self.DiscoverInfoCB,'result', \ - common.jabber.NS_P_DISC_INFO) - self.connection.registerHandler('iq',self.DiscoverInfoErrorCB,'error',\ - common.jabber.NS_P_DISC_INFO) - self.connection.registerHandler('iq',self.VersionCB,'get', \ - common.jabber.NS_VERSION) - self.connection.registerHandler('iq',self.VersionResultCB,'result', \ - common.jabber.NS_VERSION) + if self.connection: + return self.connection + if gajim.config.get_per('accounts', self.name, 'use_proxy'): + proxy = {'host': gajim.config.get_per('accounts', self.name, \ + 'proxyhost')} + proxy['port'] = gajim.config.get_per('accounts', self.name, \ + 'proxyport') + else: + proxy = None + if gajim.config.get('log'): + con = common.jabber.Client(host = hostname, debug = [],\ + log = sys.stderr, connection=common.xmlstream.TCP, port=5222, \ + proxy = proxy) + else: + con = common.jabber.Client(host = hostname, debug = [], log = None,\ + connection=common.xmlstream.TCP, port=5222, proxy = proxy) + #debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, \ + #connection=common.xmlstream.TCP_SSL, port=5223, proxy = proxy) + con.setDisconnectHandler(self._disconnectedCB) + con.registerHandler('message', self._messageCB) + con.registerHandler('presence', self._presenceCB) + con.registerHandler('iq',self._vCardCB,'result') + con.registerHandler('iq',self._rosterSetCB,'set', \ + common.jabber.NS_ROSTER) + con.registerHandler('iq',self._BrowseResultCB,'result', \ + common.jabber.NS_BROWSE) + con.registerHandler('iq',self._DiscoverItemsCB,'result', \ + common.jabber.NS_P_DISC_ITEMS) + con.registerHandler('iq',self._DiscoverInfoCB,'result', \ + common.jabber.NS_P_DISC_INFO) + con.registerHandler('iq',self._DiscoverInfoErrorCB,'error',\ + common.jabber.NS_P_DISC_INFO) + con.registerHandler('iq',self._VersionCB,'get', \ + common.jabber.NS_VERSION) + con.registerHandler('iq',self._VersionResultCB,'result', \ + common.jabber.NS_VERSION) try: - self.connection.connect() + con.connect() except: - gajim.log.debug("Couldn't connect to %s %s" % (hostname, e)) + gajim.log.debug('Couldn\'t connect to %s' % hostname) self.dispatch('STATUS', 'offline') self.dispatch('ERROR', _('Couldn\'t connect to %s') \ % hostname) self.connected = 0 - return -1 + return None gajim.log.debug('Connected to server') - if self.connection.auth(self.name, self.password, resource): - self.connection.requestRoster() - roster = self.connection.getRoster().getRaw() + if con.auth(name, self.password, resource): + con.requestRoster() + roster = con.getRoster().getRaw() if not roster : roster = {} self.dispatch('ROSTER', (0, roster)) self.connected = 2 - return 0 + return con else: - log.debug('Couldn\'t authentificate to %s' % hostname) + gajim.log.debug('Couldn\'t authentificate to %s' % hostname) self.dispatch('STATUS', 'offline') self.dispatch('ERROR', _('Authentification failed with %s, check your login and password') % hostname) self.connected = 0 - return -1 + return None # END connect def register_handler(self, event, function): @@ -473,7 +475,7 @@ class connection: if self.connected < 2: self.dispatch('BAD_PASSPHRASE', ()) if (status != 'offline') and (self.connected == 0): - self.connect() + self.connection = self.connect() if self.connected == 2: self.connected = STATUS_LIST.index(status) #send our presence @@ -481,14 +483,14 @@ class connection: if status == 'invisible': ptype = 'invisible' prio = gajim.config.get_per('accounts', self.name, 'priority') - self.connection.sendPresence(ptype, prio, status, msg, signed) + self.connection.sendPresence(ptype, str(prio), status, msg, signed) self.dispatch('STATUS', status) #ask our VCard iq = common.jabber.Iq(type='get') iq._setTag('vCard', common.jabber.NS_VCARD) - id = con.getAnID() + id = self.connection.getAnID() iq.setID(id) - con.send(iq) + self.connection.send(iq) self.myVCardID.append(id) elif (status == 'offline') and self.connected: self.connected = 0 @@ -614,7 +616,7 @@ class connection: else: self.name = name self.connected = 0 - self.password = '' + self.password = password if USE_GPG: self.gpg = GnuPG.GnuPG() gajim.config.set('usegpg', True) diff --git a/src/config.py b/src/config.py index 80796d3b2..9bf7f3ed9 100644 --- a/src/config.py +++ b/src/config.py @@ -1122,6 +1122,7 @@ class Account_modification_window: if name in gajim.connections: Error_dialog(_('An account already has this name')) return + gajim.config.add_per('accounts', name) gajim.connections[name] = connection.connection(name) self.plugin.register_handlers(gajim.connections[name]) #if we neeed to register a new account diff --git a/src/gtkgui.py b/src/gtkgui.py index cba93e3c3..82641d29b 100644 --- a/src/gtkgui.py +++ b/src/gtkgui.py @@ -679,6 +679,12 @@ class interface: conn.register_handler('BAD_PASSPHRASE', self.handle_event_bad_passphrase) conn.register_handler('ROSTER_INFO', self.handle_event_roster_info) + def process_connections(self): + for account in gajim.connections: + if gajim.connections[account].connected: + gajim.connections[account].connection.process(1) + return True + def __init__(self): if gtk.pygtk_version >= (2, 6, 0): gtk.about_dialog_set_email_hook(self.on_launch_browser_mailer, 'mail') @@ -739,7 +745,8 @@ class interface: self.register_handlers(gajim.connections[account]) gobject.timeout_add(100, self.autoconnect) - gobject.timeout_add(100, self.read_sleepy) + gobject.timeout_add(500, self.read_sleepy) + gobject.timeout_add(50, self.process_connections) if __name__ == '__main__': try: # Import Psyco if available diff --git a/src/roster_window.py b/src/roster_window.py index 877b9f9ff..8b69fbbf0 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -325,7 +325,7 @@ class Roster_window: """Clear and draw roster""" self.make_menu() self.tree.get_model().clear() - for acct in self.contacts.keys(): + for acct in gajim.connections: self.add_account_to_roster(acct) for jid in self.contacts[acct].keys(): self.add_user_to_roster(jid, acct) @@ -697,7 +697,7 @@ class Roster_window: accountIter = self.get_account_iter(account) if accountIter: model.set_value(accountIter, 0, self.pixbufs['connecting']) - gajim.connections[account].connected = 1 +# gajim.connections[account].connected = 1 if self.plugin.systray_enabled: self.plugin.systray.set_status('connecting') @@ -711,7 +711,7 @@ class Roster_window: if passphrase == -1: if accountIter: model.set_value(accountIter, 0, self.pixbufs['offline']) - gajim.connections[account].connected = 0 +# gajim.connections[account].connected = 0 self.plugin.systray.set_status('offline') self.update_status_comboxbox() return @@ -832,7 +832,7 @@ class Roster_window: luser_copy.append(user) for user in luser_copy: self.chg_user_status(user, 'offline', 'Disconnected', account) - gajim.connections[account].connected = statuss.index(status) +# gajim.connections[account].connected = statuss.index(status) self.update_status_comboxbox() def new_chat(self, user, account):