we now get transport type from disco info and save that in DB. Fixes #1990 and #1938

This commit is contained in:
Yann Leboulanger 2006-07-29 22:29:59 +00:00
parent 98928886ef
commit 32b18d9237
6 changed files with 162 additions and 4 deletions

View File

@ -134,7 +134,7 @@ class Config:
'send_on_ctrl_enter': [opt_bool, False, _('Send message on Ctrl+Enter and with Enter make new line (Mirabilis ICQ Client default behaviour).')],
'show_roster_on_startup': [opt_bool, True],
'key_up_lines': [opt_int, 25, _('How many lines to store for Ctrl+KeyUP.')],
'version': [ opt_str, '0.10.1.2' ], # which version created the config
'version': [ opt_str, '0.10.1.3' ], # which version created the config
'search_engine': [opt_str, 'http://www.google.com/search?&q=%s&sourceid=gajim'],
'dictionary_url': [opt_str, 'WIKTIONARY', _("Either custom url with %s in it where %s is the word/phrase or 'WIKTIONARY' which means use wiktionary.")],
'always_english_wikipedia': [opt_bool, False],

View File

@ -725,11 +725,15 @@ class ConnectionDisco:
if not qc:
qc = []
is_muc = False
transport_type = ''
for i in qc:
if i.getName() == 'identity':
attr = {}
for key in i.getAttrs().keys():
attr[key] = i.getAttr(key)
if attr.has_key('category') and attr['category'] in ('gateway', 'headline')\
and attr.has_key('type'):
transport_type = attr['type']
if attr.has_key('category') and attr['category'] == 'conference' \
and attr.has_key('type') and attr['type'] == 'text':
is_muc = True
@ -739,6 +743,9 @@ class ConnectionDisco:
elif i.getName() == 'x' and i.getAttr('xmlns') == common.xmpp.NS_DATA:
data.append(common.xmpp.DataForm(node=i))
jid = helpers.get_full_jid_from_iq(iq_obj)
if transport_type and jid not in gajim.transport_type:
gajim.transport_type[jid] = transport_type
gajim.logger.save_transport_type(jid, transport_type)
id = iq_obj.getID()
if not identities: # ejabberd doesn't send identities when we browse online users
#FIXME: see http://www.jabber.ru/bugzilla/show_bug.cgi?id=225

View File

@ -83,6 +83,8 @@ else:
gmail_domains = ['gmail.com', 'googlemail.com']
transport_type = {} # list the type of transport
last_message_time = {} # list of time of the latest incomming message
# {acct1: {jid1: time1, jid2: time2}, }
encrypted_chats = {} # list of encrypted chats {acct1: [jid1, jid2], ..}
@ -223,8 +225,11 @@ def get_transport_name_from_jid(jid, use_config_setting = True):
# jid was None. Yann why?
if not jid or (use_config_setting and not config.get('use_transports_iconsets')):
return
host = get_server_from_jid(jid)
if host in transport_type:
return transport_type[host]
# host is now f.e. icq.foo.org or just icq (sometimes on hacky transports)
host_splitted = host.split('.')
if len(host_splitted) != 0:
@ -293,7 +298,7 @@ def get_first_event(account, jid, typ = None):
if ev[0] == typ:
return ev
return None
def get_notification_image_prefix(jid):
'''returns the prefix for the notification images'''
transport_name = get_transport_name_from_jid(jid)

View File

@ -78,6 +78,22 @@ class Constants:
self.SHOW_OFFLINE
) = range(6)
(
self.TYPE_AIM,
self.TYPE_GG,
self.TYPE_HTTP_WS,
self.TYPE_ICQ,
self.TYPE_MSN,
self.TYPE_QQ,
self.TYPE_SMS,
self.TYPE_SMTP,
self.TYPE_TLEN,
self.TYPE_YAHOO,
self.TYPE_NEWMAIL,
self.TYPE_RSS,
self.TYPE_WEATHER,
) = range(13)
constants = Constants()
class Logger:
@ -192,7 +208,66 @@ class Logger:
show_col = 'UNKNOWN'
return kind_col, show_col
def convert_human_transport_type_to_db_api_values(self, type_):
'''converts from string style to constant ints for db'''
if type_ == 'aim':
return constants.TYPE_AIM
if type_ == 'gadu-gadu':
return constants.TYPE_GG
if type_ == 'http-ws':
return constants.TYPE_HTTP_WS
if type_ == 'icq':
return constants.TYPE_ICQ
if type_ == 'msn':
return constants.TYPE_MSN
if type_ == 'qq':
return constants.TYPE_QQ
if type_ == 'sms':
return constants.TYPE_SMS
if type_ == 'smtp':
return constants.TYPE_SMTP
if type_ == 'tlen':
return constants.TYPE_TLEN
if type_ == 'yahoo':
return constants.TYPE_YAHOO
if type_ == 'newmail':
return constants.TYPE_NEWMAIL
if type_ == 'rss':
return constants.TYPE_RSS
if type_ == 'weather':
return constants.TYPE_WEATHER
return None
def convert_api_values_to_human_transport_type(self, type_id):
'''converts from constant ints for db to string style'''
if type_id == constants.TYPE_AIM:
return 'aim'
if type_id == constants.TYPE_GG:
return 'gadu-gadu'
if type_id == constants.TYPE_HTTP_WS:
return 'http-ws'
if type_id == constants.TYPE_ICQ:
return 'icq'
if type_id == constants.TYPE_MSN:
return 'msn'
if type_id == constants.TYPE_QQ:
return 'qq'
if type_id == constants.TYPE_SMS:
return 'sms'
if type_id == constants.TYPE_SMTP:
return 'smtp'
if type_id == constants.TYPE_TLEN:
return 'tlen'
if type_id == constants.TYPE_YAHOO:
return 'yahoo'
if type_id == constants.TYPE_NEWMAIL:
return 'newmail'
if type_id == constants.TYPE_RSS:
return 'rss'
if type_id == constants.TYPE_WEATHER:
return 'weather'
def commit_to_db(self, values, write_unread = False):
#print 'saving', values
sql = 'INSERT INTO logs (jid_id, contact_name, time, kind, show, message, subject) VALUES (?, ?, ?, ?, ?, ?, ?)'
@ -498,3 +573,43 @@ class Logger:
jid_id = self.get_jid_id(jid)
where_sql = 'jid_id = %s' % jid_id
return where_sql
def save_transport_type(self, jid, type_):
'''save the type of the transport in DB'''
type_id = self.convert_human_transport_type_to_db_api_values(type_)
if not type_id:
# unknown type
return
self.cur.execute(
'SELECT type from transports_cache WHERE transport = "%s"' % jid)
results = self.cur.fetchall()
if results:
result = results[0][0]
if result == type_id:
return
self.cur.execute(
'UPDATE transports_cache SET type = %d WHERE transport = "%s"' % (type_id,
jid))
try:
self.con.commit()
except sqlite.OperationalError, e:
print >> sys.stderr, str(e)
return
self.cur.execute(
'INSERT INTO transports_cache VALUES ("%s", %d)' % (jid, type_id))
try:
self.con.commit()
except sqlite.OperationalError, e:
print >> sys.stderr, str(e)
def get_transports_type(self):
'''return all the type of the transports in DB'''
self.cur.execute(
'SELECT * from transports_cache')
results = self.cur.fetchall()
if not results:
return {}
answer = {}
for result in results:
answer[result[0]] = self.convert_api_values_to_human_transport_type(result[1])
return answer

View File

@ -144,6 +144,8 @@ class OptionsParser:
self.update_config_to_01011()
if old < [0, 10, 1, 2] and new >= [0, 10, 1, 2]:
self.update_config_to_01012()
if old < [0, 10, 1, 3] and new >= [0, 10, 1, 3]:
self.update_config_to_01013()
gajim.config.set('version', new_version)
@ -272,3 +274,29 @@ class OptionsParser:
self.old_values['emoticons_theme'] == 'Disabled':
gajim.config.set('emoticons_theme', '')
gajim.config.set('version', '0.10.1.2')
def update_config_to_01013(self):
'''create table transports_cache if there is no such table'''
import exceptions
try:
from pysqlite2 import dbapi2 as sqlite
except ImportError:
raise exceptions.PysqliteNotAvailable
import logger
con = sqlite.connect(logger.LOG_DB_PATH)
cur = con.cursor()
try:
cur.executescript(
'''
CREATE TABLE transports_cache (
transport TEXT UNIQUE,
type INTEGER
);
'''
)
con.commit()
except sqlite.OperationalError, e:
pass
con.close()
gajim.config.set('version', '0.10.1.3')

View File

@ -1891,6 +1891,9 @@ class Interface:
# get instances for windows/dialogs that will show_all()/hide()
self.instances['file_transfers'] = dialogs.FileTransfersWindow()
# get transports type from DB
gajim.transport_type = gajim.logger.get_transports_type()
gobject.timeout_add(100, self.autoconnect)
gobject.timeout_add(200, self.process_connections)
gobject.timeout_add(500, self.read_sleepy)