2014-05-04 16:23:10 +00:00
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
2018-08-15 12:21:59 +00:00
|
|
|
from typing import Dict, Callable
|
2014-05-04 16:23:10 +00:00
|
|
|
|
2016-06-30 21:36:25 +00:00
|
|
|
from poezio.tabs import ListTab
|
2018-08-15 12:21:59 +00:00
|
|
|
from poezio.core.structs import Command
|
2014-05-04 16:23:10 +00:00
|
|
|
|
2014-07-24 00:07:08 +00:00
|
|
|
from slixmpp.plugins.xep_0030.stanza.items import DiscoItem
|
2014-05-04 16:23:10 +00:00
|
|
|
|
2018-08-15 12:21:59 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2017-11-12 14:03:09 +00:00
|
|
|
|
2014-05-04 16:23:10 +00:00
|
|
|
class AdhocCommandsListTab(ListTab):
|
2018-08-15 12:21:59 +00:00
|
|
|
plugin_commands = {} # type: Dict[str, Command]
|
|
|
|
plugin_keys = {} # type: Dict[str, Callable]
|
2014-05-04 16:23:10 +00:00
|
|
|
|
2016-06-30 21:57:12 +00:00
|
|
|
def __init__(self, core, jid):
|
2017-11-12 14:03:09 +00:00
|
|
|
ListTab.__init__(
|
|
|
|
self, core, jid.full, "“Enter”: execute selected command.",
|
|
|
|
'Ad-hoc commands of JID %s (Loading)' % jid, (('Node', 0),
|
|
|
|
('Description', 1)))
|
2014-05-04 16:23:10 +00:00
|
|
|
self.key_func['^M'] = self.execute_selected_command
|
|
|
|
|
|
|
|
def execute_selected_command(self):
|
2014-07-05 22:08:43 +00:00
|
|
|
if not self.listview or not self.listview.get_selected_row():
|
|
|
|
return
|
2014-05-04 18:44:10 +00:00
|
|
|
node, name, jid = self.listview.get_selected_row()
|
2017-11-12 14:03:09 +00:00
|
|
|
session = {
|
|
|
|
'next': self.core.handler.next_adhoc_step,
|
|
|
|
'error': self.core.handler.adhoc_error
|
|
|
|
}
|
2014-05-04 18:44:10 +00:00
|
|
|
self.core.xmpp.plugin['xep_0050'].start_command(jid, node, session)
|
2014-05-04 16:23:10 +00:00
|
|
|
|
|
|
|
def get_columns_sizes(self):
|
2017-11-12 14:03:09 +00:00
|
|
|
return {
|
|
|
|
'Node': int(self.width * 3 / 8),
|
|
|
|
'Description': int(self.width * 5 / 8)
|
|
|
|
}
|
2014-05-04 16:23:10 +00:00
|
|
|
|
|
|
|
def on_list_received(self, iq):
|
|
|
|
"""
|
|
|
|
Fill the listview with the value from the received iq
|
|
|
|
"""
|
|
|
|
if iq['type'] == 'error':
|
2017-11-12 14:03:09 +00:00
|
|
|
self.set_error(iq['error']['type'], iq['error']['code'],
|
|
|
|
iq['error']['text'])
|
2014-05-04 16:23:10 +00:00
|
|
|
return
|
2017-11-12 14:03:09 +00:00
|
|
|
|
2014-05-04 16:23:10 +00:00
|
|
|
def get_items():
|
|
|
|
substanza = iq['disco_items']
|
|
|
|
for item in substanza['substanzas']:
|
|
|
|
if isinstance(item, DiscoItem):
|
|
|
|
yield item
|
2017-11-12 14:03:09 +00:00
|
|
|
|
|
|
|
items = [(item['node'], item['name'] or '', item['jid'])
|
|
|
|
for item in get_items()]
|
2014-05-04 16:23:10 +00:00
|
|
|
self.listview.set_lines(items)
|
2015-05-10 08:37:00 +00:00
|
|
|
self.info_header.message = 'Ad-hoc commands of JID %s' % self.name
|
2018-06-29 19:18:09 +00:00
|
|
|
if self.core.tabs.current_tab is self:
|
2014-05-04 16:23:10 +00:00
|
|
|
self.refresh()
|
|
|
|
else:
|
|
|
|
self.state = 'highlight'
|
|
|
|
self.refresh_tab_win()
|
|
|
|
self.core.doupdate()
|