Commit e1bef611 authored by Philipp Hörist's avatar Philipp Hörist

MUC: Rework captcha prompt

parent 239b34f4
Pipeline #3590 passed with stages
in 4 minutes and 5 seconds
......@@ -314,6 +314,8 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.msg_textview.drag_dest_set(Gtk.DestDefaults.MOTION |
Gtk.DestDefaults.HIGHLIGHT, self.dnd_list, Gdk.DragAction.COPY)
self._overlay = self.xml.get_object('overlay')
# the following vars are used to keep history of user's messages
self.sent_history = []
self.sent_history_pos = 0
......
......@@ -97,6 +97,10 @@
<property name="position_set">True</property>
<signal name="button-release-event" handler="_on_hpaned_release_button" swapped="no"/>
<signal name="notify::position" handler="_on_hpaned_handle_change" swapped="no"/>
<child>
<object class="GtkOverlay" id="overlay">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="gc_textviews_vbox">
<property name="width_request">0</property>
......@@ -400,7 +404,12 @@
</child>
</object>
<packing>
<property name="resize">True</property>
<property name="index">-1</property>
</packing>
</child>
</object>
<packing>
<property name="resize">False</property>
<property name="shrink">False</property>
</packing>
</child>
......
......@@ -264,8 +264,6 @@ class GroupchatControl(ChatControlBase):
self.setup_seclabel()
self.form_widget = None
# Send file
self.sendfile_button = self.xml.get_object('sendfile_button')
self.sendfile_button.set_action_name('win.send-file-' + \
......@@ -299,6 +297,9 @@ class GroupchatControl(ChatControlBase):
self.banner_actionbar.pack_end(self.hide_roster_button)
self.banner_actionbar.pack_start(self.subject_button)
# Holds CaptchaRequest widget
self._captcha_request = None
# GC Roster tooltip
self.gc_tooltip = GCTooltip()
......@@ -1155,42 +1156,31 @@ class GroupchatControl(ChatControlBase):
if event.jid != self.room_jid:
return
if self.form_widget:
self.form_widget.hide()
self.form_widget.destroy()
self.btn_box.destroy() # pylint: disable=access-member-before-definition
self._remove_captcha_request()
self.form_widget = DataFormWidget(event.form)
def on_send_dataform_clicked(widget):
if not self.form_widget:
return
form_node = self.form_widget.get_submit_form()
def on_send_dataform_clicked(*args):
form_node = self._captcha_request.get_submit_form()
con = app.connections[self.account]
con.get_module('MUC').send_captcha(self.room_jid, form_node)
self.form_widget.hide()
self.form_widget.destroy()
self.btn_box.destroy()
self.form_widget = None
del self.btn_box
# self.form_widget.connect('validated', on_send_dataform_clicked)
self.form_widget.show_all()
vbox = self.xml.get_object('gc_textviews_vbox')
vbox.pack_start(self.form_widget, False, True, 0)
valid_button = Gtk.Button(stock=Gtk.STOCK_OK)
valid_button.connect('clicked', on_send_dataform_clicked)
self.btn_box = Gtk.HButtonBox()
self.btn_box.set_layout(Gtk.ButtonBoxStyle.END)
self.btn_box.pack_start(valid_button, True, True, 0)
self.btn_box.show_all()
vbox.pack_start(self.btn_box, False, False, 0)
self._remove_captcha_request()
self._captcha_request = CaptchaRequest(event.form,
on_send_dataform_clicked)
self._overlay.add_overlay(self._captcha_request)
if self.parent_win:
self.parent_win.redraw_tab(self, 'attention')
else:
self.attention_flag = True
def _remove_captcha_request(self):
if self._captcha_request is None:
return
if self._captcha_request in self._overlay.get_children():
self._overlay.remove(self._captcha_request)
self._captcha_request.destroy()
self._captcha_request = None
def _nec_mam_decrypted_message_received(self, obj):
if obj.conn.name != self.account:
return
......@@ -3062,3 +3052,27 @@ class SubjectPopover(Gtk.Popover):
# is not cross-platform compatible
open_uri(uri)
return Gdk.EVENT_STOP
class CaptchaRequest(Gtk.Box):
def __init__(self, form, callback):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
options = {'no-scrolling': True}
self._form_widget = DataFormWidget(form, options=options)
self._form_widget.set_valign(Gtk.Align.START)
send_button = Gtk.Button(label='Send')
send_button.connect('clicked', callback)
send_button.set_halign(Gtk.Align.CENTER)
self.add(self._form_widget)
self.add(send_button)
self.set_valign(Gtk.Align.START)
self.set_margin_top(100)
self.show_all()
def get_submit_form(self):
return self._form_widget.get_submit_form()
......@@ -38,10 +38,13 @@ class DataFormWidget(Gtk.ScrolledWindow):
self.get_style_context().add_class('data-form-widget')
self.set_overlay_scrolling(False)
self._form_node = form_node
if options is None:
options = {}
if options.get('no-scrolling', False):
self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER)
self._form_node = form_node
self._form_grid = FormGrid(form_node, options)
self.add(self._form_grid)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment