From 549b10369e29458a6c62b415968ff990e6460ba6 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Fri, 22 Jul 2005 00:01:05 +0000 Subject: [PATCH] moving contacts-related functions to common/gajim.py --- src/common/gajim.py | 14 ++++++++++++++ src/dialogs.py | 3 ++- src/gajim.py | 18 +++++++++--------- src/gtkgui_helpers.py | 15 --------------- src/roster_window.py | 3 +-- src/tabbed_chat_window.py | 2 +- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/common/gajim.py b/src/common/gajim.py index 166201506..8ab3b3b31 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -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 diff --git a/src/dialogs.py b/src/dialogs.py index c538df9e4..02e566b41 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -674,7 +674,8 @@ class RosterTooltip(gtk.Window): else: # only one resource if contact.resource: info += '\n' + _('Resource: ') + \ - '' + gtkgui_helpers.escape_for_pango_markup(contact.resource) + ' (' + str(contact.priority) + ')' + '' + gtkgui_helpers.escape_for_pango_markup( + contact.resource) + ' (' + str(contact.priority) + ')' if contact.show: info += '\n' + _('Status: ') + \ '' + helpers.get_uf_show(contact.show) diff --git a/src/gajim.py b/src/gajim.py index 2a7a11fcb..040d5c1d1 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -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, diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 122bb5509..ab8f2ba1d 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -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: diff --git a/src/roster_window.py b/src/roster_window.py index 796ff9c78..19df36d91 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -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 diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index f8d8ae622..48170f50f 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -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):