From 1fff71ad87fd8d259fbfb077960ba54431ad2ef0 Mon Sep 17 00:00:00 2001
From: Nikos Kouremenos <kourem@gmail.com>
Date: Mon, 26 Sep 2005 22:29:52 +0000
Subject: [PATCH] refactor to allow changing our nick after nick conflict but
 first #967 needs to be fixed so I can test

---
 src/common/connection.py |  6 ++++--
 src/common/gajim.py      |  5 ++++-
 src/gajim.py             |  6 ++++++
 src/groupchat_window.py  | 10 ++++++++--
 4 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/common/connection.py b/src/common/connection.py
index cd26e51036..76252c4072 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -380,8 +380,10 @@ class Connection:
 					self.dispatch('ERROR', (_('Unable to join room'), 
 						_('You are not in the members list.')))
 				elif errcode == '409': # nick conflict
-					self.dispatch('ERROR', (_('Unable to join room'), 
-						_('Your desired nickname is in use or registered by another user.')))
+					# the jid_from in this case is FAKE JID: room_jid/nick
+					room_jid = gajim.get_room_from_fjid(jid_from)
+					self.dispatch('ASK_NEW_NICK', (room_jid, _('Unable to join room'), 
+		_('Your desired nickname is in use or registered by another occupant. Please use another:')))
 				else:	# print in the window the error
 					self.dispatch('ERROR_ANSWER', ('', jid_stripped,
 						errmsg, errcode))
diff --git a/src/common/gajim.py b/src/common/gajim.py
index 5d2824fcdc..5947c379ca 100644
--- a/src/common/gajim.py
+++ b/src/common/gajim.py
@@ -96,9 +96,12 @@ def get_room_and_nick_from_fjid(jid):
 	# gaim@conference.jabber.no/nick/nick-continued
 	# return ('gaim@conference.jabber.no', 'nick/nick-continued')
 	l = jid.split('/', 1)
-	if len(l) == 1: #No nick
+	if len(l) == 1: # No nick
 		l.append('')
 	return l
+	
+def get_room_from_fjid(jid):
+	return get_room_and_nick_from_fjid(jid)[0]
 
 def get_contact_instances_from_jid(account, jid):
 	''' we may have two or more resources on that jid '''
diff --git a/src/gajim.py b/src/gajim.py
index 6fc377edb6..8ab53acb09 100755
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -169,6 +169,11 @@ class Interface:
 	def handle_event_information(self, unused, data):
 		#('INFORMATION', account, (title_text, section_text))
 		dialogs.InformationDialog(data[0], data[1])
+		
+	def handle_event_ask_new_nick(self, unused, data):
+		#('ASK_NEW_NICK', account, (room_jid, title_text, prompt_text))
+		pass
+		# FIXME: find a way to call show_change_nick_input_dialog in GC.py
 
 	def handle_event_http_auth(self, account, data):
 		#('HTTP_AUTH', account, (method, url, iq_obj))
@@ -1043,6 +1048,7 @@ class Interface:
 			'HTTP_AUTH': self.handle_event_http_auth,
 			'VCARD_PUBLISHED': self.handle_event_vcard_published,
 			'VCARD_NOT_PUBLISHED': self.handle_event_vcard_not_published,
+			'ASK_NEW_NICK': self.handle_event_ask_new_nick,
 		}
 
 	def exec_event(self, account):
diff --git a/src/groupchat_window.py b/src/groupchat_window.py
index c584183393..db2bcefa92 100644
--- a/src/groupchat_window.py
+++ b/src/groupchat_window.py
@@ -454,8 +454,14 @@ class GroupchatWindow(chat.Chat):
 	def on_change_nick_menuitem_activate(self, widget):
 		room_jid = self.get_active_jid()
 		nick = self.nicks[room_jid]
-		instance = dialogs.InputDialog(_('Changing Nickname'),
-			_('Please specify the new nickname you want to use:'), nick)
+		title = _('Changing Nickname')
+		prompt = _('Please specify the new nickname you want to use:')
+		self.show_change_nick_input_dialog(title, prompt, nick, room_jid)
+
+	def show_change_nick_input_dialog(self, title, prompt, proposed_nick,
+		room_jid):
+		'''asks user for new nick and on ok it sets it on room'''
+		instance = dialogs.InputDialog(title, prompt, proposed_nick)
 		response = instance.get_response()
 		if response == gtk.RESPONSE_OK:
 			nick = instance.input_entry.get_text().decode('utf-8')
-- 
GitLab