agents support

This commit is contained in:
Yann Leboulanger 2003-11-15 12:38:43 +00:00
parent 5afec1f54b
commit 334497bdbe
3 changed files with 354 additions and 22 deletions

View File

@ -22,6 +22,7 @@ import Queue
import socket import socket
import sys import sys
import time import time
import string
import logging import logging
import plugins import plugins
@ -64,12 +65,11 @@ 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)
if self.cfgParser.Core_alwaysauth == 1: if self.cfgParser.Core_alwaysauth == 1 or string.find(who, "@") <= 0:
self.con.send(common.jabber.Presence(who, 'subscribed')) self.con.send(common.jabber.Presence(who, 'subscribed'))
else: else:
self.hub.sendPlugin('SUBSCRIBE', who) self.hub.sendPlugin('SUBSCRIBE', who)
elif type == 'subscribed': elif type == 'subscribed':
#plein de trucs a faire
jid = prs.getFrom() jid = prs.getFrom()
self.hub.sendPlugin('SUBSCRIBED', {'jid':jid.getBasic(), \ self.hub.sendPlugin('SUBSCRIBED', {'jid':jid.getBasic(), \
'nom':jid.getNode()}) 'nom':jid.getNode()})
@ -109,6 +109,7 @@ class GajimCore:
roster = self.con.getRoster().getRaw() roster = self.con.getRoster().getRaw()
if not roster : if not roster :
roster = {} roster = {}
print roster
self.hub.sendPlugin('ROSTER', roster) self.hub.sendPlugin('ROSTER', roster)
self.con.sendInitPresence() self.con.sendInitPresence()
self.connected = 1 self.connected = 1
@ -165,7 +166,14 @@ class GajimCore:
self.con.updateRosterItem(jid=ev[1][0], name=ev[1][1], groups=ev[1][2]) self.con.updateRosterItem(jid=ev[1][0], name=ev[1][1], groups=ev[1][2])
elif ev[0] == 'REQ_AGENTS': elif ev[0] == 'REQ_AGENTS':
agents = self.con.requestAgents() agents = self.con.requestAgents()
self.hub.sendPlugin('AGENTS', agents) self.hub.sendPlugin('AGENTS', agents)
elif ev[0] == 'REQ_AGENT_INFO':
self.con.requestRegInfo(ev[1])
agent_info = self.con.getRegInfo()
self.hub.sendPlugin('AGENT_INFO', (ev[1], agent_info))
elif ev[0] == 'REG_AGENT':
self.con.sendRegInfo(ev[1])
print ev[1]
else: else:
log.debug("Unknown Command") log.debug("Unknown Command")
elif self.connected == 1: elif self.connected == 1:
@ -183,5 +191,6 @@ def start():
gc.hub.register('gtkgui', 'SUBSCRIBED') gc.hub.register('gtkgui', 'SUBSCRIBED')
gc.hub.register('gtkgui', 'SUBSCRIBE') gc.hub.register('gtkgui', 'SUBSCRIBE')
gc.hub.register('gtkgui', 'AGENTS') gc.hub.register('gtkgui', 'AGENTS')
gc.hub.register('gtkgui', 'AGENT_INFO')
guiPl.load () guiPl.load ()
gc.mainLoop() gc.mainLoop()

View File

@ -1917,6 +1917,7 @@ David Ferlier (david@yazzy.org)</property>
<property name="default_height">250</property> <property name="default_height">250</property>
<property name="resizable">True</property> <property name="resizable">True</property>
<property name="destroy_with_parent">False</property> <property name="destroy_with_parent">False</property>
<signal name="destroy" handler="gtk_widget_destroy" last_modification_time="Fri, 14 Nov 2003 11:08:36 GMT"/>
<child> <child>
<widget class="GtkVBox" id="vbox11"> <widget class="GtkVBox" id="vbox11">
@ -1942,6 +1943,7 @@ David Ferlier (david@yazzy.org)</property>
<property name="rules_hint">False</property> <property name="rules_hint">False</property>
<property name="reorderable">False</property> <property name="reorderable">False</property>
<property name="enable_search">True</property> <property name="enable_search">True</property>
<signal name="row_activated" handler="on_row_activated" last_modification_time="Thu, 13 Nov 2003 18:19:02 GMT"/>
</widget> </widget>
</child> </child>
</widget> </widget>
@ -2111,4 +2113,219 @@ David Ferlier (david@yazzy.org)</property>
</child> </child>
</widget> </widget>
<widget class="GtkWindow" id="agent_reg">
<property name="visible">True</property>
<property name="title" translatable="yes">Register to</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="default_width">300</property>
<property name="default_height">200</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<child>
<widget class="GtkVBox" id="vbox12">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
<property name="wrap">True</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">4</property>
</widget>
<packing>
<property name="padding">4</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkTable" id="table">
<property name="border_width">5</property>
<property name="visible">True</property>
<property name="n_rows">1</property>
<property name="n_columns">2</property>
<property name="homogeneous">False</property>
<property name="row_spacing">10</property>
<property name="column_spacing">10</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkHSeparator" id="hseparator7">
<property name="visible">True</property>
</widget>
<packing>
<property name="padding">4</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox5">
<property name="border_width">9</property>
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<property name="spacing">25</property>
<child>
<widget class="GtkButton" id="button_ok">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_button_ok_clicked" last_modification_time="Fri, 14 Nov 2003 11:03:35 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment17">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<child>
<widget class="GtkHBox" id="hbox21">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image106">
<property name="visible">True</property>
<property name="stock">gtk-ok</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label33">
<property name="visible">True</property>
<property name="label" translatable="yes">_OK</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkButton" id="button_cancel">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_button_cancel_clicked" last_modification_time="Fri, 14 Nov 2003 11:04:06 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment18">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<child>
<widget class="GtkHBox" id="hbox22">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image107">
<property name="visible">True</property>
<property name="stock">gtk-cancel</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label34">
<property name="visible">True</property>
<property name="label" translatable="yes">_Cancel</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface> </glade-interface>

View File

@ -136,6 +136,58 @@ class authorize:
self.xml.signal_connect('on_button_deny_clicked', self.deny) self.xml.signal_connect('on_button_deny_clicked', self.deny)
self.xml.signal_connect('on_button_close_clicked', self.delete_event) self.xml.signal_connect('on_button_close_clicked', self.delete_event)
class agent_reg:
def delete_event(self, widget):
self.window.destroy()
def draw_table(self):
for name in self.infos.keys():
if name != 'key' and name != 'instructions' and name != 'x':
self.nbrow = self.nbrow + 1
self.table.resize(rows=self.nbrow, columns=2)
label = gtk.Label(name)
self.table.attach(label, 0, 1, self.nbrow-1, self.nbrow, 0, 0, 0, 0)
entry = gtk.Entry()
entry.set_text(self.infos[name])
self.table.attach(entry, 1, 2, self.nbrow-1, self.nbrow, 0, 0, 0, 0)
self.entries[name] = entry
if self.nbrow == 1:
entry.grab_focus()
self.table.show_all()
def on_ok(self, widget):
for name in self.entries.keys():
self.infos[name] = self.entries[name].get_text()
self.r.queueOUT.put(('REG_AGENT', self.agent))
print self.infos
# jid = string.replace(jid, '@', '')
# if not self.r.l_group.has_key('Agents'):
# iterG = self.r.treestore.append(None, (None, \
# 'Agents', 'group', FALSE))
# self.r.l_group['Agent'] = iterG
# user1 = user(jid, jid, ['Agent'], 'online', 'online', 'from')
# iterU = self.r.treestore.append(self.r.l_group['Agent'], \
# (self.r.pixbufs['online'], jid, jid, TRUE))
# self.r.l_contact[jid] = {'user':user1, 'iter':[iterU]}
self.delete_event(self)
def __init__(self, agent, infos, roster):
self.xml = gtk.glade.XML('plugins/gtkgui.glade', 'agent_reg')
self.infos = infos
self.r = roster
self.agent = agent
self.window = self.xml.get_widget('agent_reg')
self.table = self.xml.get_widget('table')
self.window.set_title('Register to ' + agent)
self.xml.get_widget('label').set_text(infos['instructions'])
self.nbrow = 0
self.entries = {}
self.draw_table()
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_button_cancel_clicked', self.delete_event)
self.xml.signal_connect('on_button_ok_clicked', self.on_ok)
class browser: class browser:
def delete_event(self, widget): def delete_event(self, widget):
global Wbrowser global Wbrowser
@ -148,11 +200,17 @@ class browser:
def agents(self, agents): def agents(self, agents):
for jid in agents.keys(): for jid in agents.keys():
iter = self.model.append() iter = self.model.append()
self.model.set(iter, 0, agents[jid]['name'], 1, jid) self.model.set(iter, 0, agents[jid]['name'], 1, agents[jid]['service'])
def on_refresh(self, widget): def on_refresh(self, widget):
self.model.clear() self.model.clear()
self.browse() self.browse()
def on_row_activated(self, widget, path, col=0):
iter = self.model.get_iter(path)
service = self.model.get_value(iter, 1)
self.r.queueOUT.put(('REQ_AGENT_INFO', service))
self.delete_event(self)
def __init__(self, roster): def __init__(self, roster):
self.xml = gtk.glade.XML('plugins/gtkgui.glade', 'browser') self.xml = gtk.glade.XML('plugins/gtkgui.glade', 'browser')
@ -167,11 +225,12 @@ class browser:
self.treeview.insert_column_with_attributes(-1, 'Name', renderer, text=0) self.treeview.insert_column_with_attributes(-1, 'Name', renderer, text=0)
renderer = gtk.CellRendererText() renderer = gtk.CellRendererText()
renderer.set_data('column', 1) renderer.set_data('column', 1)
self.treeview.insert_column_with_attributes(-1, 'JID', renderer, text=1) self.treeview.insert_column_with_attributes(-1, 'Service', renderer, text=1)
self.xml.signal_connect('gtk_widget_destroy', self.delete_event) self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_refresh_clicked', self.on_refresh) self.xml.signal_connect('on_refresh_clicked', self.on_refresh)
#TODO: Si connecté self.xml.signal_connect('on_row_activated', self.on_row_activated)
#TODO: Si connecte
self.browse() self.browse()
class message: class message:
@ -245,21 +304,30 @@ class roster:
self.l_group = {} self.l_group = {}
self.treestore.clear() self.treestore.clear()
for jid in tab.keys(): for jid in tab.keys():
#On enleve la resource
ji = string.split(jid, '/')[0]
name = tab[jid]['name'] name = tab[jid]['name']
if not name: if not name:
name = '' if string.find(ji, "@") <= 0:
name = ji
else:
name = ''
show = tab[jid]['show'] show = tab[jid]['show']
if not show: if not show:
show = 'offline' show = 'offline'
user1 = user(jid, name, tab[jid]['groups'], show, tab[jid]['status'], tab[jid]['sub']) user1 = user(ji, name, tab[jid]['groups'], show, tab[jid]['status'], tab[jid]['sub'])
self.l_contact[user1.jid] = {'user': user1, 'iter': []} self.l_contact[user1.jid] = {'user': user1, 'iter': []}
print user1.jid
if user1.groups == []: if user1.groups == []:
user1.groups.append('general') if string.find(ji, "@") <= 0:
user1.groups.append('Agents')
else:
user1.groups.append('general')
for g in user1.groups: for g in user1.groups:
if not self.l_group.has_key(g): if not self.l_group.has_key(g):
iterG = self.treestore.append(None, (None, g, 'group', FALSE)) iterG = self.treestore.append(None, (None, g, 'group', FALSE))
self.l_group[g] = iterG self.l_group[g] = iterG
if user1.show != 'offline' or self.showOffline: if user1.show != 'offline' or self.showOffline or g == 'Agents':
iterU = self.treestore.append(self.l_group[g], (self.pixbufs[user1.show], user1.name, user1.jid, TRUE)) iterU = self.treestore.append(self.l_group[g], (self.pixbufs[user1.show], user1.name, user1.jid, TRUE))
self.l_contact[user1.jid]['iter'].append(iterU) self.l_contact[user1.jid]['iter'].append(iterU)
@ -292,7 +360,8 @@ class roster:
self.l_contact[jid]['iter'] = [] self.l_contact[jid]['iter'] = []
else: else:
for i in self.l_contact[jid]['iter']: for i in self.l_contact[jid]['iter']:
self.treestore.set_value(i, 0, self.pixbufs[show]) if self.pixbufs.has_key(show):
self.treestore.set_value(i, 0, self.pixbufs[show])
u.show = show u.show = show
u.status = status u.status = status
@ -353,7 +422,7 @@ class roster:
if not self.l_contact.has_key(jid): if not self.l_contact.has_key(jid):
user1 = user(jid, jid, ['general'], 'requested', 'requested', 'sub') user1 = user(jid, jid, ['general'], 'requested', 'requested', 'sub')
if not self.l_group.has_key('general'): if not self.l_group.has_key('general'):
iterG = self.treestore.append(None, (None, 'general', 'group')) iterG = self.treestore.append(None, (None, 'general', 'group', FALSE))
self.l_group['general'] = iterG self.l_group['general'] = iterG
iterU = self.treestore.append(self.l_group['general'], (self.pixbufs['requested'], jid, jid, TRUE)) iterU = self.treestore.append(self.l_group['general'], (self.pixbufs['requested'], jid, jid, TRUE))
self.l_contact[jid] = {'user':user1, 'iter':[iterU]} self.l_contact[jid] = {'user':user1, 'iter':[iterU]}
@ -487,23 +556,60 @@ 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]): jid = string.split(ev[1][0], '/')[0]
self.r.chg_status(ev[1][0], ev[1][1], ev[1][2]) print self.r.l_contact
print jid
if string.find(jid, "@") <= 0:
#It must be an agent
jid = string.replace(jid, '@', '')
if not self.r.l_group.has_key('Agents'):
iterG = self.r.treestore.append(None, (None, \
'Agents', 'group', FALSE))
self.r.l_group['Agents'] = iterG
if not self.r.l_contact.has_key(jid):
user1 = user(jid, jid, ['Agents'], ev[1][1], ev[1][2], 'from')
iterU = self.r.treestore.append(self.r.l_group['Agents'], \
(self.r.pixbufs[ev[1][1]], jid, jid, TRUE))
self.r.l_contact[jid] = {'user':user1, 'iter':[iterU]}
else:
#On mets a jour la ligne ki existe deja
for i in self.r.l_contact[jid]['iter']:
if self.r.pixbufs.has_key(ev[1][1]):
self.r.treestore.set_value(i, 0, self.r.pixbufs[ev[1][1]])
elif self.r.l_contact.has_key(jid):
#ca n'est pas un agent
self.r.chg_status(jid, 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 string.find(ev[1][0], "@") <= 0:
jid = string.replace(ev[1][0], '@', '')
if not self.r.tab_messages.has_key(jid):
#FIXME:message d'un inconne #FIXME:message d'un inconne
self.r.tab_messages[ev[1][0]] = message(self.r.l_contact[ev[1][0]]['user'], self.r) self.r.tab_messages[jid] = message(self.r.l_contact[jid]['user'], self.r)
self.r.tab_messages[ev[1][0]].print_conversation(ev[1][1]) self.r.tab_messages[jid].print_conversation(ev[1][1])
elif ev[0] == 'SUBSCRIBE': elif ev[0] == 'SUBSCRIBE':
authorize(self.r, ev[1]) authorize(self.r, ev[1])
elif ev[0] == 'SUBSCRIBED': elif ev[0] == 'SUBSCRIBED':
u = self.r.l_contact[ev[1]['jid']]['user'] jid = ev[1]['jid']
u.name = ev[1]['nom'] if self.r.l_contact.has_key(jid):
for i in self.r.l_contact[u.jid]['iter']: u = self.r.l_contact[jid]['user']
self.r.treestore.set_value(i, 1, u.name) u.name = ev[1]['nom']
for i in self.r.l_contact[u.jid]['iter']:
self.r.treestore.set_value(i, 1, u.name)
else:
user1 = user(jid, jid, ['general'], 'online', 'online', 'to')
if not self.r.l_group.has_key('general'):
iterG = self.r.treestore.append(None, (None, \
'general', 'group', FALSE))
self.r.l_group['general'] = iterG
iterU = self.r.treestore.append(self.r.l_group['general'], \
(self.r.pixbufs['online'], jid, jid, TRUE))
self.r.l_contact[jid] = {'user':user1, 'iter':[iterU]}
#TODO: print you are now authorized
elif ev[0] == 'AGENTS': elif ev[0] == 'AGENTS':
if Wbrowser: if Wbrowser:
Wbrowser.agents(ev[1]) Wbrowser.agents(ev[1])
elif ev[0] == 'AGENT_INFO':
Wreg = agent_reg(ev[1][0], ev[1][1], self.r)
return 1 return 1
def __init__(self, quIN, quOUT): def __init__(self, quIN, quOUT):