correct some typos, process connections every 50ms
This commit is contained in:
parent
eb7cf5ba4d
commit
26df968343
|
@ -185,14 +185,14 @@ class Config:
|
||||||
def get(self, optname):
|
def get(self, optname):
|
||||||
if not self.exist(optname):
|
if not self.exist(optname):
|
||||||
return None
|
return None
|
||||||
val = self.__options[optname][OPT_VAL]
|
opt = self.__options[optname]
|
||||||
if val == 'True': return True
|
if opt[OPT_TYPE] == opt_bool:
|
||||||
if val == 'False': return False
|
if opt[OPT_VAL] == 'False': return False
|
||||||
try:
|
return True
|
||||||
val = int(val)
|
elif opt[OPT_TYPE] == opt_int:
|
||||||
except ValueError:
|
return int(opt[OPT_VAL])
|
||||||
pass
|
else:
|
||||||
return val
|
return opt[OPT_VAL]
|
||||||
|
|
||||||
def add_per(self, typename, name):
|
def add_per(self, typename, name):
|
||||||
if not self.__options_per_key.has_key(typename):
|
if not self.__options_per_key.has_key(typename):
|
||||||
|
@ -240,7 +240,7 @@ class Config:
|
||||||
return obj
|
return obj
|
||||||
if not obj.has_key(subname):
|
if not obj.has_key(subname):
|
||||||
return None
|
return None
|
||||||
return obj[subname]
|
return obj[subname][OPT_VAL]
|
||||||
|
|
||||||
def exist(self, optname):
|
def exist(self, optname):
|
||||||
return self.__options.has_key(optname)
|
return self.__options.has_key(optname)
|
||||||
|
|
|
@ -99,7 +99,7 @@ class connection:
|
||||||
self.connection = None # Jabber.py instance
|
self.connection = None # Jabber.py instance
|
||||||
self.gpg = None
|
self.gpg = None
|
||||||
self.myVCardID = []
|
self.myVCardID = []
|
||||||
self.password = gajim.config.get_per('accounts', name, 'hostname')
|
self.password = gajim.config.get_per('accounts', name, 'password')
|
||||||
if USE_GPG:
|
if USE_GPG:
|
||||||
self.gpg = GnuPG.GnuPG()
|
self.gpg = GnuPG.GnuPG()
|
||||||
gajim.config.set('usegpg', True)
|
gajim.config.set('usegpg', True)
|
||||||
|
@ -369,11 +369,13 @@ class connection:
|
||||||
def connect(self):
|
def connect(self):
|
||||||
"""Connect and authentificate to the Jabber server"""
|
"""Connect and authentificate to the Jabber server"""
|
||||||
self.connected = 1
|
self.connected = 1
|
||||||
|
name = gajim.config.get_per('accounts', self.name, 'name')
|
||||||
hostname = gajim.config.get_per('accounts', self.name, 'hostname')
|
hostname = gajim.config.get_per('accounts', self.name, 'hostname')
|
||||||
resource = gajim.config.get_per('accounts', self.name, 'resource')
|
resource = gajim.config.get_per('accounts', self.name, 'resource')
|
||||||
|
|
||||||
#create connexion if it doesn't already existe
|
#create connexion if it doesn't already existe
|
||||||
if not self.connection:
|
if self.connection:
|
||||||
|
return self.connection
|
||||||
if gajim.config.get_per('accounts', self.name, 'use_proxy'):
|
if gajim.config.get_per('accounts', self.name, 'use_proxy'):
|
||||||
proxy = {'host': gajim.config.get_per('accounts', self.name, \
|
proxy = {'host': gajim.config.get_per('accounts', self.name, \
|
||||||
'proxyhost')}
|
'proxyhost')}
|
||||||
|
@ -381,8 +383,8 @@ class connection:
|
||||||
'proxyport')
|
'proxyport')
|
||||||
else:
|
else:
|
||||||
proxy = None
|
proxy = None
|
||||||
if gajim.log:
|
if gajim.config.get('log'):
|
||||||
self.connection = common.jabber.Client(host = hostname, debug = [],\
|
con = common.jabber.Client(host = hostname, debug = [],\
|
||||||
log = sys.stderr, connection=common.xmlstream.TCP, port=5222, \
|
log = sys.stderr, connection=common.xmlstream.TCP, port=5222, \
|
||||||
proxy = proxy)
|
proxy = proxy)
|
||||||
else:
|
else:
|
||||||
|
@ -390,50 +392,50 @@ class connection:
|
||||||
connection=common.xmlstream.TCP, port=5222, proxy = proxy)
|
connection=common.xmlstream.TCP, port=5222, proxy = proxy)
|
||||||
#debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, \
|
#debug = [common.jabber.DBG_ALWAYS], log = sys.stderr, \
|
||||||
#connection=common.xmlstream.TCP_SSL, port=5223, proxy = proxy)
|
#connection=common.xmlstream.TCP_SSL, port=5223, proxy = proxy)
|
||||||
self.connection.setDisconnectHandler(self.disconnectedCB)
|
con.setDisconnectHandler(self._disconnectedCB)
|
||||||
self.connection.registerHandler('message', self.messageCB)
|
con.registerHandler('message', self._messageCB)
|
||||||
self.connection.registerHandler('presence', self.presenceCB)
|
con.registerHandler('presence', self._presenceCB)
|
||||||
self.connection.registerHandler('iq',self.vCardCB,'result')
|
con.registerHandler('iq',self._vCardCB,'result')
|
||||||
self.connection.registerHandler('iq',self.rosterSetCB,'set', \
|
con.registerHandler('iq',self._rosterSetCB,'set', \
|
||||||
common.jabber.NS_ROSTER)
|
common.jabber.NS_ROSTER)
|
||||||
self.connection.registerHandler('iq',self.BrowseResultCB,'result', \
|
con.registerHandler('iq',self._BrowseResultCB,'result', \
|
||||||
common.jabber.NS_BROWSE)
|
common.jabber.NS_BROWSE)
|
||||||
self.connection.registerHandler('iq',self.DiscoverItemsCB,'result', \
|
con.registerHandler('iq',self._DiscoverItemsCB,'result', \
|
||||||
common.jabber.NS_P_DISC_ITEMS)
|
common.jabber.NS_P_DISC_ITEMS)
|
||||||
self.connection.registerHandler('iq',self.DiscoverInfoCB,'result', \
|
con.registerHandler('iq',self._DiscoverInfoCB,'result', \
|
||||||
common.jabber.NS_P_DISC_INFO)
|
common.jabber.NS_P_DISC_INFO)
|
||||||
self.connection.registerHandler('iq',self.DiscoverInfoErrorCB,'error',\
|
con.registerHandler('iq',self._DiscoverInfoErrorCB,'error',\
|
||||||
common.jabber.NS_P_DISC_INFO)
|
common.jabber.NS_P_DISC_INFO)
|
||||||
self.connection.registerHandler('iq',self.VersionCB,'get', \
|
con.registerHandler('iq',self._VersionCB,'get', \
|
||||||
common.jabber.NS_VERSION)
|
common.jabber.NS_VERSION)
|
||||||
self.connection.registerHandler('iq',self.VersionResultCB,'result', \
|
con.registerHandler('iq',self._VersionResultCB,'result', \
|
||||||
common.jabber.NS_VERSION)
|
common.jabber.NS_VERSION)
|
||||||
try:
|
try:
|
||||||
self.connection.connect()
|
con.connect()
|
||||||
except:
|
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('STATUS', 'offline')
|
||||||
self.dispatch('ERROR', _('Couldn\'t connect to %s') \
|
self.dispatch('ERROR', _('Couldn\'t connect to %s') \
|
||||||
% hostname)
|
% hostname)
|
||||||
self.connected = 0
|
self.connected = 0
|
||||||
return -1
|
return None
|
||||||
|
|
||||||
gajim.log.debug('Connected to server')
|
gajim.log.debug('Connected to server')
|
||||||
|
|
||||||
if self.connection.auth(self.name, self.password, resource):
|
if con.auth(name, self.password, resource):
|
||||||
self.connection.requestRoster()
|
con.requestRoster()
|
||||||
roster = self.connection.getRoster().getRaw()
|
roster = con.getRoster().getRaw()
|
||||||
if not roster :
|
if not roster :
|
||||||
roster = {}
|
roster = {}
|
||||||
self.dispatch('ROSTER', (0, roster))
|
self.dispatch('ROSTER', (0, roster))
|
||||||
self.connected = 2
|
self.connected = 2
|
||||||
return 0
|
return con
|
||||||
else:
|
else:
|
||||||
log.debug('Couldn\'t authentificate to %s' % hostname)
|
gajim.log.debug('Couldn\'t authentificate to %s' % hostname)
|
||||||
self.dispatch('STATUS', 'offline')
|
self.dispatch('STATUS', 'offline')
|
||||||
self.dispatch('ERROR', _('Authentification failed with %s, check your login and password') % hostname)
|
self.dispatch('ERROR', _('Authentification failed with %s, check your login and password') % hostname)
|
||||||
self.connected = 0
|
self.connected = 0
|
||||||
return -1
|
return None
|
||||||
# END connect
|
# END connect
|
||||||
|
|
||||||
def register_handler(self, event, function):
|
def register_handler(self, event, function):
|
||||||
|
@ -473,7 +475,7 @@ class connection:
|
||||||
if self.connected < 2:
|
if self.connected < 2:
|
||||||
self.dispatch('BAD_PASSPHRASE', ())
|
self.dispatch('BAD_PASSPHRASE', ())
|
||||||
if (status != 'offline') and (self.connected == 0):
|
if (status != 'offline') and (self.connected == 0):
|
||||||
self.connect()
|
self.connection = self.connect()
|
||||||
if self.connected == 2:
|
if self.connected == 2:
|
||||||
self.connected = STATUS_LIST.index(status)
|
self.connected = STATUS_LIST.index(status)
|
||||||
#send our presence
|
#send our presence
|
||||||
|
@ -481,14 +483,14 @@ class connection:
|
||||||
if status == 'invisible':
|
if status == 'invisible':
|
||||||
ptype = 'invisible'
|
ptype = 'invisible'
|
||||||
prio = gajim.config.get_per('accounts', self.name, 'priority')
|
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)
|
self.dispatch('STATUS', status)
|
||||||
#ask our VCard
|
#ask our VCard
|
||||||
iq = common.jabber.Iq(type='get')
|
iq = common.jabber.Iq(type='get')
|
||||||
iq._setTag('vCard', common.jabber.NS_VCARD)
|
iq._setTag('vCard', common.jabber.NS_VCARD)
|
||||||
id = con.getAnID()
|
id = self.connection.getAnID()
|
||||||
iq.setID(id)
|
iq.setID(id)
|
||||||
con.send(iq)
|
self.connection.send(iq)
|
||||||
self.myVCardID.append(id)
|
self.myVCardID.append(id)
|
||||||
elif (status == 'offline') and self.connected:
|
elif (status == 'offline') and self.connected:
|
||||||
self.connected = 0
|
self.connected = 0
|
||||||
|
@ -614,7 +616,7 @@ class connection:
|
||||||
else:
|
else:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.connected = 0
|
self.connected = 0
|
||||||
self.password = ''
|
self.password = password
|
||||||
if USE_GPG:
|
if USE_GPG:
|
||||||
self.gpg = GnuPG.GnuPG()
|
self.gpg = GnuPG.GnuPG()
|
||||||
gajim.config.set('usegpg', True)
|
gajim.config.set('usegpg', True)
|
||||||
|
|
|
@ -1122,6 +1122,7 @@ class Account_modification_window:
|
||||||
if name in gajim.connections:
|
if name in gajim.connections:
|
||||||
Error_dialog(_('An account already has this name'))
|
Error_dialog(_('An account already has this name'))
|
||||||
return
|
return
|
||||||
|
gajim.config.add_per('accounts', name)
|
||||||
gajim.connections[name] = connection.connection(name)
|
gajim.connections[name] = connection.connection(name)
|
||||||
self.plugin.register_handlers(gajim.connections[name])
|
self.plugin.register_handlers(gajim.connections[name])
|
||||||
#if we neeed to register a new account
|
#if we neeed to register a new account
|
||||||
|
|
|
@ -679,6 +679,12 @@ class interface:
|
||||||
conn.register_handler('BAD_PASSPHRASE', self.handle_event_bad_passphrase)
|
conn.register_handler('BAD_PASSPHRASE', self.handle_event_bad_passphrase)
|
||||||
conn.register_handler('ROSTER_INFO', self.handle_event_roster_info)
|
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):
|
def __init__(self):
|
||||||
if gtk.pygtk_version >= (2, 6, 0):
|
if gtk.pygtk_version >= (2, 6, 0):
|
||||||
gtk.about_dialog_set_email_hook(self.on_launch_browser_mailer, 'mail')
|
gtk.about_dialog_set_email_hook(self.on_launch_browser_mailer, 'mail')
|
||||||
|
@ -739,7 +745,8 @@ class interface:
|
||||||
self.register_handlers(gajim.connections[account])
|
self.register_handlers(gajim.connections[account])
|
||||||
|
|
||||||
gobject.timeout_add(100, self.autoconnect)
|
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__':
|
if __name__ == '__main__':
|
||||||
try: # Import Psyco if available
|
try: # Import Psyco if available
|
||||||
|
|
|
@ -325,7 +325,7 @@ class Roster_window:
|
||||||
"""Clear and draw roster"""
|
"""Clear and draw roster"""
|
||||||
self.make_menu()
|
self.make_menu()
|
||||||
self.tree.get_model().clear()
|
self.tree.get_model().clear()
|
||||||
for acct in self.contacts.keys():
|
for acct in gajim.connections:
|
||||||
self.add_account_to_roster(acct)
|
self.add_account_to_roster(acct)
|
||||||
for jid in self.contacts[acct].keys():
|
for jid in self.contacts[acct].keys():
|
||||||
self.add_user_to_roster(jid, acct)
|
self.add_user_to_roster(jid, acct)
|
||||||
|
@ -697,7 +697,7 @@ class Roster_window:
|
||||||
accountIter = self.get_account_iter(account)
|
accountIter = self.get_account_iter(account)
|
||||||
if accountIter:
|
if accountIter:
|
||||||
model.set_value(accountIter, 0, self.pixbufs['connecting'])
|
model.set_value(accountIter, 0, self.pixbufs['connecting'])
|
||||||
gajim.connections[account].connected = 1
|
# gajim.connections[account].connected = 1
|
||||||
if self.plugin.systray_enabled:
|
if self.plugin.systray_enabled:
|
||||||
self.plugin.systray.set_status('connecting')
|
self.plugin.systray.set_status('connecting')
|
||||||
|
|
||||||
|
@ -711,7 +711,7 @@ class Roster_window:
|
||||||
if passphrase == -1:
|
if passphrase == -1:
|
||||||
if accountIter:
|
if accountIter:
|
||||||
model.set_value(accountIter, 0, self.pixbufs['offline'])
|
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.plugin.systray.set_status('offline')
|
||||||
self.update_status_comboxbox()
|
self.update_status_comboxbox()
|
||||||
return
|
return
|
||||||
|
@ -832,7 +832,7 @@ class Roster_window:
|
||||||
luser_copy.append(user)
|
luser_copy.append(user)
|
||||||
for user in luser_copy:
|
for user in luser_copy:
|
||||||
self.chg_user_status(user, 'offline', 'Disconnected', account)
|
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()
|
self.update_status_comboxbox()
|
||||||
|
|
||||||
def new_chat(self, user, account):
|
def new_chat(self, user, account):
|
||||||
|
|
Loading…
Reference in New Issue