From 8f239a4be07248ab3c805bf5422d143257e27c6b Mon Sep 17 00:00:00 2001
From: Dimitur Kirov <dkirov@gmail.com>
Date: Mon, 8 May 2006 21:59:09 +0000
Subject: [PATCH] moved completion definition in a function
 get_completion_liststore in gtkgui_helpers

---
 src/dialogs.py        | 17 ++---------------
 src/gtkgui_helpers.py | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/src/dialogs.py b/src/dialogs.py
index 020f49f158..6ad9754e52 100644
--- a/src/dialogs.py
+++ b/src/dialogs.py
@@ -997,20 +997,10 @@ class NewChatDialog(InputDialog):
 			title = _('Start Chat')
 		prompt_text = _('Fill in the jid, or nick of the contact you would like\nto send a chat message to:')
 		InputDialog.__init__(self, title, prompt_text, is_modal = False)
-		# create the completion model for input_entry
-		completion = gtk.EntryCompletion()
-		liststore = gtk.ListStore(gtk.gdk.Pixbuf, str)
 		
-		render_pixbuf = gtk.CellRendererPixbuf()
-		completion.pack_start(render_pixbuf, expand = False)
-		completion.add_attribute(render_pixbuf, 'pixbuf', 0)
-		
-		render_text = gtk.CellRendererText()
-		completion.pack_start(render_text, expand = True)
-		completion.add_attribute(render_text, 'text', 1)
-		completion.set_property('text_column', 1)
-		# add all contacts to the model
 		self.completion_dict = {}
+		liststore = gtkgui_helpers.get_completion_liststore(self.input_entry)
+		# add all contacts to the model
 		for jid in gajim.contacts.get_jid_list(account):
 			contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
 			self.completion_dict[jid] = contact
@@ -1027,9 +1017,6 @@ class NewChatDialog(InputDialog):
 			img =  gajim.interface.roster.jabber_state_images['16'][contact.show]
 			liststore.append((img.get_pixbuf(), jid))
 
-		completion.set_model(liststore)
-		self.input_entry.set_completion(completion)
-
 		self.ok_handler = self.new_chat_response
 		okbutton = self.xml.get_widget('okbutton')
 		okbutton.connect('clicked', self.on_okbutton_clicked)
diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py
index 13093face9..e6657b04d5 100644
--- a/src/gtkgui_helpers.py
+++ b/src/gtkgui_helpers.py
@@ -50,6 +50,25 @@ def get_glade(file_name, root = None):
 	file_path = os.path.join(GLADE_DIR, file_name)
 	return gtk.glade.XML(file_path, root=root, domain=i18n.APP)
 
+def get_completion_liststore(entry):
+	''' create a completion model for entry widget
+	completion list consists of (Pixbuf, Text) rows'''
+	completion = gtk.EntryCompletion()
+	liststore = gtk.ListStore(gtk.gdk.Pixbuf, str)
+	
+	render_pixbuf = gtk.CellRendererPixbuf()
+	completion.pack_start(render_pixbuf, expand = False)
+	completion.add_attribute(render_pixbuf, 'pixbuf', 0)
+	
+	render_text = gtk.CellRendererText()
+	completion.pack_start(render_text, expand = True)
+	completion.add_attribute(render_text, 'text', 1)
+	completion.set_property('text_column', 1)
+	completion.set_model(liststore)
+	entry.set_completion(completion)
+	return liststore
+	
+	
 def popup_emoticons_under_button(menu, button, parent_win):
 	''' pops emoticons menu under button, which is in parent_win'''
 	window_x1, window_y1 = parent_win.get_origin()
-- 
GitLab