add service line in ToplevelAgentBrowser

This commit is contained in:
Yann Leboulanger 2013-03-09 20:57:16 +01:00
parent f883a079c3
commit 70df978c79
1 changed files with 70 additions and 45 deletions

View File

@ -70,57 +70,57 @@ from common import ged
# when it advertises disco as it's feature, False means it's never browsable. # when it advertises disco as it's feature, False means it's never browsable.
def _gen_agent_type_info(): def _gen_agent_type_info():
return { return {
# Defaults # Defaults
(0, 0): (None, None), (0, 0): (None, None),
# Jabber server # Jabber server
('server', 'im'): (ToplevelAgentBrowser, 'jabber'), ('server', 'im'): (ToplevelAgentBrowser, 'jabber'),
('services', 'jabber'): (ToplevelAgentBrowser, 'jabber'), ('services', 'jabber'): (ToplevelAgentBrowser, 'jabber'),
('hierarchy', 'branch'): (AgentBrowser, 'jabber'), ('hierarchy', 'branch'): (AgentBrowser, 'jabber'),
# Services # Services
('conference', 'text'): (MucBrowser, 'conference'), ('conference', 'text'): (MucBrowser, 'conference'),
('headline', 'rss'): (AgentBrowser, 'rss'), ('headline', 'rss'): (AgentBrowser, 'rss'),
('headline', 'weather'): (False, 'weather'), ('headline', 'weather'): (False, 'weather'),
('gateway', 'weather'): (False, 'weather'), ('gateway', 'weather'): (False, 'weather'),
('_jid', 'weather'): (False, 'weather'), ('_jid', 'weather'): (False, 'weather'),
('gateway', 'sip'): (False, 'sip'), ('gateway', 'sip'): (False, 'sip'),
('directory', 'user'): (None, 'jud'), ('directory', 'user'): (None, 'jud'),
('pubsub', 'generic'): (PubSubBrowser, 'pubsub'), ('pubsub', 'generic'): (PubSubBrowser, 'pubsub'),
('pubsub', 'service'): (PubSubBrowser, 'pubsub'), ('pubsub', 'service'): (PubSubBrowser, 'pubsub'),
('proxy', 'bytestreams'): (None, 'bytestreams'), # Socks5 FT proxy ('proxy', 'bytestreams'): (None, 'bytestreams'), # Socks5 FT proxy
('headline', 'newmail'): (ToplevelAgentBrowser, 'mail'), ('headline', 'newmail'): (ToplevelAgentBrowser, 'mail'),
# Transports # Transports
('conference', 'irc'): (ToplevelAgentBrowser, 'irc'), ('conference', 'irc'): (ToplevelAgentBrowser, 'irc'),
('_jid', 'irc'): (False, 'irc'), ('_jid', 'irc'): (False, 'irc'),
('gateway', 'aim'): (False, 'aim'), ('gateway', 'aim'): (False, 'aim'),
('_jid', 'aim'): (False, 'aim'), ('_jid', 'aim'): (False, 'aim'),
('gateway', 'gadu-gadu'): (False, 'gadu-gadu'), ('gateway', 'gadu-gadu'): (False, 'gadu-gadu'),
('_jid', 'gadugadu'): (False, 'gadu-gadu'), ('_jid', 'gadugadu'): (False, 'gadu-gadu'),
('gateway', 'http-ws'): (False, 'http-ws'), ('gateway', 'http-ws'): (False, 'http-ws'),
('gateway', 'icq'): (False, 'icq'), ('gateway', 'icq'): (False, 'icq'),
('_jid', 'icq'): (False, 'icq'), ('_jid', 'icq'): (False, 'icq'),
('gateway', 'msn'): (False, 'msn'), ('gateway', 'msn'): (False, 'msn'),
('_jid', 'msn'): (False, 'msn'), ('_jid', 'msn'): (False, 'msn'),
('gateway', 'sms'): (False, 'sms'), ('gateway', 'sms'): (False, 'sms'),
('_jid', 'sms'): (False, 'sms'), ('_jid', 'sms'): (False, 'sms'),
('gateway', 'smtp'): (False, 'mail'), ('gateway', 'smtp'): (False, 'mail'),
('gateway', 'yahoo'): (False, 'yahoo'), ('gateway', 'yahoo'): (False, 'yahoo'),
('_jid', 'yahoo'): (False, 'yahoo'), ('_jid', 'yahoo'): (False, 'yahoo'),
('gateway', 'mrim'): (False, 'mrim'), ('gateway', 'mrim'): (False, 'mrim'),
('_jid', 'mrim'): (False, 'mrim'), ('_jid', 'mrim'): (False, 'mrim'),
('gateway', 'facebook'): (False, 'facebook'), ('gateway', 'facebook'): (False, 'facebook'),
('_jid', 'facebook'): (False, 'facebook'), ('_jid', 'facebook'): (False, 'facebook'),
} }
# Category type to "human-readable" description string, and sort priority # Category type to "human-readable" description string, and sort priority
_cat_to_descr = { _cat_to_descr = {
'other': (_('Others'), 2), 'other': (_('Others'), 2),
'gateway': (_('Transports'), 0), 'gateway': (_('Transports'), 0),
'_jid': (_('Transports'), 0), '_jid': (_('Transports'), 0),
#conference is a category for listing mostly groupchats in service discovery #conference is a category for listing mostly groupchats in service discovery
'conference': (_('Conference'), 1), 'conference': (_('Conference'), 1),
} }
@ -1085,11 +1085,15 @@ class AgentBrowser:
return iter_ return iter_
return None return None
def add_self_line(self):
pass
def _agent_items(self, jid, node, items, force): def _agent_items(self, jid, node, items, force):
""" """
Callback for when we receive a list of agent items Callback for when we receive a list of agent items
""" """
self.model.clear() self.model.clear()
self.add_self_line()
self._total_items = 0 self._total_items = 0
gobject.source_remove(self._pulse_timeout) gobject.source_remove(self._pulse_timeout)
self.window.progressbar.hide() self.window.progressbar.hide()
@ -1180,6 +1184,22 @@ class ToplevelAgentBrowser(AgentBrowser):
self._view_signals = [] self._view_signals = []
self._scroll_signal = None self._scroll_signal = None
def add_self_line(self):
addr = get_agent_address(self.jid, self.node)
descr = "<b>%s</b>" % addr
# Guess which kind of service this is
identities = []
type_ = gajim.get_transport_name_from_jid(self.jid,
use_config_setting=False)
if type_:
identity = {'category': '_jid', 'type': type_}
identities.append(identity)
# Set the pixmap for the row
pix = self.cache.get_icon(identities)
self.model.append(None, (self.jid, self.node, pix, descr, 1))
# Grab info on the service
self.cache.get_info(self.jid, self.node, self._agent_info, force=False)
def _pixbuf_renderer_data_func(self, col, cell, model, iter_): def _pixbuf_renderer_data_func(self, col, cell, model, iter_):
""" """
Callback for setting the pixbuf renderer's properties Callback for setting the pixbuf renderer's properties
@ -1624,6 +1644,11 @@ class ToplevelAgentBrowser(AgentBrowser):
iter_ = None iter_ = None
cat_iter = self.model.get_iter_root() cat_iter = self.model.get_iter_root()
while cat_iter and not iter_: while cat_iter and not iter_:
cjid = self.model.get_value(cat_iter, 0).decode('utf-8')
cnode = self.model.get_value(cat_iter, 1).decode('utf-8')
if jid == cjid and node == cnode:
iter_ = cat_iter
break
iter_ = self.model.iter_children(cat_iter) iter_ = self.model.iter_children(cat_iter)
while iter_: while iter_:
cjid = self.model.get_value(iter_, 0).decode('utf-8') cjid = self.model.get_value(iter_, 0).decode('utf-8')
@ -1698,8 +1723,7 @@ class ToplevelAgentBrowser(AgentBrowser):
# Check if we have to move categories # Check if we have to move categories
old_cat_iter = self.model.iter_parent(iter_) old_cat_iter = self.model.iter_parent(iter_)
old_cat = self.model.get_value(old_cat_iter, 3).decode('utf-8') if not old_cat_iter or self.model.get_value(old_cat_iter, 3) == cat:
if self.model.get_value(old_cat_iter, 3) == cat:
# Already in the right category, just update # Already in the right category, just update
self.model[iter_][2] = pix self.model[iter_][2] = pix
self.model[iter_][3] = descr self.model[iter_][3] = descr
@ -1708,6 +1732,7 @@ class ToplevelAgentBrowser(AgentBrowser):
# Not in the right category, move it. # Not in the right category, move it.
self.model.remove(iter_) self.model.remove(iter_)
old_cat = self.model.get_value(old_cat_iter, 3).decode('utf-8')
# Check if the old category is empty # Check if the old category is empty
if not self.model.iter_is_valid(old_cat_iter): if not self.model.iter_is_valid(old_cat_iter):
old_cat_iter = self._find_category(old_cat) old_cat_iter = self._find_category(old_cat)