2006-06-23 00:49:39 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-16 18:44:59 +01:00
|
|
|
## adhoc_commands.py
|
2006-06-23 00:49:39 +02:00
|
|
|
##
|
2007-10-22 13:33:50 +02:00
|
|
|
## Copyright (C) 2006 Yann Leboulanger <asterix@lagaule.org>
|
2006-06-23 00:49:39 +02:00
|
|
|
## Nikos Kouremenos <nkour@jabber.org>
|
|
|
|
##
|
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
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## 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
|
|
|
|
## 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
|
|
|
|
2006-06-23 00:49:39 +02:00
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
|
2006-07-07 17:49:44 +02:00
|
|
|
from common import xmpp, gajim, dataforms
|
2006-06-23 16:38:54 +02:00
|
|
|
|
2006-06-23 00:49:39 +02:00
|
|
|
import gtkgui_helpers
|
2006-07-09 19:55:56 +02:00
|
|
|
import dialogs
|
2006-09-13 18:07:51 +02:00
|
|
|
import dataforms_widget
|
2006-06-23 00:49:39 +02:00
|
|
|
|
|
|
|
class CommandWindow:
|
|
|
|
'''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
|
|
|
|
TODO: it will be possible to manage more than one window of one
|
2006-07-07 17:49:44 +02:00
|
|
|
TODO: account/jid pair in MessageWindowMgr.
|
|
|
|
|
|
|
|
TODO: gtk 2.10 has a special wizard-widget, consider using it...'''
|
2006-06-23 00:49:39 +02:00
|
|
|
|
|
|
|
def __init__(self, account, jid):
|
|
|
|
'''Create new window.'''
|
|
|
|
|
2006-06-23 16:38:54 +02:00
|
|
|
# an account object
|
|
|
|
self.account = gajim.connections[account]
|
|
|
|
self.jid = jid
|
2006-06-23 00:49:39 +02:00
|
|
|
|
2006-06-23 16:38:54 +02:00
|
|
|
self.pulse_id=None # to satisfy self.setup_pulsing()
|
|
|
|
self.commandlist=None # a list of (commandname, commanddescription)
|
2006-06-23 00:49:39 +02:00
|
|
|
|
2006-06-25 19:03:59 +02:00
|
|
|
# command's data
|
|
|
|
self.commandnode = None
|
|
|
|
self.sessionid = None
|
|
|
|
self.dataform = None
|
2008-08-11 10:38:35 +02:00
|
|
|
self.allow_stage3_close = False
|
2006-06-25 19:03:59 +02:00
|
|
|
|
2006-06-23 00:49:39 +02:00
|
|
|
# retrieving widgets from xml
|
|
|
|
self.xml = gtkgui_helpers.get_glade('adhoc_commands_window.glade')
|
|
|
|
self.window = self.xml.get_widget('adhoc_commands_window')
|
2007-06-03 15:54:13 +02:00
|
|
|
self.window.connect('delete-event', self.on_adhoc_commands_window_delete_event)
|
2006-11-20 23:33:08 +01:00
|
|
|
for name in ('back_button', 'forward_button',
|
2006-07-12 16:19:58 +02:00
|
|
|
'execute_button','close_button','stages_notebook',
|
2006-06-23 16:38:54 +02:00
|
|
|
'retrieving_commands_stage_vbox',
|
|
|
|
'command_list_stage_vbox','command_list_vbox',
|
2006-06-25 19:03:59 +02:00
|
|
|
'sending_form_stage_vbox','sending_form_progressbar',
|
2006-07-12 16:19:58 +02:00
|
|
|
'notes_label','no_commands_stage_vbox','error_stage_vbox',
|
2006-06-25 19:03:59 +02:00
|
|
|
'error_description_label'):
|
2006-06-23 16:38:54 +02:00
|
|
|
self.__dict__[name] = self.xml.get_widget(name)
|
2006-06-25 19:03:59 +02:00
|
|
|
|
|
|
|
# creating data forms widget
|
2006-09-13 18:07:51 +02:00
|
|
|
self.data_form_widget = dataforms_widget.DataFormWidget()
|
2006-07-07 17:49:44 +02:00
|
|
|
self.data_form_widget.show()
|
2006-06-25 19:03:59 +02:00
|
|
|
self.sending_form_stage_vbox.pack_start(self.data_form_widget)
|
|
|
|
|
2006-06-23 16:38:54 +02:00
|
|
|
# setting initial stage
|
|
|
|
self.stage1()
|
2006-06-23 00:49:39 +02:00
|
|
|
|
|
|
|
# displaying the window
|
|
|
|
self.xml.signal_autoconnect(self)
|
|
|
|
self.window.show_all()
|
|
|
|
|
2006-06-23 16:38:54 +02:00
|
|
|
# these functions are set up by appropriate stageX methods
|
|
|
|
def stage_finish(self, *anything): pass
|
2006-06-25 19:03:59 +02:00
|
|
|
def stage_back_button_clicked(self, *anything): assert False
|
|
|
|
def stage_forward_button_clicked(self, *anything): assert False
|
|
|
|
def stage_execute_button_clicked(self, *anything): assert False
|
2006-07-12 16:19:58 +02:00
|
|
|
def stage_close_button_clicked(self, *anything): assert False
|
2006-06-25 19:03:59 +02:00
|
|
|
def stage_adhoc_commands_window_delete_event(self, *anything): assert False
|
|
|
|
def do_nothing(self, *anything): return False
|
|
|
|
|
|
|
|
# widget callbacks
|
|
|
|
def on_back_button_clicked(self, *anything):
|
|
|
|
return self.stage_back_button_clicked(*anything)
|
|
|
|
|
|
|
|
def on_forward_button_clicked(self, *anything):
|
|
|
|
return self.stage_forward_button_clicked(*anything)
|
|
|
|
|
|
|
|
def on_execute_button_clicked(self, *anything):
|
|
|
|
return self.stage_execute_button_clicked(*anything)
|
|
|
|
|
2006-07-12 16:19:58 +02:00
|
|
|
def on_close_button_clicked(self, *anything):
|
|
|
|
return self.stage_close_button_clicked(*anything)
|
|
|
|
|
2006-06-25 19:03:59 +02:00
|
|
|
def on_adhoc_commands_window_destroy(self, *anything):
|
2006-07-12 16:19:58 +02:00
|
|
|
# TODO: do all actions that are needed to remove this object from memory...
|
2006-07-09 19:55:56 +02:00
|
|
|
self.remove_pulsing()
|
2006-06-25 19:03:59 +02:00
|
|
|
|
|
|
|
def on_adhoc_commands_window_delete_event(self, *anything):
|
2007-06-03 15:54:13 +02:00
|
|
|
return self.stage_adhoc_commands_window_delete_event(self.window)
|
2006-06-23 16:38:54 +02:00
|
|
|
|
2006-07-09 19:55:56 +02:00
|
|
|
def __del__(self):
|
2008-02-15 11:38:52 +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
|
|
|
|
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
|
2006-11-20 23:33:08 +01:00
|
|
|
self.close_button.set_sensitive(True)
|
2006-06-23 16:38:54 +02:00
|
|
|
self.back_button.set_sensitive(False)
|
|
|
|
self.forward_button.set_sensitive(False)
|
|
|
|
self.execute_button.set_sensitive(False)
|
|
|
|
|
|
|
|
# request command list
|
|
|
|
self.request_command_list()
|
|
|
|
self.setup_pulsing(
|
|
|
|
self.xml.get_widget('retrieving_commands_progressbar'))
|
|
|
|
|
|
|
|
# setup the callbacks
|
|
|
|
self.stage_finish = self.stage1_finish
|
2006-11-20 23:33:08 +01:00
|
|
|
self.stage_close_button_clicked = self.stage1_close_button_clicked
|
2006-06-25 19:03:59 +02:00
|
|
|
self.stage_adhoc_commands_window_delete_event = self.stage1_adhoc_commands_window_delete_event
|
2006-06-23 16:38:54 +02:00
|
|
|
|
|
|
|
def stage1_finish(self):
|
|
|
|
self.remove_pulsing()
|
|
|
|
|
2006-11-20 23:33:08 +01:00
|
|
|
def stage1_close_button_clicked(self, widget):
|
2006-06-23 16:38:54 +02:00
|
|
|
# cancelling in this stage is not critical, so we don't
|
|
|
|
# show any popups to user
|
|
|
|
self.stage1_finish()
|
|
|
|
self.window.destroy()
|
|
|
|
|
2006-06-25 19:03:59 +02:00
|
|
|
def stage1_adhoc_commands_window_delete_event(self, widget):
|
|
|
|
self.stage1_finish()
|
|
|
|
return True
|
|
|
|
|
2006-06-23 16:38:54 +02:00
|
|
|
# stage 2: choosing the command to execute
|
|
|
|
def stage2(self):
|
|
|
|
'''Populate the command list vbox with radiobuttons
|
2006-12-16 18:44:59 +01:00
|
|
|
(FIXME: if there is more commands, maybe some kind of list?),
|
2006-06-23 16:38:54 +02:00
|
|
|
set widgets' state.'''
|
|
|
|
# close old stage
|
|
|
|
self.stage_finish()
|
2006-06-23 00:49:39 +02:00
|
|
|
|
2006-06-23 16:38:54 +02:00
|
|
|
assert len(self.commandlist)>0
|
|
|
|
|
|
|
|
self.stages_notebook.set_current_page(
|
|
|
|
self.stages_notebook.page_num(
|
|
|
|
self.command_list_stage_vbox))
|
|
|
|
|
2006-11-20 23:33:08 +01:00
|
|
|
self.close_button.set_sensitive(True)
|
2006-06-23 16:38:54 +02:00
|
|
|
self.back_button.set_sensitive(False)
|
|
|
|
self.forward_button.set_sensitive(True)
|
|
|
|
self.execute_button.set_sensitive(False)
|
|
|
|
|
|
|
|
# build the commands list radiobuttons
|
|
|
|
first_radio = None
|
|
|
|
for (commandnode, commandname) in self.commandlist:
|
|
|
|
radio = gtk.RadioButton(first_radio, label=commandname)
|
2006-06-25 19:03:59 +02:00
|
|
|
radio.connect("toggled", self.on_command_radiobutton_toggled, commandnode)
|
2007-06-03 15:57:42 +02:00
|
|
|
if not first_radio:
|
2006-06-25 19:03:59 +02:00
|
|
|
first_radio = radio
|
|
|
|
self.commandnode = commandnode
|
2006-07-09 19:55:56 +02:00
|
|
|
self.command_list_vbox.pack_start(radio, expand=False)
|
2006-06-23 16:38:54 +02:00
|
|
|
self.command_list_vbox.show_all()
|
|
|
|
|
2006-06-23 20:13:35 +02:00
|
|
|
self.stage_finish = self.stage2_finish
|
2006-11-20 23:33:08 +01:00
|
|
|
self.stage_close_button_clicked = self.stage2_close_button_clicked
|
2006-06-25 19:03:59 +02:00
|
|
|
self.stage_forward_button_clicked = self.stage2_forward_button_clicked
|
|
|
|
self.stage_adhoc_commands_window_delete_event = self.do_nothing
|
2006-06-23 16:38:54 +02:00
|
|
|
|
2006-06-23 20:13:35 +02:00
|
|
|
def stage2_finish(self):
|
2006-06-25 19:03:59 +02:00
|
|
|
'''Remove widgets we created. Not needed when the window is destroyed.'''
|
2006-06-23 20:13:35 +02:00
|
|
|
def remove_widget(widget):
|
|
|
|
self.command_list_vbox.remove(widget)
|
|
|
|
self.command_list_vbox.foreach(remove_widget)
|
|
|
|
|
2006-11-20 23:33:08 +01:00
|
|
|
def stage2_close_button_clicked(self, widget):
|
2006-06-23 16:38:54 +02:00
|
|
|
self.stage_finish()
|
|
|
|
self.window.destroy()
|
|
|
|
|
2006-06-25 19:03:59 +02:00
|
|
|
def stage2_forward_button_clicked(self, widget):
|
|
|
|
self.stage3()
|
|
|
|
|
|
|
|
def on_command_radiobutton_toggled(self, widget, commandnode):
|
|
|
|
self.commandnode = commandnode
|
2006-06-23 16:38:54 +02:00
|
|
|
|
2006-06-23 20:13:35 +02:00
|
|
|
def on_check_commands_1_button_clicked(self, widget):
|
|
|
|
self.stage1()
|
|
|
|
|
2006-06-25 19:03:59 +02:00
|
|
|
# stage 3: command invocation
|
|
|
|
def stage3(self):
|
|
|
|
# close old stage
|
|
|
|
self.stage_finish()
|
|
|
|
|
|
|
|
assert isinstance(self.commandnode, unicode)
|
|
|
|
|
2006-07-12 16:19:58 +02:00
|
|
|
self.form_status = None
|
|
|
|
|
2006-06-25 19:03:59 +02:00
|
|
|
self.stages_notebook.set_current_page(
|
|
|
|
self.stages_notebook.page_num(
|
|
|
|
self.sending_form_stage_vbox))
|
|
|
|
|
2006-11-20 23:33:08 +01:00
|
|
|
self.close_button.set_sensitive(True)
|
2006-06-25 19:03:59 +02:00
|
|
|
self.back_button.set_sensitive(False)
|
|
|
|
self.forward_button.set_sensitive(False)
|
|
|
|
self.execute_button.set_sensitive(False)
|
|
|
|
|
|
|
|
self.stage3_submit_form()
|
|
|
|
|
|
|
|
self.stage_finish = self.stage3_finish
|
|
|
|
self.stage_back_button_clicked = self.stage3_back_button_clicked
|
|
|
|
self.stage_forward_button_clicked = self.stage3_forward_button_clicked
|
|
|
|
self.stage_execute_button_clicked = self.stage3_execute_button_clicked
|
2006-07-12 16:19:58 +02:00
|
|
|
self.stage_close_button_clicked = self.stage3_close_button_clicked
|
2006-11-20 23:33:08 +01:00
|
|
|
self.stage_adhoc_commands_window_delete_event = self.stage3_close_button_clicked
|
2006-06-25 19:03:59 +02:00
|
|
|
|
|
|
|
def stage3_finish(self):
|
|
|
|
pass
|
|
|
|
|
2006-11-20 23:33:08 +01:00
|
|
|
def stage3_close_button_clicked(self, widget):
|
2006-07-09 19:55:56 +02:00
|
|
|
''' We are in the middle of executing command. Ask user if he really want to cancel
|
|
|
|
the process, then... cancel it. '''
|
|
|
|
# this works also as a handler for window_delete_event, so we have to return appropriate
|
|
|
|
# values
|
2006-11-20 23:33:08 +01:00
|
|
|
if self.form_status == 'completed':
|
|
|
|
if widget!=self.window:
|
|
|
|
self.window.destroy()
|
|
|
|
return False
|
|
|
|
|
2008-08-11 10:38:35 +02:00
|
|
|
if self.allow_stage3_close:
|
2006-07-09 19:55:56 +02:00
|
|
|
return False
|
2008-08-11 10:38:35 +02:00
|
|
|
|
|
|
|
def on_yes(button):
|
|
|
|
self.send_cancel()
|
|
|
|
self.allow_stage3_close = True
|
|
|
|
self.window.destroy()
|
|
|
|
|
|
|
|
dialog = dialogs.HigDialog(self.window, gtk.DIALOG_DESTROY_WITH_PARENT | \
|
|
|
|
gtk.DIALOG_MODAL, gtk.BUTTONS_YES_NO, _('Cancel confirmation'),
|
|
|
|
_('You are in process of executing command. Do you really want to '
|
|
|
|
'cancel it?'), on_response_yes=on_yes)
|
|
|
|
dialog.popup()
|
|
|
|
return True # Block event, don't close window
|
2006-07-12 16:19:58 +02:00
|
|
|
|
2006-06-25 19:03:59 +02: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')
|
|
|
|
|
|
|
|
def stage3_submit_form(self, action='execute'):
|
|
|
|
self.data_form_widget.set_sensitive(False)
|
2007-06-03 15:57:42 +02:00
|
|
|
if self.data_form_widget.get_data_form():
|
2007-01-06 20:05:45 +01:00
|
|
|
self.data_form_widget.data_form.type='submit'
|
2007-06-03 15:57:42 +02:00
|
|
|
else:
|
|
|
|
self.data_form_widget.hide()
|
2006-07-09 19:55:56 +02:00
|
|
|
|
2006-11-20 23:33:08 +01:00
|
|
|
self.close_button.set_sensitive(True)
|
2006-07-09 19:55:56 +02:00
|
|
|
self.back_button.set_sensitive(False)
|
|
|
|
self.forward_button.set_sensitive(False)
|
|
|
|
self.execute_button.set_sensitive(False)
|
|
|
|
|
2006-06-25 19:03:59 +02:00
|
|
|
self.sending_form_progressbar.show()
|
|
|
|
self.setup_pulsing(self.sending_form_progressbar)
|
|
|
|
self.send_command(action)
|
|
|
|
|
|
|
|
def stage3_next_form(self, command):
|
|
|
|
assert isinstance(command, xmpp.Node)
|
|
|
|
|
|
|
|
self.remove_pulsing()
|
|
|
|
self.sending_form_progressbar.hide()
|
|
|
|
|
2008-02-15 11:38:52 +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)
|
2006-06-25 19:03:59 +02:00
|
|
|
|
2006-07-12 16:19:58 +02:00
|
|
|
self.form_status = command.getAttr('status')
|
2006-06-25 19:03:59 +02:00
|
|
|
|
2007-03-19 22:02:35 +01:00
|
|
|
self.commandnode = command.getAttr('node')
|
2007-06-03 15:57:42 +02:00
|
|
|
if command.getTag('x'):
|
2006-11-18 21:10:37 +01:00
|
|
|
self.dataform = dataforms.ExtendForm(node=command.getTag('x'))
|
2006-07-12 16:19:58 +02:00
|
|
|
|
|
|
|
self.data_form_widget.set_sensitive(True)
|
|
|
|
try:
|
|
|
|
self.data_form_widget.data_form=self.dataform
|
2006-11-18 21:10:37 +01:00
|
|
|
except dataforms.Error:
|
2008-02-15 11:38:52 +01:00
|
|
|
self.stage5(error=_('Service sent malformed data'), senderror=True)
|
2007-01-06 20:05:45 +01:00
|
|
|
return
|
2006-07-12 16:19:58 +02:00
|
|
|
self.data_form_widget.show()
|
2007-01-06 20:05:45 +01:00
|
|
|
if self.data_form_widget.title:
|
2008-02-15 11:38:52 +01:00
|
|
|
self.window.set_title('%s - Ad-hoc Commands - Gajim' % \
|
2007-01-06 20:05:45 +01:00
|
|
|
self.data_form_widget.title)
|
2006-07-12 16:19:58 +02:00
|
|
|
else:
|
|
|
|
self.data_form_widget.hide()
|
2006-06-25 19:03:59 +02:00
|
|
|
|
2007-06-03 15:55:46 +02:00
|
|
|
actions = command.getTag('actions')
|
2007-06-03 15:57:42 +02:00
|
|
|
if actions:
|
2006-06-25 19:03:59 +02:00
|
|
|
# actions, actions, actions...
|
2006-11-20 23:33:08 +01:00
|
|
|
self.close_button.set_sensitive(True)
|
2007-06-03 15:55:46 +02:00
|
|
|
self.back_button.set_sensitive(actions.getTag('prev') is not None)
|
|
|
|
self.forward_button.set_sensitive(actions.getTag('next') is not None)
|
2006-06-25 19:03:59 +02:00
|
|
|
self.execute_button.set_sensitive(True)
|
2007-06-03 15:57:42 +02: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)
|
2006-06-25 19:03:59 +02:00
|
|
|
|
2006-07-12 16:19:58 +02:00
|
|
|
if self.form_status == 'completed':
|
2006-11-20 23:33:08 +01:00
|
|
|
self.close_button.set_sensitive(True)
|
|
|
|
self.back_button.hide()
|
|
|
|
self.forward_button.hide()
|
2006-07-12 16:19:58 +02:00
|
|
|
self.execute_button.hide()
|
|
|
|
self.close_button.show()
|
|
|
|
self.stage_adhoc_commands_window_delete_event = self.stage3_close_button_clicked
|
|
|
|
|
|
|
|
note = command.getTag('note')
|
2007-06-03 15:57:42 +02:00
|
|
|
if note:
|
2006-07-12 16:19:58 +02:00
|
|
|
self.notes_label.set_text(note.getData().decode('utf-8'))
|
|
|
|
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-06-23 20:13:35 +02:00
|
|
|
# stage 4: no commands are exposed
|
|
|
|
def stage4(self):
|
|
|
|
'''Display the message. Wait for user to close the window'''
|
|
|
|
# close old stage
|
|
|
|
self.stage_finish()
|
|
|
|
|
|
|
|
self.stages_notebook.set_current_page(
|
|
|
|
self.stages_notebook.page_num(
|
|
|
|
self.no_commands_stage_vbox))
|
|
|
|
|
2006-11-20 23:33:08 +01:00
|
|
|
self.close_button.set_sensitive(True)
|
2006-06-23 20:13:35 +02:00
|
|
|
self.back_button.set_sensitive(False)
|
|
|
|
self.forward_button.set_sensitive(False)
|
|
|
|
self.execute_button.set_sensitive(False)
|
|
|
|
|
|
|
|
self.stage_finish = self.do_nothing
|
2006-11-20 23:33:08 +01:00
|
|
|
self.stage_close_button_clicked = self.stage4_close_button_clicked
|
2006-06-25 19:03:59 +02:00
|
|
|
self.stage_adhoc_commands_window_delete_event = self.do_nothing
|
2006-06-23 20:13:35 +02:00
|
|
|
|
2006-11-20 23:33:08 +01:00
|
|
|
def stage4_close_button_clicked(self, widget):
|
2006-06-23 20:13:35 +02:00
|
|
|
self.window.destroy()
|
|
|
|
|
|
|
|
def on_check_commands_2_button_clicked(self, widget):
|
|
|
|
self.stage1()
|
|
|
|
|
|
|
|
# stage 5: an error has occured
|
2006-08-01 17:45:42 +02:00
|
|
|
def stage5(self, error=None, errorid=None, senderror=False):
|
2006-06-23 20:13:35 +02:00
|
|
|
'''Display the error message. Wait for user to close the window'''
|
2006-12-16 18:44:59 +01:00
|
|
|
# FIXME: sending error to responder
|
2006-06-23 20:13:35 +02:00
|
|
|
# close old stage
|
|
|
|
self.stage_finish()
|
|
|
|
|
2007-06-03 15:57:42 +02:00
|
|
|
assert errorid or error
|
2006-08-01 17:45:42 +02:00
|
|
|
|
2007-06-03 15:57:42 +02:00
|
|
|
if errorid:
|
2006-08-01 17:45:42 +02:00
|
|
|
# we've got error code, display appropriate message
|
2006-11-27 21:28:24 +01:00
|
|
|
try:
|
|
|
|
errorname = xmpp.NS_STANZAS + ' ' + str(errorid)
|
|
|
|
errordesc = xmpp.ERRORS[errorname][2]
|
|
|
|
error = errordesc.decode('utf-8')
|
|
|
|
del errorname, errordesc
|
|
|
|
except KeyError: # when stanza doesn't have error description
|
2008-02-15 11:38:52 +01:00
|
|
|
error = _('Service returned an error.')
|
2007-06-03 15:57:42 +02:00
|
|
|
elif error:
|
2006-08-01 17:45:42 +02:00
|
|
|
# we've got error message
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# we don't know what's that, bailing out
|
|
|
|
assert False
|
2006-06-23 20:13:35 +02:00
|
|
|
|
|
|
|
self.stages_notebook.set_current_page(
|
|
|
|
self.stages_notebook.page_num(
|
|
|
|
self.error_stage_vbox))
|
|
|
|
|
2006-11-20 23:33:08 +01:00
|
|
|
self.close_button.set_sensitive(True)
|
|
|
|
self.back_button.hide()
|
|
|
|
self.forward_button.hide()
|
|
|
|
self.execute_button.hide()
|
2006-06-23 20:13:35 +02:00
|
|
|
|
|
|
|
self.error_description_label.set_text(error)
|
|
|
|
|
|
|
|
self.stage_finish = self.do_nothing
|
2006-11-20 23:33:08 +01:00
|
|
|
self.stage_close_button_clicked = self.stage5_close_button_clicked
|
2006-06-25 19:03:59 +02:00
|
|
|
self.stage_adhoc_commands_window_delete_event = self.do_nothing
|
2006-06-23 20:13:35 +02:00
|
|
|
|
2006-11-20 23:33:08 +01:00
|
|
|
def stage5_close_button_clicked(self, widget):
|
2006-06-23 20:13:35 +02:00
|
|
|
self.window.destroy()
|
|
|
|
|
2006-06-23 16:38:54 +02:00
|
|
|
# helpers to handle pulsing in progressbar
|
2006-06-23 00:49:39 +02:00
|
|
|
def setup_pulsing(self, progressbar):
|
2006-06-23 16:38:54 +02:00
|
|
|
'''Set the progressbar to pulse. Makes a custom
|
2006-06-23 00:49:39 +02:00
|
|
|
function to repeatedly call progressbar.pulse() method.'''
|
2007-06-03 15:57:42 +02:00
|
|
|
assert not self.pulse_id
|
2006-06-23 16:38:54 +02:00
|
|
|
assert isinstance(progressbar, gtk.ProgressBar)
|
2006-06-23 00:49:39 +02:00
|
|
|
|
|
|
|
def callback():
|
|
|
|
progressbar.pulse()
|
|
|
|
return True # important to keep callback be called back!
|
|
|
|
|
2006-06-23 16:38:54 +02:00
|
|
|
# 12 times per second (80 miliseconds)
|
2006-06-23 00:49:39 +02:00
|
|
|
self.pulse_id = gobject.timeout_add(80, callback)
|
|
|
|
|
|
|
|
def remove_pulsing(self):
|
2006-06-23 16:38:54 +02:00
|
|
|
'''Stop pulsing, useful when especially when removing widget.'''
|
2007-06-03 15:57:42 +02:00
|
|
|
if self.pulse_id:
|
2006-06-23 00:49:39 +02:00
|
|
|
gobject.source_remove(self.pulse_id)
|
|
|
|
self.pulse_id=None
|
2006-06-23 16:38:54 +02:00
|
|
|
|
|
|
|
# handling xml stanzas
|
|
|
|
def request_command_list(self):
|
|
|
|
'''Request the command list. Change stage on delivery.'''
|
|
|
|
query = xmpp.Iq(typ='get', to=xmpp.JID(self.jid), xmlns=xmpp.NS_DISCO_ITEMS)
|
|
|
|
query.setQuerynode(xmpp.NS_COMMANDS)
|
|
|
|
|
|
|
|
def callback(response):
|
|
|
|
'''Called on response to query.'''
|
2006-12-16 18:44:59 +01:00
|
|
|
# FIXME: move to connection_handlers.py
|
2006-06-23 16:38:54 +02:00
|
|
|
# is error => error stage
|
|
|
|
error = response.getError()
|
2007-06-03 15:57:42 +02:00
|
|
|
if error:
|
2006-06-23 20:13:35 +02:00
|
|
|
# extracting error description from xmpp/protocol.py
|
2006-08-01 17:45:42 +02:00
|
|
|
self.stage5(errorid = error)
|
2006-06-23 20:13:35 +02:00
|
|
|
return
|
2006-06-23 16:38:54 +02:00
|
|
|
|
|
|
|
# no commands => no commands stage
|
|
|
|
# commands => command selection stage
|
2007-01-22 19:05:59 +01:00
|
|
|
query = response.getTag('query')
|
2007-09-25 12:46:41 +02:00
|
|
|
if query and query.getAttr('node') == xmpp.NS_COMMANDS:
|
2007-01-22 19:05:59 +01:00
|
|
|
items = query.getTags('item')
|
|
|
|
else:
|
|
|
|
items = []
|
2006-06-23 16:38:54 +02:00
|
|
|
if len(items)==0:
|
|
|
|
self.commandlist = []
|
2006-06-23 20:13:35 +02:00
|
|
|
self.stage4()
|
2006-06-23 16:38:54 +02:00
|
|
|
else:
|
|
|
|
self.commandlist = [(t.getAttr('node'), t.getAttr('name')) for t in items]
|
|
|
|
self.stage2()
|
|
|
|
|
|
|
|
self.account.connection.SendAndCallForResponse(query, callback)
|
2006-06-25 19:03:59 +02:00
|
|
|
|
|
|
|
def send_command(self, action='execute'):
|
|
|
|
'''Send the command with data form. Wait for reply.'''
|
|
|
|
# create the stanza
|
|
|
|
assert isinstance(self.commandnode, unicode)
|
|
|
|
assert action in ('execute', 'prev', 'next', 'complete')
|
|
|
|
|
|
|
|
stanza = xmpp.Iq(typ='set', to=self.jid)
|
2008-01-21 00:24:03 +01:00
|
|
|
cmdnode = stanza.addChild('command', attrs={
|
|
|
|
'xmlns':xmpp.NS_COMMANDS,
|
2006-06-25 19:03:59 +02:00
|
|
|
'node':self.commandnode,
|
|
|
|
'action':action
|
|
|
|
})
|
|
|
|
|
2007-06-03 15:57:42 +02:00
|
|
|
if self.sessionid:
|
2006-06-25 19:03:59 +02:00
|
|
|
cmdnode.setAttr('sessionid', self.sessionid)
|
|
|
|
|
2007-06-03 15:57:42 +02:00
|
|
|
if self.data_form_widget.data_form:
|
2006-11-18 21:10:37 +01:00
|
|
|
# cmdnode.addChild(node=dataforms.DataForm(tofill=self.data_form_widget.data_form))
|
2006-12-16 18:44:59 +01:00
|
|
|
# FIXME: simplified form to send
|
2007-01-06 20:05:45 +01:00
|
|
|
|
2006-11-18 21:10:37 +01:00
|
|
|
cmdnode.addChild(node=self.data_form_widget.data_form)
|
2006-06-25 19:03:59 +02:00
|
|
|
|
|
|
|
def callback(response):
|
2006-12-16 18:44:59 +01:00
|
|
|
# FIXME: move to connection_handlers.py
|
2006-08-01 17:45:42 +02:00
|
|
|
err = response.getError()
|
2007-06-03 15:57:42 +02:00
|
|
|
if err:
|
2006-08-01 17:45:42 +02:00
|
|
|
self.stage5(errorid = err)
|
|
|
|
else:
|
|
|
|
self.stage3_next_form(response.getTag('command'))
|
2006-06-25 19:03:59 +02:00
|
|
|
|
|
|
|
self.account.connection.SendAndCallForResponse(stanza, callback)
|
2006-07-09 19:55:56 +02:00
|
|
|
|
|
|
|
def send_cancel(self):
|
|
|
|
'''Send the command with action='cancel'. '''
|
2007-06-03 15:57:42 +02:00
|
|
|
assert self.commandnode
|
|
|
|
if self.sessionid and self.account.connection:
|
2006-09-13 18:07:51 +02:00
|
|
|
# we already have sessionid, so the service sent at least one reply.
|
|
|
|
stanza = xmpp.Iq(typ='set', to=self.jid)
|
2008-01-21 00:24:03 +01:00
|
|
|
stanza.addChild('command', attrs={
|
|
|
|
'xmlns':xmpp.NS_COMMANDS,
|
2006-09-13 18:07:51 +02:00
|
|
|
'node':self.commandnode,
|
|
|
|
'sessionid':self.sessionid,
|
|
|
|
'action':'cancel'
|
|
|
|
})
|
2007-01-11 20:58:51 +01:00
|
|
|
|
2006-09-13 18:07:51 +02:00
|
|
|
self.account.connection.send(stanza)
|
|
|
|
else:
|
2006-12-16 18:44:59 +01:00
|
|
|
# we did not received any reply from service; FIXME: we should wait and
|
2006-09-13 18:07:51 +02:00
|
|
|
# then send cancel; for now we do nothing
|
|
|
|
pass
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2008-08-11 10:38:35 +02:00
|
|
|
# vim: se ts=3:
|