summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core.py5
-rw-r--r--src/core/handlers.py53
2 files changed, 57 insertions, 1 deletions
diff --git a/src/core/core.py b/src/core/core.py
index d53782b5..88d8ea80 100644
--- a/src/core/core.py
+++ b/src/core/core.py
@@ -1891,6 +1891,11 @@ class Core(object):
outgoing_stanza = handlers.outgoing_stanza
incoming_stanza = handlers.incoming_stanza
validate_ssl = handlers.validate_ssl
+ on_next_adhoc_step = handlers.on_next_adhoc_step
+ on_adhoc_error = handlers.on_adhoc_error
+ cancel_adhoc_command = handlers.cancel_adhoc_command
+ validate_adhoc_step = handlers.validate_adhoc_step
+ terminate_adhoc_command = handlers.terminate_adhoc_command
command_help = commands.command_help
command_runkey = commands.command_runkey
command_status = commands.command_status
diff --git a/src/core/handlers.py b/src/core/handlers.py
index 45a4ff2a..525613aa 100644
--- a/src/core/handlers.py
+++ b/src/core/handlers.py
@@ -1098,7 +1098,6 @@ def validate_ssl(self, pem):
if not config.silent_set('certificate', found_cert):
self.information(_('Unable to write in the config file'), 'Error')
-
def _composing_tab_state(tab, state):
"""
Set a tab state to or from the "composing" state
@@ -1125,4 +1124,56 @@ def _composing_tab_state(tab, state):
elif tab.state == 'composing' and state != 'composing':
tab.restore_state()
+### Ad-hoc commands
+def on_next_adhoc_step(self, iq, adhoc_session):
+ status = iq['command']['status']
+ xform = iq.xml.find('{http://jabber.org/protocol/commands}command/{jabber:x:data}x')
+ if xform is not None:
+ form = self.xmpp.plugin['xep_0004'].buildForm(xform)
+ else:
+ form = None
+
+ if status == 'error':
+ return self.information("An error occured while executing the command")
+
+ if status == 'executing':
+ if not form:
+ self.information("Adhoc command step does not contain a data-form. Aborting the execution.", "Error")
+ return self.xmpp.plugin['xep_0050'].cancel_command(adhoc_session)
+ on_validate = self.validate_adhoc_step
+ on_cancel = self.cancel_adhoc_command
+ if status == 'completed':
+ on_validate = lambda form, session: self.close_tab()
+ on_cancel = lambda form, session: self.close_tab()
+
+ # If a form is available, use it, and add the Notes from the
+ # response to it, if any
+ if form:
+ for note in iq['command']['notes']:
+ form.add_field(type='fixed', label=note[1])
+ self.open_new_form(form, on_cancel, on_validate,
+ session=adhoc_session)
+ else: # otherwise, just display an information
+ # message
+ notes = '\n'.join([note[1] for note in iq['command']['notes']])
+ self.information("Adhoc command %s: %s" % (status, notes), "Info")
+
+def on_adhoc_error(self, iq, adhoc_session):
+ self.xmpp.plugin['xep_0050'].terminate_command(session)
+ error_message = self.get_error_message(iq)
+ self.information("An error occured while executing the command: %s" % (error_message),
+ 'Error')
+
+def cancel_adhoc_command(self, form, session):
+ self.xmpp.plugin['xep_0050'].cancel_command(session)
+ self.close_tab()
+
+def validate_adhoc_step(self, form, session):
+ session['payload'] = form
+ self.xmpp.plugin['xep_0050'].continue_command(session)
+ self.close_tab()
+
+def terminate_adhoc_command(self, form, session):
+ self.xmpp.plugin['xep_0050'].terminate_command(session)
+ self.close_tab()