Close all opened windows before quitting gtkgui plugin

New agent Browser (JEP 30 complient)
Upgrade of french translation
This commit is contained in:
Yann Leboulanger 2004-09-06 14:55:10 +00:00
parent 4ea21d3fce
commit f78acc3bf1
8 changed files with 516 additions and 280 deletions

File diff suppressed because it is too large Load Diff

View File

@ -705,7 +705,9 @@ class Client(Connection):
def discoverItems(self,jid,node=None):
""" According to JEP-0030: jid is mandatory, name, node, action is optional. """
ret=[]
for i in self._discover(NS_P_DISC_ITEMS,jid,node):
disco = self._discover(NS_P_DISC_ITEMS,jid,node)
if disco:
for i in disco:
ret.append(i.attrs)
return ret
@ -714,11 +716,32 @@ class Client(Connection):
For identity: category, name is mandatory, type is optional.
For feature: var is mandatory"""
identities , features = [] , []
for i in self._discover(NS_P_DISC_INFO,jid,node):
disco = self._discover(NS_P_DISC_INFO,jid,node)
if disco:
for i in disco:
if i.getName()=='identity': identities.append(i.attrs)
elif i.getName()=='feature': features.append(i.getAttr('var'))
return identities, features
def browseAgent(self,jid,node=None):
identities, features, items = [], [], []
iq=Iq(to=jid,type='get',query=NS_BROWSE)
rep=self.SendAndWaitForResponse(iq)
if not rep:
return identities, features, items
q = rep.getTag('service')
identities = [q.attrs]
if not q:
return identities, features, items
for node in q.kids:
if node.getName() == 'ns':
features.append(node.getData())
else:
infos = node.attrs
infos['category'] = node.getName()
items.append(node.attrs)
return identities, features, items
#############################################################################
class Protocol(xmlstream.Node):

View File

@ -31,7 +31,7 @@ class GajimPlugin:
def load(self):
thr = common.thread.GajimThread(self.name, self.queueIn, self.queueOut)
thr.setDaemon(1)
# thr.setDaemon(1)
thr.start()
# END load
# END GajimPlugin

View File

@ -348,6 +348,16 @@ class GajimCore:
self.data = self.data[end+1:]
return list_ev
def request_infos(self, account, con, jid):
identities, features = con.discoverInfo(jid)
if not identities:
identities, features, items = con.browseAgent(jid)
else:
items = con.discoverItems(jid)
self.hub.sendPlugin('AGENT_INFO', account, (jid, identities, features, items))
for item in items:
self.request_infos(account, con, item['jid'])
def read_queue(self):
while self.hub.queueIn.empty() == 0:
ev = self.hub.queueIn.get()
@ -513,13 +523,18 @@ class GajimCore:
groups=ev[2][2])
#('REQ_AGENTS', account, ())
elif ev[0] == 'REQ_AGENTS':
agents = con.requestAgents()
# agents = con.requestAgents()
#do we need that ?
#con.discoverInfo('jabber.lagaule.org')
agents = con.discoverItems('jabber.lagaule.org')
self.hub.sendPlugin('AGENTS', ev[1], agents)
#('REQ_AGENT_INFO', account, agent)
elif ev[0] == 'REQ_AGENT_INFO':
for agent in agents:
self.request_infos(ev[1], con, agent['jid'])
#('REG_AGENT_INFO', account, agent)
elif ev[0] == 'REG_AGENT_INFO':
con.requestRegInfo(ev[2])
agent_info = con.getRegInfo()
self.hub.sendPlugin('AGENT_INFO', ev[1], (ev[2], agent_info))
self.hub.sendPlugin('REG_AGENT_INFO', ev[1], (ev[2], agent_info))
#('REG_AGENT', account, infos)
elif ev[0] == 'REG_AGENT':
con.sendRegInfo(ev[2])

View File

@ -116,6 +116,7 @@ class vCard_Window:
def __init__(self, jid, plugin, account):
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'vcard', APP)
self.window = self.xml.get_widget('vcard')
self.jid = jid
self.plugin = plugin
self.account = account
@ -254,6 +255,7 @@ class preference_Window:
def __init__(self, plugin):
"""Initialize Preference window"""
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Preferences', APP)
self.window = self.xml.get_widget('Preferences')
self.plugin = plugin
self.da_in = self.xml.get_widget('drawing_in')
self.da_out = self.xml.get_widget('drawing_out')
@ -497,6 +499,7 @@ class accountPreference_Window:
#info must be a dictionnary
def __init__(self, plugin, infos = {}):
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Account', APP)
self.window = self.xml.get_widget("Account")
self.plugin = plugin
self.account = ''
self.modify = False
@ -595,6 +598,7 @@ class accounts_Window:
def __init__(self, plugin):
self.plugin = plugin
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Accounts', APP)
self.window = self.xml.get_widget("Accounts")
self.treeview = self.xml.get_widget("treeview")
model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
self.treeview.set_model(model)
@ -688,10 +692,35 @@ class browseAgent_Window:
"""When list of available agent arrive :
Fill the treeview with it"""
model = self.treeview.get_model()
for jid in agents.keys():
iter = model.append()
# model.set(iter, 0, agents[jid]['name'], 1, agents[jid]['service'])
model.set(iter, 0, agents[jid]['name'], 1, jid)
for agent in agents:
iter = model.append(None, (agent['name'], agent['jid']))
self.agent_infos[agent['jid']] = {'features' : []}
def agent_info(self, agent, identities, features, items):
"""When we recieve informations about an agent"""
model = self.treeview.get_model()
iter = model.get_iter_root()
if not iter:
return
while (1):
if agent == model.get_value(iter, 1):
break
if model.iter_has_child(iter):
iter = model.iter_children(iter)
else:
if not model.iter_next(iter):
iter = model.iter_parent(iter)
iter = model.iter_next(iter)
if not iter:
return
self.agent_infos[agent]['features'] = features
if len(identities):
self.agent_infos[agent]['identities'] = identities
if identities[0].has_key('name'):
model.set_value(iter, 0, identities[0]['name'])
for item in items:
model.append(iter, (item['name'], item['jid']))
self.agent_infos[item['jid']] = {'identities': [item]}
def on_refresh(self, widget):
"""When refresh button is clicked :
@ -701,19 +730,54 @@ class browseAgent_Window:
def on_row_activated(self, widget, path, col=0):
"""When a row is activated :
Register or join the selected agent"""
pass
def on_join_button_clicked(self, widget):
"""When we want to join a conference :
Ask specific informations about the selected agent and close the window"""
model = self.treeview.get_model()
iter = model.get_iter(path)
model, iter = self.treeview.get_selection().get_selected()
service = model.get_value(iter, 1)
self.plugin.send('REQ_AGENT_INFO', self.account, service)
room = ''
if string.find(service, '@') > -1:
services = string.split(service, '@')
room = services[0]
service = services[1]
if not self.plugin.windows.has_key('join_gc'):
self.plugin.windows['join_gc'] = join_gc(self.plugin, self.account, service, room)
def on_register_button_clicked(self, widget):
"""When we want to register an agent :
Ask specific informations about the selected agent and close the window"""
model, iter = self.treeview.get_selection().get_selected()
service = model.get_value(iter, 1)
self.plugin.send('REG_AGENT_INFO', self.account, service)
widget.get_toplevel().destroy()
def on_cursor_changed(self, widget):
"""When we select a row :
activate buttons if needed"""
model, iter = self.treeview.get_selection().get_selected()
jid = model.get_value(iter, 1)
self.register_button.set_sensitive(False)
if self.agent_infos[jid].has_key('features'):
if common.jabber.NS_REGISTER in self.agent_infos[jid]['features']:
self.register_button.set_sensitive(True)
self.join_button.set_sensitive(False)
if self.agent_infos[jid].has_key('identities'):
if len(self.agent_infos[jid]['identities']):
if self.agent_infos[jid]['identities'][0].has_key('category'):
if self.agent_infos[jid]['identities'][0]['category'] == 'conference':
self.join_button.set_sensitive(True)
def __init__(self, plugin, account):
xml = gtk.glade.XML(GTKGUI_GLADE, 'browser', APP)
self.window = xml.get_widget('browser')
self.treeview = xml.get_widget('treeview')
self.plugin = plugin
self.account = account
model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
self.agent_infos = {}
model = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
self.treeview.set_model(model)
#columns
renderer = gtk.CellRendererText()
@ -724,11 +788,53 @@ class browseAgent_Window:
self.treeview.insert_column_with_attributes(-1, 'Service', \
renderer, text=1)
self.register_button = xml.get_widget('register_button')
self.register_button.set_sensitive(False)
self.join_button = xml.get_widget('join_button')
self.join_button.set_sensitive(False)
xml.signal_connect('gtk_widget_destroy', self.delete_event)
xml.signal_connect('on_refresh_clicked', self.on_refresh)
xml.signal_connect('on_row_activated', self.on_row_activated)
xml.signal_connect('on_join_button_clicked', self.on_join_button_clicked)
xml.signal_connect('on_register_button_clicked', self.on_register_button_clicked)
xml.signal_connect('on_cursor_changed', self.on_cursor_changed)
xml.signal_connect('on_close_clicked', self.on_close)
if self.plugin.connected[account]:
self.browse()
else:
warning_Window(_("You must be connected to view Agents"))
class join_gc:
def delete_event(self, widget):
"""close window"""
del self.plugin.windows['join_gc']
def on_close(self, widget):
"""When Cancel button is clicked"""
widget.get_toplevel().destroy()
def on_join(self, widget):
"""When Join button is clicked"""
nick = self.xml.get_widget('entry_nick').get_text()
room = self.xml.get_widget('entry_room').get_text()
server = self.xml.get_widget('entry_server').get_text()
passw = self.xml.get_widget('entry_pass').get_text()
jid = '%s@%s' % (room, server)
self.plugin.windows[self.account]['gc'][jid] = gtkgui.gc(jid, nick, \
self.plugin, self.account)
#TODO: verify entries
self.plugin.send('GC_JOIN', self.account, (nick, room, server, passw))
widget.get_toplevel().destroy()
def __init__(self, plugin, account, server='', room = ''):
self.plugin = plugin
self.account = account
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Join_gc', APP)
self.window = self.xml.get_widget('Join_gc')
self.xml.get_widget('entry_server').set_text(server)
self.xml.get_widget('entry_room').set_text(room)
self.xml.get_widget('entry_nick').set_text(self.plugin.nicks[self.account])
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_cancel_clicked', self.on_close)
self.xml.signal_connect('on_join_clicked', self.on_join)

View File

@ -151,6 +151,7 @@ class infoUser_Window:
def __init__(self, user, plugin, account):
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Info_user', APP)
self.window = self.xml.get_widget("Info_user")
self.plugin = plugin
self.user = user
self.account = account
@ -234,6 +235,7 @@ class addContact_Window:
self.plugin = plugin
self.account = account
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Add', APP)
self.window = self.xml.get_widget('Add')
if jid:
self.xml.get_widget('entry_who').set_text(jid)
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
@ -263,6 +265,7 @@ class about_Window:
def __init__(self, plugin):
xml = gtk.glade.XML(GTKGUI_GLADE, 'About', APP)
self.window = xml.get_widget('About')
self.plugin = plugin
xml.signal_connect('gtk_widget_destroy', self.delete_event)
xml.signal_connect('on_close_clicked', self.on_close)

View File

@ -2515,6 +2515,45 @@ on the server.</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox13">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_START</property>
<property name="spacing">5</property>
<child>
<widget class="GtkButton" id="register_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Re_gister</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_register_button_clicked" last_modification_time="Sat, 04 Sep 2004 20:59:29 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="join_button">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Join</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_join_button_clicked" last_modification_time="Sat, 04 Sep 2004 20:59:36 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">2</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow9">
<property name="border_width">5</property>
@ -2534,6 +2573,7 @@ on the server.</property>
<property name="reorderable">False</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"/>
<signal name="cursor_changed" handler="on_cursor_changed" last_modification_time="Wed, 01 Sep 2004 21:00:56 GMT"/>
</widget>
</child>
</widget>
@ -7152,6 +7192,7 @@ when NOT online</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<signal name="destroy" handler="gtk_widget_destroy" last_modification_time="Tue, 03 Aug 2004 22:05:41 GMT"/>
<signal name="focus_in_event" handler="on_focus" last_modification_time="Sun, 05 Sep 2004 09:15:16 GMT"/>
<child>
<widget class="GtkVBox" id="vbox27">

View File

@ -63,8 +63,8 @@ APP = i18n.APP
gtk.glade.bindtextdomain (APP, i18n.DIR)
gtk.glade.textdomain (APP)
from config import *
from dialogs import *
from config import *
GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade'
@ -393,6 +393,10 @@ class gc:
#scroll to the end of the textview
conversation.scroll_to_mark(buffer.get_mark('end'), 0.1, 0, 0, 0)
def on_focus(self, widget, event):
"""When window get focus"""
self.plugin.systray.remove_jid(self.jid, self.account)
def __init__(self, jid, nick, plugin, account):
self.jid = jid
self.nick = nick
@ -435,39 +439,10 @@ class gc:
color = self.plugin.config['statusmsgcolor']
self.tagStatus.set_property("foreground", color)
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_focus', self.on_focus)
self.xml.signal_connect('on_msg_key_press_event', \
self.on_msg_key_press_event)
class join_gc:
def delete_event(self, widget):
"""close window"""
del self.plugin.windows['join_gc']
def on_close(self, widget):
"""When Cancel button is clicked"""
widget.get_toplevel().destroy()
def on_join(self, widget):
"""When Join button is clicked"""
nick = self.xml.get_widget('entry_nick').get_text()
room = self.xml.get_widget('entry_room').get_text()
server = self.xml.get_widget('entry_server').get_text()
passw = self.xml.get_widget('entry_pass').get_text()
jid = '%s@%s' % (room, server)
self.plugin.windows[self.account]['gc'][jid] = gc(jid, nick, \
self.plugin, self.account)
#TODO: verify entries
self.plugin.send('GC_JOIN', self.account, (nick, room, server, passw))
widget.get_toplevel().destroy()
def __init__(self, plugin, account):
self.plugin = plugin
self.account = account
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Join_gc', APP)
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_cancel_clicked', self.on_close)
self.xml.signal_connect('on_join_clicked', self.on_join)
class log_Window:
"""Class for bowser agent window :
to know the agents on the selected server"""
@ -581,6 +556,7 @@ class log_Window:
self.nb_line = 0
self.num_begin = 0
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'Log', APP)
self.window = self.xml.get_widget('Log')
self.xml.signal_connect('gtk_widget_destroy', self.delete_event)
self.xml.signal_connect('on_close_clicked', self.on_close)
self.xml.signal_connect('on_earliest_clicked', self.on_earliest)
@ -1076,6 +1052,9 @@ class roster_Window:
item = gtk.MenuItem(_("Edit account"))
menu.append(item)
item.connect("activate", self.on_edit_account, account)
item = gtk.MenuItem(_("_Browse agents"))
menu.append(item)
item.connect("activate", self.on_browse, account)
menu.popup(None, None, None, event.button, event.time)
menu.show_all()
@ -1293,7 +1272,7 @@ class roster_Window:
if type(w) == type({}):
self.close_all(w)
else:
w.event(gtk.gdk.Event(gtk.gdk.DESTROY))
w.window.destroy()
def on_quit(self, widget):
"""When we quit the gtk plugin :
@ -1302,7 +1281,7 @@ class roster_Window:
self.plugin.send('CONFIG', None, ('GtkGui', self.plugin.config))
self.plugin.send('QUIT', None, ('gtkgui', 0))
print _("plugin gtkgui stopped")
# self.close_all(self.plugin.windows)
self.close_all(self.plugin.windows)
self.plugin.systray.t.destroy()
gtk.main_quit()
# gtk.gdk.threads_leave()
@ -1427,9 +1406,6 @@ class roster_Window:
image.set_from_pixbuf(pix)
break
for state in ('online', 'away', 'xa', 'dnd', 'invisible', 'offline'):
# image = gtk.Image()
# image.set_from_pixbuf(self.pixbufs[state])
# image.show()
self.xml.get_widget(state).set_image(self.pixbufs[state])
def on_show_off(self, widget):
@ -1747,6 +1723,10 @@ class systray:
else:
account = self.jids[0][0]
jid = self.jids[0][1]
if string.find(jid, '@'):
if self.plugin.windows[account]['gc'].has_key(jid):
self.plugin.windows[account]['gc'][jid].window.present()
return
if self.plugin.windows[account]['chats'].has_key(jid):
self.plugin.windows[account]['chats'][jid].window.present()
else:
@ -1933,13 +1913,19 @@ class plugin:
#TODO: change icon
warning_Window(_("You are now unsubscribed by %s") % jid)
def handle_event_agents(self, account, para):
def handle_event_agents(self, account, agents):
#('AGENTS', account, agents)
if self.windows[account].has_key('browser'):
self.windows[account]['browser'].agents(para)
self.windows[account]['browser'].agents(agents)
def handle_event_agent_info(self, account, array):
#('AGENTS_INFO', account, (agent, infos))
#('AGENT_INFO', account, (agent, identities, features, items))
if self.windows[account].has_key('browser'):
self.windows[account]['browser'].agent_info(array[0], array[1], \
array[2], array[3])
def handle_event_reg_agent_info(self, account, array):
#('REG_AGENTS_INFO', account, (agent, infos))
if not array[1].has_key('instructions'):
warning_Window(_("error contacting %s") % array[0])
else:
@ -2044,6 +2030,8 @@ class plugin:
self.handle_event_agents(ev[1], ev[2])
elif ev[0] == 'AGENT_INFO':
self.handle_event_agent_info(ev[1], ev[2])
elif ev[0] == 'REG_AGENT_INFO':
self.handle_event_reg_agent_info(ev[1], ev[2])
elif ev[0] == 'ACC_OK':
self.handle_event_acc_ok(ev[1], ev[2])
elif ev[0] == 'QUIT':
@ -2091,13 +2079,16 @@ class plugin:
def __init__(self, quIN, quOUT):
gtk.gdk.threads_init()
#in pygtk2.4
#gtk.window_set_default_icon(??pixbuf??)
# gtk.gdk.threads_enter()
self.queueIN = quIN
self.queueOUT = quOUT
self.send('REG_MESSAGE', 'gtkgui', ['ROSTER', 'WARNING', 'STATUS', \
'NOTIFY', 'MSG', 'MSGERROR', 'SUBSCRIBED', 'UNSUBSCRIBED', \
'SUBSCRIBE', 'AGENTS', 'AGENT_INFO', 'QUIT', 'ACC_OK', 'CONFIG', \
'MYVCARD', 'VCARD', 'LOG_NB_LINE', 'LOG_LINE', 'VISUAL', 'GC_MSG'])
'SUBSCRIBE', 'AGENTS', 'AGENT_INFO', 'REG_AGENT_INFO', 'QUIT', \
'ACC_OK', 'CONFIG', 'MYVCARD', 'VCARD', 'LOG_NB_LINE', 'LOG_LINE', \
'VISUAL', 'GC_MSG'])
self.send('ASK_CONFIG', None, ('GtkGui', 'GtkGui', {'autopopup':1,\
'autopopupaway':1,\
'showoffline':0,\