summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/connection.py1
-rw-r--r--src/core/commands.py16
-rw-r--r--src/core/core.py4
-rw-r--r--src/tabs/__init__.py1
-rw-r--r--src/tabs/adhoc_commands_list.py57
5 files changed, 79 insertions, 0 deletions
diff --git a/src/connection.py b/src/connection.py
index 649cd0a2..a0e9a395 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -79,6 +79,7 @@ class Connection(sleekxmpp.ClientXMPP):
self.register_plugin('xep_0030')
self.register_plugin('xep_0045')
self.register_plugin('xep_0048')
+ self.register_plugin('xep_0050')
self.register_plugin('xep_0060')
self.register_plugin('xep_0066')
self.register_plugin('xep_0071')
diff --git a/src/core/commands.py b/src/core/commands.py
index d4df1099..c2e453e9 100644
--- a/src/core/commands.py
+++ b/src/core/commands.py
@@ -940,6 +940,22 @@ def command_xml_tab(self, arg=''):
tab = tabs.XMLTab()
self.add_tab(tab, True)
+def command_adhoc(self, arg):
+ arg = arg.split()
+ if len(arg) > 1:
+ return self.command_help('list')
+ elif arg:
+ jid = safeJID(arg[0]).server
+ else:
+ return self.information('Please provide a jid', 'Error')
+ list_tab = tabs.AdhocCommandsListTab(jid)
+ self.add_tab(list_tab, True)
+ cb = list_tab.on_list_received
+ self.xmpp.plugin['xep_0050'].get_commands(jid=jid,
+ local=False,
+ block=False,
+ callback=cb)
+
def command_self(self, arg=None):
"""
/self
diff --git a/src/core/core.py b/src/core/core.py
index d49845dc..d53782b5 100644
--- a/src/core/core.py
+++ b/src/core/core.py
@@ -1809,6 +1809,9 @@ class Core(object):
desc=_('Informs you of the last activity of a JID.'),
shortdesc=_('Get the activity of someone.'),
completion=self.completion_last_activity)
+ self.register_command('ad-hoc', self.command_adhoc,
+ usage='<jid>',
+ shortdesc=_('List available ad-hoc commands on the given jid'))
if config.get('enable_user_activity', True):
self.register_command('activity', self.command_activity,
@@ -1921,6 +1924,7 @@ class Core(object):
command_plugins = commands.command_plugins
command_message = commands.command_message
command_xml_tab = commands.command_xml_tab
+ command_adhoc = commands.command_adhoc
command_self = commands.command_self
completion_help = completions.completion_help
completion_status = completions.completion_status
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()