From 75ee2169d7525be17c15c3e1b3249349a69eed38 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Fri, 30 Nov 2007 15:18:26 +0000
Subject: [PATCH] fix the ability to choose GPG key before we connect remove
 useless config option usegpg

---
 src/common/config.py                       | 1 -
 src/common/connection.py                   | 8 ++------
 src/common/zeroconf/connection_zeroconf.py | 7 +++----
 src/config.py                              | 6 +++---
 4 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/src/common/config.py b/src/common/config.py
index 441d43b993..3c403f460f 100644
--- a/src/common/config.py
+++ b/src/common/config.py
@@ -157,7 +157,6 @@ class Config:
 		'lastfm_username': [ opt_str, '', _('The username used to identify the Last.fm account.')],
 		'notify_on_new_gmail_email': [ opt_bool, True ],
 		'notify_on_new_gmail_email_extra': [ opt_bool, False ],
-		'usegpg': [ opt_bool, False, '', True ],
 		'use_gpg_agent': [ opt_bool, False ],
 		'change_roster_title': [ opt_bool, True, _('Add * and [n] in roster title?')],
 		'restore_lines': [opt_int, 4, _('How many lines to remember from previous conversation when a chat tab/window is reopened.')],
diff --git a/src/common/connection.py b/src/common/connection.py
index d568143643..55d6d6627c 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -107,6 +107,8 @@ class Connection(ConnectionHandlers):
 		self.last_connection = None # last ClientCommon instance
 		self.is_zeroconf = False
 		self.gpg = None
+		if USE_GPG:
+			self.gpg = GnuPG.GnuPG(gajim.config.get('use_gpg_agent'))
 		self.status = ''
 		self.priority = gajim.get_priority(name, 'offline')
 		self.old_show = ''
@@ -767,9 +769,6 @@ class Connection(ConnectionHandlers):
 					})
 			if USE_GPG and not self.gpg:
 				self.gpg = GnuPG.GnuPG(gajim.config.get('use_gpg_agent'))
-				gajim.config.set('usegpg', True)
-			else:
-				gajim.config.set('usegpg', False)
 			self.connect_and_init(show, msg, sign_msg)
 
 		elif show == 'offline':
@@ -1036,9 +1035,6 @@ class Connection(ConnectionHandlers):
 				return
 			if USE_GPG:
 				self.gpg = GnuPG.GnuPG(gajim.config.get('use_gpg_agent'))
-				gajim.config.set('usegpg', True)
-			else:
-				gajim.config.set('usegpg', False)
 			gajim.connections[self.name] = self
 			self.dispatch('ACC_OK', (self.new_account_info))
 			self.new_account_info = None
diff --git a/src/common/zeroconf/connection_zeroconf.py b/src/common/zeroconf/connection_zeroconf.py
index 235bada1a3..36f56a3476 100644
--- a/src/common/zeroconf/connection_zeroconf.py
+++ b/src/common/zeroconf/connection_zeroconf.py
@@ -62,6 +62,8 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
 		self.connected = 0 # offline
 		self.connection = None
 		self.gpg = None
+		if USE_GPG:
+			self.gpg = GnuPG.GnuPG(gajim.config.get('use_gpg_agent'))
 		self.is_zeroconf = True
 		self.privacy_rules_supported = False
 		self.blocked_contacts = []
@@ -87,10 +89,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
 		# Do we continue connection when we get roster (send presence,get vcard...)
 		self.continue_connect_info = None
 		if USE_GPG:
-			self.gpg = GnuPG.GnuPG()
-			gajim.config.set('usegpg', True)
-		else:
-			gajim.config.set('usegpg', False)
+			self.gpg = GnuPG.GnuPG(gajim.config.get('use_gpg_agent'))
 		
 		self.get_config_values_or_default()
 		
diff --git a/src/config.py b/src/config.py
index 20540364e6..20f09dd161 100644
--- a/src/config.py
+++ b/src/config.py
@@ -1514,7 +1514,7 @@ class AccountsWindow:
 
 		# Personal tab
 		gpg_key_label = self.xml.get_widget('gpg_key_label2')
-		if gajim.config.get('usegpg'):
+		if rajim.connections[gajim.ZEROCONF_ACC_NAME].gpg:
 			self.xml.get_widget('gpg_choose_button2').set_sensitive(True)
 			self.init_account_gpg()
 		else:
@@ -1542,7 +1542,7 @@ class AccountsWindow:
 		use_gpg_agent_checkbutton = self.xml.get_widget(
 			'use_gpg_agent_checkbutton' + widget_name_add)
 
-		if not keyid or not gajim.config.get('usegpg'):
+		if not keyid or not gajim.connections[account].gpg:
 			use_gpg_agent_checkbutton.set_sensitive(False)
 			gpg_key_label.set_text(_('No key selected'))
 			gpg_name_label.set_text('')
@@ -1605,7 +1605,7 @@ class AccountsWindow:
 
 		# Personal tab
 		gpg_key_label = self.xml.get_widget('gpg_key_label1')
-		if gajim.config.get('usegpg'):
+		if gajim.connections[account].gpg:
 			self.xml.get_widget('gpg_choose_button1').set_sensitive(True)
 			self.init_account_gpg()
 		else:
-- 
GitLab