some more helpers for our API

This commit is contained in:
Nikos Kouremenos 2005-08-26 13:11:20 +00:00
parent 4c75c558e0
commit 21a3971952
4 changed files with 36 additions and 35 deletions

View file

@ -147,3 +147,34 @@ def get_resource_from_jid(jid):
def get_number_of_accounts():
return len(connections.keys())
def get_transport_name_from_jid(self, jid, use_config_setting = True):
'''returns 'aim', 'gg', 'irc' etc'''
if use_config_setting or not gajim.config.get('use_transports_iconsets'):
return
host = jid.split('@')[-1]
if host.startswith('aim'):
return 'aim'
elif host.startswith('gadugadu'):
return 'gadugadu'
elif host.startswith('gg'):
return 'gadugadu'
elif host.startswith('irc'):
return 'irc'
# abc@icqsucks.org will match as ICQ, but what to do..
elif host.startswith('icq'):
return 'icq'
elif host.startswith('msn'):
return 'msn'
elif host.startswith('sms'):
return 'sms'
elif host.startswith('tlen'):
return 'tlen'
elif host.startswith('yahoo'):
return 'yahoo'
def jid_is_transport(jid):
is_transport = jid.startswith('aim') or jid.startswith('gadugadu') or\
jid.startswith('irc') or jid.startswith('icq') or\
jid.startswith('msn') or jid.startswith('sms') or\
jid.startswith('yahoo')

View file

@ -192,34 +192,9 @@ class RosterWindow:
if group_empty:
del gajim.groups[account][group]
def get_transport_name_by_jid(self,jid):
if not jid or not gajim.config.get('use_transports_iconsets'):
return None
host = jid.split('@')[-1]
if host.startswith('aim'):
return 'aim'
elif host.startswith('gadugadu'):
return 'gadugadu'
elif host.startswith('gg'):
return 'gadugadu'
elif host.startswith('irc'):
return 'irc'
# abc@icqsucks.org will match as ICQ, but what to do..
elif host.startswith('icq'):
return 'icq'
elif host.startswith('msn'):
return 'msn'
elif host.startswith('sms'):
return 'sms'
elif host.startswith('tlen'):
return 'tlen'
elif host.startswith('yahoo'):
return 'yahoo'
return None
def get_appropriate_state_images(self, jid):
'''check jid and return the appropriate state images dict'''
transport = self.get_transport_name_by_jid(jid)
transport = gajim.get_transport_name_from_jid(jid)
if transport:
return self.transports_state_images[transport]
return self.jabber_state_images
@ -248,7 +223,7 @@ class RosterWindow:
if contact.ask == 'subscribe':
img = state_images['requested']
else:
transport = self.get_transport_name_by_jid(jid)
transport = gajim.get_transport_name_from_jid(jid)
if transport and state_images.has_key(contact.show):
img = state_images[contact.show]
else:

View file

@ -730,13 +730,8 @@ timestamp, contact):
def restore_conversation(self, jid):
# don't restore lines if it's a transport
is_transport = jid.startswith('aim') or jid.startswith('gadugadu') or\
jid.startswith('irc') or jid.startswith('icq') or\
jid.startswith('msn') or jid.startswith('sms') or\
jid.startswith('yahoo')
if is_transport:
return
if gajim.jid_is_transport(jid):
return
# How many lines to restore and when to time them out
restore = gajim.config.get('restore_lines')

View file

@ -304,7 +304,7 @@ class RosterTooltip(BaseTooltip, StatusTable):
# try to find the image for the contact status
state_file = prim_contact.show.replace(' ', '_')
transport = self.plugin.roster.get_transport_name_by_jid(prim_contact.jid)
transport = gajim.get_transport_name_from_jid(prim_contact.jid)
if transport:
file_path = os.path.join(gajim.DATA_DIR, 'iconsets', 'transports',
transport , '16x16')