many improvements in add / remove contacts

This commit is contained in:
Yann Leboulanger 2003-10-28 19:37:40 +00:00
parent c1035c159b
commit 26553b576a
4 changed files with 47 additions and 16 deletions

View File

@ -56,7 +56,8 @@ class GajimHub:
""" Sends an event to registered plugins """ Sends an event to registered plugins
NOTIFY : ('NOTIFY', (user, status, message)) NOTIFY : ('NOTIFY', (user, status, message))
MSG : ('MSG', (user, msg)) MSG : ('MSG', (user, msg))
ROSTER : ('ROSTER', {jid:{'Online':_, 'Status':_, 'Show':_} ,jid:{}})""" ROSTER : ('ROSTER', {jid:{'Online':_, 'nom':_, 'server':_, 'resource':_, 'group':_, 'status':_, 'show':_} ,jid:{}})
SUBSCRIBED : ('SUBSCRIBED', {'jid':_, 'nom':_, 'server':_, 'resource':_, 'status':_, 'show':_})"""
if self.events.has_key(event): if self.events.has_key(event):
for i in self.events[event]: for i in self.events[event]:

View File

@ -64,8 +64,13 @@ class GajimCore:
(prs.getFrom().getBasic(), 'offline', prs.getStatus())) (prs.getFrom().getBasic(), 'offline', prs.getStatus()))
elif type == 'subscribe': elif type == 'subscribe':
log.debug("subscribe request from %s" % who) log.debug("subscribe request from %s" % who)
self.con.send(common.jabber.Presence(who, 'subscribed'))
elif type == 'subscribed': elif type == 'subscribed':
#plein de trucs a faire #plein de trucs a faire
jid = prs.getFrom()
self.hub.sendPlugin('SUBSCRIBED', {'jid':jid.getBasic(), \
'nom':jid.getNode(), 'server':jid.getDomain(), \
'resource':jid.getResource()})
log.debug("we are now subscribed to %s" % who) log.debug("we are now subscribed to %s" % who)
elif type == 'unsubscribe': elif type == 'unsubscribe':
log.debug("unsubscribe request from %s" % who) log.debug("unsubscribe request from %s" % who)
@ -106,7 +111,10 @@ class GajimCore:
else: else:
show = roster.getOnline(jid) show = roster.getOnline(jid)
tab_roster[jid.getBasic()] = \ tab_roster[jid.getBasic()] = \
{"Online":roster.getOnline(jid), "nom":jid.getNode(), "server":jid.getDomain(), "resource":jid.getResource(), "group":'general', "status":roster.getStatus(jid), "show":show} {"Online":roster.getOnline(jid), "nom":jid.getNode(), \
"server":jid.getDomain(), "resource":jid.getResource(), \
"group":'general', "status":roster.getStatus(jid), \
"show":show}
self.hub.sendPlugin('ROSTER', tab_roster) self.hub.sendPlugin('ROSTER', tab_roster)
self.con.sendInitPresence() self.con.sendInitPresence()
self.connected = 1 self.connected = 1
@ -145,7 +153,14 @@ class GajimCore:
self.con.send(common.jabber.Presence(ev[1][0], 'subscribe')) self.con.send(common.jabber.Presence(ev[1][0], 'subscribe'))
#('UNSUB', jid) #('UNSUB', jid)
elif ev[0] == 'UNSUB': elif ev[0] == 'UNSUB':
delauth = self.cfgParser.Core_delauth
if not delauth: delauth = 1
delroster = self.cfgParser.Core_delroster
if not delroster: delroster = 1
if delauth:
self.con.send(common.jabber.Presence(ev[1], 'unsubscribe')) self.con.send(common.jabber.Presence(ev[1], 'unsubscribe'))
if delroster:
self.con.removeRosterItem(ev[1])
else: else:
log.debug("Unknown Command") log.debug("Unknown Command")
elif self.connected == 1: elif self.connected == 1:

View File

@ -8,6 +8,11 @@ name = LOGIN NAME
password = PASSWORD password = PASSWORD
ressource = gajim ressource = gajim
[Core]
delauth = 1
delroster = 1
[GtkGui] [GtkGui]
showoffline = 0 showoffline = 0

View File

@ -24,8 +24,6 @@ import gtk
import gtk.glade import gtk.glade
import gobject import gobject
import string import string
import pickle
import marshal
import common.optparser import common.optparser
CONFPATH = "~/.gajimrc" CONFPATH = "~/.gajimrc"
@ -156,23 +154,27 @@ class roster:
def mkl_group(self): def mkl_group(self):
""" l_group = {name:iter} """ """ l_group = {name:iter} """
self.l_group = {} self.l_group = {}
for u in self.l_contact.values(): for d in self.l_contact.values():
u=d['user']
if not self.l_group.has_key(u.group): if not self.l_group.has_key(u.group):
iterG = self.treestore.append(None, (self.pixbufs['online'], u.group, 'group')) iterG = self.treestore.append(None, (self.pixbufs['online'], u.group, 'group'))
self.l_group[u.group]=iterG self.l_group[u.group]=iterG
def mkroster(self, tab): def mkroster(self, tab):
""" l_contact = {jid:{'user':_, 'iter':_] """
self.l_contact = {} self.l_contact = {}
for jid in tab.keys(): for jid in tab.keys():
user1 = user(tab[jid]['nom'], tab[jid]['server'], tab[jid]['resource'], tab[jid]['group'], tab[jid]["show"], tab[jid]["status"]) user1 = user(tab[jid]['nom'], tab[jid]['server'], tab[jid]['resource'], tab[jid]['group'], tab[jid]["show"], tab[jid]["status"])
self.l_contact[user1.jid] = user1 self.l_contact[user1.jid] = {'user': user1, 'iter': None}
self.treestore.clear() self.treestore.clear()
self.mkl_group() self.mkl_group()
for g in self.l_group.keys(): for g in self.l_group.keys():
for c in self.l_contact.values(): for d in self.l_contact.values():
c=d['user']
if c.group == g: if c.group == g:
if c.show != 'offline' or self.showOffline: if c.show != 'offline' or self.showOffline:
self.treestore.append(self.l_group[g], (self.pixbufs[c.show], c.name, c.jid)) iterU = self.treestore.append(self.l_group[g], (self.pixbufs[c.show], c.name, c.jid))
self.l_contact[c.jid]['iter'] = iterU
def update_iter(self, widget, path, iter, data): def update_iter(self, widget, path, iter, data):
jid = self.treestore.get_value(iter, 2) jid = self.treestore.get_value(iter, 2)
@ -188,14 +190,15 @@ class roster:
return 0 return 0
def chg_status(self, jid, show, status): def chg_status(self, jid, show, status):
u = self.l_contact[jid] u = self.l_contact[jid]['user']
self.found = 0 self.found = 0
self.treestore.foreach(self.update_iter, (jid, show)) self.treestore.foreach(self.update_iter, (jid, show))
if self.found == 0: if self.found == 0:
if not self.l_group.has_key(u.group): if not self.l_group.has_key(u.group):
iterG = self.treestore.append(None, (self.pixbufs['online'], u.group, 'group')) iterG = self.treestore.append(None, (self.pixbufs['online'], u.group, 'group'))
self.l_group[u.group] = iterG self.l_group[u.group] = iterG
self.treestore.append(self.l_group[u.group], (self.pixbufs[show], u.name, u.jid)) iterU = self.treestore.append(self.l_group[u.group], (self.pixbufs[show], u.name, u.jid))
self.l_contact[u.jid]['iter'] = iterU
u.show = show u.show = show
u.status = status u.status = status
return 1 return 1
@ -246,9 +249,9 @@ class roster:
self.queueOUT.put(('SUB', (jid, txt))) self.queueOUT.put(('SUB', (jid, txt)))
if not self.l_contact.has_key(jid): if not self.l_contact.has_key(jid):
user1 = user(jid, jid, jid, 'general', 'requested', 'requested') user1 = user(jid, jid, jid, 'general', 'requested', 'requested')
self.l_contact[jid] = user1
#TODO: ajouter un grp si necessaire #TODO: ajouter un grp si necessaire
self.treestore.append(self.l_group['general'], (self.pixbufs['requested'], jid, jid)) iterU = self.treestore.append(self.l_group['general'], (self.pixbufs['requested'], jid, jid))
self.l_contact[jid] = {'user':user1, 'iter':iterU}
def on_status_changed(self, widget): def on_status_changed(self, widget):
self.queueOUT.put(('STATUS',widget.name)) self.queueOUT.put(('STATUS',widget.name))
@ -273,7 +276,7 @@ class roster:
#NE FONCTIONNE PAS ! #NE FONCTIONNE PAS !
self.tab_messages[jid].window.grab_focus() self.tab_messages[jid].window.grab_focus()
else: else:
self.tab_messages[jid] = message(self.l_contact[jid], self) self.tab_messages[jid] = message(self.l_contact[jid]['user'], self)
def __init__(self, queueOUT): def __init__(self, queueOUT):
#initialisation des variables #initialisation des variables
@ -330,11 +333,18 @@ class plugin:
if ev[0] == 'ROSTER': if ev[0] == 'ROSTER':
self.r.mkroster(ev[1]) self.r.mkroster(ev[1])
elif ev[0] == 'NOTIFY': elif ev[0] == 'NOTIFY':
if self.r.l_contact.has_key(ev[1][0]):
self.r.chg_status(ev[1][0], ev[1][1], ev[1][2]) self.r.chg_status(ev[1][0], ev[1][1], ev[1][2])
elif ev[0] == 'MSG': elif ev[0] == 'MSG':
if not self.r.tab_messages.has_key(ev[1][0]): if not self.r.tab_messages.has_key(ev[1][0]):
self.r.tab_messages[ev[1][0]] = message(self.r.l_contact[ev[1][0]], self.r) self.r.tab_messages[ev[1][0]] = message(self.r.l_contact[ev[1][0]]['user'], self.r)
self.r.tab_messages[ev[1][0]].print_conversation(ev[1][1]) self.r.tab_messages[ev[1][0]].print_conversation(ev[1][1])
elif ev[0] == 'SUBSCRIBED':
u = self.r.l_contact[ev[1]['jid'][0]]
u.name = ev[1]['nom']
u.server = ev[1]['server']
u.resource = ev[1]['resource']
self.r.treestore.set_value(self.r.l_contact[u.jid]['iter'], 1, u.name)
return 1 return 1
def __init__(self, quIN, quOUT): def __init__(self, quIN, quOUT):