moving contacts-related functions to common/gajim.py

This commit is contained in:
Nikos Kouremenos 2005-07-22 00:01:05 +00:00
parent f6d16b1db0
commit 549b10369e
6 changed files with 27 additions and 28 deletions

View File

@ -59,3 +59,17 @@ sleeper_state = {} # whether we pass auto away / xa or not
#'online': online and use sleeper
#'autoaway': autoaway and use sleeper
#'autoxa': autoxa and use sleeper
def get_contact_instances_from_jid(account, jid):
''' we may have two or more resources on that jid '''
contact_instances = gajim.contacts[account][jid]
return contact_instances
def get_first_contact_instance_from_jid(account, jid):
contact_instances = get_contact_instances_from_jid(account, jid)
return contact_instances[0]
def get_contact_name_from_jid(account, jid):
contact_instances = get_contact_instances_from_jid(account, jid)
return contact_instances[0].name

View File

@ -674,7 +674,8 @@ class RosterTooltip(gtk.Window):
else: # only one resource
if contact.resource:
info += '\n<span weight="bold">' + _('Resource: ') + \
'</span>' + gtkgui_helpers.escape_for_pango_markup(contact.resource) + ' (' + str(contact.priority) + ')'
'</span>' + gtkgui_helpers.escape_for_pango_markup(
contact.resource) + ' (' + str(contact.priority) + ')'
if contact.show:
info += '\n<span weight="bold">' + _('Status: ') + \
'</span>' + helpers.get_uf_show(contact.show)

View File

@ -476,15 +476,15 @@ class Interface:
#('SUBSCRIBED', account, (jid, resource))
jid = array[0]
if gajim.contacts[account].has_key(jid):
u = gajim.contacts[account][jid][0]
u.resource = array[1]
self.roster.remove_contact(u, account)
if _('not in the roster') in u.groups:
u.groups.remove(_('not in the roster'))
if len(u.groups) == 0:
u.groups = [_('General')]
self.roster.add_contact_to_roster(u.jid, account)
gajim.connections[account].update_contact(u.jid, u.name, u.groups)
c = gajim.get_first_contact_instance_from_jid(account, jid)
c.resource = array[1]
self.roster.remove_contact(c, account)
if _('not in the roster') in c.groups:
c.groups.remove(_('not in the roster'))
if len(c.groups) == 0:
c.groups = [_('General')]
self.roster.add_contact_to_roster(c.jid, account)
gajim.connections[account].update_contact(c.jid, c.name, c.groups)
else:
keyID = ''
attached_keys = gajim.config.get_per('accounts', account,

View File

@ -22,21 +22,6 @@
import cgi
from common import gajim
def get_contact_instances_from_jid(account, jid):
''' we may have two or more resources on that jid '''
contact_instances = gajim.contacts[account][jid]
return contact_instances
def get_first_contact_instance_from_jid(account, jid):
contact_instances = get_contact_instances_from_jid(account, jid)
return contact_instances[0]
def get_contact_name_from_jid(account, jid):
contact_instances = get_contact_instances_from_jid(account, jid)
return contact_instances[0].name
def escape_for_pango_markup(string):
# escapes chars for pango markup not to break
if string is not None:

View File

@ -31,7 +31,6 @@ import history_window
import dialogs
import config
import cell_renderer_image
import gtkgui_helpers
from gajim import Contact
from common import gajim
@ -227,7 +226,7 @@ class RosterWindow:
iters = self.get_contact_iter(jid, account)
if len(iters) == 0:
return
contact_instances = gtkgui_helpers.get_contact_instances_from_jid(account,
contact_instances = gajim.get_contact_instances_from_jid(account,
jid)
contact = contact_instances[0]
name = contact.name

View File

@ -339,7 +339,7 @@ class TabbedChatWindow(chat.Chat):
def handle_incoming_chatstate(self, account, jid, chatstate):
''' handle incoming chatstate that jid SENT TO us '''
contact = gtkgui_helpers.get_first_contact_instance_from_jid(account, jid)
contact = gajim.get_first_contact_instance_from_jid(account, jid)
self.draw_name_banner(contact, chatstate)
def check_for_possible_paused_chatstate(self, contact):