correct some typos, process connections every 50ms

This commit is contained in:
Yann Leboulanger 2005-04-14 11:06:58 +00:00
parent eb7cf5ba4d
commit 26df968343
5 changed files with 74 additions and 64 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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):