Commit 0dbad0ca authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Groupchat: Integrate password entry into GroupChatControl

parent b51b99f9
......@@ -84,6 +84,7 @@
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="notify::visible-child-name" handler="_on_page_change" swapped="no"/>
<child>
<object class="GtkBox" id="groupchat_control_vbox">
<property name="can_focus">True</property>
......@@ -704,6 +705,112 @@
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="row_spacing">12</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Enter password</property>
<property name="xalign">0</property>
<style>
<class name="bold16"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">_Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="_on_password_cancel_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="password_set_button">
<property name="label" translatable="yes">_Join</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="halign">end</property>
<property name="valign">start</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="_on_password_set_clicked" swapped="no"/>
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="password_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="visibility">False</property>
<property name="invisible_char">*</property>
<property name="input_purpose">password</property>
<signal name="notify::text" handler="_on_password_changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="name">password</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
......
......@@ -1951,8 +1951,7 @@ def _on_presence_error(self, event):
error_message = event.properties.error.message
if error_type == Error.NOT_AUTHORIZED:
app.interface.handle_gc_password_required(
self.account, self.room_jid, nick)
self._show_page('password')
elif error_type == Error.FORBIDDEN:
# we are banned
......@@ -2475,7 +2474,11 @@ def delegate_action(self, action):
if action == 'escape':
if self._get_current_page() == 'groupchat':
return Gdk.EVENT_PROPAGATE
self._show_page('groupchat')
if self._get_current_page() == 'password':
self._on_password_cancel_clicked()
else:
self._show_page('groupchat')
return Gdk.EVENT_STOP
if action == 'change-subject':
......@@ -2926,6 +2929,13 @@ def on_owner_checkmenuitem_activate(self, widget, jid):
else:
self.revoke_owner(widget, jid)
def _on_page_change(self, stack, _param):
page_name = stack.get_visible_child_name()
if page_name == 'password':
self.xml.password_entry.set_text('')
self.xml.password_entry.grab_focus()
self.xml.password_set_button.grab_default()
def _on_change_nick(self, _action, _param):
if self._get_current_page() == 'nickname':
return
......@@ -2968,6 +2978,21 @@ def _on_subject_change_clicked(self, _button):
con.get_module('MUC').set_subject(self.room_jid, subject)
self._show_page('groupchat')
def _on_password_set_clicked(self, _button):
password = self.xml.password_entry.get_text()
app.gc_passwords[self.room_jid] = password
app.connections[self.account].get_module('MUC').join(
self.room_jid, self.nick, password)
self._show_page('groupchat')
def _on_password_changed(self, entry, _param):
self.xml.password_set_button.set_sensitive(bool(entry.get_text()))
def _on_password_cancel_clicked(self, _button=None):
self.force_non_minimizable = True
self.parent_win.remove_tab(self, self.parent_win.CLOSE_COMMAND)
self.force_non_minimizable = False
def _on_page_cancel_clicked(self, _button):
self._show_page('groupchat')
......
......@@ -266,34 +266,6 @@ def on_close(dummy):
d.set_transient_for(gc_control.parent_win.window)
d.set_modal(False)
def handle_gc_password_required(self, account, room_jid, nick):
def on_ok(text):
app.connections[account].get_module('MUC').join(
room_jid, nick, text)
app.gc_passwords[room_jid] = text
gc_control.error_dialog = None
def on_cancel():
# get and destroy window
if room_jid in app.interface.minimized_controls[account]:
self.roster.on_disconnect(None, room_jid, account)
else:
win = self.msg_win_mgr.get_window(room_jid, account)
ctrl = self.msg_win_mgr.get_gc_control(room_jid, account)
win.remove_tab(ctrl, 3)
gc_control.error_dialog = None
gc_control = self.msg_win_mgr.get_gc_control(room_jid, account)
if gc_control:
if gc_control.error_dialog:
gc_control.error_dialog.destroy()
gc_control.error_dialog = InputDialog(_('Password Required'),
_('A Password is required to join the group chat %s. Please type it.') % \
room_jid, is_modal=False, ok_handler=on_ok,
cancel_handler=on_cancel)
gc_control.error_dialog.input_entry.set_visibility(False)
def handle_event_presence(self, obj):
# 'NOTIFY' (account, (jid, status, status message, resource,
# priority, timestamp))
......
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