From df895d4817a92456793fcefe09d34eecb6248944 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Thu, 7 Aug 2008 21:57:19 +0000
Subject: [PATCH] nearly no blocking dialogs

---
 src/config.py            | 15 ++++------
 src/dialogs.py           |  2 ++
 src/groupchat_control.py | 61 ++++++++++++++++------------------------
 3 files changed, 32 insertions(+), 46 deletions(-)

diff --git a/src/config.py b/src/config.py
index f6367ffbf9..9c8431a51d 100644
--- a/src/config.py
+++ b/src/config.py
@@ -2442,15 +2442,12 @@ def on_add_button_clicked(self, widget, affiliation):
 				'4. domain (the domain itself matches, as does any user@domain,\n'
 				'domain/resource, or address containing a subdomain.')
 
-		instance = dialogs.InputDialog(title, prompt)
-		response = instance.get_response()
-		if response != gtk.RESPONSE_OK:
-			return
-		jid = instance.input_entry.get_text().decode('utf-8')
-		if not jid:
-			return
-		model = self.affiliation_treeview[affiliation].get_model()
-		model.append((jid,'', '', ''))
+		def on_ok(jid):
+			if not jid:
+				return
+			model = self.affiliation_treeview[affiliation].get_model()
+			model.append((jid,'', '', ''))
+		instance = dialogs.InputDialog(title, prompt, ok_handler=on_ok)
 
 	def on_remove_button_clicked(self, widget, affiliation):
 		selection = self.affiliation_treeview[affiliation].get_selection()
diff --git a/src/dialogs.py b/src/dialogs.py
index 3c879d57a8..f6eee75292 100644
--- a/src/dialogs.py
+++ b/src/dialogs.py
@@ -1495,6 +1495,8 @@ def on_input_dialog_destroy(self, widget):
 
 	def on_okbutton_clicked(self, widget):
 		user_input = self.get_text()
+		if user_input:
+			user_input = user_input.decode('utf-8')
 		self.cancel_handler = None
 		self.dialog.destroy()
 		if isinstance(self.ok_handler, tuple):
diff --git a/src/groupchat_control.py b/src/groupchat_control.py
index f136025bed..6a64d0b239 100644
--- a/src/groupchat_control.py
+++ b/src/groupchat_control.py
@@ -1721,17 +1721,15 @@ def get_specific_unread(self):
 		return nb
 
 	def _on_change_subject_menuitem_activate(self, widget):
-		instance = dialogs.InputTextDialog(_('Changing Subject'),
-			_('Please specify the new subject:'), self.subject)
-		response = instance.get_response()
-		if response == gtk.RESPONSE_OK:
+		def on_ok(subject):
 			# Note, we don't update self.subject since we don't know whether it
 			# will work yet
-			start_iter, end_iter = instance.input_buffer.get_bounds()
-			subject = instance.input_buffer.get_text(start_iter, end_iter).decode(
-				'utf-8')
 			gajim.connections[self.account].send_gc_subject(self.room_jid, subject)
 
+		instance = dialogs.InputTextDialog(_('Changing Subject'),
+			_('Please specify the new subject:'), input_str=self.subject,
+			ok_handler=on_ok)
+
 	def _on_change_nick_menuitem_activate(self, widget):
 		title = _('Changing Nickname')
 		prompt = _('Please specify the new nickname you want to use:')
@@ -1748,15 +1746,7 @@ def _on_configure_room_menuitem_activate(self, widget):
 					= config.GroupchatConfigWindow(self.account, self.room_jid)
 
 	def _on_destroy_room_menuitem_activate(self, widget):
-		# Ask for a reason
-		instance = dialogs.DubbleInputDialog(_('Destroying %s') % self.room_jid,
-			_('You are going to definitively destroy this room.\n'
-			'You may specify a reason below:'),
-			_('You may also enter an alternate venue:'))
-		response = instance.get_response()
-		if response == gtk.RESPONSE_OK:
-			reason = instance.input_entry1.get_text().decode('utf-8')
-			jid = instance.input_entry2.get_text().decode('utf-8')
+		def on_ok(reason, jid):
 			if jid:
 				# Test jid
 				try:
@@ -1765,11 +1755,14 @@ def _on_destroy_room_menuitem_activate(self, widget):
 					dialogs.ErrorDialog(_('Invalid group chat Jabber ID'),
 					_('The group chat Jabber ID has not allowed characters.'))
 					return
-		else:
-			# Abord destroy operation
-			return
-		gajim.connections[self.account].destroy_gc_room(self.room_jid, reason,
-			jid)
+			gajim.connections[self.account].destroy_gc_room(self.room_jid, reason,
+				jid)
+
+		# Ask for a reason
+		instance = dialogs.DubbleInputDialog(_('Destroying %s') % self.room_jid,
+			_('You are going to definitively destroy this room.\n'
+			'You may specify a reason below:'),
+			_('You may also enter an alternate venue:'), ok_handler=on_ok)
 
 	def _on_bookmark_room_menuitem_activate(self, widget):
 		'''bookmark the room, without autojoin and not minimized'''
@@ -1937,16 +1930,13 @@ def on_list_treeview_row_collapsed(self, widget, iter, path):
 
 	def kick(self, widget, nick):
 		'''kick a user'''
+		def on_ok(reason):
+			gajim.connections[self.account].gc_set_role(self.room_jid, nick,
+				'none', reason)
+
 		# ask for reason
 		instance = dialogs.InputDialog(_('Kicking %s') % nick,
-					_('You may specify a reason below:'))
-		response = instance.get_response()
-		if response == gtk.RESPONSE_OK:
-			reason = instance.input_entry.get_text().decode('utf-8')
-		else:
-			return # stop kicking procedure
-		gajim.connections[self.account].gc_set_role(self.room_jid, nick, 'none',
-								reason)
+					_('You may specify a reason below:'), ok_handler=on_ok)
 
 	def mk_menu(self, event, iter):
 		'''Make contact's popup menu'''
@@ -2235,18 +2225,15 @@ def revoke_moderator(self, widget, nick):
 
 	def ban(self, widget, jid):
 		'''ban a user'''
+		def on_ok(reason):
+			gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
+				'outcast', reason)
+
 		# to ban we know the real jid. so jid is not fakejid
 		nick = gajim.get_nick_from_jid(jid)
 		# ask for reason
 		instance = dialogs.InputDialog(_('Banning %s') % nick,
-			_('You may specify a reason below:'))
-		response = instance.get_response()
-		if response == gtk.RESPONSE_OK:
-			reason = instance.input_entry.get_text().decode('utf-8')
-		else:
-			return # stop banning procedure
-		gajim.connections[self.account].gc_set_affiliation(self.room_jid, jid,
-			'outcast', reason)
+			_('You may specify a reason below:'), ok_handler=on_ok)
 
 	def grant_membership(self, widget, jid):
 		'''grant membership privilege to a user'''
-- 
GitLab