ask to change nickname for a groupchat only once. Fixes #4250

This commit is contained in:
Yann Leboulanger 2008-08-29 08:06:28 +00:00
parent 88103f03df
commit bcc39c4e1c
3 changed files with 22 additions and 18 deletions

View File

@ -2014,13 +2014,8 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
_('You are not in the members list in groupchat %s.') % \
room_jid))
elif errcode == '409': # nick conflict
# the jid_from in this case is FAKE JID: room_jid/nick
# resource holds the bad nick so propose a new one
proposed_nickname = resource + \
gajim.config.get('gc_proposed_nick_char')
room_jid = gajim.get_room_from_fjid(who)
self.dispatch('ASK_NEW_NICK', (room_jid, _('Unable to join group chat'),
_('Your desired nickname in group chat %s is in use or registered by another occupant.\nPlease specify another nickname below:') % room_jid, proposed_nickname))
self.dispatch('ASK_NEW_NICK', (room_jid,))
else: # print in the window the error
self.dispatch('ERROR_ANSWER', ('', jid_stripped,
errmsg, errcode))

View File

@ -536,17 +536,18 @@ class Interface:
dialogs.InformationDialog(data[0], data[1])
def handle_event_ask_new_nick(self, account, data):
#('ASK_NEW_NICK', account, (room_jid, title_text, prompt_text, proposed_nick))
#('ASK_NEW_NICK', account, (room_jid,))
room_jid = data[0]
title = data[1]
prompt = data[2]
proposed_nick = data[3]
gc_control = self.msg_win_mgr.get_gc_control(room_jid, account)
if not gc_control and \
room_jid in self.minimized_controls[account]:
gc_control = self.minimized_controls[account][room_jid]
if gc_control: # user may close the window before we are here
gc_control.show_change_nick_input_dialog(title, prompt, proposed_nick)
title = _('Unable to join group chat')
prompt = _('Your desired nickname in group chat %s is in use or '
'registered by another occupant.\nPlease specify another nickname '
'below:') % room_jid
gc_control.show_change_nick_input_dialog(title, prompt)
def handle_event_http_auth(self, account, data):
#('HTTP_AUTH', account, (method, url, transaction_id, iq_obj, msg))

View File

@ -171,6 +171,7 @@ class GroupchatControl(ChatControlBase):
self.is_continued=is_continued
self.is_anonymous = True
self.change_nick_dialog = None
self.actions_button = self.xml.get_widget('muc_window_actions_button')
id = self.actions_button.connect('clicked', self.on_actions_button_clicked)
@ -1589,10 +1590,14 @@ class GroupchatControl(ChatControlBase):
else:
return 'visitor'
def show_change_nick_input_dialog(self, title, prompt, proposed_nick = None):
def show_change_nick_input_dialog(self, title, prompt):
'''asks user for new nick and on ok it sets it on room'''
if self.change_nick_dialog:
# A dialog is already opened
return
def on_ok(widget):
nick = instance.input_entry.get_text().decode('utf-8')
nick = self.change_nick_dialog.input_entry.get_text().decode('utf-8')
self.change_nick_dialog = None
try:
nick = helpers.parse_resource(nick)
except:
@ -1602,7 +1607,7 @@ class GroupchatControl(ChatControlBase):
return
gajim.connections[self.account].join_gc(nick, self.room_jid, None)
if gajim.gc_connected[self.account][self.room_jid]:
# We are changing nick, we will change self.nick when we receive
# We are changing nick, we will change self.nick when we receive
# presence that inform that it works
self.new_nick = nick
else:
@ -1610,9 +1615,12 @@ class GroupchatControl(ChatControlBase):
# change it NOW. We don't already have a nick so it's harmless
self.nick = nick
def on_cancel():
self.new_nick = ''
instance = dialogs.InputDialog(title, prompt, proposed_nick,
is_modal = False, ok_handler = on_ok, cancel_handler = on_cancel)
self.change_nick_dialog = None
self.new_nick = ''
proposed_nick = self.nick + gajim.config.get('gc_proposed_nick_char')
self.change_nick_dialog = dialogs.InputDialog(title, prompt,
proposed_nick, is_modal=False, ok_handler=on_ok,
cancel_handler=on_cancel)
def minimize(self, status='offline'):
# Minimize it
@ -1744,7 +1752,7 @@ class GroupchatControl(ChatControlBase):
def _on_change_nick_menuitem_activate(self, widget):
title = _('Changing Nickname')
prompt = _('Please specify the new nickname you want to use:')
self.show_change_nick_input_dialog(title, prompt, self.nick)
self.show_change_nick_input_dialog(title, prompt)
def _on_configure_room_menuitem_activate(self, widget):
c = gajim.contacts.get_gc_contact(self.account, self.room_jid, self.nick)