summaryrefslogtreecommitdiff
path: root/src/tabs
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-05-04 18:23:10 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-05-04 21:05:47 +0200
commitbbc55fa40eaaed6bb57fddd2e9cc5eb1d3baa8cc (patch)
tree4ad7c355a84617e7f42f71e569665faf9d7db173 /src/tabs
parent36620901e85a02fec31256b30eec55c754c80e85 (diff)
downloadpoezio-bbc55fa40eaaed6bb57fddd2e9cc5eb1d3baa8cc.tar.gz
poezio-bbc55fa40eaaed6bb57fddd2e9cc5eb1d3baa8cc.tar.bz2
poezio-bbc55fa40eaaed6bb57fddd2e9cc5eb1d3baa8cc.tar.xz
poezio-bbc55fa40eaaed6bb57fddd2e9cc5eb1d3baa8cc.zip
Add the /ad-hoc <jid> command to list commands of the given jid
Diffstat (limited to 'src/tabs')
-rw-r--r--src/tabs/__init__.py1
-rw-r--r--src/tabs/adhoc_commands_list.py57
2 files changed, 58 insertions, 0 deletions
diff --git a/src/tabs/__init__.py b/src/tabs/__init__.py
index 8826ede2..5f09bf38 100644
--- a/src/tabs/__init__.py
+++ b/src/tabs/__init__.py
@@ -8,4 +8,5 @@ from . conversationtab import ConversationTab, StaticConversationTab,\
from . xmltab import XMLTab
from . listtab import ListTab
from . muclisttab import MucListTab
+from . adhoc_commands_list import AdhocCommandsListTab
from . data_forms import DataFormsTab
diff --git a/src/tabs/adhoc_commands_list.py b/src/tabs/adhoc_commands_list.py
new file mode 100644
index 00000000..d0504677
--- /dev/null
+++ b/src/tabs/adhoc_commands_list.py
@@ -0,0 +1,57 @@
+"""
+A tab listing the ad-hoc commands on a specific JID. The user can
+select one of them and start executing it, or just close the tab and do
+nothing.
+"""
+
+from gettext import gettext as _
+
+import logging
+log = logging.getLogger(__name__)
+
+from . import ListTab
+
+from sleekxmpp.plugins.xep_0030.stanza.items import DiscoItem
+
+class AdhocCommandsListTab(ListTab):
+ plugin_commands = {}
+ plugin_keys = {}
+
+ def __init__(self, jid):
+ ListTab.__init__(self, jid,
+ "“Enter”: execute selected command.",
+ _('Ad-hoc commands of JID %s (Loading)') % jid,
+ (('Node', 0), ('Description', 1)))
+ self.key_func['^M'] = self.execute_selected_command
+
+ def execute_selected_command(self):
+ row = self.listview.get_selected_row()
+ log.debug("Executing command %s", row)
+
+ def get_columns_sizes(self):
+ return {'Node': int(self.width * 2 / 8),
+ 'Description': int(self.width * 6 / 8)}
+
+ def on_list_received(self, iq):
+ """
+ Fill the listview with the value from the received iq
+ """
+ if iq['type'] == 'error':
+ self.set_error(iq['error']['type'], iq['error']['code'], iq['error']['text'])
+ return
+ log.debug("iq: %s", iq)
+ def get_items():
+ substanza = iq['disco_items']
+ for item in substanza['substanzas']:
+ if isinstance(item, DiscoItem):
+ yield item
+ items = [(item['node'], item['name'] or '', item['jid']) for item in get_items()]
+ log.debug(items)
+ self.listview.set_lines(items)
+ self.info_header.message = _('Ad-hoc commands of JID %s') % self.name
+ if self.core.current_tab() is self:
+ self.refresh()
+ else:
+ self.state = 'highlight'
+ self.refresh_tab_win()
+ self.core.doupdate()