2006-06-23 00:49:39 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/adhoc_commands.py
|
2006-06-23 00:49:39 +02:00
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2006 Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
## Copyright (C) 2006-2007 Tomasz Melcer <liori AT exroot.org>
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
|
|
|
|
## Stephan Erb <steve-e AT h3c.de>
|
2006-06-23 00:49:39 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2006-06-23 00:49:39 +02:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2006-06-23 00:49:39 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2006-06-23 00:49:39 +02:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2006-06-23 00:49:39 +02:00
|
|
|
## GNU General Public License for more details.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
2006-06-23 00:49:39 +02:00
|
|
|
|
2006-12-16 18:44:59 +01:00
|
|
|
# FIXME: think if we need caching command list. it may be wrong if there will
|
|
|
|
# be entities that often change the list, it may be slow to fetch it every time
|
2006-06-23 16:38:54 +02:00
|
|
|
|
2013-07-28 20:50:30 +02:00
|
|
|
from gi.repository import GLib
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import Gtk
|
2006-06-23 00:49:39 +02:00
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
import nbxmpp
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import dataforms
|
2006-06-23 16:38:54 +02:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import gtkgui_helpers
|
|
|
|
from gajim import dialogs
|
|
|
|
from gajim import dataforms_widget
|
2006-06-23 00:49:39 +02:00
|
|
|
|
|
|
|
class CommandWindow:
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Class for a window for single ad-hoc commands session
|
|
|
|
|
|
|
|
Note, that there might be more than one for one account/jid pair in one
|
|
|
|
moment.
|
|
|
|
|
|
|
|
TODO: Maybe put this window into MessageWindow? consider this when it will
|
|
|
|
be possible to manage more than one window of one.
|
|
|
|
TODO: Account/jid pair in MessageWindowMgr.
|
|
|
|
TODO: GTK 2.10 has a special wizard-widget, consider using it...
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, account, jid, commandnode=None):
|
|
|
|
"""
|
|
|
|
Create new window
|
|
|
|
"""
|
|
|
|
|
|
|
|
# an account object
|
2017-08-13 13:18:56 +02:00
|
|
|
self.account = app.connections[account]
|
2010-02-08 15:08:40 +01:00
|
|
|
self.jid = jid
|
|
|
|
self.commandnode = commandnode
|
2010-05-12 10:18:52 +02:00
|
|
|
self.data_form_widget = None
|
2017-08-24 15:41:39 +02:00
|
|
|
self.stage_finish_cb = None
|
|
|
|
self.stage_back_button_cb = None
|
|
|
|
self.stage_forward_button_cb = None
|
|
|
|
self.stage_execute_button_cb = None
|
|
|
|
self.stage_close_button_cb = None
|
|
|
|
self.stage_restart_button_cb = None
|
|
|
|
self.stage_window_delete_cb = None
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# retrieving widgets from xml
|
|
|
|
self.xml = gtkgui_helpers.get_gtk_builder('adhoc_commands_window.ui')
|
|
|
|
self.window = self.xml.get_object('adhoc_commands_window')
|
2010-02-10 15:29:50 +01:00
|
|
|
self.window.connect('delete-event',
|
|
|
|
self.on_adhoc_commands_window_delete_event)
|
2010-05-12 10:18:52 +02:00
|
|
|
for name in ('restart_button', 'back_button', 'forward_button',
|
2010-07-22 17:55:52 +02:00
|
|
|
'execute_button', 'finish_button', 'close_button', 'stages_notebook',
|
2018-06-24 00:57:10 +02:00
|
|
|
'retrieving_commands_stage_vbox', 'retrieving_commands_spinner',
|
|
|
|
'command_list_stage_vbox', 'command_treeview',
|
|
|
|
'sending_form_stage_vbox', 'sending_form_spinner',
|
|
|
|
'notes_label', 'no_commands_stage_vbox',
|
2010-07-22 17:55:52 +02:00
|
|
|
'error_stage_vbox', 'error_description_label'):
|
|
|
|
setattr(self, name, self.xml.get_object(name))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-06-23 00:59:14 +02:00
|
|
|
self.command_store = Gtk.ListStore(str, str)
|
|
|
|
self.command_treeview.set_model(self.command_store)
|
|
|
|
renderer = Gtk.CellRendererText()
|
|
|
|
column = Gtk.TreeViewColumn("Command", renderer, text=0)
|
|
|
|
self.command_treeview.append_column(column)
|
|
|
|
|
2010-05-12 10:18:52 +02:00
|
|
|
self.initiate()
|
|
|
|
|
|
|
|
def initiate(self):
|
|
|
|
|
|
|
|
self.commandlist = None # a list of (commandname, commanddescription)
|
|
|
|
|
|
|
|
# command's data
|
|
|
|
self.sessionid = None
|
|
|
|
self.dataform = None
|
|
|
|
self.allow_stage3_close = False
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# creating data forms widget
|
2010-05-12 10:18:52 +02:00
|
|
|
if self.data_form_widget:
|
|
|
|
self.sending_form_stage_vbox.remove(self.data_form_widget)
|
|
|
|
self.data_form_widget.destroy()
|
2010-02-08 15:08:40 +01:00
|
|
|
self.data_form_widget = dataforms_widget.DataFormWidget()
|
|
|
|
self.data_form_widget.show()
|
2012-12-23 16:23:43 +01:00
|
|
|
self.sending_form_stage_vbox.pack_start(self.data_form_widget, True, True, 0)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if self.commandnode:
|
|
|
|
# Execute command
|
|
|
|
self.stage3()
|
|
|
|
else:
|
|
|
|
# setting initial stage
|
|
|
|
self.stage1()
|
|
|
|
|
|
|
|
# displaying the window
|
2012-02-14 20:42:32 +01:00
|
|
|
self.window.set_title(_('Ad-hoc Commands - Gajim'))
|
2010-02-08 15:08:40 +01:00
|
|
|
self.xml.connect_signals(self)
|
|
|
|
self.window.show_all()
|
|
|
|
|
2010-05-12 10:18:52 +02:00
|
|
|
self.restart_button.set_sensitive(False)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# These functions are set up by appropriate stageX methods.
|
|
|
|
def stage_finish(self, *anything):
|
2017-08-24 15:41:39 +02:00
|
|
|
if self.stage_finish_cb:
|
|
|
|
self.stage_finish_cb(*anything)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# Widget callbacks...
|
|
|
|
def on_back_button_clicked(self, *anything):
|
2017-08-24 15:41:39 +02:00
|
|
|
if self.stage_back_button_cb:
|
|
|
|
return self.stage_back_button_cb(*anything)
|
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_forward_button_clicked(self, *anything):
|
2017-08-24 15:41:39 +02:00
|
|
|
if self.stage_forward_button_cb:
|
|
|
|
return self.stage_forward_button_cb(*anything)
|
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_execute_button_clicked(self, *anything):
|
2017-08-24 15:41:39 +02:00
|
|
|
if self.stage_execute_button_cb:
|
|
|
|
return self.stage_execute_button_cb(*anything)
|
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2010-07-21 20:15:47 +02:00
|
|
|
def on_finish_button_clicked(self, *anything):
|
2017-08-24 15:41:39 +02:00
|
|
|
if self.stage_finish_button_cb:
|
|
|
|
return self.stage_finish_button_cb(*anything)
|
|
|
|
return False
|
2010-07-21 20:15:47 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_close_button_clicked(self, *anything):
|
2017-08-24 15:41:39 +02:00
|
|
|
if self.stage_close_button_cb:
|
|
|
|
return self.stage_close_button_cb(*anything)
|
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2010-08-10 17:03:29 +02:00
|
|
|
def on_restart_button_clicked(self, *anything):
|
2017-08-24 15:41:39 +02:00
|
|
|
if self.stage_restart_button_cb:
|
|
|
|
return self.stage_restart_button_cb(*anything)
|
|
|
|
return False
|
2010-08-10 17:03:29 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_adhoc_commands_window_destroy(self, *anything):
|
2010-02-10 15:29:50 +01:00
|
|
|
# TODO: do all actions that are needed to remove this object from memory
|
2018-06-24 00:57:10 +02:00
|
|
|
pass
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_adhoc_commands_window_delete_event(self, *anything):
|
2017-08-24 15:41:39 +02:00
|
|
|
if self.stage_window_delete_cb:
|
|
|
|
return self.stage_window_delete_cb(self.window)
|
|
|
|
return False
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def __del__(self):
|
2013-01-01 19:36:56 +01:00
|
|
|
print('Object has been deleted.')
|
2006-07-09 19:55:56 +02:00
|
|
|
|
2006-06-23 16:38:54 +02:00
|
|
|
# stage 1: waiting for command list
|
2010-02-08 15:08:40 +01:00
|
|
|
def stage1(self):
|
|
|
|
"""
|
|
|
|
Prepare the first stage. Request command list, set appropriate state of
|
|
|
|
widgets
|
|
|
|
"""
|
|
|
|
# close old stage...
|
|
|
|
self.stage_finish()
|
|
|
|
|
|
|
|
# show the stage
|
|
|
|
self.stages_notebook.set_current_page(
|
|
|
|
self.stages_notebook.page_num(
|
|
|
|
self.retrieving_commands_stage_vbox))
|
|
|
|
|
|
|
|
# set widgets' state
|
|
|
|
self.close_button.set_sensitive(True)
|
|
|
|
self.back_button.set_sensitive(False)
|
|
|
|
self.forward_button.set_sensitive(False)
|
|
|
|
self.execute_button.set_sensitive(False)
|
2010-07-21 20:15:47 +02:00
|
|
|
self.finish_button.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# request command list
|
|
|
|
self.request_command_list()
|
2018-06-24 00:57:10 +02:00
|
|
|
self.retrieving_commands_spinner.start()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# setup the callbacks
|
2017-08-24 15:41:39 +02:00
|
|
|
self.stage_finish_cb = self.stage1_finish
|
|
|
|
self.stage_close_button_cb = self.stage1_close_button_clicked
|
|
|
|
self.stage_restart_button_cb = self.stage1_restart_button_clicked
|
|
|
|
self.stage_window_delete_cb = \
|
2010-02-10 15:29:50 +01:00
|
|
|
self.stage1_adhoc_commands_window_delete_event
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def stage1_finish(self):
|
2018-06-24 00:57:10 +02:00
|
|
|
self.retrieving_commands_spinner.stop()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def stage1_close_button_clicked(self, widget):
|
|
|
|
# cancelling in this stage is not critical, so we don't
|
|
|
|
# show any popups to user
|
2010-08-10 17:03:29 +02:00
|
|
|
self.stage_finish()
|
2010-02-08 15:08:40 +01:00
|
|
|
self.window.destroy()
|
|
|
|
|
2010-08-10 17:03:29 +02:00
|
|
|
def stage1_restart_button_clicked(self, widget):
|
|
|
|
self.stage_finish()
|
|
|
|
self.restart()
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def stage1_adhoc_commands_window_delete_event(self, widget):
|
|
|
|
self.stage1_finish()
|
|
|
|
return True
|
2006-06-25 19:03:59 +02:00
|
|
|
|
2006-06-23 16:38:54 +02:00
|
|
|
# stage 2: choosing the command to execute
|
2010-02-08 15:08:40 +01:00
|
|
|
def stage2(self):
|
|
|
|
"""
|
2018-06-23 00:59:14 +02:00
|
|
|
Populate the command list
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
# close old stage
|
|
|
|
self.stage_finish()
|
|
|
|
|
|
|
|
assert len(self.commandlist)>0
|
|
|
|
|
|
|
|
self.stages_notebook.set_current_page(
|
2010-02-10 15:29:50 +01:00
|
|
|
self.stages_notebook.page_num(self.command_list_stage_vbox))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.close_button.set_sensitive(True)
|
|
|
|
self.back_button.set_sensitive(False)
|
|
|
|
self.forward_button.set_sensitive(True)
|
|
|
|
self.execute_button.set_sensitive(False)
|
2010-07-21 20:15:47 +02:00
|
|
|
self.finish_button.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-06-23 00:59:14 +02:00
|
|
|
# build the commands list
|
|
|
|
self.command_store.clear()
|
2010-02-08 15:08:40 +01:00
|
|
|
for (commandnode, commandname) in self.commandlist:
|
2018-06-23 00:59:14 +02:00
|
|
|
self.command_store.append([commandname, commandnode])
|
|
|
|
self.command_treeview.get_selection().select_iter(self.command_store.get_iter_first())
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-24 15:41:39 +02:00
|
|
|
self.stage_finish_cb = self.stage2_finish
|
|
|
|
self.stage_close_button_cb = self.stage2_close_button_clicked
|
|
|
|
self.stage_restart_button_cb = self.stage2_restart_button_clicked
|
|
|
|
self.stage_forward_button_cb = self.stage2_forward_button_clicked
|
|
|
|
self.stage_window_delete_cb = None
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def stage2_finish(self):
|
|
|
|
"""
|
2018-06-23 00:59:14 +02:00
|
|
|
Save selected command to self.commandnode
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
2018-06-23 00:59:14 +02:00
|
|
|
model, treeiter = self.command_treeview.get_selection().get_selected()
|
|
|
|
self.commandnode = model[treeiter][1]
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def stage2_close_button_clicked(self, widget):
|
|
|
|
self.stage_finish()
|
|
|
|
self.window.destroy()
|
|
|
|
|
2010-08-10 17:03:29 +02:00
|
|
|
def stage2_restart_button_clicked(self, widget):
|
|
|
|
self.stage_finish()
|
|
|
|
self.restart()
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def stage2_forward_button_clicked(self, widget):
|
|
|
|
self.stage3()
|
|
|
|
|
|
|
|
def on_check_commands_1_button_clicked(self, widget):
|
|
|
|
self.stage1()
|
2006-06-23 20:13:35 +02:00
|
|
|
|
2006-06-25 19:03:59 +02:00
|
|
|
# stage 3: command invocation
|
2010-02-08 15:08:40 +01:00
|
|
|
def stage3(self):
|
|
|
|
# close old stage
|
|
|
|
self.stage_finish()
|
|
|
|
|
|
|
|
self.form_status = None
|
|
|
|
|
|
|
|
self.stages_notebook.set_current_page(
|
|
|
|
self.stages_notebook.page_num(
|
|
|
|
self.sending_form_stage_vbox))
|
|
|
|
|
2010-08-10 17:03:29 +02:00
|
|
|
self.restart_button.set_sensitive(True)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.close_button.set_sensitive(True)
|
|
|
|
self.back_button.set_sensitive(False)
|
|
|
|
self.forward_button.set_sensitive(False)
|
|
|
|
self.execute_button.set_sensitive(False)
|
2010-07-21 20:15:47 +02:00
|
|
|
self.finish_button.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.stage3_submit_form()
|
|
|
|
|
2017-08-24 15:41:39 +02:00
|
|
|
self.stage_finish_cb = None
|
|
|
|
self.stage_back_button_cb = self.stage3_back_button_clicked
|
|
|
|
self.stage_forward_button_cb = self.stage3_forward_button_clicked
|
|
|
|
self.stage_execute_button_cb = self.stage3_execute_button_clicked
|
|
|
|
self.stage_finish_button_cb = self.stage3_finish_button_clicked
|
|
|
|
self.stage_close_button_cb = self.stage3_close_button_clicked
|
|
|
|
self.stage_restart_button_cb = self.stage3_restart_button_clicked
|
|
|
|
self.stage_window_delete_cb = self.stage3_close_button_clicked
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2010-08-10 17:03:29 +02:00
|
|
|
def stage3_can_close(self, cb):
|
|
|
|
if self.form_status == 'completed':
|
|
|
|
cb()
|
|
|
|
return
|
|
|
|
|
|
|
|
def on_yes(button):
|
|
|
|
self.send_cancel()
|
|
|
|
dialog.destroy()
|
|
|
|
cb()
|
|
|
|
|
2013-09-03 21:17:36 +02:00
|
|
|
dialog = dialogs.HigDialog(self.window, Gtk.MessageType.WARNING,
|
|
|
|
Gtk.ButtonsType.YES_NO, _('Cancel confirmation'),
|
2010-08-10 17:03:29 +02:00
|
|
|
_('You are in process of executing command. Do you really want to '
|
|
|
|
'cancel it?'), on_response_yes=on_yes)
|
|
|
|
dialog.popup()
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def stage3_close_button_clicked(self, widget):
|
|
|
|
"""
|
|
|
|
We are in the middle of executing command. Ask user if he really want to
|
|
|
|
cancel the process, then cancel it
|
|
|
|
"""
|
2010-02-10 15:29:50 +01:00
|
|
|
# this works also as a handler for window_delete_event, so we have to
|
|
|
|
# return appropriate values
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.allow_stage3_close:
|
|
|
|
return False
|
|
|
|
|
2010-08-10 17:03:29 +02:00
|
|
|
def on_ok():
|
2010-02-08 15:08:40 +01:00
|
|
|
self.allow_stage3_close = True
|
|
|
|
self.window.destroy()
|
|
|
|
|
2010-08-10 17:03:29 +02:00
|
|
|
self.stage3_can_close(on_ok)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
return True # Block event, don't close window
|
|
|
|
|
2010-08-10 17:03:29 +02:00
|
|
|
def stage3_restart_button_clicked(self, widget):
|
|
|
|
def on_ok():
|
|
|
|
self.restart()
|
|
|
|
|
|
|
|
self.stage3_can_close(on_ok)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def stage3_back_button_clicked(self, widget):
|
|
|
|
self.stage3_submit_form('prev')
|
|
|
|
|
|
|
|
def stage3_forward_button_clicked(self, widget):
|
|
|
|
self.stage3_submit_form('next')
|
|
|
|
|
|
|
|
def stage3_execute_button_clicked(self, widget):
|
|
|
|
self.stage3_submit_form('execute')
|
|
|
|
|
2010-07-21 20:15:47 +02:00
|
|
|
def stage3_finish_button_clicked(self, widget):
|
|
|
|
self.stage3_submit_form('complete')
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def stage3_submit_form(self, action='execute'):
|
|
|
|
self.data_form_widget.set_sensitive(False)
|
2010-08-10 16:08:06 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.data_form_widget.get_data_form():
|
2010-08-10 16:08:06 +02:00
|
|
|
df = self.data_form_widget.get_data_form()
|
|
|
|
if not df.is_valid():
|
2017-12-08 20:19:10 +01:00
|
|
|
app.interface.raise_dialog(
|
|
|
|
'invalid-form', transient_for=self.window)
|
2010-08-10 16:08:06 +02:00
|
|
|
self.data_form_widget.set_sensitive(True)
|
|
|
|
return
|
2012-08-22 12:55:57 +02:00
|
|
|
self.data_form_widget.data_form.type_ = 'submit'
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
self.data_form_widget.hide()
|
|
|
|
|
|
|
|
self.close_button.set_sensitive(True)
|
|
|
|
self.back_button.set_sensitive(False)
|
|
|
|
self.forward_button.set_sensitive(False)
|
|
|
|
self.execute_button.set_sensitive(False)
|
2010-07-21 20:15:47 +02:00
|
|
|
self.finish_button.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2018-06-24 00:57:10 +02:00
|
|
|
self.sending_form_spinner.start()
|
2010-02-08 15:08:40 +01:00
|
|
|
self.send_command(action)
|
|
|
|
|
|
|
|
def stage3_next_form(self, command):
|
2012-12-09 21:37:51 +01:00
|
|
|
if not isinstance(command, nbxmpp.Node):
|
2010-02-08 15:08:40 +01:00
|
|
|
self.stage5(error=_('Service sent malformed data'), senderror=True)
|
|
|
|
return
|
|
|
|
|
2018-06-24 00:57:10 +02:00
|
|
|
self.sending_form_spinner.stop()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if not self.sessionid:
|
|
|
|
self.sessionid = command.getAttr('sessionid')
|
|
|
|
elif self.sessionid != command.getAttr('sessionid'):
|
|
|
|
self.stage5(error=_('Service changed the session identifier.'),
|
|
|
|
senderror=True)
|
|
|
|
return
|
|
|
|
|
|
|
|
self.form_status = command.getAttr('status')
|
|
|
|
|
|
|
|
self.commandnode = command.getAttr('node')
|
|
|
|
if command.getTag('x'):
|
|
|
|
self.dataform = dataforms.ExtendForm(node=command.getTag('x'))
|
|
|
|
|
|
|
|
self.data_form_widget.set_sensitive(True)
|
|
|
|
try:
|
2012-04-17 15:23:32 +02:00
|
|
|
self.data_form_widget.selectable = True
|
2010-02-10 15:29:50 +01:00
|
|
|
self.data_form_widget.data_form = self.dataform
|
2010-02-08 15:08:40 +01:00
|
|
|
except dataforms.Error:
|
2010-02-10 15:29:50 +01:00
|
|
|
self.stage5(error=_('Service sent malformed data'),
|
|
|
|
senderror=True)
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
|
|
|
self.data_form_widget.show()
|
|
|
|
if self.data_form_widget.title:
|
2012-02-14 20:42:32 +01:00
|
|
|
self.window.set_title(_('%s - Ad-hoc Commands - Gajim') % \
|
2010-02-08 15:08:40 +01:00
|
|
|
self.data_form_widget.title)
|
|
|
|
else:
|
|
|
|
self.data_form_widget.hide()
|
|
|
|
|
|
|
|
actions = command.getTag('actions')
|
|
|
|
if actions:
|
|
|
|
# actions, actions, actions...
|
|
|
|
self.close_button.set_sensitive(True)
|
|
|
|
self.back_button.set_sensitive(actions.getTag('prev') is not None)
|
2010-02-10 15:29:50 +01:00
|
|
|
self.forward_button.set_sensitive(
|
|
|
|
actions.getTag('next') is not None)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.execute_button.set_sensitive(True)
|
2010-07-21 20:15:47 +02:00
|
|
|
self.finish_button.set_sensitive(actions.getTag('complete') is not \
|
|
|
|
None)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
self.close_button.set_sensitive(True)
|
|
|
|
self.back_button.set_sensitive(False)
|
|
|
|
self.forward_button.set_sensitive(False)
|
|
|
|
self.execute_button.set_sensitive(True)
|
2010-07-21 20:15:47 +02:00
|
|
|
self.finish_button.set_sensitive(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if self.form_status == 'completed':
|
|
|
|
self.close_button.set_sensitive(True)
|
|
|
|
self.back_button.hide()
|
|
|
|
self.forward_button.hide()
|
|
|
|
self.execute_button.hide()
|
2010-07-21 20:15:47 +02:00
|
|
|
self.finish_button.hide()
|
2010-02-08 15:08:40 +01:00
|
|
|
self.close_button.show()
|
2017-08-24 15:41:39 +02:00
|
|
|
self.stage_window_delete_cb = self.stage3_close_button_clicked
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
note = command.getTag('note')
|
|
|
|
if note:
|
2013-01-01 19:44:25 +01:00
|
|
|
self.notes_label.set_text(note.getData())
|
2010-02-08 15:08:40 +01:00
|
|
|
self.notes_label.set_no_show_all(False)
|
|
|
|
self.notes_label.show()
|
|
|
|
else:
|
|
|
|
self.notes_label.set_no_show_all(True)
|
|
|
|
self.notes_label.hide()
|
2006-07-12 16:19:58 +02:00
|
|
|
|
2010-08-10 17:03:29 +02:00
|
|
|
def restart(self):
|
2010-05-12 10:18:52 +02:00
|
|
|
self.commandnode = None
|
|
|
|
self.initiate()
|
|
|
|
|
2006-06-23 20:13:35 +02:00
|
|
|
# stage 4: no commands are exposed
|
2010-02-08 15:08:40 +01:00
|
|
|
def stage4(self):
|
|
|
|
"""
|
|
|
|
Display the message. Wait for user to close the window
|
|
|
|
"""
|
|
|
|
# close old stage
|
|
|
|
self.stage_finish()
|
2006-06-23 20:13:35 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.stages_notebook.set_current_page(
|
2010-02-10 15:29:50 +01:00
|
|
|
self.stages_notebook.page_num(self.no_commands_stage_vbox))
|
2006-06-23 20:13:35 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.close_button.set_sensitive(True)
|
|
|
|
self.back_button.set_sensitive(False)
|
|
|
|
self.forward_button.set_sensitive(False)
|
|
|
|
self.execute_button.set_sensitive(False)
|
2010-07-21 20:15:47 +02:00
|
|
|
self.finish_button.set_sensitive(False)
|
2006-06-23 20:13:35 +02:00
|
|
|
|
2017-08-24 15:41:39 +02:00
|
|
|
self.stage_finish_cb = None
|
|
|
|
self.stage_close_button_cb = self.stage4_close_button_clicked
|
|
|
|
self.stage_restart_button_cb = self.stage4_restart_button_clicked
|
|
|
|
self.stage_window_delete_cb = None
|
2006-06-23 20:13:35 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def stage4_close_button_clicked(self, widget):
|
|
|
|
self.window.destroy()
|
2006-06-23 20:13:35 +02:00
|
|
|
|
2010-08-10 17:03:29 +02:00
|
|
|
def stage4_restart_button_clicked(self, widget):
|
|
|
|
self.restart()
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_check_commands_2_button_clicked(self, widget):
|
|
|
|
self.stage1()
|
2006-06-23 20:13:35 +02:00
|
|
|
|
2018-06-27 00:52:14 +02:00
|
|
|
# stage 5: an error has occurred
|
2010-02-08 15:08:40 +01:00
|
|
|
def stage5(self, error=None, errorid=None, senderror=False):
|
|
|
|
"""
|
|
|
|
Display the error message. Wait for user to close the window
|
|
|
|
"""
|
|
|
|
# FIXME: sending error to responder
|
|
|
|
# close old stage
|
|
|
|
self.stage_finish()
|
|
|
|
|
|
|
|
assert errorid or error
|
|
|
|
|
|
|
|
if errorid:
|
|
|
|
# we've got error code, display appropriate message
|
|
|
|
try:
|
2012-12-09 21:37:51 +01:00
|
|
|
errorname = nbxmpp.NS_STANZAS + ' ' + str(errorid)
|
|
|
|
errordesc = nbxmpp.ERRORS[errorname][2]
|
2013-01-01 19:44:25 +01:00
|
|
|
error = errordesc
|
2010-02-08 15:08:40 +01:00
|
|
|
del errorname, errordesc
|
|
|
|
except KeyError: # when stanza doesn't have error description
|
|
|
|
error = _('Service returned an error.')
|
|
|
|
elif error:
|
|
|
|
# we've got error message
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# we don't know what's that, bailing out
|
|
|
|
assert False
|
|
|
|
|
|
|
|
self.stages_notebook.set_current_page(
|
2010-02-10 15:29:50 +01:00
|
|
|
self.stages_notebook.page_num(self.error_stage_vbox))
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.close_button.set_sensitive(True)
|
|
|
|
self.back_button.hide()
|
|
|
|
self.forward_button.hide()
|
|
|
|
self.execute_button.hide()
|
2010-07-21 20:15:47 +02:00
|
|
|
self.finish_button.hide()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.error_description_label.set_text(error)
|
|
|
|
|
2017-08-24 15:41:39 +02:00
|
|
|
self.stage_finish_cb = None
|
|
|
|
self.stage_close_button_cb = self.stage5_close_button_clicked
|
|
|
|
self.stage_restart_button_cb = self.stage5_restart_button_clicked
|
|
|
|
self.stage_window_delete_cb = None
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def stage5_close_button_clicked(self, widget):
|
|
|
|
self.window.destroy()
|
2006-06-23 20:13:35 +02:00
|
|
|
|
2010-08-10 17:03:29 +02:00
|
|
|
def stage5_restart_button_clicked(self, widget):
|
|
|
|
self.restart()
|
|
|
|
|
2006-06-23 16:38:54 +02:00
|
|
|
# handling xml stanzas
|
2010-02-08 15:08:40 +01:00
|
|
|
def request_command_list(self):
|
|
|
|
"""
|
|
|
|
Request the command list. Change stage on delivery
|
|
|
|
"""
|
2012-12-16 23:53:32 +01:00
|
|
|
query = nbxmpp.Iq(typ='get', to=nbxmpp.JID(self.jid),
|
2012-12-09 21:37:51 +01:00
|
|
|
queryNS=nbxmpp.NS_DISCO_ITEMS)
|
|
|
|
query.setQuerynode(nbxmpp.NS_COMMANDS)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def callback(response):
|
|
|
|
'''Called on response to query.'''
|
|
|
|
# FIXME: move to connection_handlers.py
|
|
|
|
# is error => error stage
|
|
|
|
error = response.getError()
|
|
|
|
if error:
|
2012-12-09 21:37:51 +01:00
|
|
|
# extracting error description
|
|
|
|
self.stage5(errorid=error)
|
2010-02-08 15:08:40 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
# no commands => no commands stage
|
|
|
|
# commands => command selection stage
|
|
|
|
query = response.getTag('query')
|
2012-12-09 21:37:51 +01:00
|
|
|
if query and query.getAttr('node') == nbxmpp.NS_COMMANDS:
|
2010-02-08 15:08:40 +01:00
|
|
|
items = query.getTags('item')
|
|
|
|
else:
|
|
|
|
items = []
|
|
|
|
if len(items)==0:
|
|
|
|
self.commandlist = []
|
|
|
|
self.stage4()
|
|
|
|
else:
|
2010-02-10 15:29:50 +01:00
|
|
|
self.commandlist = [(t.getAttr('node'), t.getAttr('name')) \
|
|
|
|
for t in items]
|
2010-02-08 15:08:40 +01:00
|
|
|
self.stage2()
|
|
|
|
|
|
|
|
self.account.connection.SendAndCallForResponse(query, callback)
|
|
|
|
|
|
|
|
def send_command(self, action='execute'):
|
|
|
|
"""
|
|
|
|
Send the command with data form. Wait for reply
|
|
|
|
"""
|
|
|
|
# create the stanza
|
|
|
|
assert action in ('execute', 'prev', 'next', 'complete')
|
|
|
|
|
2012-12-09 21:37:51 +01:00
|
|
|
stanza = nbxmpp.Iq(typ='set', to=self.jid)
|
|
|
|
cmdnode = stanza.addChild('command', namespace=nbxmpp.NS_COMMANDS,
|
|
|
|
attrs={'node':self.commandnode, 'action':action})
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if self.sessionid:
|
|
|
|
cmdnode.setAttr('sessionid', self.sessionid)
|
|
|
|
|
|
|
|
if self.data_form_widget.data_form:
|
2010-08-10 18:25:45 +02:00
|
|
|
cmdnode.addChild(node=self.data_form_widget.data_form.get_purged())
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def callback(response):
|
|
|
|
# FIXME: move to connection_handlers.py
|
|
|
|
err = response.getError()
|
|
|
|
if err:
|
|
|
|
self.stage5(errorid = err)
|
|
|
|
else:
|
|
|
|
self.stage3_next_form(response.getTag('command'))
|
|
|
|
|
|
|
|
self.account.connection.SendAndCallForResponse(stanza, callback)
|
|
|
|
|
|
|
|
def send_cancel(self):
|
|
|
|
"""
|
|
|
|
Send the command with action='cancel'
|
|
|
|
"""
|
|
|
|
assert self.commandnode
|
|
|
|
if self.sessionid and self.account.connection:
|
|
|
|
# we already have sessionid, so the service sent at least one reply.
|
2012-12-09 21:37:51 +01:00
|
|
|
stanza = nbxmpp.Iq(typ='set', to=self.jid)
|
|
|
|
stanza.addChild('command', namespace=nbxmpp.NS_COMMANDS, attrs={
|
2010-02-08 15:08:40 +01:00
|
|
|
'node':self.commandnode,
|
|
|
|
'sessionid':self.sessionid,
|
|
|
|
'action':'cancel'
|
|
|
|
})
|
|
|
|
|
|
|
|
self.account.connection.send(stanza)
|
|
|
|
else:
|
2010-02-10 15:29:50 +01:00
|
|
|
# we did not received any reply from service;
|
|
|
|
# FIXME: we should wait and then send cancel; for now we do nothing
|
2010-02-08 15:08:40 +01:00
|
|
|
pass
|