2005-04-15 19:02:23 +02:00
|
|
|
## common/gajim.py
|
|
|
|
##
|
2006-04-04 19:09:29 +02:00
|
|
|
## Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com>
|
|
|
|
## Copyright (C) 2005-2006 Dimitur Kirov <dkirov@gmail.com>
|
|
|
|
## Copyright (C) 2005-2006 Travis Shirk <travis@pobox.com>
|
2005-04-15 19:02:23 +02:00
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
|
2005-06-25 03:23:21 +02:00
|
|
|
import os
|
2005-10-30 12:20:24 +01:00
|
|
|
import sys
|
2006-02-10 14:03:32 +01:00
|
|
|
import tempfile
|
2005-04-15 19:02:23 +02:00
|
|
|
import logging
|
2006-02-10 14:18:33 +01:00
|
|
|
import locale
|
2005-08-09 20:45:16 +02:00
|
|
|
|
2005-12-05 12:13:08 +01:00
|
|
|
import config
|
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
|
|
|
from contacts import Contacts
|
2005-04-15 19:02:23 +02:00
|
|
|
|
2005-10-20 13:17:17 +02:00
|
|
|
interface = None # The actual interface (the gtk one for the moment)
|
2005-12-30 22:37:36 +01:00
|
|
|
version = '0.10'
|
2005-12-05 12:13:08 +01:00
|
|
|
config = config.Config()
|
2005-04-15 19:02:23 +02:00
|
|
|
connections = {}
|
2005-05-29 21:04:01 +02:00
|
|
|
verbose = False
|
2005-05-17 22:31:43 +02:00
|
|
|
|
|
|
|
h = logging.StreamHandler()
|
|
|
|
f = logging.Formatter('%(asctime)s %(name)s: %(message)s', '%d %b %Y %H:%M:%S')
|
|
|
|
h.setFormatter(f)
|
2005-04-15 19:02:23 +02:00
|
|
|
log = logging.getLogger('Gajim')
|
2005-05-17 22:31:43 +02:00
|
|
|
log.addHandler(h)
|
|
|
|
|
2005-12-05 12:13:08 +01:00
|
|
|
import logger
|
|
|
|
logger = logger.Logger() # init the logger
|
2005-11-22 15:46:37 +01:00
|
|
|
|
2005-10-30 12:20:24 +01:00
|
|
|
if os.name == 'nt':
|
2005-12-06 01:08:57 +01:00
|
|
|
DATA_DIR = os.path.join('..', 'data')
|
2005-10-30 12:20:24 +01:00
|
|
|
try:
|
2005-11-23 20:12:52 +01:00
|
|
|
# Documents and Settings\[User Name]\Application Data\Gajim
|
2005-11-22 12:54:33 +01:00
|
|
|
LOGPATH = os.path.join(os.environ['appdata'], 'Gajim', 'Logs') # deprecated
|
2006-02-15 11:44:41 +01:00
|
|
|
VCARD_PATH = os.path.join(os.environ['appdata'], 'Gajim', 'Vcards')
|
2006-01-17 12:20:55 +01:00
|
|
|
AVATAR_PATH = os.path.join(os.environ['appdata'], 'Gajim', 'Avatars')
|
2006-03-17 15:24:58 +01:00
|
|
|
MY_EMOTS_PATH = os.path.join(os.environ['appdata'], 'Gajim', 'Emoticons')
|
2005-10-30 12:20:24 +01:00
|
|
|
except KeyError:
|
2005-11-23 20:12:52 +01:00
|
|
|
# win9x, in cwd
|
2005-11-22 12:54:33 +01:00
|
|
|
LOGPATH = 'Logs' # deprecated
|
2006-02-15 11:44:41 +01:00
|
|
|
VCARD_PATH = 'Vcards'
|
2006-01-17 12:20:55 +01:00
|
|
|
AVATAR_PATH = 'Avatars'
|
2006-03-17 15:24:58 +01:00
|
|
|
MY_EMOTS_PATH = 'Emoticons'
|
2005-11-22 12:54:33 +01:00
|
|
|
else: # Unices
|
|
|
|
DATA_DIR = '../data'
|
|
|
|
LOGPATH = os.path.expanduser('~/.gajim/logs') # deprecated
|
2006-02-15 11:44:41 +01:00
|
|
|
VCARD_PATH = os.path.expanduser('~/.gajim/vcards')
|
2006-01-17 12:20:55 +01:00
|
|
|
AVATAR_PATH = os.path.expanduser('~/.gajim/avatars')
|
2006-03-17 15:24:58 +01:00
|
|
|
MY_EMOTS_PATH = os.path.expanduser('~/.gajim/emoticons')
|
2005-11-22 12:54:33 +01:00
|
|
|
|
2006-02-10 17:12:16 +01:00
|
|
|
HOME_DIR = os.path.expanduser('~')
|
2006-02-10 14:03:32 +01:00
|
|
|
TMP = tempfile.gettempdir()
|
|
|
|
|
2005-10-30 12:20:24 +01:00
|
|
|
try:
|
|
|
|
LOGPATH = LOGPATH.decode(sys.getfilesystemencoding())
|
2006-02-15 11:44:41 +01:00
|
|
|
VCARD_PATH = VCARD_PATH.decode(sys.getfilesystemencoding())
|
2006-01-12 23:48:49 +01:00
|
|
|
TMP = TMP.decode(sys.getfilesystemencoding())
|
2006-02-15 11:35:13 +01:00
|
|
|
AVATAR_PATH = AVATAR_PATH.decode(sys.getfilesystemencoding())
|
2006-03-17 15:24:58 +01:00
|
|
|
MY_EMOTS_PATH = MY_EMOTS_PATH.decode(sys.getfilesystemencoding())
|
2005-10-30 12:20:24 +01:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2006-02-10 14:19:02 +01:00
|
|
|
LANG = locale.getdefaultlocale()[0] # en_US, fr_FR, el_GR etc..
|
2006-02-10 14:18:33 +01:00
|
|
|
if LANG is None:
|
2005-06-25 09:37:14 +02:00
|
|
|
LANG = 'en'
|
2006-02-10 14:18:33 +01:00
|
|
|
else:
|
|
|
|
LANG = LANG[:2] # en, fr, el etc..
|
2005-07-02 13:06:02 +02:00
|
|
|
|
2005-07-03 17:27:41 +02:00
|
|
|
last_message_time = {} # list of time of the latest incomming message
|
|
|
|
# {acct1: {jid1: time1, jid2: time2}, }
|
2005-07-02 13:06:02 +02:00
|
|
|
encrypted_chats = {} # list of encrypted chats {acct1: [jid1, jid2], ..}
|
2005-07-18 23:08:31 +02:00
|
|
|
|
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
|
|
|
contacts = Contacts()
|
2005-11-14 11:51:32 +01:00
|
|
|
gc_connected = {} # tell if we are connected to the room or not {acct: {room_jid: True}}
|
2005-11-13 18:24:08 +01:00
|
|
|
gc_passwords = {} # list of the pass required to enter a room {room_jid: password}
|
2005-07-25 22:04:24 +02:00
|
|
|
|
2005-07-18 23:08:31 +02:00
|
|
|
groups = {} # list of groups
|
|
|
|
newly_added = {} # list of contacts that has just signed in
|
|
|
|
to_be_removed = {} # list of contacts that has just signed out
|
2005-11-23 19:15:24 +01:00
|
|
|
|
2005-10-15 22:49:08 +02:00
|
|
|
awaiting_events = {} # list of messages/FT reveived but not printed
|
|
|
|
# awaiting_events[jid] = (type, (data1, data2, ...))
|
2005-10-16 15:18:34 +02:00
|
|
|
# if type in ('chat', 'normal'): data = (message, subject, kind, time,
|
2005-11-23 19:15:24 +01:00
|
|
|
# encrypted, resource)
|
2005-10-15 22:49:08 +02:00
|
|
|
# kind can be (incoming, error)
|
2005-12-06 18:43:21 +01:00
|
|
|
# if type in file-request, file-request-error, file-send-error, file-error,
|
2005-10-19 23:14:51 +02:00
|
|
|
# file-completed, file-stopped:
|
2005-10-19 22:16:22 +02:00
|
|
|
# data = file_props
|
2005-07-18 23:08:31 +02:00
|
|
|
nicks = {} # list of our nick names in each account
|
2006-03-28 01:32:39 +02:00
|
|
|
# should we block 'contact signed in' notifications for this account?
|
2006-03-28 01:35:46 +02:00
|
|
|
# this is only for the first 30 seconds after we change our show
|
|
|
|
# to something else than offline
|
2006-03-28 01:32:39 +02:00
|
|
|
block_signed_in_notifications = {}
|
2005-07-18 23:08:31 +02:00
|
|
|
con_types = {} # type of each connection (ssl, tls, tcp, ...)
|
2005-07-22 01:47:27 +02:00
|
|
|
|
|
|
|
sleeper_state = {} # whether we pass auto away / xa or not
|
|
|
|
#'off': don't use sleeper for this account
|
|
|
|
#'online': online and use sleeper
|
|
|
|
#'autoaway': autoaway and use sleeper
|
|
|
|
#'autoxa': autoxa and use sleeper
|
2005-07-22 23:27:04 +02:00
|
|
|
status_before_autoaway = {}
|
2005-07-22 02:01:05 +02:00
|
|
|
|
2005-08-16 21:26:11 +02:00
|
|
|
SHOW_LIST = ['offline', 'connecting', 'online', 'chat', 'away', 'xa', 'dnd',
|
|
|
|
'invisible']
|
2005-07-22 02:01:05 +02:00
|
|
|
|
2005-07-22 16:30:35 +02:00
|
|
|
def get_nick_from_jid(jid):
|
|
|
|
pos = jid.find('@')
|
|
|
|
return jid[:pos]
|
|
|
|
|
2005-09-11 17:02:22 +02:00
|
|
|
def get_server_from_jid(jid):
|
2005-09-11 19:06:37 +02:00
|
|
|
pos = jid.find('@') + 1 # after @
|
2005-09-11 17:02:22 +02:00
|
|
|
return jid[pos:]
|
|
|
|
|
2005-07-22 16:30:35 +02:00
|
|
|
def get_nick_from_fjid(jid):
|
|
|
|
# fake jid is the jid for a contact in a room
|
2005-08-30 00:24:13 +02:00
|
|
|
# gaim@conference.jabber.no/nick/nick-continued
|
2005-07-22 16:30:35 +02:00
|
|
|
return jid.split('/', 1)[1]
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-09-11 17:02:22 +02:00
|
|
|
def get_room_name_and_server_from_room_jid(jid):
|
|
|
|
room_name = get_nick_from_jid(jid)
|
|
|
|
server = get_server_from_jid(jid)
|
|
|
|
return room_name, server
|
|
|
|
|
2005-07-26 09:22:08 +02:00
|
|
|
def get_room_and_nick_from_fjid(jid):
|
|
|
|
# fake jid is the jid for a contact in a room
|
2005-08-30 00:24:13 +02:00
|
|
|
# gaim@conference.jabber.no/nick/nick-continued
|
|
|
|
# return ('gaim@conference.jabber.no', 'nick/nick-continued')
|
|
|
|
l = jid.split('/', 1)
|
2005-09-27 00:29:52 +02:00
|
|
|
if len(l) == 1: # No nick
|
2005-08-30 00:24:13 +02:00
|
|
|
l.append('')
|
2005-08-14 23:02:51 +02:00
|
|
|
return l
|
2005-11-02 09:12:54 +01:00
|
|
|
|
|
|
|
def get_real_jid_from_fjid(account, fjid):
|
2005-11-03 21:48:27 +01:00
|
|
|
'''returns real jid or returns None
|
2005-11-02 12:06:51 +01:00
|
|
|
if we don't know the real jid'''
|
2005-11-02 09:12:54 +01:00
|
|
|
room_jid, nick = get_room_and_nick_from_fjid(fjid)
|
2005-11-02 12:06:51 +01:00
|
|
|
if not nick: # It's not a fake_jid, it is a real jid
|
2005-11-02 12:13:05 +01:00
|
|
|
return fjid # we return the real jid
|
2005-11-02 09:12:54 +01:00
|
|
|
real_jid = fjid
|
2006-01-25 03:43:55 +01:00
|
|
|
if interface.msg_win_mgr.get_control(room_jid, account):
|
2005-11-02 09:12:54 +01:00
|
|
|
# It's a pm, so if we have real jid it's in contact.jid
|
2006-01-06 03:20:38 +01:00
|
|
|
gc_contact = contacts.get_gc_contact(account, room_jid, nick)
|
|
|
|
if not gc_contact:
|
2005-11-03 21:48:27 +01:00
|
|
|
return
|
2006-01-06 03:20:38 +01:00
|
|
|
# gc_contact.jid is None when it's not a real jid (we don't know real jid)
|
|
|
|
real_jid = gc_contact.jid
|
2005-11-02 09:12:54 +01:00
|
|
|
return real_jid
|
|
|
|
|
2005-09-27 00:29:52 +02:00
|
|
|
def get_room_from_fjid(jid):
|
|
|
|
return get_room_and_nick_from_fjid(jid)[0]
|
2005-07-22 16:30:35 +02:00
|
|
|
|
2005-07-22 02:01:05 +02:00
|
|
|
def get_contact_name_from_jid(account, jid):
|
2006-01-06 03:20:38 +01:00
|
|
|
c = contacts.get_first_contact_from_jid(account, jid)
|
|
|
|
return c.name
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-07-22 02:34:08 +02:00
|
|
|
def get_jid_without_resource(jid):
|
|
|
|
return jid.split('/')[0]
|
2005-07-22 16:30:35 +02:00
|
|
|
|
|
|
|
def construct_fjid(room_jid, nick):
|
|
|
|
''' nick is in utf8 (taken from treeview); room_jid is in unicode'''
|
2005-08-04 16:30:41 +02:00
|
|
|
# fake jid is the jid for a contact in a room
|
|
|
|
# gaim@conference.jabber.org/nick
|
2005-09-11 17:02:22 +02:00
|
|
|
if isinstance(nick, str):
|
2005-08-04 16:30:41 +02:00
|
|
|
nick = unicode(nick, 'utf-8')
|
|
|
|
return room_jid + '/' + nick
|
2005-12-06 18:43:21 +01:00
|
|
|
|
2005-07-22 16:30:35 +02:00
|
|
|
def get_resource_from_jid(jid):
|
2005-10-07 15:45:58 +02:00
|
|
|
jids = jid.split('/', 1)
|
|
|
|
if len(jids) > 1:
|
|
|
|
return jids[1] # abc@doremi.org/res/res-continued
|
|
|
|
else:
|
|
|
|
return ''
|
2005-07-22 16:30:35 +02:00
|
|
|
'''\
|
|
|
|
[15:34:28] <asterix> we should add contact.fake_jid I think
|
|
|
|
[15:34:46] <asterix> so if we know real jid, it wil be in contact.jid, or we look in contact.fake_jid
|
|
|
|
[15:32:54] <asterix> they can have resource if we know the real jid
|
|
|
|
[15:33:07] <asterix> and that resource is in contact.resource
|
|
|
|
'''
|
2005-08-03 15:46:48 +02:00
|
|
|
|
|
|
|
def get_number_of_accounts():
|
2006-04-08 12:28:53 +02:00
|
|
|
'''returns the number of ALL accounts'''
|
2005-08-03 15:46:48 +02:00
|
|
|
return len(connections.keys())
|
2005-08-26 15:11:20 +02:00
|
|
|
|
2006-04-08 12:28:53 +02:00
|
|
|
def get_number_of_connected_accounts(accounts_list = None):
|
|
|
|
'''returns the number of CONNECTED accounts
|
|
|
|
you can optionally pass an accounts_list
|
|
|
|
and if you do those will be checked, else all will be checked'''
|
|
|
|
connected_accounts = 0
|
|
|
|
if accounts_list is None:
|
|
|
|
accounts = connections.keys()
|
|
|
|
else:
|
|
|
|
accounts = accounts_list
|
|
|
|
for acct in accounts:
|
|
|
|
if gajim.connections[acct].connected > 1:
|
|
|
|
connected_accounts = connected_accounts + 1
|
|
|
|
return connected_accounts
|
|
|
|
|
2005-08-26 15:15:16 +02:00
|
|
|
def get_transport_name_from_jid(jid, use_config_setting = True):
|
Merged revisions 4987-4989,4991-4996,4999,5003 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4987 | nk | 2006-01-03 04:00:51 -0700 (Tue, 03 Jan 2006) | 1 line
commit 48x48 transport online/offline imgs by Grenshad (I pngcrushed them)
........
r4988 | nk | 2006-01-03 04:32:01 -0700 (Tue, 03 Jan 2006) | 1 line
icon in notification window not always jabber now. MSN if he uses msn etc. thanks stian barmen for helping me test
........
r4989 | nk | 2006-01-03 04:40:44 -0700 (Tue, 03 Jan 2006) | 1 line
all strings I got report about them, are not translatable; pot/po update
........
r4991 | asterix | 2006-01-03 08:08:21 -0700 (Tue, 03 Jan 2006) | 2 lines
don't remove the jid entry in _contacts[account] when we remove a contact
........
r4992 | asterix | 2006-01-03 08:18:30 -0700 (Tue, 03 Jan 2006) | 2 lines
fix logic
........
r4993 | asterix | 2006-01-03 09:04:14 -0700 (Tue, 03 Jan 2006) | 2 lines
a GC_Contact can have a resource if we knoe his real JID
........
r4994 | asterix | 2006-01-03 09:32:58 -0700 (Tue, 03 Jan 2006) | 2 lines
missing argument in create_gc_contact
........
r4995 | asterix | 2006-01-03 10:36:41 -0700 (Tue, 03 Jan 2006) | 2 lines
we save gc_contact vcard instance in instances[self.account]['infos'][Fake_jid]
........
r4996 | asterix | 2006-01-03 11:17:43 -0700 (Tue, 03 Jan 2006) | 2 lines
in DataForm, a field of type 'list-single' can have no <value> element. Create a default one in such a case to prevent TB
........
r4999 | asterix | 2006-01-04 05:52:26 -0700 (Wed, 04 Jan 2006) | 2 lines
prevent TB when we move a contact that was in no group
........
r5003 | asterix | 2006-01-04 09:03:42 -0700 (Wed, 04 Jan 2006) | 2 lines
handle correctly unlabeled option values in DataForms
........
2006-01-05 04:17:36 +01:00
|
|
|
'''returns 'aim', 'gg', 'irc' etc
|
|
|
|
if JID is not from transport returns None'''
|
2005-08-26 16:44:46 +02:00
|
|
|
#FIXME: jid can be None! one TB I saw had this problem:
|
|
|
|
# in the code block # it is a groupchat presence in handle_event_notify
|
|
|
|
# jid was None. Yann why?
|
|
|
|
if not jid or (use_config_setting and not config.get('use_transports_iconsets')):
|
2005-08-26 15:11:20 +02:00
|
|
|
return
|
2006-01-22 00:40:54 +01:00
|
|
|
|
|
|
|
host = get_server_from_jid(jid)
|
|
|
|
# host is now f.e. icq.foo.org or just icq (sometimes on hacky transports)
|
|
|
|
host_splitted = host.split('.')
|
|
|
|
if len(host_splitted) != 0:
|
|
|
|
# now we support both 'icq.' and 'icq' but not icqsucks.org
|
|
|
|
host = host_splitted[0]
|
|
|
|
|
|
|
|
if host == 'aim':
|
2005-08-26 15:11:20 +02:00
|
|
|
return 'aim'
|
2006-01-22 00:40:54 +01:00
|
|
|
elif host == 'gg':
|
2005-08-26 15:11:20 +02:00
|
|
|
return 'gadugadu'
|
2006-01-22 00:40:54 +01:00
|
|
|
elif host == 'irc':
|
2005-08-26 15:11:20 +02:00
|
|
|
return 'irc'
|
2006-01-22 00:40:54 +01:00
|
|
|
elif host == 'icq':
|
2005-08-26 15:11:20 +02:00
|
|
|
return 'icq'
|
2006-02-24 14:07:44 +01:00
|
|
|
elif host == 'jit':
|
|
|
|
return 'icq'
|
2006-01-22 00:40:54 +01:00
|
|
|
elif host == 'msn':
|
2005-08-26 15:11:20 +02:00
|
|
|
return 'msn'
|
2006-01-22 00:40:54 +01:00
|
|
|
elif host == 'sms':
|
2005-08-26 15:11:20 +02:00
|
|
|
return 'sms'
|
2006-01-22 00:40:54 +01:00
|
|
|
elif host == 'tlen':
|
2005-08-26 15:11:20 +02:00
|
|
|
return 'tlen'
|
2006-01-22 00:40:54 +01:00
|
|
|
elif host == 'weather':
|
2005-08-30 00:24:13 +02:00
|
|
|
return 'weather'
|
2006-01-22 00:40:54 +01:00
|
|
|
elif host == 'yahoo':
|
2005-08-26 15:11:20 +02:00
|
|
|
return 'yahoo'
|
2005-10-24 16:32:13 +02:00
|
|
|
else:
|
|
|
|
return None
|
2005-08-26 15:11:20 +02:00
|
|
|
|
|
|
|
def jid_is_transport(jid):
|
2006-03-28 13:32:53 +02:00
|
|
|
# if not '@' or '@' starts the jid then it is transport
|
|
|
|
if jid.find('@') <= 0:
|
|
|
|
return True
|
2005-10-24 16:32:13 +02:00
|
|
|
else:
|
2006-03-28 13:32:53 +02:00
|
|
|
return False
|
2005-09-09 22:52:29 +02:00
|
|
|
|
|
|
|
def get_jid_from_account(account_name):
|
2006-02-26 15:13:13 +01:00
|
|
|
'''return the jid we use in the given account'''
|
2005-09-09 22:52:29 +02:00
|
|
|
name = config.get_per('accounts', account_name, 'name')
|
2005-09-09 23:03:53 +02:00
|
|
|
hostname = config.get_per('accounts', account_name, 'hostname')
|
2005-09-09 22:52:29 +02:00
|
|
|
jid = name + '@' + hostname
|
|
|
|
return jid
|
2005-09-11 02:32:58 +02:00
|
|
|
|
2006-02-26 15:13:13 +01:00
|
|
|
def get_our_jids():
|
|
|
|
'''returns a list of the jids we use in our accounts'''
|
|
|
|
our_jids = list()
|
|
|
|
for account in contacts.get_accounts():
|
|
|
|
our_jids.append(get_jid_from_account(account))
|
|
|
|
return our_jids
|
|
|
|
|
2005-11-20 14:27:37 +01:00
|
|
|
def get_hostname_from_account(account_name, use_srv = False):
|
2005-09-11 02:32:58 +02:00
|
|
|
'''returns hostname (if custom hostname is used, that is returned)'''
|
2005-11-20 14:27:37 +01:00
|
|
|
if use_srv and connections[account_name].connected_hostname:
|
|
|
|
return connections[account_name].connected_hostname
|
2005-09-12 08:27:20 +02:00
|
|
|
if config.get_per('accounts', account_name, 'use_custom_host'):
|
|
|
|
return config.get_per('accounts', account_name, 'custom_host')
|
|
|
|
return config.get_per('accounts', account_name, 'hostname')
|
2005-10-18 11:07:52 +02:00
|
|
|
|
|
|
|
def get_first_event(account, jid, typ = None):
|
|
|
|
'''returns the first event of the given type from the awaiting_events queue'''
|
|
|
|
if not awaiting_events[account].has_key(jid):
|
|
|
|
return None
|
|
|
|
q = awaiting_events[account][jid]
|
|
|
|
if not typ:
|
|
|
|
return q[0]
|
|
|
|
for ev in q:
|
|
|
|
if ev[0] == typ:
|
|
|
|
return ev
|
|
|
|
return None
|
2006-01-20 18:40:45 +01:00
|
|
|
|
|
|
|
def get_notification_image_prefix(jid):
|
|
|
|
'''returns the prefix for the notification images'''
|
|
|
|
transport_name = get_transport_name_from_jid(jid)
|
|
|
|
if transport_name in ('aim', 'icq', 'msn', 'yahoo'):
|
|
|
|
prefix = transport_name
|
|
|
|
else:
|
|
|
|
prefix = 'jabber'
|
|
|
|
return prefix
|
|
|
|
|
2006-01-20 18:50:01 +01:00
|
|
|
def get_name_from_jid(account, jid):
|
|
|
|
'''returns from JID's shown name and if no contact returns jids'''
|
|
|
|
contact = contacts.get_first_contact_from_jid(account, jid)
|
|
|
|
if contact:
|
|
|
|
actor = contact.get_shown_name()
|
|
|
|
else:
|
|
|
|
actor = jid
|
|
|
|
return actor
|