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.

This commit is contained in:
Yann Leboulanger 2006-01-01 18:41:04 +00:00
commit 63e5defe39
18 changed files with 602 additions and 558 deletions

View File

@ -188,7 +188,7 @@ class Chat:
add = _('Group Chat') add = _('Group Chat')
elif len(self.xmls) == 1: # just one tab elif len(self.xmls) == 1: # just one tab
if self.widget_name == 'tabbed_chat_window': if self.widget_name == 'tabbed_chat_window':
c = gajim.get_first_contact_instance_from_jid(self.account, jid) c = gajim.contacts.get_first_contact_from_jid(self.account, jid)
if c is None: if c is None:
add = '' add = ''
else: else:
@ -296,9 +296,9 @@ class Chat:
def get_message_type(self, jid): def get_message_type(self, jid):
if self.widget_name == 'groupchat_window': if self.widget_name == 'groupchat_window':
return 'gc' return 'gc'
if gajim.contacts[self.account].has_key(jid): if gajim.contacts.is_pm_from_jid(self.account, jid):
return 'chat' return 'pm'
return 'pm' return 'chat'
def get_nth_jid(self, page_number = None): def get_nth_jid(self, page_number = None):
notebook = self.notebook notebook = self.notebook
@ -463,7 +463,7 @@ class Chat:
if self.widget_name == 'tabbed_chat_window': if self.widget_name == 'tabbed_chat_window':
jid = self.get_active_jid() jid = self.get_active_jid()
c = gajim.get_first_contact_instance_from_jid(self.account, jid) c = gajim.contacts.get_first_contact_from_jid(self.account, jid)
if _('not in the roster') in c.groups: # for add_to_roster_menuitem if _('not in the roster') in c.groups: # for add_to_roster_menuitem
childs[5].show() childs[5].show()
childs[5].set_no_show_all(False) childs[5].set_no_show_all(False)
@ -501,7 +501,7 @@ class Chat:
childs[3].set_active(isactive) childs[3].set_active(isactive)
childs[3].set_property('sensitive', issensitive) childs[3].set_property('sensitive', issensitive)
# If we don't have resource, we can't do file transfert # If we don't have resource, we can't do file transfert
c = gajim.get_first_contact_instance_from_jid(self.account, jid) c = gajim.contacts.get_first_contact_from_jid(self.account, jid)
if not c.resource: if not c.resource:
childs[2].set_sensitive(False) childs[2].set_sensitive(False)
else: else:

106
src/common/contacts.py Normal file
View File

@ -0,0 +1,106 @@
## common/contacts.py
##
## Contributors for this file:
## - Yann Le Boulanger <asterix@lagaule.org>
##
## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org>
## Vincent Hanquez <tab@snarc.org>
## Copyright (C) 2005 Yann Le Boulanger <asterix@lagaule.org>
## Vincent Hanquez <tab@snarc.org>
## Nikos Kouremenos <nkour@jabber.org>
## Dimitur Kirov <dkirov@gmail.com>
## Travis Shirk <travis@pobox.com>
## Norman Rasmussen <norman@rasmussen.co.za>
##
## 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.
##
class Contact:
'''Information concerning each contact'''
def __init__(self, jid='', name='', groups=[], show='', status='', sub='',
ask='', resource='', priority=5, keyID='', role='', affiliation='',
our_chatstate=None, chatstate=None):
self.jid = jid
self.name = name
self.groups = groups
self.show = show
self.status = status
self.sub = sub
self.ask = ask
self.resource = resource
self.priority = priority
self.keyID = keyID
self.role = role
self.affiliation = affiliation
# please read jep-85 http://www.jabber.org/jeps/jep-0085.html
# we keep track of jep85 support by the peer by three extra states:
# None, False and 'ask'
# None if no info about peer
# False if peer does not support jep85
# 'ask' if we sent the first 'active' chatstate and are waiting for reply
# this holds what WE SEND to contact (our current chatstate)
self.our_chatstate = our_chatstate
# this is contact's chatstate
self.chatstate = chatstate
def get_full_jid(self):
if self.resource:
return self.jid + '/' + self.resource
return self.jid
class Contacts:
'''Information concerning all contacts and groupchat contacts'''
def __init__(self):
self._contacts = {} # list of contacts {acct: {jid1: [C1, C2]}, } one Contact per resource
self._gc_contacts = {} # list of contacts that are in gc {acct: {room_jid: {nick: C}}}
self._sub_contacts = {} # {acct: {jid1: jid2}} means jid1 is sub of jid2
def is_subcontact(self, account, contact):
if contact.jid in self._sub_contacts[account]:
return True
def get_contact_instances_from_jid(self, account, jid):
''' we may have two or more resources on that jid '''
if jid in self._contacts[account]:
contacts_instances = self._contacts[account][jid]
return contacts_instances
return []
def get_highest_prio_contact_from_contacts(self, contacts):
if not contacts:
return None
prim_contact = contacts[0]
for contact in contacts[1:]:
if int(contact.priority) > int(prim_contact.priority):
prim_contact = contact
return prim_contact
def get_contact_instance_with_highest_priority(self, account, jid):
contact_instances = self.get_contact_instances_from_jid(account, jid)
return self.get_highest_prio_contact_from_contacts(contact_instances)
def get_parent_contact(self, account, contact):
'''Returns the parent contact of contact if it's a sub-contact,
else contact'''
if is_subcontact(account, contact):
parrent_jid = self._sub_contacts[account][contact.jid]
return self.get_contact_instance_with_highest_priority(account,
parrent_jid)
return contact
def get_master_contact(self, account, contact):
'''Returns the master contact of contact (parent of parent...) if it's a
sub-contact, else contact'''
while is_subcontact(account, contact):
parrent_jid = self._sub_contacts[account][contact.jid]
contact = self.get_contact_instance_with_highest_priority(account,
parrent_jid)
return contact

View File

@ -29,7 +29,7 @@ import logging
import mutex import mutex
import config import config
from contacts import Contacts
interface = None # The actual interface (the gtk one for the moment) interface = None # The actual interface (the gtk one for the moment)
version = '0.10' version = '0.10'
@ -77,8 +77,7 @@ last_message_time = {} # list of time of the latest incomming message
# {acct1: {jid1: time1, jid2: time2}, } # {acct1: {jid1: time1, jid2: time2}, }
encrypted_chats = {} # list of encrypted chats {acct1: [jid1, jid2], ..} encrypted_chats = {} # list of encrypted chats {acct1: [jid1, jid2], ..}
contacts = {} # list of contacts {acct: {jid1: [C1, C2]}, } one Contact per resource contacts = Contacts()
gc_contacts = {} # list of contacts that are in gc {acct: {room_jid: {nick: C}}}
gc_connected = {} # tell if we are connected to the room or not {acct: {room_jid: True}} gc_connected = {} # tell if we are connected to the room or not {acct: {room_jid: True}}
gc_passwords = {} # list of the pass required to enter a room {room_jid: password} gc_passwords = {} # list of the pass required to enter a room {room_jid: password}
@ -159,40 +158,9 @@ def get_real_jid_from_fjid(account, fjid):
def get_room_from_fjid(jid): def get_room_from_fjid(jid):
return get_room_and_nick_from_fjid(jid)[0] return get_room_and_nick_from_fjid(jid)[0]
def get_contact_instances_from_jid(account, jid):
''' we may have two or more resources on that jid '''
if jid in contacts[account]:
contacts_instances = contacts[account][jid]
return contacts_instances
def get_first_contact_instance_from_jid(account, jid):
contact = None
if jid in contacts[account]:
contact = contacts[account][jid][0]
else: # it's fake jid
#FIXME: problem see comment in next line
room, nick = \
get_room_and_nick_from_fjid(jid) # if we ban/kick we now real jid
if gc_contacts[account].has_key(room) and \
nick in gc_contacts[account][room]:
contact = gc_contacts[account][room][nick]
return contact
def get_contact_instance_with_highest_priority(account, jid):
contact_instances = contacts[account][jid]
return get_highest_prio_contact_from_contacts(contact_instances)
def get_contact_name_from_jid(account, jid): def get_contact_name_from_jid(account, jid):
return contacts[account][jid][0].name return contacts[account][jid][0].name
def get_highest_prio_contact_from_contacts(contacts):
prim_contact = None # primary contact
for contact in contacts:
if prim_contact == None or int(contact.priority) > \
int(prim_contact.priority):
prim_contact = contact
return prim_contact
def get_jid_without_resource(jid): def get_jid_without_resource(jid):
return jid.split('/')[0] return jid.split('/')[0]

View File

@ -43,7 +43,6 @@ try:
except: except:
HAS_GTK_SPELL = False HAS_GTK_SPELL = False
from gajim import Contact
from common import helpers from common import helpers
from common import gajim from common import gajim
from common import connection from common import connection
@ -555,7 +554,7 @@ class PreferencesWindow:
# open new tabbed chat windows # open new tabbed chat windows
for jid in jids: for jid in jids:
if kind == 'chats': if kind == 'chats':
c = gajim.get_contact_instance_with_highest_priority(acct, jid) c = gajim.contacts.get_contact_with_highest_priority(acct, jid)
gajim.interface.roster.new_chat(c, acct) gajim.interface.roster.new_chat(c, acct)
if kind == 'gc': if kind == 'gc':
gajim.interface.roster.new_room(jid, saved_var[jid]['nick'], acct) gajim.interface.roster.new_room(jid, saved_var[jid]['nick'], acct)
@ -584,7 +583,7 @@ class PreferencesWindow:
# open new tabbed chat windows # open new tabbed chat windows
for jid in jids: for jid in jids:
if kind == 'chats': if kind == 'chats':
c = gajim.get_contact_instance_with_highest_priority(acct, jid) c = gajim.contacts.get_contact_with_highest_priority(acct, jid)
gajim.interface.roster.new_chat(c, acct) gajim.interface.roster.new_chat(c, acct)
if kind == 'gc': if kind == 'gc':
gajim.interface.roster.new_room(jid, saved_var[jid]['nick'], acct) gajim.interface.roster.new_room(jid, saved_var[jid]['nick'], acct)
@ -1278,8 +1277,6 @@ class AccountModificationWindow:
gajim.allow_notifications[name] = \ gajim.allow_notifications[name] = \
gajim.allow_notifications[self.account] gajim.allow_notifications[self.account]
gajim.groups[name] = gajim.groups[self.account] gajim.groups[name] = gajim.groups[self.account]
gajim.contacts[name] = gajim.contacts[self.account]
gajim.gc_contacts[name] = gajim.gc_contacts[self.account]
gajim.gc_connected[name] = gajim.gc_connected[self.account] gajim.gc_connected[name] = gajim.gc_connected[self.account]
gajim.newly_added[name] = gajim.newly_added[self.account] gajim.newly_added[name] = gajim.newly_added[self.account]
gajim.to_be_removed[name] = gajim.to_be_removed[self.account] gajim.to_be_removed[name] = gajim.to_be_removed[self.account]
@ -1291,6 +1288,8 @@ class AccountModificationWindow:
gajim.status_before_autoaway[self.account] gajim.status_before_autoaway[self.account]
gajim.events_for_ui[name] = gajim.events_for_ui[self.account] gajim.events_for_ui[name] = gajim.events_for_ui[self.account]
gajim.contacts.change_account_name(self.account, name)
#upgrade account variable in opened windows #upgrade account variable in opened windows
for kind in ('infos', 'disco', 'chats', 'gc', 'gc_config'): for kind in ('infos', 'disco', 'chats', 'gc', 'gc_config'):
for j in gajim.interface.instances[name][kind]: for j in gajim.interface.instances[name][kind]:
@ -1307,8 +1306,6 @@ class AccountModificationWindow:
del gajim.nicks[self.account] del gajim.nicks[self.account]
del gajim.allow_notifications[self.account] del gajim.allow_notifications[self.account]
del gajim.groups[self.account] del gajim.groups[self.account]
del gajim.contacts[self.account]
del gajim.gc_contacts[self.account]
del gajim.gc_connected[self.account] del gajim.gc_connected[self.account]
del gajim.newly_added[self.account] del gajim.newly_added[self.account]
del gajim.to_be_removed[self.account] del gajim.to_be_removed[self.account]
@ -1879,13 +1876,6 @@ class ServiceRegistrationWindow(DataFormWindow):
entry.grab_focus() entry.grab_focus()
table.show_all() table.show_all()
def add_transport_to_roster(self):
user1 = Contact(jid = self.service, name = self.service,
groups = [_('Transports')], show = 'offline', status = 'offline',
sub = 'from')
gajim.contacts[self.account][self.service] = [user1]
gajim.interface.roster.add_contact_to_roster(self.service, self.account)
def on_ok_button_clicked(self, widget): def on_ok_button_clicked(self, widget):
'''When Ok button is clicked: '''When Ok button is clicked:
send registration info to the core''' send registration info to the core'''
@ -1896,7 +1886,8 @@ class ServiceRegistrationWindow(DataFormWindow):
if self.infos.has_key('registered'): if self.infos.has_key('registered'):
del self.infos['registered'] del self.infos['registered']
else: else:
self.add_transport_to_roster() gajim.interface.roster.add_transport_to_roster(self.account,
self.service)
gajim.connections[self.account].register_agent(self.service, self.infos) gajim.connections[self.account].register_agent(self.service, self.infos)
self.window.destroy() self.window.destroy()
@ -1905,7 +1896,8 @@ class ServiceRegistrationWindow(DataFormWindow):
if self.infos.has_key('registered'): if self.infos.has_key('registered'):
del self.infos['registered'] del self.infos['registered']
else: else:
self.add_transport_to_roster() gajim.interface.roster.add_transport_to_roster(self.account,
self.service)
gajim.connections[self.account].register_agent(self.service, self.infos, gajim.connections[self.account].register_agent(self.service, self.infos,
True) # True is for is_form True) # True is for is_form
self.window.destroy() self.window.destroy()
@ -2202,8 +2194,7 @@ class RemoveAccountWindow:
del gajim.nicks[self.account] del gajim.nicks[self.account]
del gajim.allow_notifications[self.account] del gajim.allow_notifications[self.account]
del gajim.groups[self.account] del gajim.groups[self.account]
del gajim.contacts[self.account] gajim.contacts.remove_account(self.account)
del gajim.gc_contacts[self.account]
del gajim.gc_connected[self.account] del gajim.gc_connected[self.account]
del gajim.to_be_removed[self.account] del gajim.to_be_removed[self.account]
del gajim.newly_added[self.account] del gajim.newly_added[self.account]
@ -2743,8 +2734,7 @@ _('You can set advanced account options by pressing Advanced button, or later by
gajim.awaiting_events[self.account] = {} gajim.awaiting_events[self.account] = {}
gajim.connections[self.account].connected = 0 gajim.connections[self.account].connected = 0
gajim.groups[self.account] = {} gajim.groups[self.account] = {}
gajim.contacts[self.account] = {} gajim.contacts.add_account(self.account)
gajim.gc_contacts[self.account] = {}
gajim.gc_connected[self.account] = {} gajim.gc_connected[self.account] = {}
gajim.newly_added[self.account] = [] gajim.newly_added[self.account] = []
gajim.to_be_removed[self.account] = [] gajim.to_be_removed[self.account] = []

View File

@ -371,8 +371,8 @@ class ConversationTextview(gtk.TextView):
self.on_join_group_chat_menuitem_activate, text) self.on_join_group_chat_menuitem_activate, text)
allow_add = False allow_add = False
if gajim.contacts[self.account].has_key(text): c = gajim.contacts.get_first_contact_from_jid(self.account, text)
c = gajim.contacts[self.account][text][0] if c and not gajim.contacts.is_pm_from_contact(self.account, c):
if _('not in the roster') in c.groups: if _('not in the roster') in c.groups:
allow_add = True allow_add = True
else: # he or she's not at all in the account contacts else: # he or she's not at all in the account contacts

View File

@ -43,7 +43,6 @@ except:
from filetransfers_window import FileTransfersWindow from filetransfers_window import FileTransfersWindow
from gajim_themes_window import GajimThemesWindow from gajim_themes_window import GajimThemesWindow
from advanced import AdvancedConfigurationWindow from advanced import AdvancedConfigurationWindow
from gajim import Contact
from common import gajim from common import gajim
from common import helpers from common import helpers
from common import i18n from common import i18n
@ -107,11 +106,6 @@ class EditGroupsDialog:
def group_toggled_cb(self, cell, path): def group_toggled_cb(self, cell, path):
self.changes_made = True self.changes_made = True
model = self.list.get_model() model = self.list.get_model()
if model[path][1] and len(self.user.groups) == 1: # we try to remove
# the last group
ErrorDialog(_('Cannot remove last group'),
_('At least one contact group must be present.')).get_response()
return
model[path][1] = not model[path][1] model[path][1] = not model[path][1]
if model[path][1]: if model[path][1]:
self.user.groups.append(model[path][0].decode('utf-8')) self.user.groups.append(model[path][0].decode('utf-8'))
@ -304,10 +298,10 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
liststore.append(['Jabber', '']) liststore.append(['Jabber', ''])
self.agents = ['Jabber'] self.agents = ['Jabber']
jid_agents = [] jid_agents = []
for j in gajim.contacts[account]: for j in gajim.contacts.get_jid_list(account):
user = gajim.contacts[account][j][0] contact = gajim.contacts.get_first_contact_from_jid(account, j)
if _('Transports') in user.groups and user.show != 'offline' and \ if _('Transports') in contact.groups and contact.show != 'offline' and\
user.show != 'error': contact.show != 'error':
jid_agents.append(j) jid_agents.append(j)
for a in jid_agents: for a in jid_agents:
if a.find('aim') > -1: if a.find('aim') > -1:
@ -382,8 +376,9 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
return return
# Check if jid is already in roster # Check if jid is already in roster
if jid in gajim.contacts[self.account] and _('not in the roster') not in \ if jid in gajim.contacts.get_jid_list(self.account) and \
gajim.contacts[self.account][jid][0].groups: _('not in the roster') not in \
gajim.contacts.get_first_contact_from_jid(self.account, jid).groups:
ErrorDialog(_('Contact already in roster'), ErrorDialog(_('Contact already in roster'),
_('This contact is already listed in your roster.')).get_response() _('This contact is already listed in your roster.')).get_response()
return return
@ -629,7 +624,7 @@ class SubscriptionRequestWindow:
'''accept the request''' '''accept the request'''
gajim.connections[self.account].send_authorization(self.jid) gajim.connections[self.account].send_authorization(self.jid)
self.window.destroy() self.window.destroy()
if not gajim.contacts[self.account].has_key(self.jid): if self.jid not in gajim.contacts.get_jid_list(self.account):
AddNewContactWindow(self.account, self.jid) AddNewContactWindow(self.account, self.jid)
def on_contact_info_button_clicked(self, widget): def on_contact_info_button_clicked(self, widget):
@ -826,8 +821,8 @@ class PopupNotificationWindow:
event_type_label.set_markup('<span foreground="black" weight="bold">%s</span>' %event_type) event_type_label.set_markup('<span foreground="black" weight="bold">%s</span>' %event_type)
if self.jid in gajim.contacts[account]: if self.jid in gajim.contacts.get_jid_list(account):
txt = gajim.contacts[account][self.jid][0].name txt = gajim.contacts.get_first_contact_from_jid(account, self.jid).name
else: else:
txt = self.jid txt = self.jid
@ -867,7 +862,8 @@ class PopupNotificationWindow:
close_button.modify_bg(gtk.STATE_NORMAL, bg_color) close_button.modify_bg(gtk.STATE_NORMAL, bg_color)
eventbox.modify_bg(gtk.STATE_NORMAL, bg_color) eventbox.modify_bg(gtk.STATE_NORMAL, bg_color)
event_description_label.set_markup('<span foreground="black">%s</span>' % txt) event_description_label.set_markup('<span foreground="black">%s</span>' % txt)
elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')): elif event_type in (_('File Transfer Completed'),
_('File Transfer Stopped')):
bg_color = gtk.gdk.color_parse('yellowgreen') bg_color = gtk.gdk.color_parse('yellowgreen')
close_button.modify_bg(gtk.STATE_NORMAL, bg_color) close_button.modify_bg(gtk.STATE_NORMAL, bg_color)
eventbox.modify_bg(gtk.STATE_NORMAL, bg_color) eventbox.modify_bg(gtk.STATE_NORMAL, bg_color)
@ -875,8 +871,8 @@ class PopupNotificationWindow:
if file_props['type'] == 'r': if file_props['type'] == 'r':
# get the name of the sender, as it is in the roster # get the name of the sender, as it is in the roster
sender = unicode(file_props['sender']).split('/')[0] sender = unicode(file_props['sender']).split('/')[0]
name = gajim.get_first_contact_instance_from_jid( name = gajim.contacts.get_first_contact_from_jid(account,
account, sender).name sender).name
txt = _('From %s') % name txt = _('From %s') % name
else: else:
receiver = file_props['receiver'] receiver = file_props['receiver']
@ -884,8 +880,8 @@ class PopupNotificationWindow:
receiver = receiver.jid receiver = receiver.jid
receiver = receiver.split('/')[0] receiver = receiver.split('/')[0]
# get the name of the contact, as it is in the roster # get the name of the contact, as it is in the roster
name = gajim.get_first_contact_instance_from_jid( name = gajim.contacts.get_first_contact_from_jid(account,
account, receiver).name receiver).name
txt = _('To %s') % name txt = _('To %s') % name
else: else:
txt = '' txt = ''
@ -930,8 +926,8 @@ class PopupNotificationWindow:
return return
# use Contact class, new_chat expects it that way # use Contact class, new_chat expects it that way
# is it in the roster? # is it in the roster?
if gajim.contacts[self.account].has_key(self.jid): if self.jid in gajim.contacts.get_jid_list(self.account):
contact = gajim.get_contact_instance_with_highest_priority( contact = gajim.contacts.get_contact_with_highest_priority(
self.account, self.jid) self.account, self.jid)
else: else:
keyID = '' keyID = ''
@ -942,14 +938,15 @@ class PopupNotificationWindow:
if self.msg_type.find('file') != 0: if self.msg_type.find('file') != 0:
if self.msg_type == 'pm': if self.msg_type == 'pm':
room_jid, nick = self.jid.split('/', 1) room_jid, nick = self.jid.split('/', 1)
show = gajim.gc_contacts[self.account][room_jid][nick].show gc_contact = gajim.contacts.get_gc_contact(self.account,
contact = Contact(jid = self.jid, name = nick, groups = ['none'], room_jid, nick)
show = show, sub = 'none') contact = gajim.contacts.contact_from_gc_contact(gc_contact)
else: else:
contact = Contact(jid = self.jid, name = self.jid.split('@')[0], contact = gajim.contacts.create_contact(jid = self.jid,
name = self.jid.split('@')[0],
groups = [_('not in the roster')], show = 'not in the roster', groups = [_('not in the roster')], show = 'not in the roster',
status = _('not in the roster'), sub = 'none', keyID = keyID) status = '', sub = 'none', keyID = keyID)
gajim.contacts[self.account][self.jid] = [contact] gajim.contacts.add_contact(self.account, contact)
gajim.interface.roster.add_contact_to_roster(contact.jid, gajim.interface.roster.add_contact_to_roster(contact.jid,
self.account) self.account)

View File

@ -56,7 +56,6 @@ import gtk.glade
import dialogs import dialogs
import tooltips import tooltips
from gajim import Contact
from common import helpers from common import helpers
from common import gajim from common import gajim
from common import xmpp from common import xmpp
@ -1194,9 +1193,10 @@ class ToplevelAgentBrowser(AgentBrowser):
if self.register_button and xmpp.NS_REGISTER in features: if self.register_button and xmpp.NS_REGISTER in features:
# We can register this agent # We can register this agent
registered_transports = [] registered_transports = []
contacts = gajim.contacts[self.account] jid_list = gajim.contacts.get_jid_list(self.account)
for j in contacts: for j in jid_list:
if _('Transports') in contacts[j][0].groups: contact = gajim.contacts.get_first_contact_from_jid(self.account, j)
if _('Transports') in contact.groups:
registered_transports.append(j) registered_transports.append(j)
if jid in registered_transports: if jid in registered_transports:
self.register_button.set_label(_('_Edit')) self.register_button.set_label(_('_Edit'))

View File

@ -177,7 +177,7 @@ class FileTransfersWindow:
helpers.convert_bytes(file_props['size']) helpers.convert_bytes(file_props['size'])
if file_props['type'] == 'r': if file_props['type'] == 'r':
jid = unicode(file_props['sender']).split('/')[0] jid = unicode(file_props['sender']).split('/')[0]
sender_name = gajim.get_first_contact_instance_from_jid( sender_name = gajim.contacts.get_first_contact_from_jid(
file_props['tt_account'], jid).name file_props['tt_account'], jid).name
sender = gtkgui_helpers.escape_for_pango_markup(sender_name) sender = gtkgui_helpers.escape_for_pango_markup(sender_name)
else: else:
@ -187,7 +187,7 @@ class FileTransfersWindow:
sectext += '\n\t' +_('Recipient: ') sectext += '\n\t' +_('Recipient: ')
if file_props['type'] == 's': if file_props['type'] == 's':
jid = unicode(file_props['receiver']).split('/')[0] jid = unicode(file_props['receiver']).split('/')[0]
receiver_name = gajim.get_first_contact_instance_from_jid( receiver_name = gajim.contacts.get_first_contact_from_jid(
file_props['tt_account'], jid).name file_props['tt_account'], jid).name
recipient = gtkgui_helpers.escape_for_pango_markup(receiver_name) recipient = gtkgui_helpers.escape_for_pango_markup(receiver_name)
else: else:
@ -289,7 +289,8 @@ _('Connection with peer cannot be established.'))
if contact.find('/') == -1: if contact.find('/') == -1:
return return
(jid, resource) = contact.split('/', 1) (jid, resource) = contact.split('/', 1)
contact = gajim.Contact(jid = jid, resource = resource) contact = gajim.contacts.create_contact(jid = jid,
resource = resource)
(file_dir, file_name) = os.path.split(file_path) (file_dir, file_name) = os.path.split(file_path)
file_props = self.get_send_file_props(account, contact, file_props = self.get_send_file_props(account, contact,
file_path, file_name) file_path, file_name)

View File

@ -138,35 +138,6 @@ if profile:
parser = optparser.OptionsParser(config_filename) parser = optparser.OptionsParser(config_filename)
class Contact:
'''Information concerning each contact'''
def __init__(self, jid='', name='', groups=[], show='', status='', sub='',
ask='', resource='', priority=5, keyID='', role='', affiliation='',
our_chatstate=None, chatstate=None):
self.jid = jid
self.name = name
self.groups = groups
self.show = show
self.status = status
self.sub = sub
self.ask = ask
self.resource = resource
self.priority = priority
self.keyID = keyID
self.role = role
self.affiliation = affiliation
# please read jep-85 http://www.jabber.org/jeps/jep-0085.html
# we keep track of jep85 support by the peer by three extra states:
# None, False and 'ask'
# None if no info about peer
# False if peer does not support jep85
# 'ask' if we sent the first 'active' chatstate and are waiting for reply
# this holds what WE SEND to contact (our current chatstate)
self.our_chatstate = our_chatstate
# this is contact's chatstate
self.chatstate = chatstate
import roster_window import roster_window
import systray import systray
import dialogs import dialogs
@ -305,8 +276,10 @@ class Interface:
else: else:
ji = jid ji = jid
# Update contact # Update contact
if gajim.contacts[account].has_key(ji):
lcontact = gajim.contacts[account][ji] jid_list = gajim.contacts.get_jid_list(account)
if ji in jid_list:
lcontact = gajim.contacts.get_contacts_from_jid(account, ji)
contact1 = None contact1 = None
resources = [] resources = []
for c in lcontact: for c in lcontact:
@ -320,17 +293,13 @@ class Interface:
if old_show == new_show and contact1.status == array[2]: #no change if old_show == new_show and contact1.status == array[2]: #no change
return return
else: else:
contact1 = gajim.contacts[account][ji][0] contact1 = gajim.contacts.get_first_contact_from_jid(account, ji)
if contact1.show in statuss: if contact1.show in statuss:
old_show = statuss.index(contact1.show) old_show = statuss.index(contact1.show)
if (resources != [''] and (len(lcontact) != 1 or if (resources != [''] and (len(lcontact) != 1 or
lcontact[0].show != 'offline')) and jid.find('@') > 0: lcontact[0].show != 'offline')) and jid.find('@') > 0:
old_show = 0 old_show = 0
contact1 = Contact(jid = contact1.jid, name = contact1.name, contact1 = gajim.contacts.copy_contact(contact1)
groups = contact1.groups, show = contact1.show,
status = contact1.status, sub = contact1.sub,
ask = contact1.ask, resource = contact1.resource,
priority = contact1.priority, keyID = contact1.keyID)
lcontact.append(contact1) lcontact.append(contact1)
contact1.resource = resource contact1.resource = resource
if contact1.jid.find('@') > 0 and len(lcontact) == 1: # It's not an agent if contact1.jid.find('@') > 0 and len(lcontact) == 1: # It's not an agent
@ -357,13 +326,13 @@ class Interface:
contact1.keyID = keyID contact1.keyID = keyID
if jid.find('@') <= 0: if jid.find('@') <= 0:
# It must be an agent # It must be an agent
if gajim.contacts[account].has_key(ji): if ji in jid_list:
# Update existing iter # Update existing iter
self.roster.draw_contact(ji, account) self.roster.draw_contact(ji, account)
elif jid == gajim.get_jid_from_account(account): elif jid == gajim.get_jid_from_account(account):
# It's another of our resources. We don't need to see that! # It's another of our resources. We don't need to see that!
return return
elif gajim.contacts[account].has_key(ji): elif ji in jid_list:
# It isn't an agent # It isn't an agent
# reset chatstate if needed: # reset chatstate if needed:
# (when contact signs out or has errors) # (when contact signs out or has errors)
@ -451,7 +420,7 @@ class Interface:
return return
# Handle chat states # Handle chat states
contact = gajim.get_first_contact_instance_from_jid(account, jid) contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if self.instances[account]['chats'].has_key(jid): if self.instances[account]['chats'].has_key(jid):
chat_win = self.instances[account]['chats'][jid] chat_win = self.instances[account]['chats'][jid]
if chatstate is not None: # he or she sent us reply, so he supports jep85 if chatstate is not None: # he or she sent us reply, so he supports jep85
@ -518,8 +487,9 @@ class Interface:
show = model[i][3] show = model[i][3]
else: else:
show = 'offline' show = 'offline'
c = Contact(jid = fjid, name = nick, groups = ['none'], gc_c = gajim.contacts.create_gc_contact(room_jid = jid,
show = show, ask = 'none') nick = nick, show = show)
c = gajim.contacts.contact_from_gc_contct(c)
self.roster.new_chat(c, account) self.roster.new_chat(c, account)
self.instances[account]['chats'][fjid].print_conversation( self.instances[account]['chats'][fjid].print_conversation(
'Error %s: %s' % (array[1], array[2]), fjid, 'status') 'Error %s: %s' % (array[1], array[2]), fjid, 'status')
@ -552,14 +522,12 @@ class Interface:
def handle_event_subscribed(self, account, array): def handle_event_subscribed(self, account, array):
#('SUBSCRIBED', account, (jid, resource)) #('SUBSCRIBED', account, (jid, resource))
jid = array[0] jid = array[0]
if gajim.contacts[account].has_key(jid): if jid in gajim.contacts.get_jid_list(account):
c = gajim.get_first_contact_instance_from_jid(account, jid) c = gajim.contacts.get_first_contact_from_jid(account, jid)
c.resource = array[1] c.resource = array[1]
self.roster.remove_contact(c, account) self.roster.remove_contact(c, account)
if _('not in the roster') in c.groups: if _('not in the roster') in c.groups:
c.groups.remove(_('not in the roster')) c.groups.remove(_('not in the roster'))
if len(c.groups) == 0:
c.groups = [_('General')]
self.roster.add_contact_to_roster(c.jid, account) self.roster.add_contact_to_roster(c.jid, account)
gajim.connections[account].update_contact(c.jid, c.name, c.groups) gajim.connections[account].update_contact(c.jid, c.name, c.groups)
else: else:
@ -570,10 +538,10 @@ class Interface:
keyID = attached_keys[attached_keys.index(jid) + 1] keyID = attached_keys[attached_keys.index(jid) + 1]
name = jid.split('@', 1)[0] name = jid.split('@', 1)[0]
name = name.split('%', 1)[0] name = name.split('%', 1)[0]
contact1 = Contact(jid = jid, name = name, groups = [_('General')], contact1 = gajim.contacts.create_contact(jid = jid, name = name,
show = 'online', status = 'online', ask = 'to', groups = None, show = 'online', status = 'online',
resource = array[1], keyID = keyID) ask = 'to', resource = array[1], keyID = keyID)
gajim.contacts[account][jid] = [contact1] gajim.contacts.add_contact(account, contact1)
self.roster.add_contact_to_roster(jid, account) self.roster.add_contact_to_roster(jid, account)
dialogs.InformationDialog(_('Authorization accepted'), dialogs.InformationDialog(_('Authorization accepted'),
_('The contact "%s" has authorized you to see his or her status.') _('The contact "%s" has authorized you to see his or her status.')
@ -780,12 +748,12 @@ class Interface:
def handle_event_roster_info(self, account, array): def handle_event_roster_info(self, account, array):
#('ROSTER_INFO', account, (jid, name, sub, ask, groups)) #('ROSTER_INFO', account, (jid, name, sub, ask, groups))
jid = array[0] jid = array[0]
if not gajim.contacts[account].has_key(jid): if not jid in gajim.contacts.get_jid_list(account):
return return
contacts = gajim.contacts[account][jid] contacts = gajim.contacts.get_contacts_from_jid(account, jid)
if not (array[2] or array[3]): if not (array[2] or array[3]):
self.roster.remove_contact(contacts[0], account) self.roster.remove_contact(contacts[0], account)
del gajim.contacts[account][jid] gajim.contacts.remove_jid(account, jid)
#FIXME if it was the only one in its group, remove the group #FIXME if it was the only one in its group, remove the group
return return
for contact in contacts: for contact in contacts:
@ -892,10 +860,10 @@ class Interface:
def handle_event_file_request(self, account, array): def handle_event_file_request(self, account, array):
jid = array[0] jid = array[0]
if not gajim.contacts[account].has_key(jid): if jid not in gajim.contacts.get_jid_list(account):
return return
file_props = array[1] file_props = array[1]
contact = gajim.contacts[account][jid][0] contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if gajim.popup_window(account): if gajim.popup_window(account):
self.instances['file_transfers'].show_file_request(account, contact, self.instances['file_transfers'].show_file_request(account, contact,
@ -1276,19 +1244,22 @@ class Interface:
if wins['chats'].has_key(jid): if wins['chats'].has_key(jid):
w = wins['chats'][jid] w = wins['chats'][jid]
else: else:
self.roster.new_chat(gajim.contacts[account][jid][0], account) contact = gajim.contacts.get_first_contact_from_jid(account, jid)
self.roster.new_chat(contact, account)
w = wins['chats'][jid] w = wins['chats'][jid]
elif typ == 'pm': elif typ == 'pm':
if wins['chats'].has_key(jid): if wins['chats'].has_key(jid):
w = wins['chats'][jid] w = wins['chats'][jid]
else: else:
room_jid, nick = jid.split('/', 1) room_jid, nick = jid.split('/', 1)
if gajim.gc_contacts[account][room_jid].has_key(nick): gc_contact = gajim.contacts.get_gc_contact(account, room_jid, nick)
show = gajim.gc_contacts[account][room_jid][nick].show if gc_contact:
show = gc_contact.show
else: else:
show = 'offline' show = 'offline'
c = Contact(jid = jid, name = nick, groups = ['none'], gc_contact = gajim.contacts.create_gc_contact(room_jid = room_jid,
show = show, ask = 'none') nick = nick, show = show)
c = gajim.contacts.contact_from_gc_contct(gc_contact)
self.roster.new_chat(c, account) self.roster.new_chat(c, account)
w = wins['chats'][jid] w = wins['chats'][jid]
elif typ in ('normal', 'file-request', 'file-request-error', elif typ in ('normal', 'file-request', 'file-request-error',
@ -1370,9 +1341,8 @@ class Interface:
for a in gajim.connections: for a in gajim.connections:
self.instances[a] = {'infos': {}, 'disco': {}, 'chats': {}, self.instances[a] = {'infos': {}, 'disco': {}, 'chats': {},
'gc': {}, 'gc_config': {}} 'gc': {}, 'gc_config': {}}
gajim.contacts[a] = {} gajim.contacts.add_account(a)
gajim.groups[a] = {} gajim.groups[a] = {}
gajim.gc_contacts[a] = {}
gajim.gc_connected[a] = {} gajim.gc_connected[a] = {}
gajim.newly_added[a] = [] gajim.newly_added[a] = []
gajim.to_be_removed[a] = [] gajim.to_be_removed[a] = []

View File

@ -39,7 +39,6 @@ import gtkgui_helpers
import history_window import history_window
import tooltips import tooltips
from gajim import Contact
from common import gajim from common import gajim
from common import helpers from common import helpers
from gettext import ngettext from gettext import ngettext
@ -121,8 +120,6 @@ class GroupchatWindow(chat.Chat):
'nick': self.nicks[room_jid], 'nick': self.nicks[room_jid],
'model': self.list_treeview[room_jid].get_model(), 'model': self.list_treeview[room_jid].get_model(),
'subject': self.subjects[room_jid], 'subject': self.subjects[room_jid],
'contacts': gajim.gc_contacts[self.account][room_jid],
'connected': gajim.gc_connected[self.account][room_jid],
} }
def load_var(self, room_jid, var): def load_var(self, room_jid, var):
@ -132,8 +129,6 @@ class GroupchatWindow(chat.Chat):
self.list_treeview[room_jid].expand_all() self.list_treeview[room_jid].expand_all()
self.set_subject(room_jid, var['subject']) self.set_subject(room_jid, var['subject'])
self.subjects[room_jid] = var['subject'] self.subjects[room_jid] = var['subject']
gajim.gc_contacts[self.account][room_jid] = var['contacts']
gajim.gc_connected[self.account][room_jid] = var['connected']
if gajim.gc_connected[self.account][room_jid]: if gajim.gc_connected[self.account][room_jid]:
self.got_connected(room_jid) self.got_connected(room_jid)
@ -194,7 +189,7 @@ class GroupchatWindow(chat.Chat):
def on_groupchat_window_destroy(self, widget): def on_groupchat_window_destroy(self, widget):
chat.Chat.on_window_destroy(self, widget, 'gc') chat.Chat.on_window_destroy(self, widget, 'gc')
for room_jid in self.xmls: for room_jid in self.xmls:
del gajim.gc_contacts[self.account][room_jid] gajim.contacts.remove_room(self.account, room_jid)
del gajim.gc_connected[self.account][room_jid] del gajim.gc_connected[self.account][room_jid]
def on_groupchat_window_focus_in_event(self, widget, event): def on_groupchat_window_focus_in_event(self, widget, event):
@ -347,18 +342,15 @@ class GroupchatWindow(chat.Chat):
fin = True fin = True
return None return None
def get_nick_list(self, room_jid):
'''get nicks of contacts in a room'''
return gajim.gc_contacts[self.account][room_jid].keys()
def remove_contact(self, room_jid, nick): def remove_contact(self, room_jid, nick):
'''Remove a user from the contacts_list''' '''Remove a user from the contacts_list'''
model = self.list_treeview[room_jid].get_model() model = self.list_treeview[room_jid].get_model()
iter = self.get_contact_iter(room_jid, nick) iter = self.get_contact_iter(room_jid, nick)
if not iter: if not iter:
return return
if gajim.gc_contacts[self.account][room_jid].has_key(nick): gc_contact = gajim.contacts.get_gc_contact(self.account, room_jid, nick)
del gajim.gc_contacts[self.account][room_jid][nick] if gc_contact:
gajim.contacts.remove_gc_contact(self.account, gc_contact)
parent_iter = model.iter_parent(iter) parent_iter = model.iter_parent(iter)
model.remove(iter) model.remove(iter)
if model.iter_n_children(parent_iter) == 0: if model.iter_n_children(parent_iter) == 0:
@ -366,16 +358,12 @@ class GroupchatWindow(chat.Chat):
def add_contact_to_roster(self, room_jid, nick, show, role, jid, affiliation, status): def add_contact_to_roster(self, room_jid, nick, show, role, jid, affiliation, status):
model = self.list_treeview[room_jid].get_model() model = self.list_treeview[room_jid].get_model()
resource = ''
role_name = helpers.get_uf_role(role, plural = True) role_name = helpers.get_uf_role(role, plural = True)
if jid: if jid:
jids = jid.split('/', 1) jid = jid.split('/', 1)[0]
j = jids[0]
if len(jids) > 1:
resource = jids[1]
else: else:
j = '' jid = ''
name = nick name = nick
@ -385,10 +373,11 @@ class GroupchatWindow(chat.Chat):
(gajim.interface.roster.jabber_state_images['16']['closed'], 'role', role, (gajim.interface.roster.jabber_state_images['16']['closed'], 'role', role,
'<b>%s</b>' % role_name)) '<b>%s</b>' % role_name))
iter = model.append(role_iter, (None, 'contact', nick, name)) iter = model.append(role_iter, (None, 'contact', nick, name))
if not gajim.gc_contacts[self.account][room_jid].has_key(nick): if not nick in gajim.contacts.get_nick_list(self.account, room_jid):
gajim.gc_contacts[self.account][room_jid][nick] = \ gc_contact = gajim.contacts.create_gc_contact(room_jid = room_jid,
Contact(jid = j, name = nick, show = show, resource = resource, nick = nick, show = show, status = status, role = role,
role = role, affiliation = affiliation, status = status) affiliation = affiliation, jid = jid)
gajim.contacts.add_gc_contact(self.account, gc_contact)
self.draw_contact(room_jid, nick) self.draw_contact(room_jid, nick)
if nick == self.nicks[room_jid]: # we became online if nick == self.nicks[room_jid]: # we became online
self.got_connected(room_jid) self.got_connected(room_jid)
@ -401,15 +390,15 @@ class GroupchatWindow(chat.Chat):
if not iter: if not iter:
return return
model = self.list_treeview[room_jid].get_model() model = self.list_treeview[room_jid].get_model()
contact = gajim.gc_contacts[self.account][room_jid][nick] gc_contact = gajim.contacts.get_gc_contact(self.account, room_jid, nick)
state_images = gajim.interface.roster.jabber_state_images['16'] state_images = gajim.interface.roster.jabber_state_images['16']
if gajim.awaiting_events[self.account].has_key(room_jid + '/' + nick): if gajim.awaiting_events[self.account].has_key(room_jid + '/' + nick):
image = state_images['message'] image = state_images['message']
else: else:
image = state_images[contact.show] image = state_images[gc_contact.show]
name = gtkgui_helpers.escape_for_pango_markup(contact.name) name = gtkgui_helpers.escape_for_pango_markup(gc_contact.name)
status = contact.status status = gc_contact.status
# add status msg, if not empty, under contact name in the treeview # add status msg, if not empty, under contact name in the treeview
if status and gajim.config.get('show_status_msgs_in_roster'): if status and gajim.config.get('show_status_msgs_in_roster'):
status = status.strip() status = status.strip()
@ -428,17 +417,16 @@ class GroupchatWindow(chat.Chat):
def draw_roster(self, room_jid): def draw_roster(self, room_jid):
model = self.list_treeview[room_jid].get_model() model = self.list_treeview[room_jid].get_model()
model.clear() model.clear()
for nick in gajim.gc_contacts[self.account][room_jid]: for nick in gajim.contacts.get_nick_list(self.account, room_jid):
contact = gajim.gc_contacts[self.account][room_jid][nick] gc_contact = gajim.contacts.get_gc_contact(self.account, room_jid, nick)
fjid = contact.jid self.add_contact_to_roster(room_jid, nick, gc_contact.show,
if contact.resource: gc_contact.role, gc_contact.jid, gc_contact.affiliation,
fjid += '/' + contact.resource gc_contact.status)
self.add_contact_to_roster(room_jid, nick, contact.show, contact.role,
fjid, contact.affiliation, contact.status)
def get_role(self, room_jid, nick): def get_role(self, room_jid, nick):
if gajim.gc_contacts[self.account][room_jid].has_key(nick): gc_contact = gajim.contacts.get_gc_contact(self.account, room_jid, nick)
return gajim.gc_contacts[self.account][room_jid][nick].role if gc_contact:
return gc_contact.role
else: else:
return 'visitor' return 'visitor'
@ -490,7 +478,7 @@ class GroupchatWindow(chat.Chat):
room_jid + '/' + nick): room_jid + '/' + nick):
self.remove_contact(room_jid, nick) self.remove_contact(room_jid, nick)
else: else:
c = gajim.gc_contacts[self.account][room_jid][nick] c = gajim.contacts.get_gc_contact(self.account, room_jid, nick)
c.show = show c.show = show
c.status = status c.status = status
if nick == self.nicks[room_jid] and statusCode != '303': # We became offline if nick == self.nicks[room_jid] and statusCode != '303': # We became offline
@ -507,7 +495,7 @@ class GroupchatWindow(chat.Chat):
self.add_contact_to_roster(room_jid, nick, show, role, jid, self.add_contact_to_roster(room_jid, nick, show, role, jid,
affiliation, status) affiliation, status)
else: else:
c = gajim.gc_contacts[self.account][room_jid][nick] c = gajim.contacts.get_gc_contact(self.account, room_jid, nick)
if c.show == show and c.status == status and \ if c.show == show and c.status == status and \
c.affiliation == affiliation: #no change c.affiliation == affiliation: #no change
return return
@ -547,7 +535,7 @@ class GroupchatWindow(chat.Chat):
# for room_jid & number of unread private msgs with each contact # for room_jid & number of unread private msgs with each contact
# that we have # that we have
nb = 0 nb = 0
for nick in self.get_nick_list(room_jid): for nick in gajim.contacts.get_nick_list(self.account, room_jid):
fjid = room_jid + '/' + nick fjid = room_jid + '/' + nick
if gajim.awaiting_events[self.account].has_key(fjid): if gajim.awaiting_events[self.account].has_key(fjid):
# gc can only have messages as event # gc can only have messages as event
@ -689,7 +677,8 @@ class GroupchatWindow(chat.Chat):
self.nick_hits[room_jid].pop(0) self.nick_hits[room_jid].pop(0)
else: else:
self.nick_hits[room_jid] = [] # clear the hit list self.nick_hits[room_jid] = [] # clear the hit list
list_nick = self.get_nick_list(room_jid) list_nick = gajim.contacts.get_nick_list(self.account,
room_jid)
for nick in list_nick: for nick in list_nick:
if nick.lower().startswith(begin.lower()): # the word is the begining of a nick if nick.lower().startswith(begin.lower()): # the word is the begining of a nick
self.nick_hits[room_jid].append(nick) self.nick_hits[room_jid].append(nick)
@ -807,7 +796,7 @@ class GroupchatWindow(chat.Chat):
# example: /query foo # example: /query foo
if len(message_array): if len(message_array):
nick = message_array.pop(0) nick = message_array.pop(0)
nicks = self.get_nick_list(room_jid) nicks = gajim.contacts.get_nick_list(self.account, room_jid)
if nick in nicks: if nick in nicks:
self.on_send_pm(nick = nick) self.on_send_pm(nick = nick)
self.clear(message_textview) self.clear(message_textview)
@ -822,7 +811,8 @@ class GroupchatWindow(chat.Chat):
if len(message_array): if len(message_array):
message_array = message_array[0].split() message_array = message_array[0].split()
nick = message_array.pop(0) nick = message_array.pop(0)
room_nicks = self.get_nick_list(room_jid) room_nicks = gajim.contacts.get_nick_list(self.account,
room_jid)
if nick in room_nicks: if nick in room_nicks:
privmsg = ' '.join(message_array) privmsg = ' '.join(message_array)
self.on_send_pm(nick=nick, msg=privmsg) self.on_send_pm(nick=nick, msg=privmsg)
@ -904,7 +894,8 @@ class GroupchatWindow(chat.Chat):
if len(message_array): if len(message_array):
message_array = message_array[0].split() message_array = message_array[0].split()
nick = message_array.pop(0) nick = message_array.pop(0)
room_nicks = self.get_nick_list(room_jid) room_nicks = gajim.contacts.get_nick_list(self.account,
room_jid)
reason = ' '.join(message_array) reason = ' '.join(message_array)
if nick in room_nicks: if nick in room_nicks:
ban_jid = gajim.construct_fjid(room_jid, nick) ban_jid = gajim.construct_fjid(room_jid, nick)
@ -924,7 +915,8 @@ class GroupchatWindow(chat.Chat):
if len(message_array): if len(message_array):
message_array = message_array[0].split() message_array = message_array[0].split()
nick = message_array.pop(0) nick = message_array.pop(0)
room_nicks = self.get_nick_list(room_jid) room_nicks = gajim.contacts.get_nick_list(self.account,
room_jid)
reason = ' '.join(message_array) reason = ' '.join(message_array)
if nick in room_nicks: if nick in room_nicks:
gajim.connections[self.account].gc_set_role(room_jid, nick, gajim.connections[self.account].gc_set_role(room_jid, nick,
@ -1162,7 +1154,7 @@ current room topic.') % command, room_jid)
def on_info(self, widget, room_jid, nick): def on_info(self, widget, room_jid, nick):
'''Call vcard_information_window class to display user's information''' '''Call vcard_information_window class to display user's information'''
c = gajim.gc_contacts[self.account][room_jid][nick] c = gajim.contacts.get_gc_contact(self.account, room_jid, nick)
if c.jid and c.resource: if c.jid and c.resource:
# on GC, we know resource only if we're mod and up # on GC, we know resource only if we're mod and up
jid = c.jid jid = c.jid
@ -1174,9 +1166,7 @@ current room topic.') % command, room_jid)
gajim.interface.instances[self.account]['infos'][jid].window.present() gajim.interface.instances[self.account]['infos'][jid].window.present()
else: else:
# we copy contact because c.jid must contain the fakeJid for vcard # we copy contact because c.jid must contain the fakeJid for vcard
c2 = Contact(jid = jid, name = c.name, groups = c.groups, c2 = gajim.contacts.contact_from_gc_contact(c)
show = c.show, status = c.status, sub = c.sub,
resource = c.resource, role = c.role, affiliation = c.affiliation)
gajim.interface.instances[self.account]['infos'][jid] = \ gajim.interface.instances[self.account]['infos'][jid] = \
vcard.VcardWindow(c2, self.account, False) vcard.VcardWindow(c2, self.account, False)
@ -1195,10 +1185,9 @@ current room topic.') % command, room_jid)
room_jid = self.get_active_jid() room_jid = self.get_active_jid()
fjid = gajim.construct_fjid(room_jid, nick) # 'fake' jid fjid = gajim.construct_fjid(room_jid, nick) # 'fake' jid
if not gajim.interface.instances[self.account]['chats'].has_key(fjid): if not gajim.interface.instances[self.account]['chats'].has_key(fjid):
show = gajim.gc_contacts[self.account][room_jid][nick].show gc_c = gajim.contacts.get_gc_contact(self.account, room_jid, nick)
u = Contact(jid = fjid, name = nick, groups = ['none'], show = show, c = gajim.contacts.contact_from_gc_contact(gc_c)
sub = 'none') gajim.interface.roster.new_chat(c, self.account)
gajim.interface.roster.new_chat(u, self.account)
#make active here in case we need to send a message #make active here in case we need to send a message
gajim.interface.instances[self.account]['chats'][fjid].set_active_tab(fjid) gajim.interface.instances[self.account]['chats'][fjid].set_active_tab(fjid)
@ -1241,15 +1230,15 @@ current room topic.') % command, room_jid)
'''Make contact's popup menu''' '''Make contact's popup menu'''
model = self.list_treeview[room_jid].get_model() model = self.list_treeview[room_jid].get_model()
nick = model[iter][C_NICK].decode('utf-8') nick = model[iter][C_NICK].decode('utf-8')
c = gajim.gc_contacts[self.account][room_jid][nick] c = gajim.contacts.get_gc_contact(self.account, room_jid, nick)
jid = c.jid jid = c.jid
target_affiliation = c.affiliation target_affiliation = c.affiliation
target_role = c.role target_role = c.role
# looking for user's affiliation and role # looking for user's affiliation and role
user_nick = self.nicks[room_jid] user_nick = self.nicks[room_jid]
user_affiliation = gajim.gc_contacts[self.account][room_jid][user_nick].\ user_affiliation = gajim.contacts.get_gc_contact(self.account, room_jid,
affiliation user_nick).affiliation
user_role = self.get_role(room_jid, user_nick) user_role = self.get_role(room_jid, user_nick)
# making menu from glade # making menu from glade
@ -1340,8 +1329,8 @@ current room topic.') % command, room_jid)
room_jid, show='offline', status=reason) room_jid, show='offline', status=reason)
del self.nicks[room_jid] del self.nicks[room_jid]
# They can already be removed by the destroy function # They can already be removed by the destroy function
if gajim.gc_contacts[self.account].has_key(room_jid): if room_jid in gajim.contacts.get_room_list(self.account):
del gajim.gc_contacts[self.account][room_jid] gajim.contacts.remove_room(self.account, room_jid)
del gajim.gc_connected[self.account][room_jid] del gajim.gc_connected[self.account][room_jid]
del self.list_treeview[room_jid] del self.list_treeview[room_jid]
del self.subjects[room_jid] del self.subjects[room_jid]
@ -1357,7 +1346,11 @@ current room topic.') % command, room_jid)
def got_disconnected(self, room_jid): def got_disconnected(self, room_jid):
model = self.list_treeview[room_jid].get_model() model = self.list_treeview[room_jid].get_model()
model.clear() model.clear()
gajim.gc_contacts[self.account][room_jid] = {} nick_list = gajim.contacts.get_nick_list(self.account, room_jid)
for nick in nick_list:
gc_contact = gajim.contacts.get_gc_contact(self.account, room_jid,
nick)
gajim.contacts.remove_gc_contact(self.account, gc_contact)
gajim.gc_connected[self.account][room_jid] = False gajim.gc_connected[self.account][room_jid] = False
message_textview = self.message_textviews[room_jid] message_textview = self.message_textviews[room_jid]
message_textview.set_sensitive(False) message_textview.set_sensitive(False)
@ -1525,10 +1518,8 @@ current room topic.') % command, room_jid)
gajim.interface.systray.add_jid(fjid, self.account, 'pm') gajim.interface.systray.add_jid(fjid, self.account, 'pm')
self.show_title() self.show_title()
else: else:
show = gajim.gc_contacts[self.account][room_jid][nick].show gc_c = gajim.contacts.get_gc_contact(self.account, room_jid, nick)
c = Contact(jid = fjid, name = nick, groups = ['none'], show = show, gajim.interface.roster.new_chat(gc_c, self.account)
ask = 'none')
gajim.interface.roster.new_chat(c, self.account)
# Scroll to line # Scroll to line
self.list_treeview[room_jid].expand_row(path[0:1], False) self.list_treeview[room_jid].expand_row(path[0:1], False)
self.list_treeview[room_jid].scroll_to_cell(path) self.list_treeview[room_jid].scroll_to_cell(path)
@ -1562,7 +1553,8 @@ current room topic.') % command, room_jid)
self.tooltip.id = row self.tooltip.id = row
nick = model[iter][C_NICK].decode('utf-8') nick = model[iter][C_NICK].decode('utf-8')
self.tooltip.timeout = gobject.timeout_add(500, self.tooltip.timeout = gobject.timeout_add(500,
self.show_tooltip, gajim.gc_contacts[account][room_jid][nick]) self.show_tooltip, gajim.contacts.get_gc_contact(account,
room_jid, nick))
def on_list_treeview_leave_notify_event(self, widget, event): def on_list_treeview_leave_notify_event(self, widget, event):
model = widget.get_model() model = widget.get_model()
@ -1636,10 +1628,9 @@ current room topic.') % command, room_jid)
nick = model[iter][C_NICK].decode('utf-8') nick = model[iter][C_NICK].decode('utf-8')
fjid = gajim.construct_fjid(room_jid, nick) fjid = gajim.construct_fjid(room_jid, nick)
if not gajim.interface.instances[self.account]['chats'].has_key(fjid): if not gajim.interface.instances[self.account]['chats'].has_key(fjid):
show = gajim.gc_contacts[self.account][room_jid][nick].show gc_c = gajim.contacts.get_gc_contact(self.account, room_jid,
u = Contact(jid = fjid, name = nick, groups = ['none'], nick)
show = show, sub = 'none') gajim.interface.roster.new_chat(gc_c, self.account)
gajim.interface.roster.new_chat(u, self.account)
gajim.interface.instances[self.account]['chats'][fjid].set_active_tab(fjid) gajim.interface.instances[self.account]['chats'][fjid].set_active_tab(fjid)
gajim.interface.instances[self.account]['chats'][fjid].window.present() gajim.interface.instances[self.account]['chats'][fjid].window.present()
return True return True
@ -1655,7 +1646,8 @@ current room topic.') % command, room_jid)
model = widget.get_model() model = widget.get_model()
iter = model.get_iter(path) iter = model.get_iter(path)
nick = model[iter][C_NICK].decode('utf-8') nick = model[iter][C_NICK].decode('utf-8')
if not nick in gajim.gc_contacts[self.account][room_jid]: #it's a group if not nick in gajim.contacts.get_nick_list(self.account, room_jid):
#it's a group
if x < 20: # first cell in 1st column (the arrow SINGLE clicked) if x < 20: # first cell in 1st column (the arrow SINGLE clicked)
if (widget.row_expanded(path)): if (widget.row_expanded(path)):
widget.collapse_row(path) widget.collapse_row(path)
@ -1680,11 +1672,9 @@ current room topic.') % command, room_jid)
nick = model[iter][C_NICK].decode('utf-8') nick = model[iter][C_NICK].decode('utf-8')
jid = gajim.construct_fjid(room_jid, nick) jid = gajim.construct_fjid(room_jid, nick)
if not gajim.interface.instances[self.account]['chats'].has_key(jid): if not gajim.interface.instances[self.account]['chats'].has_key(jid):
show = gajim.gc_contacts[self.account][room_jid][nick].show gc_c = gajim.contacts.get_gc_contact(self.account, room_jid, nick)
contact = Contact(jid = jid, name = nick, groups = ['none'], gajim.interface.roster.new_chat(gc_c, self.account)
show = show, sub = 'none') jid = gc_c.jid
gajim.interface.roster.new_chat(contact, self.account)
jid = contact.jid
gajim.interface.instances[self.account]['chats'][jid].set_active_tab(jid) gajim.interface.instances[self.account]['chats'][jid].set_active_tab(jid)
gajim.interface.instances[self.account]['chats'][jid].window.present() gajim.interface.instances[self.account]['chats'][jid].window.present()

View File

@ -106,8 +106,8 @@ class HistoryWindow:
col.set_attributes(renderer, text = C_MESSAGE) col.set_attributes(renderer, text = C_MESSAGE)
col.set_resizable(True) col.set_resizable(True)
if account and gajim.contacts[account].has_key(jid): contact = gajim.contacts.get_first_contact_from_jid(account, jid)
contact = gajim.get_first_contact_instance_from_jid(account, jid) if contact:
title = _('Conversation History with %s') % contact.name title = _('Conversation History with %s') % contact.name
else: else:
title = _('Conversation History with %s') % jid title = _('Conversation History with %s') % jid
@ -237,14 +237,17 @@ class HistoryWindow:
if kind == constants.KIND_GC_MSG: if kind == constants.KIND_GC_MSG:
tag_name = 'incoming' tag_name = 'incoming'
elif kind in (constants.KIND_SINGLE_MSG_RECV, constants.KIND_CHAT_MSG_RECV): elif kind in (constants.KIND_SINGLE_MSG_RECV, constants.KIND_CHAT_MSG_RECV):
try: contact = gajim.contacts.get_first_contact_from_jid(self.account,
# is he in our roster? if yes use the name self.jid)
contact_name = gajim.contacts[self.account][self.jid][0].name if contact:
except: # he is in our roster, use the name
contact_name = contact.name
else:
room_jid, nick = gajim.get_room_and_nick_from_fjid(self.jid) room_jid, nick = gajim.get_room_and_nick_from_fjid(self.jid)
# do we have him as gc_contact? # do we have him as gc_contact?
if nick and gajim.gc_contacts[self.account].has_key(room_jid) and\ gc_contact = gajim.contacts.get_gc_contact(self.account, room_jid,
gajim.gc_contacts[self.account][room_jid].has_key(nick): nick)
if gc_contact:
# so yes, it's pm! # so yes, it's pm!
contact_name = nick contact_name = nick
else: else:

View File

@ -105,8 +105,9 @@ class DesktopNotification:
self.msg_type = msg_type self.msg_type = msg_type
self.file_props = file_props self.file_props = file_props
if jid in gajim.contacts[account]: contact = gajim.contacts.get_first_contact_from_jid(account, jid)
actor = gajim.get_first_contact_instance_from_jid(account, jid).name if contact:
actor = contact.name
else: else:
actor = jid actor = jid
@ -148,8 +149,8 @@ class DesktopNotification:
if file_props['type'] == 'r': if file_props['type'] == 'r':
# get the name of the sender, as it is in the roster # get the name of the sender, as it is in the roster
sender = unicode(file_props['sender']).split('/')[0] sender = unicode(file_props['sender']).split('/')[0]
name = gajim.get_first_contact_instance_from_jid( name = gajim.contacts.get_first_contact_from_jid(account,
account, sender).name sender).name
filename = os.path.basename(file_props['file-name']) filename = os.path.basename(file_props['file-name'])
if event_type == _('File Transfer Completed'): if event_type == _('File Transfer Completed'):
txt = _('You successfully received %(filename)s from %(name)s.')\ txt = _('You successfully received %(filename)s from %(name)s.')\
@ -165,8 +166,8 @@ class DesktopNotification:
receiver = receiver.jid receiver = receiver.jid
receiver = receiver.split('/')[0] receiver = receiver.split('/')[0]
# get the name of the contact, as it is in the roster # get the name of the contact, as it is in the roster
name = gajim.get_first_contact_instance_from_jid( name = gajim.contacts.get_first_contact_from_jid(account,
account, receiver).name receiver).name
filename = os.path.basename(file_props['file-name']) filename = os.path.basename(file_props['file-name'])
if event_type == _('File Transfer Completed'): if event_type == _('File Transfer Completed'):
txt = _('You successfully sent %(filename)s to %(name)s.')\ txt = _('You successfully sent %(filename)s to %(name)s.')\

View File

@ -74,7 +74,7 @@ class Remote:
def raise_signal(self, signal, arg): def raise_signal(self, signal, arg):
if self.signal_object: if self.signal_object:
self.signal_object.raise_signal(signal, repr(arg)) self.signal_object.raise_signal(signal, repr(arg))
class SignalObject(DbusPrototype): class SignalObject(DbusPrototype):
''' Local object definition for /org/gajim/dbus/RemoteObject. This doc must ''' Local object definition for /org/gajim/dbus/RemoteObject. This doc must
@ -121,7 +121,6 @@ class SignalObject(DbusPrototype):
else: else:
self.emit_signal(INTERFACE, signal, arg) self.emit_signal(INTERFACE, signal, arg)
# signals # signals
def VcardInfo(self, *vcard): def VcardInfo(self, *vcard):
pass pass
@ -131,7 +130,7 @@ class SignalObject(DbusPrototype):
returns status (show to be exact) which is the global one returns status (show to be exact) which is the global one
unless account is given''' unless account is given'''
account = self._get_real_arguments(args, 1)[0] account = self._get_real_arguments(args, 1)[0]
accounts = gajim.contacts.keys() accounts = gajim.contacts.get_accounts()
if not account: if not account:
# If user did not ask for account, returns the global status # If user did not ask for account, returns the global status
return helpers.get_global_show() return helpers.get_global_show()
@ -153,40 +152,48 @@ class SignalObject(DbusPrototype):
return str(status) return str(status)
def send_file(self, *args): def get_account_and_contact(self, account, jid):
'''send_file(file_path, jid, account=None) ''' get the account (if not given) and contact instance from jid'''
send file, located at 'file_path' to 'jid', using account connected_account = None
(optional) 'account' ''' contact = None
file_path, jid, account = self._get_real_arguments(args, 3) accounts = gajim.contacts.get_accounts()
accounts = gajim.contacts.keys()
# if there is only one account in roster, take it as default # if there is only one account in roster, take it as default
# if user did not ask for account # if user did not ask for account
if not account and len(accounts) == 1: if not account and len(accounts) == 1:
account = accounts[0] account = accounts[0]
if account: if account:
if gajim.connections[account].connected > 1: # account is online if gajim.connections[account].connected > 1: # account is connected
connected_account = gajim.connections[account] connected_account = account
contact = gajim.contacts.get_contact_with_highest_priority(account,
jid)
else: else:
for account in accounts: for account in accounts:
if gajim.contacts[account].has_key(jid) and \ contact = gajim.contacts.get_contact_with_highest_priority(account,
gajim.connections[account].connected > 1: # account is online jid)
connected_account = gajim.connections[account] if contact and gajim.connections[account].connected > 1:
# account is connected
connected_account = account
break break
if gajim.contacts.has_key(account) and \ if not contact:
gajim.contacts[account].has_key(jid):
contact = gajim.get_highest_prio_contact_from_contacts(
gajim.contacts[account][jid])
else:
contact = jid contact = jid
return connected_account, contact
def send_file(self, *args):
'''send_file(file_path, jid, account=None)
send file, located at 'file_path' to 'jid', using account
(optional) 'account' '''
file_path, jid, account = self._get_real_arguments(args, 3)
connected_account, contact = self.get_account_and_contact(account, jid)
if connected_account: if connected_account:
if os.path.isfile(file_path): # is it file? if os.path.isfile(file_path): # is it file?
gajim.interface.instances['file_transfers'].send_file(account, gajim.interface.instances['file_transfers'].send_file(
contact, file_path) connected_account, contact, file_path)
return True return True
return False return False
def send_message(self, *args): def send_message(self, *args):
''' send_message(jid, message, keyID=None, account=None) ''' send_message(jid, message, keyID=None, account=None)
send 'message' to 'jid', using account (optional) 'account'. send 'message' to 'jid', using account (optional) 'account'.
@ -196,23 +203,12 @@ class SignalObject(DbusPrototype):
return None # or raise error return None # or raise error
if not keyID: if not keyID:
keyID = '' keyID = ''
connected_account = None
accounts = gajim.contacts.keys() connected_account, contact = self.get_account_and_contact(account, jid)
# if there is only one account in roster, take it as default
if not account and len(accounts) == 1:
account = accounts[0]
if account:
if gajim.connections[account].connected > 1: # account is online
connected_account = gajim.connections[account]
else:
for account in accounts:
if gajim.contacts[account].has_key(jid) and \
gajim.connections[account].connected > 1: # account is online
connected_account = gajim.connections[account]
break
if connected_account: if connected_account:
res = connected_account.send_message(jid, message, keyID) connection = gajim.connections[connected_account]
res = connection.send_message(jid, message, keyID)
return True return True
return False return False
@ -236,24 +232,25 @@ class SignalObject(DbusPrototype):
first_connected_acct = None first_connected_acct = None
for acct in accounts: for acct in accounts:
if gajim.connections[acct].connected > 1: # account is online if gajim.connections[acct].connected > 1: # account is online
contact = gajim.contacts.get_first_contact_from_jid(acct, jid)
if gajim.interface.instances[acct]['chats'].has_key(jid): if gajim.interface.instances[acct]['chats'].has_key(jid):
connected_account = acct connected_account = acct
break break
# jid is in roster # jid is in roster
elif gajim.contacts[acct].has_key(jid): elif contact:
connected_account = acct connected_account = acct
break break
# we send the message to jid not in roster, because account is specified, # we send the message to jid not in roster, because account is
# or there is only one account # specified, or there is only one account
elif account: elif account:
connected_account = acct connected_account = acct
elif first_connected_acct is None: elif first_connected_acct is None:
first_connected_acct = acct first_connected_acct = acct
# if jid is not a conntact, open-chat with first connected account # if jid is not a conntact, open-chat with first connected account
if connected_account is None and first_connected_acct: if connected_account is None and first_connected_acct:
connected_account = first_connected_acct connected_account = first_connected_acct
if connected_account: if connected_account:
gajim.interface.roster.new_chat_from_jid(connected_account, jid) gajim.interface.roster.new_chat_from_jid(connected_account, jid)
# preserve the 'steal focus preservation' # preserve the 'steal focus preservation'
@ -262,7 +259,7 @@ class SignalObject(DbusPrototype):
win.window.focus() win.window.focus()
return True return True
return False return False
def change_status(self, *args, **keywords): def change_status(self, *args, **keywords):
''' change_status(status, message, account). account is optional - ''' change_status(status, message, account). account is optional -
if not specified status is changed for all accounts. ''' if not specified status is changed for all accounts. '''
@ -276,7 +273,7 @@ class SignalObject(DbusPrototype):
status, message) status, message)
else: else:
# account not specified, so change the status of all accounts # account not specified, so change the status of all accounts
for acc in gajim.contacts.keys(): for acc in gajim.contacts.get_accounts():
gobject.idle_add(gajim.interface.roster.send_status, acc, gobject.idle_add(gajim.interface.roster.send_status, acc,
status, message) status, message)
return None return None
@ -297,10 +294,11 @@ class SignalObject(DbusPrototype):
# FIXME: raise exception for missing argument (0.3+) # FIXME: raise exception for missing argument (0.3+)
return None return None
accounts = gajim.contacts.keys() accounts = gajim.contacts.get_accounts()
for account in accounts: for account in accounts:
if gajim.contacts[account].__contains__(jid): contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if contact:
self.vcard_account = account self.vcard_account = account
gajim.connections[account].request_vcard(jid) gajim.connections[account].request_vcard(jid)
break break
@ -308,13 +306,12 @@ class SignalObject(DbusPrototype):
def list_accounts(self, *args): def list_accounts(self, *args):
''' list register accounts ''' ''' list register accounts '''
if gajim.contacts: result = gajim.contacts.get_accounts()
result = gajim.contacts.keys() if result and len(result) > 0:
if result and len(result) > 0: result_array = []
result_array = [] for account in result:
for account in result: result_array.append(account.encode('utf-8'))
result_array.append(account.encode('utf-8')) return result_array
return result_array
return None return None
def list_contacts(self, *args): def list_contacts(self, *args):
@ -322,24 +319,22 @@ class SignalObject(DbusPrototype):
then return the contacts for the specified account ''' then return the contacts for the specified account '''
[for_account] = self._get_real_arguments(args, 1) [for_account] = self._get_real_arguments(args, 1)
result = [] result = []
if not gajim.contacts or len(gajim.contacts) == 0: accounts = gajim.contacts.get_accounts()
if len(accounts) == 0:
return None return None
if for_account: if for_account:
if gajim.contacts.has_key(for_account): accounts_to_search = [for_account]
for jid in gajim.contacts[for_account]: else:
item = self._serialized_contacts( accounts_to_search = accounts
gajim.contacts[for_account][jid]) for account in accounts_to_search:
if account in accounts:
for jid in gajim.contacts.get_jid_list(for_account):
item = self._serialized_contacts(gajim.contacts.get_contact(
for_account, jid))
if item: if item:
result.append(item) result.append(item)
else: else:
# 'for_account: is not recognised:', continue
return None
else:
for account in gajim.contacts:
for jid in gajim.contacts[account]:
item = self._serialized_contacts(gajim.contacts[account][jid])
if item:
result.append(item)
# dbus 0.40 does not support return result as empty list # dbus 0.40 does not support return result as empty list
if result == []: if result == []:
return None return None
@ -407,27 +402,27 @@ class SignalObject(DbusPrototype):
def add_contact(self, *args): def add_contact(self, *args):
[account] = self._get_real_arguments(args, 1) [account] = self._get_real_arguments(args, 1)
if gajim.contacts.has_key(account): accounts = gajim.contacts.get_accounts()
if account in accounts:
AddNewContactWindow(account) AddNewContactWindow(account)
return True return True
return False return False
def remove_contact(self, *args): def remove_contact(self, *args):
[jid, account] = self._get_real_arguments(args, 2) [jid, account] = self._get_real_arguments(args, 2)
accounts = gajim.contacts.keys() accounts = gajim.contacts.get_accounts()
# if there is only one account in roster, take it as default # if there is only one account in roster, take it as default
if account: if account:
accounts = [account] accounts = [account]
else:
accounts = gajim.contacts.keys()
contact_exists = False contact_exists = False
for account in accounts: for account in accounts:
if gajim.contacts[account].has_key(jid): contacts = gajim.contacts.get_contact(account, jid)
if contacts:
gajim.connections[account].unsubscribe(jid) gajim.connections[account].unsubscribe(jid)
for contact in gajim.contacts[account][jid]: for contact in contacts:
gajim.interface.roster.remove_contact(contact, account) gajim.interface.roster.remove_contact(contact, account)
del gajim.contacts[account][jid] gajim.contacts.remove_jid(account, jid)
contact_exists = True contact_exists = True
return contact_exists return contact_exists

View File

@ -42,7 +42,6 @@ import gtkgui_helpers
import cell_renderer_image import cell_renderer_image
import tooltips import tooltips
from gajim import Contact
from common import gajim from common import gajim
from common import helpers from common import helpers
from common import i18n from common import i18n
@ -104,12 +103,12 @@ class RosterWindow:
return found return found
group_iter = model.iter_children(acct) group_iter = model.iter_children(acct)
while group_iter: while group_iter:
user_iter = model.iter_children(group_iter) contact_iter = model.iter_children(group_iter)
while user_iter: while contact_iter:
if jid == model[user_iter][C_JID].decode('utf-8') and \ if jid == model[contact_iter][C_JID].decode('utf-8') and \
account == model[user_iter][C_ACCOUNT].decode('utf-8'): account == model[contact_iter][C_ACCOUNT].decode('utf-8'):
found.append(user_iter) found.append(contact_iter)
user_iter = model.iter_next(user_iter) contact_iter = model.iter_next(contact_iter)
group_iter = model.iter_next(group_iter) group_iter = model.iter_next(group_iter)
return found return found
@ -146,36 +145,35 @@ class RosterWindow:
def add_contact_to_roster(self, jid, account): def add_contact_to_roster(self, jid, account):
'''Add a contact to the roster and add groups if they aren't in roster''' '''Add a contact to the roster and add groups if they aren't in roster'''
showOffline = gajim.config.get('showoffline') showOffline = gajim.config.get('showoffline')
if not gajim.contacts[account].has_key(jid): contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if not contact:
return return
users = gajim.contacts[account][jid] if contact.jid.find('@') <= 0:
user = users[0] # if not '@' or '@' starts the jid ==> agent
if user.jid.find('@') <= 0: # if not '@' or '@' starts the jid ==> agent contact.groups = [_('Transports')]
user.groups = [_('Transports')]
elif user.groups == []:
user.groups.append(_('General'))
hide = True hide = True
if user.sub in ('both', 'to'): if contact.sub in ('both', 'to'):
hide = False hide = False
elif user.ask == 'subscribe': elif contact.ask == 'subscribe':
hide = False hide = False
# FIXME: uncomment when we support contacts in no group elif contact.name or len(contact.groups):
# elif user.name or len(user.groups):
elif user.name:
hide = False hide = False
# JEP-0162 # JEP-0162
if hide: if hide:
return return
if user.show in ('offline', 'error') and \ if contact.show in ('offline', 'error') and \
not showOffline and (not _('Transports') in user.groups or \ not showOffline and (not _('Transports') in contact.groups or \
gajim.connections[account].connected < 2) and \ gajim.connections[account].connected < 2) and \
not gajim.awaiting_events[account].has_key(user.jid): not gajim.awaiting_events[account].has_key(jid):
return return
model = self.tree.get_model() model = self.tree.get_model()
for g in user.groups: groups = contact.groups
if not groups:
groups = [_('General')]
for g in groups:
iterG = self.get_group_iter(g, account) iterG = self.get_group_iter(g, account)
if not iterG: if not iterG:
IterAcct = self.get_account_iter(account) IterAcct = self.get_account_iter(account)
@ -197,40 +195,48 @@ class RosterWindow:
typestr = 'agent' typestr = 'agent'
# we add some values here. see draw_contact for more # we add some values here. see draw_contact for more
model.append(iterG, (None, user.name, model.append(iterG, (None, contact.name,
typestr, user.jid, account, False, None)) typestr, contact.jid, account, False, None))
if gajim.groups[account][g]['expand']: if gajim.groups[account][g]['expand']:
self.tree.expand_row(model.get_path(iterG), False) self.tree.expand_row(model.get_path(iterG), False)
self.draw_contact(jid, account) self.draw_contact(jid, account)
self.draw_avatar(jid, account) self.draw_avatar(jid, account)
def really_remove_contact(self, user, account): def add_transport_to_roster(self, account, transport):
if user.jid in gajim.newly_added[account]: c = gajim.contacts.create_contact(jid = transport, name = transport,
return groups = [_('Transports')], show = 'offline', status = 'offline',
if user.jid.find('@') < 1 and gajim.connections[account].connected > 1: # It's an agent sub = 'from')
return gajim.contacts.add_contact(account, c)
if user.jid in gajim.to_be_removed[account]: gajim.interface.roster.add_contact_to_roster(transport, account)
gajim.to_be_removed[account].remove(user.jid)
if gajim.config.get('showoffline'):
self.draw_contact(user.jid, account)
return
self.remove_contact(user, account)
def remove_contact(self, user, account): def really_remove_contact(self, contact, account):
'''Remove a user from the roster''' if contact.jid in gajim.newly_added[account]:
if user.jid in gajim.to_be_removed[account]: return
if contact.jid.find('@') < 1 and gajim.connections[account].connected > 1: # It's an agent
return
if contact.jid in gajim.to_be_removed[account]:
gajim.to_be_removed[account].remove(contact.jid)
if gajim.config.get('showoffline'):
self.draw_contact(contact.jid, account)
return
self.remove_contact(contact, account)
def remove_contact(self, contact, account):
'''Remove a contact from the roster'''
if contact.jid in gajim.to_be_removed[account]:
return return
model = self.tree.get_model() model = self.tree.get_model()
for i in self.get_contact_iter(user.jid, account): for i in self.get_contact_iter(contact.jid, account):
parent_i = model.iter_parent(i) parent_i = model.iter_parent(i)
group = model.get_value(parent_i, 3).decode('utf-8') group = model.get_value(parent_i, 3).decode('utf-8')
model.remove(i) model.remove(i)
if model.iter_n_children(parent_i) == 0: if model.iter_n_children(parent_i) == 0:
model.remove(parent_i) model.remove(parent_i)
# We need to check all contacts, even offline contacts # We need to check all contacts, even offline contacts
for jid in gajim.contacts[account]: for jid in gajim.contacts.get_jid_list(account):
if group in gajim.get_contact_instance_with_highest_priority(account, jid).groups: if group in gajim.contacts.get_contact_with_highest_priority(
account, jid).groups:
break break
else: else:
if gajim.groups[account].has_key(group): if gajim.groups[account].has_key(group):
@ -251,8 +257,11 @@ class RosterWindow:
iters = self.get_contact_iter(jid, account) iters = self.get_contact_iter(jid, account)
if len(iters) == 0: if len(iters) == 0:
return return
contact_instances = gajim.get_contact_instances_from_jid(account, jid) contact_instances = gajim.contacts.get_contact(account, jid)
contact = gajim.get_highest_prio_contact_from_contacts(contact_instances) contact = gajim.contacts.get_highest_prio_contact_from_contacts(
contact_instances)
if not contact:
return
name = gtkgui_helpers.escape_for_pango_markup(contact.name) name = gtkgui_helpers.escape_for_pango_markup(contact.name)
if len(contact_instances) > 1: if len(contact_instances) > 1:
@ -264,9 +273,9 @@ class RosterWindow:
add_acct = False add_acct = False
# look through all contacts of all accounts # look through all contacts of all accounts
for a in gajim.connections: for a in gajim.connections:
for j in gajim.contacts[a]: for j in gajim.contacts.get_jid_list(a):
# [0] cause it'fster than highest_prio # [0] cause it'fster than highest_prio
c = gajim.contacts[a][j][0] c = gajim.contacts.get_first_contact_from_jid(a, j)
if c.name == contact.name and (j, a) != (jid, account): if c.name == contact.name and (j, a) != (jid, account):
add_acct = True add_acct = True
break break
@ -629,15 +638,15 @@ class RosterWindow:
self.tree.get_model().clear() self.tree.get_model().clear()
for acct in gajim.connections: for acct in gajim.connections:
self.add_account_to_roster(acct) self.add_account_to_roster(acct)
for jid in gajim.contacts[acct].keys(): for jid in gajim.contacts.get_jid_list(acct):
self.add_contact_to_roster(jid, acct) self.add_contact_to_roster(jid, acct)
self.make_menu() # re-make menu in case an account was removed self.make_menu() # re-make menu in case an account was removed
#FIXME: maybe move thie make_menu() in where we remove the account? #FIXME: maybe move thie make_menu() in where we remove the account?
def fill_contacts_and_groups_dicts(self, array, account): def fill_contacts_and_groups_dicts(self, array, account):
'''fill gajim.contacts and gajim.groups''' '''fill gajim.contacts and gajim.groups'''
if not gajim.contacts.has_key(account): if account not in gajim.contacts.get_accounts():
gajim.contacts[account] = {} gajim.contacts.add_account(account)
if not gajim.groups.has_key(account): if not gajim.groups.has_key(account):
gajim.groups[account] = {} gajim.groups[account] = {}
for jid in array.keys(): for jid in array.keys():
@ -663,13 +672,14 @@ class RosterWindow:
'attached_gpg_keys').split() 'attached_gpg_keys').split()
if jid in attached_keys: if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1] keyID = attached_keys[attached_keys.index(jid) + 1]
contact1 = Contact(jid = ji, name = name, groups = array[jid]['groups'], contact1 = gajim.contacts.create_contact(jid = ji, name = name,
show = show, status = status, sub = array[jid]['subscription'], groups = array[jid]['groups'], show = show, status = status,
ask = array[jid]['ask'], resource = resource, keyID = keyID) sub = array[jid]['subscription'], ask = array[jid]['ask'],
resource = resource, keyID = keyID)
gajim.contacts.add_contact(account, contact1)
# when we draw the roster, we avoid having the same contact # when we draw the roster, we avoid having the same contact
# more than once (f.e. we avoid showing it twice when 2 resources) # more than once (f.e. we avoid showing it twice when 2 resources)
gajim.contacts[account][ji] = [contact1]
for g in array[jid]['groups']: for g in array[jid]['groups']:
if g in gajim.groups[account].keys(): if g in gajim.groups[account].keys():
continue continue
@ -690,18 +700,15 @@ class RosterWindow:
def chg_contact_status(self, contact, show, status, account): def chg_contact_status(self, contact, show, status, account):
'''When a contact changes his or her status''' '''When a contact changes his or her status'''
showOffline = gajim.config.get('showoffline') showOffline = gajim.config.get('showoffline')
contact_instances = gajim.contacts[account][contact.jid] contact_instances = gajim.contacts.get_contact(account, contact.jid)
contact.show = show contact.show = show
contact.status = status contact.status = status
if show in ('offline', 'error') and \ if show in ('offline', 'error') and \
not gajim.awaiting_events[account].has_key(contact.jid): not gajim.awaiting_events[account].has_key(contact.jid):
if len(contact_instances) > 1: # if multiple resources if len(contact_instances) > 1 or not showOffline:
contact_instances.remove(contact) # if multiple resources or we don't show offline contacts
self.draw_contact(contact.jid, account) gajim.contacts.remove_contact(account, contact)
elif not showOffline: self.draw_contact(contact.jid, account)
self.remove_contact(contact, account)
else:
self.draw_contact(contact.jid, account)
else: else:
if not self.get_contact_iter(contact.jid, account): if not self.get_contact_iter(contact.jid, account):
self.add_contact_to_roster(contact.jid, account) self.add_contact_to_roster(contact.jid, account)
@ -717,17 +724,17 @@ class RosterWindow:
gajim.interface.instances[account]['chats'][jid].print_conversation( gajim.interface.instances[account]['chats'][jid].print_conversation(
_('%s is now %s (%s)') % (name, uf_show, status), jid, 'status') _('%s is now %s (%s)') % (name, uf_show, status), jid, 'status')
if contact == gajim.get_contact_instance_with_highest_priority(\ if contact == gajim.contacts.get_contact_with_highest_priority(
account, contact.jid): account, contact.jid):
gajim.interface.instances[account]['chats'][jid].draw_name_banner(contact) gajim.interface.instances[account]['chats'][jid].draw_name_banner(contact)
def on_info(self, widget, user, account): def on_info(self, widget, contact, account):
'''Call vcard_information_window class to display user's information''' '''Call vcard_information_window class to display contact's information'''
info = gajim.interface.instances[account]['infos'] info = gajim.interface.instances[account]['infos']
if info.has_key(user.jid): if info.has_key(contact.jid):
info[user.jid].window.present() info[contact.jid].window.present()
else: else:
info[user.jid] = vcard.VcardWindow(user, account) info[contact.jid] = vcard.VcardWindow(contact, account)
def show_tooltip(self, contact): def show_tooltip(self, contact):
pointer = self.tree.get_pointer() pointer = self.tree.get_pointer()
@ -770,8 +777,9 @@ class RosterWindow:
jid = model[iter][C_JID].decode('utf-8') jid = model[iter][C_JID].decode('utf-8')
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]: if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
self.tooltip.id = row self.tooltip.id = row
contacts = gajim.contacts.get_contact(account, jid)
self.tooltip.timeout = gobject.timeout_add(500, self.tooltip.timeout = gobject.timeout_add(500,
self.show_tooltip, gajim.contacts[account][jid]) self.show_tooltip, contacts)
elif model[iter][C_TYPE] == 'account': elif model[iter][C_TYPE] == 'account':
# we're on an account entry in the roster # we're on an account entry in the roster
account = model[iter][C_ACCOUNT].decode('utf-8') account = model[iter][C_ACCOUNT].decode('utf-8')
@ -785,9 +793,8 @@ class RosterWindow:
contacts = [] contacts = []
connection = gajim.connections[account] connection = gajim.connections[account]
# get our current contact info # get our current contact info
contact = Contact(jid = jid, name = account, contact = gajim.contacts.create_contact(jid = jid, name = account,
show = connection.get_status(), show = connection.get_status(), sub = 'both',
sub = 'both',
status = connection.status, status = connection.status,
resource = gajim.config.get_per('accounts', connection.name, resource = gajim.config.get_per('accounts', connection.name,
'resource'), 'resource'),
@ -806,10 +813,11 @@ class RosterWindow:
show = roster.getShow(jid+'/'+resource) show = roster.getShow(jid+'/'+resource)
if not show: if not show:
show = 'online' show = 'online'
contact = Contact(jid=jid, name=account, contact = gajim.contacts.create_contact(jid = jid,
show=show, name = account, show = show,
status=roster.getStatus(jid+'/'+resource), resource=resource, status = roster.getStatus(jid+'/'+resource),
priority=roster.getPriority(jid+'/'+resource)) resource = resource,
priority = roster.getPriority(jid+'/'+resource))
contacts.append(contact) contacts.append(contact)
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]: if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
self.tooltip.id = row self.tooltip.id = row
@ -830,7 +838,7 @@ class RosterWindow:
# We remove the server contact # We remove the server contact
# remove it from treeview # remove it from treeview
self.remove_contact(contact, account) self.remove_contact(contact, account)
del gajim.contacts[account][contact.jid] gajim.contacts.remove_contact(account, contact)
return return
window = dialogs.ConfirmationDialog(_('Transport "%s" will be removed') % contact.jid, _('You will no longer be able to send and receive messages to contacts from this transport.')) window = dialogs.ConfirmationDialog(_('Transport "%s" will be removed') % contact.jid, _('You will no longer be able to send and receive messages to contacts from this transport.'))
@ -840,14 +848,16 @@ class RosterWindow:
# remove transport from treeview # remove transport from treeview
self.remove_contact(contact, account) self.remove_contact(contact, account)
# remove transport's contacts from treeview # remove transport's contacts from treeview
for jid, contacts in gajim.contacts[account].items(): jid_list = gajim.contacts.get_jid_list(account)
contact = contacts[0] for jid in jid_list:
if jid.endswith('@' + contact.jid): if jid.endswith('@' + contact.jid):
c = gajim.contacts.get_first_contact_from_jid(account, jid)
gajim.log.debug( gajim.log.debug(
'Removing contact %s due to unregistered transport %s'\ 'Removing contact %s due to unregistered transport %s'\
% (contact.jid, contact.name)) % (jid, contact.jid))
self.remove_contact(contact, account) # Transport contacts can't have 2 resources
del gajim.contacts[account][contact.jid] self.remove_contact(c, account)
gajim.contacts.remove_contact(account, contact)
def on_rename(self, widget, iter, path): def on_rename(self, widget, iter, path):
# this function is called either by F2 or by Rename menuitem # this function is called either by F2 or by Rename menuitem
@ -864,22 +874,22 @@ class RosterWindow:
account = model[iter][C_ACCOUNT].decode('utf-8') account = model[iter][C_ACCOUNT].decode('utf-8')
if row_type == 'contact': if row_type == 'contact':
# it's jid # it's jid
#Remove resource indicator (Name (2)) # Remove resource indicator (Name (2))
contacts = gajim.contacts[account][jid] contact = gajim.contacts.get_first_contact_from_jid(account, jid)
name = contacts[0].name name = contact.name
model[iter][C_NAME] = gtkgui_helpers.escape_for_pango_markup(name) model[iter][C_NAME] = gtkgui_helpers.escape_for_pango_markup(name)
model[iter][C_EDITABLE] = True # set 'editable' to True model[iter][C_EDITABLE] = True # set 'editable' to True
self.tree.set_cursor(path, self.tree.get_column(0), True) self.tree.set_cursor(path, self.tree.get_column(0), True)
def on_assign_pgp_key(self, widget, user, account): def on_assign_pgp_key(self, widget, contact, account):
attached_keys = gajim.config.get_per('accounts', account, attached_keys = gajim.config.get_per('accounts', account,
'attached_gpg_keys').split() 'attached_gpg_keys').split()
keys = {} keys = {}
keyID = 'None' keyID = 'None'
for i in xrange(0, len(attached_keys)/2): for i in xrange(0, len(attached_keys)/2):
keys[attached_keys[2*i]] = attached_keys[2*i+1] keys[attached_keys[2*i]] = attached_keys[2*i+1]
if attached_keys[2*i] == user.jid: if attached_keys[2*i] == contact.jid:
keyID = attached_keys[2*i+1] keyID = attached_keys[2*i+1]
public_keys = gajim.connections[account].ask_gpg_keys() public_keys = gajim.connections[account].ask_gpg_keys()
public_keys['None'] = 'None' public_keys['None'] = 'None'
@ -889,21 +899,22 @@ class RosterWindow:
if keyID is None: if keyID is None:
return return
if keyID[0] == 'None': if keyID[0] == 'None':
if user.jid in keys: if contact.jid in keys:
del keys[user.jid] del keys[contact.jid]
else: else:
keys[user.jid] = keyID[0] keys[contact.jid] = keyID[0]
for u in gajim.contacts[account][user.jid]: for u in gajim.contacts.get_contact(account, contact.jid):
u.keyID = keyID[0] u.keyID = keyID[0]
if gajim.interface.instances[account]['chats'].has_key(user.jid): if gajim.interface.instances[account]['chats'].has_key(contact.jid):
gajim.interface.instances[account]['chats'][user.jid].draw_widgets(user) gajim.interface.instances[account]['chats'][contact.jid].\
draw_widgets(contact)
keys_str = '' keys_str = ''
for jid in keys: for jid in keys:
keys_str += jid + ' ' + keys[jid] + ' ' keys_str += jid + ' ' + keys[jid] + ' '
gajim.config.set_per('accounts', account, 'attached_gpg_keys', keys_str) gajim.config.set_per('accounts', account, 'attached_gpg_keys', keys_str)
def on_edit_groups(self, widget, user, account): def on_edit_groups(self, widget, contact, account):
dlg = dialogs.EditGroupsDialog(user, account) dlg = dialogs.EditGroupsDialog(contact, account)
dlg.run() dlg.run()
def on_history(self, widget, contact, account): def on_history(self, widget, contact, account):
@ -931,8 +942,7 @@ class RosterWindow:
jid = model[iter][C_JID].decode('utf-8') jid = model[iter][C_JID].decode('utf-8')
path = model.get_path(iter) path = model.get_path(iter)
account = model[iter][C_ACCOUNT].decode('utf-8') account = model[iter][C_ACCOUNT].decode('utf-8')
contact = gajim.get_highest_prio_contact_from_contacts( contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
gajim.contacts[account][jid])
xml = gtk.glade.XML(GTKGUI_GLADE, 'roster_contact_context_menu', xml = gtk.glade.XML(GTKGUI_GLADE, 'roster_contact_context_menu',
APP) APP)
@ -1050,14 +1060,14 @@ class RosterWindow:
jid = model[iter][C_JID].decode('utf-8') jid = model[iter][C_JID].decode('utf-8')
path = model.get_path(iter) path = model.get_path(iter)
account = model[iter][C_ACCOUNT].decode('utf-8') account = model[iter][C_ACCOUNT].decode('utf-8')
user = gajim.get_contact_instance_with_highest_priority(account, jid) contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
menu = gtk.Menu() menu = gtk.Menu()
item = gtk.ImageMenuItem(_('_Log on')) item = gtk.ImageMenuItem(_('_Log on'))
icon = gtk.image_new_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU) icon = gtk.image_new_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU)
item.set_image(icon) item.set_image(icon)
menu.append(item) menu.append(item)
show = gajim.get_contact_instance_with_highest_priority(account, jid).show show = contact.show
if show != 'offline' and show != 'error': if show != 'offline' and show != 'error':
item.set_sensitive(False) item.set_sensitive(False)
item.connect('activate', self.on_agent_logging, jid, None, account) item.connect('activate', self.on_agent_logging, jid, None, account)
@ -1078,13 +1088,13 @@ class RosterWindow:
icon = gtk.image_new_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU) icon = gtk.image_new_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU)
item.set_image(icon) item.set_image(icon)
menu.append(item) menu.append(item)
item.connect('activate', self.on_edit_agent, user, account) item.connect('activate', self.on_edit_agent, contact, account)
item = gtk.ImageMenuItem(_('_Remove from Roster')) item = gtk.ImageMenuItem(_('_Remove from Roster'))
icon = gtk.image_new_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_MENU) icon = gtk.image_new_from_stock(gtk.STOCK_REMOVE, gtk.ICON_SIZE_MENU)
item.set_image(icon) item.set_image(icon)
menu.append(item) menu.append(item)
item.connect('activate', self.on_remove_agent, user, account) item.connect('activate', self.on_remove_agent, contact, account)
event_button = self.get_possible_button_event(event) event_button = self.get_possible_button_event(event)
@ -1221,41 +1231,41 @@ class RosterWindow:
event.time) event.time)
menu.show_all() menu.show_all()
def on_add_to_roster(self, widget, user, account): def on_add_to_roster(self, widget, contact, account):
dialogs.AddNewContactWindow(account, user.jid) dialogs.AddNewContactWindow(account, contact.jid)
def authorize(self, widget, jid, account): def authorize(self, widget, jid, account):
'''Authorize a user (by re-sending auth menuitem)''' '''Authorize a contact (by re-sending auth menuitem)'''
gajim.connections[account].send_authorization(jid) gajim.connections[account].send_authorization(jid)
dialogs.InformationDialog(_('Authorization has been sent'), dialogs.InformationDialog(_('Authorization has been sent'),
_('Now "%s" will know your status.') %jid) _('Now "%s" will know your status.') %jid)
def req_sub(self, widget, jid, txt, account, group=None, pseudo=None): def req_sub(self, widget, jid, txt, account, group=None, pseudo=None):
'''Request subscription to a user''' '''Request subscription to a contact'''
if not pseudo: if not pseudo:
pseudo = jid pseudo = jid
gajim.connections[account].request_subscription(jid, txt) gajim.connections[account].request_subscription(jid, txt)
if not group: if group:
group = _('General') group = [group]
if not gajim.contacts[account].has_key(jid): contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
if not contact:
keyID = '' keyID = ''
attached_keys = gajim.config.get_per('accounts', account, attached_keys = gajim.config.get_per('accounts', account,
'attached_gpg_keys').split() 'attached_gpg_keys').split()
if jid in attached_keys: if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1] keyID = attached_keys[attached_keys.index(jid) + 1]
user1 = Contact(jid = jid, name = pseudo, groups = [group], contact = gajim.contacts.create_contact(jid = jid, name = pseudo,
show = 'requested', status = '', ask = 'none', groups = group, show = 'requested', status = '', ask = 'none',
sub = 'subscribe', keyID = keyID) sub = 'subscribe', keyID = keyID)
gajim.contacts[account][jid] = [user1] gajim.contacts.add_contact(account, contact)
else: else:
user1 = gajim.get_contact_instance_with_highest_priority(account, jid) if not _('not in the roster') in contact.groups:
if not _('not in the roster') in user1.groups:
dialogs.InformationDialog(_('Subscription request has been sent'), dialogs.InformationDialog(_('Subscription request has been sent'),
_('If "%s" accepts this request you will know his or her status.') %jid) _('If "%s" accepts this request you will know his or her status.') % jid)
return return
user1.groups = [group] contact.groups = group
user1.name = pseudo contact.name = pseudo
self.remove_contact(user1, account) self.remove_contact(contact, account)
self.add_contact_to_roster(jid, account) self.add_contact_to_roster(jid, account)
def revoke_auth(self, widget, jid, account): def revoke_auth(self, widget, jid, account):
@ -1295,11 +1305,12 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
type = model[iter][C_TYPE] type = model[iter][C_TYPE]
if type in ('account', 'group'): if type in ('account', 'group'):
return return
user = gajim.get_contact_instance_with_highest_priority(account, jid) contact = gajim.contacts.get_contact_with_highest_priority(account,
jid)
if type == 'contact': if type == 'contact':
self.on_req_usub(widget, user, account) self.on_req_usub(widget, contact, account)
elif type == 'agent': elif type == 'agent':
self.on_remove_agent(widget, user, account) self.on_remove_agent(widget, contact, account)
def show_appropriate_context_menu(self, event, iter): def show_appropriate_context_menu(self, event, iter):
model = self.tree.get_model() model = self.tree.get_model()
@ -1357,10 +1368,10 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
if type in ('agent', 'contact'): if type in ('agent', 'contact'):
account = model[iter][C_ACCOUNT].decode('utf-8') account = model[iter][C_ACCOUNT].decode('utf-8')
jid = model[iter][C_JID].decode('utf-8') jid = model[iter][C_JID].decode('utf-8')
c = gajim.contacts.get_contact_with_highest_priority(account, jid)
if gajim.interface.instances[account]['chats'].has_key(jid): if gajim.interface.instances[account]['chats'].has_key(jid):
gajim.interface.instances[account]['chats'][jid].set_active_tab(jid) gajim.interface.instances[account]['chats'][jid].set_active_tab(jid)
elif gajim.contacts[account].has_key(jid): elif c:
c = gajim.get_contact_instance_with_highest_priority(account, jid)
self.new_chat(c, account) self.new_chat(c, account)
gajim.interface.instances[account]['chats'][jid].set_active_tab(jid) gajim.interface.instances[account]['chats'][jid].set_active_tab(jid)
gajim.interface.instances[account]['chats'][jid].window.present() gajim.interface.instances[account]['chats'][jid].window.present()
@ -1403,28 +1414,29 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
else: else:
self.tree.expand_row(path, False) self.tree.expand_row(path, False)
def on_req_usub(self, widget, user, account): def on_req_usub(self, widget, contact, account):
'''Remove a contact''' '''Remove a contact'''
window = dialogs.ConfirmationDialogCheck( window = dialogs.ConfirmationDialogCheck(
_('Contact "%s" will be removed from your roster') % (user.name), _('Contact "%s" will be removed from your roster') % (contact.name),
_('By removing this contact you also by default remove authorization resulting in him or her always seeing you as offline.'), _('By removing this contact you also by default remove authorization resulting in him or her always seeing you as offline.'),
_('I want this contact to know my status after removal')) _('I want this contact to know my status after removal'))
# FIXME: # FIXME:
# maybe use 2 optionboxes from which the user can select? (better) # maybe use 2 optionboxes from which the contact can select? (better)
if window.get_response() == gtk.RESPONSE_OK: if window.get_response() == gtk.RESPONSE_OK:
remove_auth = True remove_auth = True
if window.is_checked(): if window.is_checked():
remove_auth = False remove_auth = False
gajim.connections[account].unsubscribe(user.jid, remove_auth) gajim.connections[account].unsubscribe(contact.jid, remove_auth)
for u in gajim.contacts[account][user.jid]: for u in gajim.contacts.get_contact(account, contact.jid):
self.remove_contact(u, account) self.remove_contact(u, account)
del gajim.contacts[account][u.jid] gajim.contacts.remove_jid(account, u.jid)
if user.jid in gajim.interface.instances[account]['chats']: if contact.jid in gajim.interface.instances[account]['chats']:
user1 = Contact(jid = user.jid, name = user.name, c = gajim.contacts.create_contact(jid = contact.jid,
groups = [_('not in the roster')], show = 'not in the roster', name = contact.name, groups = [_('not in the roster')],
status = '', ask = 'none', keyID = user.keyID) show = 'not in the roster', status = '', ask = 'none',
gajim.contacts[account][user.jid] = [user1] keyID = contact.keyID)
self.add_contact_to_roster(user.jid, account) gajim.contacts.add_contact(account, c)
self.add_contact_to_roster(contact.jid, account)
def forget_gpg_passphrase(self, keyid): def forget_gpg_passphrase(self, keyid):
if self.gpg_passphrase.has_key(keyid): if self.gpg_passphrase.has_key(keyid):
@ -1627,7 +1639,7 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
def on_status_changed(self, account, status): def on_status_changed(self, account, status):
'''the core tells us that our status has changed''' '''the core tells us that our status has changed'''
if not gajim.contacts.has_key(account): if account not in gajim.contacts.get_accounts():
return return
model = self.tree.get_model() model = self.tree.get_model()
accountIter = self.get_account_iter(account) accountIter = self.get_account_iter(account)
@ -1636,13 +1648,14 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
if status == 'offline': if status == 'offline':
if accountIter: if accountIter:
model[accountIter][6] = None model[accountIter][6] = None
for jid in gajim.contacts[account]: for jid in gajim.contacts.get_jid_list(account):
luser = gajim.contacts[account][jid] lcontact = gajim.contacts.get_contact(account, jid)
luser_copy = [] lcontact_copy = []
for user in luser: for contact in lcontact:
luser_copy.append(user) lcontact_copy.append(contact)
for user in luser_copy: for contact in lcontact_copy:
self.chg_contact_status(user, 'offline', 'Disconnected', account) self.chg_contact_status(contact, 'offline', 'Disconnected',
account)
self.update_status_combobox() self.update_status_combobox()
self.make_menu() self.make_menu()
@ -1661,18 +1674,18 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
account) account)
def new_chat_from_jid(self, account, jid): def new_chat_from_jid(self, account, jid):
if gajim.contacts[account].has_key(jid): contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
contact = gajim.get_contact_instance_with_highest_priority(account, jid) if not contact:
else:
keyID = '' keyID = ''
attached_keys = gajim.config.get_per('accounts', account, attached_keys = gajim.config.get_per('accounts', account,
'attached_gpg_keys').split() 'attached_gpg_keys').split()
if jid in attached_keys: if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1] keyID = attached_keys[attached_keys.index(jid) + 1]
contact = Contact(jid = jid, name = jid.split('@')[0], contact = gajim.contacts.create_contact(jid = jid,
groups = [_('not in the roster')], show = 'not in the roster', name = jid.split('@')[0], groups = [_('not in the roster')],
status = '', sub = 'none', keyID = keyID) show = 'not in the roster', status = '', sub = 'none',
gajim.contacts[account][jid] = [contact] keyID = keyID)
gajim.contacts.add_contact(account, contact)
self.add_contact_to_roster(contact.jid, account) self.add_contact_to_roster(contact.jid, account)
if not gajim.interface.instances[account]['chats'].has_key(jid): if not gajim.interface.instances[account]['chats'].has_key(jid):
@ -1696,16 +1709,18 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
def on_message(self, jid, msg, tim, account, encrypted = False, def on_message(self, jid, msg, tim, account, encrypted = False,
msg_type = '', subject = None, resource = ''): msg_type = '', subject = None, resource = ''):
'''when we receive a message''' '''when we receive a message'''
if not gajim.contacts[account].has_key(jid): contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
if not contact:
keyID = '' keyID = ''
attached_keys = gajim.config.get_per('accounts', account, attached_keys = gajim.config.get_per('accounts', account,
'attached_gpg_keys').split() 'attached_gpg_keys').split()
if jid in attached_keys: if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1] keyID = attached_keys[attached_keys.index(jid) + 1]
user1 = Contact(jid = jid, name = jid.split('@')[0], contact = gajim.contacts.create_contact(jid = jid,
groups = [_('not in the roster')], show = 'not in the roster', name = jid.split('@')[0], groups = [_('not in the roster')],
status = '', ask = 'none', keyID = keyID, resource = resource) show = 'not in the roster', status = '', ask = 'none',
gajim.contacts[account][jid] = [user1] keyID = keyID, resource = resource)
gajim.contacts.add_contact(account, contact)
self.add_contact_to_roster(jid, account) self.add_contact_to_roster(jid, account)
iters = self.get_contact_iter(jid, account) iters = self.get_contact_iter(jid, account)
@ -1727,8 +1742,6 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
popup = True popup = True
if msg_type == 'normal' and popup: # it's single message to be autopopuped if msg_type == 'normal' and popup: # it's single message to be autopopuped
contact = gajim.get_contact_instance_with_highest_priority(account,
jid)
dialogs.SingleMessageWindow(account, contact.jid, dialogs.SingleMessageWindow(account, contact.jid,
action = 'receive', from_whom = jid, subject = subject, action = 'receive', from_whom = jid, subject = subject,
message = msg, resource = resource) message = msg, resource = resource)
@ -1754,8 +1767,7 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
self.nb_unread += 1 self.nb_unread += 1
if popup: if popup:
if not gajim.interface.instances[account]['chats'].has_key(jid): if not gajim.interface.instances[account]['chats'].has_key(jid):
c = gajim.get_contact_instance_with_highest_priority(account, jid) self.new_chat(contact, account)
self.new_chat(c, account)
if path: if path:
self.tree.expand_row(path[0:1], False) self.tree.expand_row(path[0:1], False)
self.tree.expand_row(path[0:2], False) self.tree.expand_row(path[0:2], False)
@ -1976,7 +1988,8 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
gajim.interface.remove_first_event(account, jid, typ) gajim.interface.remove_first_event(account, jid, typ)
return True return True
elif typ == 'file-request': elif typ == 'file-request':
contact = gajim.get_contact_instance_with_highest_priority(account, jid) contact = gajim.contacts.get_contact_with_highest_priority(account,
jid)
gajim.interface.remove_first_event(account, jid, typ) gajim.interface.remove_first_event(account, jid, typ)
ft.show_file_request(account, contact, data) ft.show_file_request(account, contact, data)
return True return True
@ -2012,10 +2025,10 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
if self.open_event(account, jid, first_ev): if self.open_event(account, jid, first_ev):
return return
chats = gajim.interface.instances[account]['chats'] chats = gajim.interface.instances[account]['chats']
c = gajim.contacts.get_contact_with_highest_priority(account, jid)
if chats.has_key(jid): if chats.has_key(jid):
chats[jid].set_active_tab(jid) chats[jid].set_active_tab(jid)
elif gajim.contacts[account].has_key(jid): elif c:
c = gajim.get_contact_instance_with_highest_priority(account, jid)
self.new_chat(c, account) self.new_chat(c, account)
chats[jid].set_active_tab(jid) chats[jid].set_active_tab(jid)
chats[jid].window.present() chats[jid].window.present()
@ -2087,7 +2100,8 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
jid = model[iter][C_JID].decode('utf-8') jid = model[iter][C_JID].decode('utf-8')
type = model[iter][C_TYPE] type = model[iter][C_TYPE]
# restore the number of resources string at the end of contact name # restore the number of resources string at the end of contact name
if type == 'contact' and len(gajim.contacts[account][jid]) > 1: contacts = gajim.contacts.get_contact(account, jid)
if type == 'contact' and len(contacts) > 1:
self.draw_contact(jid, account) self.draw_contact(jid, account)
# reset editable to False # reset editable to False
model[iter][C_EDITABLE] = False model[iter][C_EDITABLE] = False
@ -2113,29 +2127,31 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
jid = model[iter][C_JID].decode('utf-8') jid = model[iter][C_JID].decode('utf-8')
type = model[iter][C_TYPE] type = model[iter][C_TYPE]
if type == 'contact': if type == 'contact':
old_text = gajim.get_contact_instance_with_highest_priority(account, jid).name old_text = gajim.contacts.get_contact_with_highest_priority(account,
jid).name
if old_text != new_text: if old_text != new_text:
for u in gajim.contacts[account][jid]: for u in gajim.contacts.get_contact(account, jid):
u.name = new_text u.name = new_text
gajim.connections[account].update_contact(jid, new_text, u.groups) gajim.connections[account].update_contact(jid, new_text, u.groups)
self.draw_contact(jid, account) self.draw_contact(jid, account)
elif type == 'group': elif type == 'group':
# in C_JID cilumn it's not escaped # in C_JID cilumn it's not escaped
old_name = model[iter][C_JID].decode('utf-8') old_name = model[iter][C_JID].decode('utf-8')
# Groups maynot change name from or to 'not in the roster' # Groups maynot change name from or to 'not in the roster'
if _('not in the roster') in (new_text, old_name): if _('not in the roster') in (new_text, old_name):
return return
#get all users in that group # get all contacts in that group
for jid in gajim.contacts[account]: for jid in gajim.contacts.get_jid_list(account):
user = gajim.get_contact_instance_with_highest_priority(account, jid) contact = gajim.contacts.get_contact_with_highest_priority(account,
if old_name in user.groups: jid)
if old_name in contact.groups:
#set them in the new one and remove it from the old #set them in the new one and remove it from the old
self.remove_contact(user, account) self.remove_contact(contact, account)
user.groups.remove(old_name) contact.groups.remove(old_name)
user.groups.append(new_text) contact.groups.append(new_text)
self.add_contact_to_roster(user.jid, account) self.add_contact_to_roster(contact.jid, account)
gajim.connections[account].update_contact(user.jid, user.name, gajim.connections[account].update_contact(contact.jid,
user.groups) contact.name, contact.groups)
model.set_value(iter, 5, False) model.set_value(iter, 5, False)
def on_service_disco_menuitem_activate(self, widget, account): def on_service_disco_menuitem_activate(self, widget, account):
@ -2347,10 +2363,10 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
renderer.set_property('cell-background', None) renderer.set_property('cell-background', None)
renderer.set_property('xalign', 1) # align pixbuf to the right renderer.set_property('xalign', 1) # align pixbuf to the right
def get_show(self, luser): def get_show(self, lcontact):
prio = luser[0].priority prio = lcontact[0].priority
show = luser[0].show show = lcontact[0].show
for u in luser: for u in lcontact:
if u.priority > prio: if u.priority > prio:
prio = u.priority prio = u.priority
show = u.show show = u.show
@ -2384,22 +2400,28 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
jid1 = model[iter1][C_JID].decode('utf-8') jid1 = model[iter1][C_JID].decode('utf-8')
jid2 = model[iter2][C_JID].decode('utf-8') jid2 = model[iter2][C_JID].decode('utf-8')
if type1 == 'contact': if type1 == 'contact':
luser1 = gajim.contacts[account1][jid1] lcontact1 = gajim.contacts.get_contact(account1, jid1)
name1 = luser1[0].name contact1 = gajim.contacts.get_first_contact_from_jid(account1, jid1)
if not contact1:
return 0
name1 = contact1.name
if type2 == 'contact': if type2 == 'contact':
luser2 = gajim.contacts[account2][jid2] lcontact2 = gajim.contacts.get_contact(account2, jid2)
name2 = luser2[0].name contact2 = gajim.contacts.get_first_contact_from_jid(account2, jid2)
if not contact2:
return 0
name2 = contact2.name
# We first compare by show if sort_by_show is True # We first compare by show if sort_by_show is True
if type1 == 'contact' and type2 == 'contact' and \ if type1 == 'contact' and type2 == 'contact' and \
gajim.config.get('sort_by_show'): gajim.config.get('sort_by_show'):
cshow = {'online':0, 'chat': 1, 'away': 2, 'xa': 3, 'dnd': 4, cshow = {'online':0, 'chat': 1, 'away': 2, 'xa': 3, 'dnd': 4,
'invisible': 5, 'offline': 6, 'not in the roster': 7, 'error': 8} 'invisible': 5, 'offline': 6, 'not in the roster': 7, 'error': 8}
s = self.get_show(luser1) s = self.get_show(lcontact1)
if s in cshow: if s in cshow:
show1 = cshow[s] show1 = cshow[s]
else: else:
show1 = 9 show1 = 9
s = self.get_show(luser2) s = self.get_show(lcontact2)
if s in cshow: if s in cshow:
show2 = cshow[s] show2 = cshow[s]
else: else:
@ -2474,22 +2496,23 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
return return
# We upgrade only the first user because user2.groups is a pointer to # We upgrade only the first user because user2.groups is a pointer to
# user1.groups # user1.groups
u = gajim.contacts[account][data][0] c = gajim.contacts.get_first_contact_from_jid(account, data)
if context.action != gtk.gdk.ACTION_COPY: if context.action != gtk.gdk.ACTION_COPY:
u.groups.remove(grp_source) c.groups.remove(grp_source)
if model.iter_n_children(iter_group_source) == 1: if model.iter_n_children(iter_group_source) == 1:
# this was the only child # this was the only child
model.remove(iter_group_source) model.remove(iter_group_source)
# delete the group if it is empty (need to look for offline users too) # delete the group if it is empty (need to look for offline users too)
for jid in gajim.contacts[account]: for jid in gajim.contacts.get_jid_list(account):
if grp_source in gajim.get_contact_instance_with_highest_priority(account, jid).groups: if grp_source in gajim.contacts.get_contact_with_highest_priority(
account, jid).groups:
break break
else: else:
del gajim.groups[account][grp_source] del gajim.groups[account][grp_source]
if not grp_dest in u.groups: if not grp_dest in c.groups:
u.groups.append(grp_dest) c.groups.append(grp_dest)
self.add_contact_to_roster(data, account) self.add_contact_to_roster(data, account)
gajim.connections[account].update_contact(u.jid, u.name, u.groups) gajim.connections[account].update_contact(c.jid, c.name, c.groups)
if context.action in (gtk.gdk.ACTION_MOVE, gtk.gdk.ACTION_COPY): if context.action in (gtk.gdk.ACTION_MOVE, gtk.gdk.ACTION_COPY):
context.finish(True, True, etime) context.finish(True, True, etime)
return return

View File

@ -33,7 +33,6 @@ import os
import tooltips import tooltips
import gtkgui_helpers import gtkgui_helpers
from gajim import Contact
from common import gajim from common import gajim
from common import helpers from common import helpers
from common import i18n from common import i18n
@ -101,12 +100,12 @@ class Systray:
self.set_img() self.set_img()
def start_chat(self, widget, account, jid): def start_chat(self, widget, account, jid):
contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if gajim.interface.instances[account]['chats'].has_key(jid): if gajim.interface.instances[account]['chats'].has_key(jid):
gajim.interface.instances[account]['chats'][jid].window.present() gajim.interface.instances[account]['chats'][jid].window.present()
gajim.interface.instances[account]['chats'][jid].set_active_tab(jid) gajim.interface.instances[account]['chats'][jid].set_active_tab(jid)
elif gajim.contacts[account].has_key(jid): elif contact:
gajim.interface.roster.new_chat( gajim.interface.roster.new_chat(contacts, account)
gajim.contacts[account][jid][0], account)
gajim.interface.instances[account]['chats'][jid].set_active_tab(jid) gajim.interface.instances[account]['chats'][jid].set_active_tab(jid)
def on_new_message_menuitem_activate(self, widget, account): def on_new_message_menuitem_activate(self, widget, account):
@ -249,8 +248,8 @@ class Systray:
groups_menu.append(item) groups_menu.append(item)
contacts_menu = gtk.Menu() contacts_menu = gtk.Menu()
item.set_submenu(contacts_menu) item.set_submenu(contacts_menu)
for contacts in gajim.contacts[account].values(): for jid in gajim.contacts.get_jid_list(account):
contact = gajim.get_highest_prio_contact_from_contacts(contacts) contact = gajim.get_contact_with_highest_priority(account, jid)
if group in contact.groups and contact.show != 'offline' and \ if group in contact.groups and contact.show != 'offline' and \
contact.show != 'error': contact.show != 'error':
at_least_one = True at_least_one = True

View File

@ -338,17 +338,16 @@ class TabbedChatWindow(chat.Chat):
def set_state_image(self, jid): def set_state_image(self, jid):
prio = 0 prio = 0
if gajim.contacts[self.account].has_key(jid): contact_list = gajim.contacts.get_contact(self.account, jid)
contacts_list = gajim.contacts[self.account][jid] if contact_list:
else: contact_list = [self.contacts[jid]]
contacts_list = [self.contacts[jid]]
contact = contacts_list[0] contact = contact_list[0]
show = contact.show show = contact.show
jid = contact.jid jid = contact.jid
keyID = contact.keyID keyID = contact.keyID
for u in contacts_list: for u in contact_list:
if u.priority > prio: if u.priority > prio:
prio = u.priority prio = u.priority
show = u.show show = u.show
@ -436,7 +435,7 @@ class TabbedChatWindow(chat.Chat):
def on_send_file_menuitem_activate(self, widget): def on_send_file_menuitem_activate(self, widget):
jid = self.get_active_jid() jid = self.get_active_jid()
contact = gajim.get_first_contact_instance_from_jid(self.account, jid) contact = gajim.contacts.get_first_contact_from_jid(self.account, jid)
gajim.interface.instances['file_transfers'].show_file_send_request( gajim.interface.instances['file_transfers'].show_file_send_request(
self.account, contact) self.account, contact)
@ -532,7 +531,7 @@ class TabbedChatWindow(chat.Chat):
in the last 5 seconds? in the last 5 seconds?
if yes we go active for mouse, composing for kbd if yes we go active for mouse, composing for kbd
if no we go paused if we were previously composing ''' if no we go paused if we were previously composing '''
contact = gajim.get_first_contact_instance_from_jid(self.account, jid) contact = gajim.contacts.get_first_contact_from_jid(self.account, jid)
if jid not in self.xmls or contact is None: if jid not in self.xmls or contact is None:
# the tab with jid is no longer open or contact left # the tab with jid is no longer open or contact left
# stop timer # stop timer
@ -564,7 +563,7 @@ class TabbedChatWindow(chat.Chat):
in the last 30 seconds? in the last 30 seconds?
if yes we go active if yes we go active
if no we go inactive ''' if no we go inactive '''
contact = gajim.get_first_contact_instance_from_jid(self.account, jid) contact = gajim.contacts.get_first_contact_from_jid(self.account, jid)
if jid not in self.xmls or contact is None: if jid not in self.xmls or contact is None:
# the tab with jid is no longer open or contact left # the tab with jid is no longer open or contact left
return False # stop looping return False # stop looping
@ -691,7 +690,7 @@ class TabbedChatWindow(chat.Chat):
if jid is None: if jid is None:
jid = self.get_active_jid() jid = self.get_active_jid()
contact = gajim.get_first_contact_instance_from_jid(self.account, jid) contact = gajim.contacts.get_first_contact_from_jid(self.account, jid)
if contact is None: if contact is None:
# contact was from pm in MUC, and left the room so contact is None # contact was from pm in MUC, and left the room so contact is None
@ -748,7 +747,7 @@ class TabbedChatWindow(chat.Chat):
return return
jid = self.get_active_jid() jid = self.get_active_jid()
contact = gajim.get_first_contact_instance_from_jid(self.account, jid) contact = gajim.contacts.get_first_contact_from_jid(self.account, jid)
if contact is None: if contact is None:
# contact was from pm in MUC, and left the room, or we left the room # contact was from pm in MUC, and left the room, or we left the room
room, nick = gajim.get_room_and_nick_from_fjid(jid) room, nick = gajim.get_room_and_nick_from_fjid(jid)
@ -877,7 +876,7 @@ class TabbedChatWindow(chat.Chat):
if (contact.show == 'offline' or contact.show == 'error'): if (contact.show == 'offline' or contact.show == 'error'):
showOffline = gajim.config.get('showoffline') showOffline = gajim.config.get('showoffline')
if not showOffline and typ == 'chat' and \ if not showOffline and typ == 'chat' and \
len(gajim.contacts[self.account][jid]) == 1: len(gajim.contacts.get_contact(self.account, jid)) == 1:
gajim.interface.roster.really_remove_contact(contact, self.account) gajim.interface.roster.really_remove_contact(contact, self.account)
elif typ == 'pm': elif typ == 'pm':
gcs[room_jid].remove_contact(room_jid, nick) gcs[room_jid].remove_contact(room_jid, nick)

View File

@ -186,25 +186,24 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
def get_accounts_info(self): def get_accounts_info(self):
accounts = [] accounts = []
if gajim.contacts: for account in gajim.contacts.get_accounts():
for account in gajim.contacts.keys(): status_idx = gajim.connections[account].connected
status_idx = gajim.connections[account].connected # uncomment the following to hide offline accounts
# uncomment the following to hide offline accounts # if status_idx == 0: continue
# if status_idx == 0: continue status = gajim.SHOW_LIST[status_idx]
status = gajim.SHOW_LIST[status_idx] message = gajim.connections[account].status
message = gajim.connections[account].status single_line = helpers.get_uf_show(status)
single_line = helpers.get_uf_show(status) if message is None:
if message is None: message = ''
message = '' else:
else: message = message.strip()
message = message.strip() if message != '':
if message != '': single_line += ': ' + message
single_line += ': ' + message # the other solution is to hide offline accounts
# the other solution is to hide offline accounts elif status == 'offline':
elif status == 'offline': message = helpers.get_uf_show(status)
message = helpers.get_uf_show(status) accounts.append({'name': account, 'status_line': single_line,
accounts.append({'name': account, 'status_line': single_line, 'show': status, 'message': message})
'show': status, 'message': message})
return accounts return accounts
def fill_table_with_accounts(self, accounts): def fill_table_with_accounts(self, accounts):
@ -247,7 +246,8 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
chat_wins = gajim.interface.instances[acct]['chats'] chat_wins = gajim.interface.instances[acct]['chats']
for jid in chat_wins: for jid in chat_wins:
if jid != 'tabbed': if jid != 'tabbed':
if gajim.contacts[acct].has_key(jid): c = gajim.contacts.get_first_contact_from_jid(acct, jid)
if c:
unread_chat += chat_wins[jid].nb_unread[jid] unread_chat += chat_wins[jid].nb_unread[jid]
else: else:
unread_pm += chat_wins[jid].nb_unread[jid] unread_pm += chat_wins[jid].nb_unread[jid]
@ -342,7 +342,7 @@ class GCTooltip(BaseTooltip):
# escape markup entities # escape markup entities
info += ' - ' + gtkgui_helpers.escape_for_pango_markup(status) info += ' - ' + gtkgui_helpers.escape_for_pango_markup(status)
if contact.resource.strip() != '': if hasattr(contact, 'resource') and contact.resource.strip() != '':
info += '\n<span weight="bold">' + _('Resource: ') + \ info += '\n<span weight="bold">' + _('Resource: ') + \
'</span>' + gtkgui_helpers.escape_for_pango_markup( '</span>' + gtkgui_helpers.escape_for_pango_markup(
contact.resource) contact.resource)
@ -378,7 +378,8 @@ class RosterTooltip(NotificationAreaTooltip):
self.win.add(self.hbox) self.win.add(self.hbox)
return return
# primary contact # primary contact
prim_contact = gajim.get_highest_prio_contact_from_contacts(contacts) prim_contact = gajim.contacts.get_highest_prio_contact_from_contacts(
contacts)
# try to find the image for the contact status # try to find the image for the contact status
icon_name = helpers.get_icon_name_to_show(prim_contact) icon_name = helpers.get_icon_name_to_show(prim_contact)
@ -484,7 +485,7 @@ class FileTransfersTooltip(BaseTooltip):
if file_props['type'] == 'r': if file_props['type'] == 'r':
text += '\n<b>' + _('Sender: ') + '</b>' text += '\n<b>' + _('Sender: ') + '</b>'
sender = unicode(file_props['sender']).split('/')[0] sender = unicode(file_props['sender']).split('/')[0]
name = gajim.get_first_contact_instance_from_jid( name = gajim.contacts.get_first_contact_from_jid(
file_props['tt_account'], sender).name file_props['tt_account'], sender).name
else: else:
text += '\n<b>' + _('Recipient: ') + '</b>' text += '\n<b>' + _('Recipient: ') + '</b>'
@ -495,7 +496,7 @@ class FileTransfersTooltip(BaseTooltip):
if receiver.find('@') == -1: if receiver.find('@') == -1:
name = receiver name = receiver
else: else:
name = gajim.get_first_contact_instance_from_jid( name = gajim.contacts.get_first_contact_from_jid(
file_props['tt_account'], receiver).name file_props['tt_account'], receiver).name
text += gtkgui_helpers.escape_for_pango_markup(name) text += gtkgui_helpers.escape_for_pango_markup(name)
text += '\n<b>' + _('Size: ') + '</b>' text += '\n<b>' + _('Size: ') + '</b>'

View File

@ -78,7 +78,7 @@ class VcardWindow:
'''Class for contact's information window''' '''Class for contact's information window'''
def __init__(self, contact, account, vcard = False): def __init__(self, contact, account, vcard = False):
#the contact variable is the jid if vcard is true # the contact variable is the jid if vcard is true
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'vcard_information_window', APP) self.xml = gtk.glade.XML(GTKGUI_GLADE, 'vcard_information_window', APP)
self.window = self.xml.get_widget('vcard_information_window') self.window = self.xml.get_widget('vcard_information_window')
self.xml.get_widget('photo_vbuttonbox').set_no_show_all(True) self.xml.get_widget('photo_vbuttonbox').set_no_show_all(True)
@ -330,8 +330,9 @@ class VcardWindow:
self.os_info = {0: {'resource': self.contact.resource, 'client': '', self.os_info = {0: {'resource': self.contact.resource, 'client': '',
'os': ''}} 'os': ''}}
i = 1 i = 1
if gajim.contacts[self.account].has_key(self.contact.jid): contact_list = gajim.contacts.get_contact(self.account, self.contact.jid)
for c in gajim.contacts[self.account][self.contact.jid]: if contact_list:
for c in contact_list:
if c.resource != self.contact.resource: if c.resource != self.contact.resource:
resources += '\n%s (%s)' % (c.resource, resources += '\n%s (%s)' % (c.resource,
unicode(c.priority)) unicode(c.priority))