From f1e6a30dccf7446484542df918e69b59d9758adc Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Sun, 27 Mar 2005 21:35:55 +0000
Subject: [PATCH] we can now choose a group when we add a user

---
 Core/core.py                    |  2 +-
 plugins/gtkgui/dialogs.py       | 11 ++++++++++-
 plugins/gtkgui/gtkgui.glade     |  2 +-
 plugins/gtkgui/gtkgui.py        |  3 ++-
 plugins/gtkgui/roster_window.py |  6 ++++--
 5 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/Core/core.py b/Core/core.py
index a661b4de2a..b73ae94e5c 100644
--- a/Core/core.py
+++ b/Core/core.py
@@ -572,7 +572,7 @@ class GajimCore:
 
 	def connect(self, account):
 		"""Connect and authentificate to the Jabber server"""
-		hostname = self.cfgParser.tab[account]["hostname"]
+		hostname = self.cfgParser.tab[account]['hostname']
 		name = self.cfgParser.tab[account]["name"]
 		password = self.passwords[account]
 		if not self.cfgParser.tab[account].has_key('resource'):
diff --git a/plugins/gtkgui/dialogs.py b/plugins/gtkgui/dialogs.py
index efc9d0824e..7993d436d8 100644
--- a/plugins/gtkgui/dialogs.py
+++ b/plugins/gtkgui/dialogs.py
@@ -423,7 +423,9 @@ class Add_contact_window:
 		start_iter = message_buffer.get_start_iter()
 		end_iter = message_buffer.get_end_iter()
 		message = message_buffer.get_text(start_iter, end_iter, 0)
-		self.plugin.roster.req_sub(self, jid, message, self.account, nickname)
+		group = self.group_comboboxentry.child.get_text()
+		self.plugin.roster.req_sub(self, jid, message, self.account, group,\
+			nickname)
 		if self.xml.get_widget('auto_authorize_checkbutton').get_active():
 			self.plugin.send('AUTH', self.account, jid)
 		widget.get_toplevel().destroy()
@@ -512,6 +514,13 @@ class Add_contact_window:
 			self.xml.get_widget('uid_entry').set_text(jid_splited[0])
 			if jid_splited[1] in jid_agents:
 				protocol_combobox.set_active(jid_agents.index(jid_splited[1])+1)
+
+		self.group_comboboxentry = self.xml.get_widget('group_comboboxentry')
+		liststore = gtk.ListStore(str)
+		self.group_comboboxentry.set_model(liststore)
+		for g in self.plugin.roster.groups[account].keys():
+			self.group_comboboxentry.append_text(g)
+
 		self.xml.signal_autoconnect(self)
 
 class About_dialog:
diff --git a/plugins/gtkgui/gtkgui.glade b/plugins/gtkgui/gtkgui.glade
index 2e60bfda2d..7e2b6b5c26 100644
--- a/plugins/gtkgui/gtkgui.glade
+++ b/plugins/gtkgui/gtkgui.glade
@@ -1944,7 +1944,7 @@
 	  </child>
 
 	  <child>
-	    <widget class="GtkComboBoxEntry" id="comboboxentry1">
+	    <widget class="GtkComboBoxEntry" id="group_comboboxentry">
 	      <property name="visible">True</property>
 	      <property name="items" translatable="yes"></property>
 	      <property name="add_tearoffs">False</property>
diff --git a/plugins/gtkgui/gtkgui.py b/plugins/gtkgui/gtkgui.py
index 7b755ca222..7431ba66d2 100644
--- a/plugins/gtkgui/gtkgui.py
+++ b/plugins/gtkgui/gtkgui.py
@@ -585,7 +585,8 @@ class plugin:
 				user.name = name
 			user.sub = array[2]
 			user.ask = array[3]
-			user.groups = array[4]
+			if array[4]:
+				user.groups = array[4]
 		self.roster.redraw_jid(jid, account)
 
 	def read_queue(self):
diff --git a/plugins/gtkgui/roster_window.py b/plugins/gtkgui/roster_window.py
index 508b877575..2591e6f7f9 100644
--- a/plugins/gtkgui/roster_window.py
+++ b/plugins/gtkgui/roster_window.py
@@ -590,13 +590,15 @@ class Roster_window:
 		"""Authorize a user"""
 		self.plugin.send('AUTH', account, jid)
 
-	def req_sub(self, widget, jid, txt, account, pseudo=None):
+	def req_sub(self, widget, jid, txt, account, group=None, pseudo=None):
 		"""Request subscription to a user"""
 		if not pseudo:
 			pseudo = jid
 		self.plugin.send('SUB', account, (jid, txt))
 		if not self.contacts[account].has_key(jid):
-			user1 = User(jid, pseudo, ['General'], 'requested', \
+			if not group:
+				group = 'General'
+			user1 = User(jid, pseudo, [group], 'requested', \
 				'requested', 'none', 'subscribe', '', 0, '')
 			self.contacts[account][jid] = [user1]
 			self.add_user_to_roster(jid, account)
-- 
GitLab