Commit 358eab4a authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Groupchat: Integrate change nickname into control

Use a Stack page to display the change nickname entry instead of a popup dialog
parent 37b5be8b
This diff is collapsed.
......@@ -34,6 +34,8 @@
import nbxmpp
from nbxmpp.protocol import JID
from nbxmpp.protocol import InvalidJid
from nbxmpp.protocol import validate_resourcepart
from nbxmpp.const import StatusCode
from nbxmpp.const import Affiliation
from nbxmpp.const import Role
......@@ -76,7 +78,6 @@
from gajim.gtk.dialogs import InputTextDialog
from gajim.gtk.dialogs import DestroyMucDialog
from gajim.gtk.dialogs import InputDialog
from gajim.gtk.dialogs import ChangeNickDialog
from gajim.gtk.single_message import SingleMessageWindow
from gajim.gtk.filechoosers import AvatarChooserDialog
from gajim.gtk.add_contact import AddNewContactWindow
......@@ -346,9 +347,14 @@ def __init__(self, parent_win, contact, nick, acct, is_continued=False):
# disable win, we are not connected yet
ChatControlBase.got_disconnected(self)
# Stack
self.xml.stack.show_all()
self.xml.stack.set_visible_child_name('groupchat')
self.update_ui()
self.widget.show_all()
if app.config.get('hide_groupchat_occupants_list'):
# Roster is shown by default, so toggle the roster button to hide it
self.show_roster()
......@@ -537,6 +543,12 @@ def _get_action(self, name):
win = self.parent_win.window
return win.lookup_action(name + self.control_id)
def _show_page(self, name):
transition = Gtk.StackTransitionType.SLIDE_DOWN
if name == 'groupchat':
transition = Gtk.StackTransitionType.SLIDE_UP
self.xml.stack.set_visible_child_full(name, transition)
def _cell_data_func(self, column, renderer, model, iter_, user_data):
# Background color has to be rendered for all cells
theme = app.config.get('roster_theme')
......@@ -632,16 +644,6 @@ def on_ok(subject):
_('Please specify the new subject:'), input_str=self.subject,
ok_handler=on_ok, transient_for=self.parent_win.window)
def _on_change_nick(self, action, param):
if 'change_nick_dialog' in app.interface.instances:
app.interface.instances['change_nick_dialog'].dialog.present()
else:
title = _('Changing Nickname')
prompt = _('Please specify the new nickname you want to use:')
app.interface.instances['change_nick_dialog'] = \
ChangeNickDialog(self.account, self.room_jid, title,
prompt, change_nick=True, transient_for=self.parent_win.window)
def _on_disconnect(self, action, param):
app.connections[self.account].get_module('MUC').leave(self.room_jid)
self.force_non_minimizable = True
......@@ -2941,6 +2943,32 @@ def on_owner_checkmenuitem_activate(self, widget, jid):
else:
self.revoke_owner(widget, jid)
def _on_change_nick(self, _action, _param):
self.xml.nickname_entry.set_text(self.nick)
self.xml.nickname_entry.grab_focus()
self._show_page('nickname')
def _on_nickname_text_changed(self, entry, _param):
text = entry.get_text()
if not text or text == self.nick:
self.xml.nickname_change_button.set_sensitive(False)
else:
try:
validate_resourcepart(text)
except InvalidJid:
self.xml.nickname_change_button.set_sensitive(False)
else:
self.xml.nickname_change_button.set_sensitive(True)
def _on_nickname_change_clicked(self, _button):
new_nick = self.xml.nickname_entry.get_text()
app.connections[self.account].get_module('MUC').change_nick(
self.room_jid, new_nick)
self._show_page('groupchat')
def _on_nickname_cancel_clicked(self, _button):
self._show_page('groupchat')
class SubjectPopover(Gtk.Popover):
def __init__(self):
......
......@@ -22,7 +22,6 @@
from gi.repository import Pango
from gajim.common import app
from gajim.common import helpers
from gajim.common.i18n import _
from gajim.common.const import ButtonAction
......@@ -526,91 +525,6 @@ def is_checked(self):
return False
class ChangeNickDialog(InputDialogCheck):
"""
Class for changing room nickname in case of conflict
"""
def __init__(self, account, room_jid, title, prompt, check_text=None,
change_nick=False, transient_for=None):
"""
change_nick must be set to True when we are already occupant of the room
and we are changing our nick
"""
InputDialogCheck.__init__(self, title, '',
input_str='', is_modal=True, ok_handler=None,
cancel_handler=None,
transient_for=transient_for)
self.room_queue = [(account, room_jid, prompt, change_nick)]
self.check_next()
def on_input_dialog_delete_event(self, widget, event):
self.on_cancelbutton_clicked(widget)
return True
def setup_dialog(self):
self.gc_control = app.interface.msg_win_mgr.get_gc_control(
self.room_jid, self.account)
if not self.gc_control and \
self.room_jid in app.interface.minimized_controls[self.account]:
self.gc_control = \
app.interface.minimized_controls[self.account][self.room_jid]
if not self.gc_control:
self.check_next()
return
label = self.xml.get_object('label')
label.set_markup(self.prompt)
self.set_entry(self.gc_control.nick + \
app.config.get('gc_proposed_nick_char'))
def check_next(self):
if not self.room_queue:
self.cancel_handler = None
self.dialog.destroy()
if 'change_nick_dialog' in app.interface.instances:
del app.interface.instances['change_nick_dialog']
return
self.account, self.room_jid, self.prompt, self.change_nick = \
self.room_queue.pop(0)
self.setup_dialog()
self.dialog.show()
def on_okbutton_clicked(self, widget):
nick = self.get_text()
if nick:
nick = nick
# send presence to room
try:
nick = helpers.parse_resource(nick)
except Exception:
# invalid char
ErrorDialog(_('Invalid nickname'),
_('The nickname contains invalid characters.'))
return
self.on_ok(nick, self.is_checked())
def on_ok(self, nick, is_checked):
app.connections[self.account].get_module('MUC').change_nick(
self.room_jid, nick)
if app.gc_connected[self.account][self.room_jid]:
# We are changing nick, we will change self.nick when we receive
# presence that inform that it works
self.gc_control.new_nick = nick
else:
# We are connecting, we will not get a changed nick presence so
# change it NOW. We don't already have a nick so it's harmless
self.gc_control.nick = nick
self.check_next()
def on_cancelbutton_clicked(self, widget):
self.gc_control.new_nick = ''
self.check_next()
def add_room(self, account, room_jid, prompt, change_nick=False):
if (account, room_jid, prompt, change_nick) not in self.room_queue:
self.room_queue.append((account, room_jid, prompt, change_nick))
class InputTextDialog(CommonInputDialog):
"""
Class for multilines Input dialog (more place than InputDialog)
......
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