get correctly parent node when browsing pubsub. Fixes #3438

This commit is contained in:
Yann Leboulanger 2009-09-06 20:59:42 +02:00
parent 3f366db009
commit b8f0732de7
1 changed files with 25 additions and 20 deletions

View File

@ -34,7 +34,7 @@
# - def update_actions(self) # - def update_actions(self)
# - def default_action(self) # - def default_action(self)
# - def _find_item(self, jid, node) # - def _find_item(self, jid, node)
# - def _add_item(self, jid, node, item, force) # - def _add_item(self, jid, node, parent_node, item, force)
# - def _update_item(self, iter_, jid, node, item) # - def _update_item(self, iter_, jid, node, item)
# - def _update_info(self, iter_, jid, node, identities, features, data) # - def _update_info(self, iter_, jid, node, identities, features, data)
# - def _update_error(self, iter_, jid, node) # - def _update_error(self, iter_, jid, node)
@ -963,13 +963,13 @@ _('This service does not contain any items to browse.'))
# We got a list of items # We got a list of items
self.window.services_treeview.set_model(None) self.window.services_treeview.set_model(None)
for item in items: for item in items:
jid = item['jid'] jid_ = item['jid']
node = item.get('node', '') node_ = item.get('node', '')
# If such an item is already here: don't add it # If such an item is already here: don't add it
if self._find_item(jid, node): if self._find_item(jid_, node_):
continue continue
self._total_items += 1 self._total_items += 1
self._add_item(jid, node, item, force) self._add_item(jid_, node_, node, item, force)
self.window.services_treeview.set_model(self.model) self.window.services_treeview.set_model(self.model)
def _agent_info(self, jid, node, identities, features, data): def _agent_info(self, jid, node, identities, features, data):
@ -986,7 +986,7 @@ _('This service does not contain any items to browse.'))
self._update_info(iter_, jid, node, identities, features, data) self._update_info(iter_, jid, node, identities, features, data)
self.update_actions() self.update_actions()
def _add_item(self, jid, node, item, force): def _add_item(self, jid, node, parent_node, item, force):
'''Called when an item should be added to the model. The result of a '''Called when an item should be added to the model. The result of a
disco#items query.''' disco#items query.'''
self.model.append((jid, node, item.get('name', ''), self.model.append((jid, node, item.get('name', ''),
@ -1462,7 +1462,7 @@ class ToplevelAgentBrowser(AgentBrowser):
return iter_ return iter_
return None return None
def _add_item(self, jid, node, item, force): def _add_item(self, jid, node, parent_node, item, force):
# Row text # Row text
addr = get_agent_address(jid, node) addr = get_agent_address(jid, node)
if 'name' in item: if 'name' in item:
@ -1486,10 +1486,10 @@ class ToplevelAgentBrowser(AgentBrowser):
cat = self._find_category(*cat_args) cat = self._find_category(*cat_args)
if not cat: if not cat:
cat = self._create_category(*cat_args) cat = self._create_category(*cat_args)
self.model.append(cat, (item['jid'], item.get('node', ''), pix, descr, 1)) self.model.append(cat, (jid, node, pix, descr, 1))
self._expand_all() self._expand_all()
# Grab info on the service # Grab info on the service
self.cache.get_info(jid, node, self._agent_info, force = force) self.cache.get_info(jid, node, self._agent_info, force=force)
self._update_progressbar() self._update_progressbar()
def _update_item(self, iter_, jid, node, item): def _update_item(self, iter_, jid, node, item):
@ -1778,7 +1778,7 @@ class MucBrowser(AgentBrowser):
self._fetch_source = None self._fetch_source = None
self._query_visible() self._query_visible()
def _add_item(self, jid, node, item, force): def _add_item(self, jid, node, parent_node, item, force):
self.model.append((jid, node, item.get('name', ''), -1, '', '', False)) self.model.append((jid, node, item.get('name', ''), -1, '', '', False))
if not self._fetch_source: if not self._fetch_source:
self._fetch_source = gobject.idle_add(self._start_info_query) self._fetch_source = gobject.idle_add(self._start_info_query)
@ -1876,10 +1876,10 @@ class DiscussionGroupsBrowser(AgentBrowser):
def _add_items(self, jid, node, items, force): def _add_items(self, jid, node, items, force):
for item in items: for item in items:
jid = item['jid'] jid_ = item['jid']
node = item.get('node', '') node_ = item.get('node', '')
self._total_items += 1 self._total_items += 1
self._add_item(jid, node, item, force) self._add_item(jid_, node_, node, item, force)
def _in_list_foreach(self, model, path, iter_, node): def _in_list_foreach(self, model, path, iter_, node):
if model[path][1] == node: if model[path][1] == node:
@ -1890,7 +1890,7 @@ class DiscussionGroupsBrowser(AgentBrowser):
self.model.foreach(self._in_list_foreach, node) self.model.foreach(self._in_list_foreach, node)
return self.in_list return self.in_list
def _add_item(self, jid, node, item, force): def _add_item(self, jid, node, parent_node, item, force):
''' Called when we got basic information about new node from query. ''' Called when we got basic information about new node from query.
Show the item. ''' Show the item. '''
name = item.get('name', '') name = item.get('name', '')
@ -1905,12 +1905,7 @@ class DiscussionGroupsBrowser(AgentBrowser):
name = gobject.markup_escape_text(name) name = gobject.markup_escape_text(name)
name = '<b>%s</b>' % name name = '<b>%s</b>' % name
node_splitted = node.split('/') parent_iter = self._get_iter(parent_node)
parent_iter = None
while len(node_splitted) > 1:
parent_node = node_splitted.pop(0)
parent_iter = self._get_child_iter(parent_iter, parent_node)
node_splitted[0] = parent_node + '/' + node_splitted[0]
if not self._in_list(node): if not self._in_list(node):
self.model.append(parent_iter, (jid, node, name, dunno, subscribed)) self.model.append(parent_iter, (jid, node, name, dunno, subscribed))
self.cache.get_items(jid, node, self._add_items, force = force, self.cache.get_items(jid, node, self._add_items, force = force,
@ -1924,6 +1919,16 @@ class DiscussionGroupsBrowser(AgentBrowser):
child_iter = self.model.iter_next(child_iter) child_iter = self.model.iter_next(child_iter)
return None return None
def _get_iter(self, node):
''' Look for an iter with the given node '''
self.found_iter = None
def is_node(model, path, iter, node):
if model[iter][1] == node:
self.found_iter = iter
return True
self.model.foreach(is_node, node)
return self.found_iter
def _add_actions(self): def _add_actions(self):
self.post_button = gtk.Button(label=_('New post'), use_underline=True) self.post_button = gtk.Button(label=_('New post'), use_underline=True)
self.post_button.set_sensitive(False) self.post_button.set_sensitive(False)