summaryrefslogtreecommitdiff
path: root/plugins/reorder.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/reorder.py')
-rw-r--r--plugins/reorder.py44
1 files changed, 32 insertions, 12 deletions
diff --git a/plugins/reorder.py b/plugins/reorder.py
index 8d9516f8..158b89bb 100644
--- a/plugins/reorder.py
+++ b/plugins/reorder.py
@@ -59,6 +59,8 @@ And finally, the ``[tab name]`` must be:
- For a type ``static``, the full JID of the contact
"""
+from slixmpp import InvalidJID, JID
+
from poezio import tabs
from poezio.decorators import command_args_parser
from poezio.plugin import BasePlugin
@@ -90,7 +92,11 @@ def parse_config(tab_config):
if pos in result or pos <= 0:
return None
- typ, name = tab_config.get(option, default=':').split(':', maxsplit=1)
+ spec = tab_config.get(option, default=':').split(':', maxsplit=1)
+ # Gap tabs are recreated automatically if there's a gap in indices.
+ if spec == 'empty':
+ return None
+ typ, name = spec
if typ not in TEXT_TO_TAB:
return None
result[pos] = (TEXT_TO_TAB[typ], name)
@@ -111,7 +117,8 @@ def parse_runtime_tablist(tablist):
for tab in tablist[1:]:
i += 1
result = check_tab(tab)
- if result:
+ # Don't serialize gap tabs as they're recreated automatically
+ if result != 'empty' and isinstance(tab, tuple(TEXT_TO_TAB.values())):
props.append((i, '%s:%s' % (result, tab.jid.full)))
return props
@@ -160,23 +167,36 @@ class Plugin(BasePlugin):
for pos in sorted(tabs_spec):
if create_gaps and pos > last + 1:
new_tabs += [
- tabs.GapTab(self.core) for i in range(pos - last - 1)
+ tabs.GapTab() for i in range(pos - last - 1)
]
- cls, name = tabs_spec[pos]
- tab = self.core.tabs.by_name_and_class(name, cls=cls)
- if tab and tab in old_tabs:
- new_tabs.append(tab)
- old_tabs.remove(tab)
- else:
- self.api.information('Tab %s not found' % name, 'Warning')
+ cls, jid = tabs_spec[pos]
+ try:
+ jid = JID(jid)
+ tab = self.core.tabs.by_name_and_class(str(jid), cls=cls)
+ if tab and tab in old_tabs:
+ new_tabs.append(tab)
+ old_tabs.remove(tab)
+ else:
+ # TODO: Add support for MucTab. Requires nickname.
+ if cls in (tabs.DynamicConversationTab, tabs.StaticConversationTab):
+ self.api.information('Tab %s not found. Creating it' % jid, 'Warning')
+ new_tab = cls(self.core, jid)
+ new_tabs.append(new_tab)
+ else:
+ new_tabs.append(tabs.GapTab())
+ except:
+ self.api.information('Failed to create tab \'%s\'.' % jid, 'Error')
if create_gaps:
- new_tabs.append(tabs.GapTab(self.core))
- last = pos
+ new_tabs.append(tabs.GapTab())
+ finally:
+ last = pos
for tab in old_tabs:
if tab:
new_tabs.append(tab)
+ # TODO: Ensure we don't break poezio and call this with whatever
+ # tablist we have. The roster tab at least needs to be in there.
self.core.tabs.replace_tabs(new_tabs)
self.core.refresh_window()