From 316ca92083d49abbb43d2410b5b50de4538c7d75 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Wed, 8 Jun 2005 15:48:53 +0000
Subject: [PATCH] proxy is fixed (TODO: mange proxies)

---
 src/common/config.py     | 13 +++++---
 src/common/connection.py | 24 +++++++-------
 src/config.py            | 70 +++++++++++-----------------------------
 src/gtkgui.glade         |  4 +--
 4 files changed, 41 insertions(+), 70 deletions(-)

diff --git a/src/common/config.py b/src/common/config.py
index 25c6090486..ec6e8e7cbd 100644
--- a/src/common/config.py
+++ b/src/common/config.py
@@ -115,11 +115,7 @@ class Config:
 			'resource': [ opt_str, 'gajim' ],
 			'priority': [ opt_int, 5 ],
 			'autoconnect': [ opt_bool, False ],
-			'use_proxy': [ opt_bool, False ],
-			'proxyhost': [ opt_str, '' ],
-			'proxyport': [ opt_int, 3128 ],
-			'proxyuser': [ opt_str, '' ],
-			'proxypass': [ opt_str, '' ],
+			'proxy': [ opt_str, '' ],
 			'keyid': [ opt_str, '' ],
 			'keyname': [ opt_str, '' ],
 			'usessl': [ opt_bool, False ],
@@ -139,6 +135,13 @@ class Config:
 			'enabled': [ opt_bool, True ],
 			'path': [ opt_str, '' ],
 		}, {}),
+		'proxies': ({
+			'type': [ opt_str, 'http' ],
+			'host': [ opt_str, '' ],
+			'port': [ opt_int, 3128 ],
+			'user': [ opt_str, '' ],
+			'password': [ opt_str, '' ],
+		}, {}),
 	}
 
 	emoticons_default = {
diff --git a/src/common/connection.py b/src/common/connection.py
index cf23a5f5f2..f9bd765f81 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -597,15 +597,12 @@ def connect(self):
 		if self.connection:
 			return self.connection
 		self.connected = 1
-		if gajim.config.get_per('accounts', self.name, 'use_proxy'):
-			proxy = {'host': gajim.config.get_per('accounts', self.name,
-				'proxyhost')}
-			proxy['port'] = gajim.config.get_per('accounts', self.name,
-				'proxyport')
-			proxy['user'] = gajim.config.get_per('accounts', self.name,
-				'proxyuser')
-			proxy['password'] = gajim.config.get_per('accounts', self.name,
-				'proxypass')
+		p = gajim.config.get_per('accounts', self.name, 'proxy')
+		if p and gajim.config.get_per('proxies').has_key(p):
+			proxy = {'host': gajim.config.get_per('proxies', p, 'host')}
+			proxy['port'] = gajim.config.get_per('proxies', p, 'port')
+			proxy['user'] = gajim.config.get_per('proxies', p, 'user')
+			proxy['password'] = gajim.config.get_per('proxies', p, 'pass')
 		else:
 			proxy = None
 		if gajim.verbose:
@@ -880,9 +877,12 @@ def new_account(self, name, config):
 		# If a connection already exist we cannot create a new account
 		if self.connection:
 			return
-		if config['use_proxy']:
-			proxy = {'host': config['proxyhost'], 'port': config['proxyport'],
-				'user': config['proxyuser'], 'password': config['proxypass']}
+		p = config['proxy']
+		if p and gajim.config.get_per('proxies').has_key(p):
+			proxy = {'host': gajim.config.get_per('proxies', p, 'host')}
+			proxy['port'] = gajim.config.get_per('proxies', p, 'port')
+			proxy['user'] = gajim.config.get_per('proxies', p, 'user')
+			proxy['password'] = gajim.config.get_per('proxies', p, 'pass')
 		else:
 			proxy = None
 		if gajim.verbose:
diff --git a/src/config.py b/src/config.py
index fe0999a93e..8ae4eddf98 100644
--- a/src/config.py
+++ b/src/config.py
@@ -1069,13 +1069,6 @@ def on_checkbutton_toggled(self, widget, widgets):
 		for w in widgets:
 			w.set_sensitive(widget.get_active())
 
-	def on_use_proxy_checkbutton_toggled(self, widget):
-		proxy_table = self.xml.get_widget('proxy_table')
-		widgets = proxy_table.get_children()
-		widgets.append(proxy_table)
-		self.on_checkbutton_toggled(widget, widgets)
-
-
 	def init_account_gpg(self):
 		keyid = gajim.config.get_per('accounts', self.account, 'keyid')
 		keyname = gajim.config.get_per('accounts', self.account, 'keyname')
@@ -1119,28 +1112,20 @@ def init_account(self):
 			'accounts', self.account, 'resource'))
 		self.xml.get_widget('priority_spinbutton').set_value(gajim.config.\
 			get_per('accounts', self.account, 'priority'))
-		
-		use_proxy = gajim.config.get_per('accounts', self.account, 'use_proxy')
-		self.xml.get_widget('use_proxy_checkbutton').set_active(use_proxy)
-		
-		entry = self.xml.get_widget('proxyhost_entry')
-		entry.set_sensitive(use_proxy)
-		entry.set_text(gajim.config.get_per('accounts', self.account,
-							'proxyhost'))
-		entry = self.xml.get_widget('proxyport_entry')
-		entry.set_sensitive(use_proxy)
-		entry.set_text(str(gajim.config.get_per('accounts', self.account,
-							'proxyport')))
-			
-		entry = self.xml.get_widget('proxyuser_entry')
-		entry.set_sensitive(use_proxy)
-		entry.set_text(gajim.config.get_per('accounts', self.account,
-							'proxyuser'))
-			
-		entry = self.xml.get_widget('proxypass_entry')
-		entry.set_sensitive(use_proxy)
-		entry.set_text(gajim.config.get_per('accounts', self.account,
-							'proxypass'))
+
+		# init proxy list
+		our_proxy = gajim.config.get_per('accounts', self.account, 'proxy')
+		if not our_proxy:
+			our_proxy = 'None'
+		self.proxy_combobox = self.xml.get_widget('proxies_combobox')
+		model = gtk.ListStore(gobject.TYPE_STRING)
+		self.proxy_combobox.set_model(model)
+		l = gajim.config.get_per('proxies')
+		l.insert(0, 'None')
+		for i in range(len(l)):
+			model.append([l[i]])
+			if our_proxy == l[i]:
+				self.proxy_combobox.set_active(i)
 
 		usessl = gajim.config.get_per('accounts', self.account, 'usessl')
 		self.xml.get_widget('use_ssl_checkbutton').set_active(usessl)
@@ -1212,28 +1197,11 @@ def on_save_button_clicked(self, widget):
 		config['sync_with_global_status'] = self.xml.get_widget(
 				'sync_with_global_status_checkbutton').get_active()
 		
-		config['use_proxy'] = self.xml.get_widget('use_proxy_checkbutton').\
-																					get_active()
-		config['proxyhost'] = self.xml.get_widget('proxyhost_entry').get_text()
-		config['proxyport'] = self.xml.get_widget('proxyport_entry').get_text()
-		config['proxyuser'] = self.xml.get_widget('proxyuser_entry').get_text()
-		config['proxypass'] = self.xml.get_widget('proxypass_entry').get_text()
-		if config['use_proxy']:
-			if config['proxyport'] != '':
-				if not config['proxyport'].isdigit():
-					dialogs.Error_dialog(_('Invalid proxy port'),
-						_('Port numbers must contain digits only.')).get_response()
-					return
-				config['proxyport'] = int(config['proxyport'])
-
-			else:
-				dialogs.Error_dialog(_('Invalid proxy port'),
-					_('You must enter a port number to use a proxy.')).get_response()
-				return
-			if config['proxyhost'] == '':
-				dialogs.Error_dialog(_('Invalid proxy host'),
-					_('You must enter a proxy host to use a proxy.')).get_response()
-				return
+		active = self.proxy_combobox.get_active()
+		proxy = self.proxy_combobox.get_model()[active][0]
+		if proxy == 'None':
+			proxy = ''
+		config['proxy'] = proxy
 
 		config['usessl'] = self.xml.get_widget('use_ssl_checkbutton').get_active()
 		(config['name'], config['hostname']) = jid.split('@')
diff --git a/src/gtkgui.glade b/src/gtkgui.glade
index 729047f26d..80fbb3a1e5 100644
--- a/src/gtkgui.glade
+++ b/src/gtkgui.glade
@@ -1058,7 +1058,7 @@
 		  <child>
 		    <widget class="GtkComboBox" id="proxies_combobox">
 		      <property name="visible">True</property>
-		      <property name="items" translatable="yes">None</property>
+		      <property name="items" translatable="yes"></property>
 		    </widget>
 		    <packing>
 		      <property name="padding">0</property>
@@ -13724,7 +13724,7 @@ the Jabber network.</property>
   </child>
 </widget>
 
-<widget class="GtkWindow" id="manage_proxy_profiles_window">
+<widget class="GtkWindow" id="manage_proxies_window">
   <property name="border_width">6</property>
   <property name="visible">True</property>
   <property name="title" translatable="yes">Manage Proxy Profiles</property>
-- 
GitLab