2005-04-15 19:02:23 +02:00
|
|
|
## common/gajim.py
|
|
|
|
##
|
|
|
|
## Gajim Team:
|
2005-06-06 01:42:30 +02:00
|
|
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## - Vincent Hanquez <tab@snarc.org>
|
2005-04-18 16:05:30 +02:00
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
2005-04-15 19:02:23 +02:00
|
|
|
##
|
|
|
|
## Copyright (C) 2003-2005 Gajim Team
|
|
|
|
##
|
|
|
|
## 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-04-15 19:02:23 +02:00
|
|
|
import logging
|
|
|
|
import common.config
|
2005-04-16 00:02:13 +02:00
|
|
|
import common.logger
|
2005-04-15 19:02:23 +02:00
|
|
|
|
2005-06-19 15:17:32 +02:00
|
|
|
version = '0.8'
|
2005-04-15 19:02:23 +02:00
|
|
|
config = common.config.Config()
|
|
|
|
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-04-16 00:02:13 +02:00
|
|
|
logger = common.logger.Logger()
|
2005-05-17 19:37:50 +02:00
|
|
|
DATA_DIR = '../data'
|
2005-06-25 11:35:31 +02:00
|
|
|
LANG = os.getenv('LANG') # en_US, fr_FR, el_GR etc..
|
2005-06-25 09:37:14 +02:00
|
|
|
if LANG:
|
2005-06-25 11:35:31 +02:00
|
|
|
LANG = LANG[:2] # en, fr, el etc..
|
2005-06-25 09:37:14 +02:00
|
|
|
else:
|
|
|
|
LANG = 'en'
|
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
|
|
|
|
|
|
|
contacts = {} # list of contacts {acct: {jid1: [C1, C2]}, } one Contact per resource
|
|
|
|
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
|
|
|
|
awaiting_messages = {} # list of messages reveived but not printed
|
|
|
|
nicks = {} # list of our nick names in each account
|
|
|
|
allow_notifications = {} # do we allow notifications for each account ?
|
|
|
|
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 02:01:05 +02:00
|
|
|
|
|
|
|
|
2005-07-22 16:30:35 +02:00
|
|
|
def get_fjid_from_nick(room_jid, nick):
|
|
|
|
# fake jid is the jid for a contact in a room
|
|
|
|
# gaim@conference.jabber.org/nick
|
|
|
|
fjid = room_jid + '/' + nick
|
|
|
|
return fjid
|
|
|
|
|
|
|
|
def get_nick_from_jid(jid):
|
|
|
|
pos = jid.find('@')
|
|
|
|
return jid[:pos]
|
|
|
|
|
|
|
|
def get_nick_from_fjid(jid):
|
|
|
|
# fake jid is the jid for a contact in a room
|
|
|
|
# gaim@conference.jabber.org/nick/nick-continued
|
|
|
|
return jid.split('/', 1)[1]
|
|
|
|
|
2005-07-22 02:01:05 +02:00
|
|
|
def get_contact_instances_from_jid(account, jid):
|
|
|
|
''' we may have two or more resources on that jid '''
|
2005-07-22 16:30:35 +02:00
|
|
|
if jid in contacts[account]:
|
|
|
|
contacts_instances = contacts[account][jid]
|
|
|
|
return contacts_instances
|
2005-07-22 02:01:05 +02:00
|
|
|
|
|
|
|
def get_first_contact_instance_from_jid(account, jid):
|
2005-07-22 16:30:35 +02:00
|
|
|
if jid in contacts[account]:
|
|
|
|
contact = contacts[account][jid][0]
|
|
|
|
else: # it's fake jid
|
2005-07-22 20:10:55 +02:00
|
|
|
#FIXME: problem see comment in next line
|
|
|
|
nick = get_nick_from_fjid(jid) # if we ban/kick we now real jid
|
2005-07-22 16:30:35 +02:00
|
|
|
if nick in gc_contacts[room_jid]:
|
|
|
|
contact = gc_contacts[room_jid][nick] # always only one instance
|
|
|
|
return contact
|
2005-07-22 02:01:05 +02:00
|
|
|
|
|
|
|
def get_contact_name_from_jid(account, jid):
|
2005-07-22 02:34:08 +02:00
|
|
|
return contacts[account][jid][0].name
|
|
|
|
|
|
|
|
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'''
|
|
|
|
return room_jid + '/' + unicode(nick, 'utf-8')
|
|
|
|
|
|
|
|
def get_resource_from_jid(jid):
|
|
|
|
return jid.split('/', 1)[1] # abc@doremi.org/res/res-continued
|
|
|
|
'''\
|
|
|
|
[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
|
|
|
|
'''
|