From 210d9895253f355cb2f4c7fd187188aac254f25f Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Sat, 2 Jul 2005 11:06:02 +0000
Subject: [PATCH] encrytion state is keeped even if we close the chat window

---
 src/common/gajim.py       |  2 ++
 src/config.py             |  3 +++
 src/gajim.py              |  2 ++
 src/tabbed_chat_window.py | 13 ++++++++-----
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/common/gajim.py b/src/common/gajim.py
index 733eae901f..44e78a7d93 100644
--- a/src/common/gajim.py
+++ b/src/common/gajim.py
@@ -40,3 +40,5 @@ if LANG:
 	LANG = LANG[:2] # en, fr, el etc..
 else:
 	LANG = 'en'
+
+encrypted_chats = {} # list of encrypted chats {acct1: [jid1, jid2], ..}
diff --git a/src/config.py b/src/config.py
index a28690c22b..24c238a959 100644
--- a/src/config.py
+++ b/src/config.py
@@ -1163,6 +1163,7 @@ _('To change the account name, it must be disconnected.')).get_response()
 					self.plugin.roster.to_be_removed[self.account]
 				self.plugin.sleeper_state[name] = \
 					self.plugin.sleeper_state[self.account]
+				gajim.encrypted_chats[name] = gajim.encrypted_chats[self.account]
 				#upgrade account variable in opened windows
 				for kind in ['infos', 'chats', 'gc', 'gc_config']:
 					for j in self.plugin.windows[name][kind]:
@@ -1178,6 +1179,7 @@ _('To change the account name, it must be disconnected.')).get_response()
 				del self.plugin.roster.groups[self.account]
 				del self.plugin.roster.contacts[self.account]
 				del self.plugin.sleeper_state[self.account]
+				del gajim.encrypted_chats[self.account]
 				gajim.connections[self.account].name = name
 				gajim.connections[name] = gajim.connections[self.account]
 				del gajim.connections[self.account]
@@ -1227,6 +1229,7 @@ _('To change the account name, it must be disconnected.')).get_response()
 		self.plugin.nicks[name] = config['name']
 		self.plugin.allow_notifications[name] = False
 		self.plugin.sleeper_state[name] = 0
+		gajim.encrypted_chats[name] = []
 		#refresh accounts window
 		if self.plugin.windows.has_key('accounts'):
 			self.plugin.windows['accounts'].init_accounts()
diff --git a/src/gajim.py b/src/gajim.py
index 73bc693adc..f177ace9ed 100755
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -508,6 +508,7 @@ class Interface:
 		self.roster.newly_added[name] = []
 		self.roster.to_be_removed[name] = []
 		self.sleeper_state[name] = 0
+		gajim.encrypted_chats[name] = []
 		if self.windows.has_key('accounts'):
 			self.windows['accounts'].init_accounts()
 		self.roster.draw_roster()
@@ -844,6 +845,7 @@ class Interface:
 												#1:online and use sleeper
 												#2:autoaway and use sleeper
 												#3:autoxa and use sleeper
+			gajim.encrypted_chats[a] = []
 
 		self.roster = roster_window.RosterWindow(self)
 		path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps/gajim.png')
diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py
index e991e196f6..ae6183fcbf 100644
--- a/src/tabbed_chat_window.py
+++ b/src/tabbed_chat_window.py
@@ -44,7 +44,6 @@ class TabbedChatWindow(chat.Chat):
 	def __init__(self, user, plugin, account):
 		chat.Chat.__init__(self, plugin, account, 'tabbed_chat_window')
 		self.users = {}
-		self.encrypted = {}
 		self.new_user(user)
 		self.show_title()
 		self.xml.signal_connect('on_tabbed_chat_window_destroy',
@@ -238,7 +237,9 @@ class TabbedChatWindow(chat.Chat):
 		self.xmls[user.jid] = gtk.glade.XML(GTKGUI_GLADE, 'chats_vbox', APP)
 		self.childs[user.jid] = self.xmls[user.jid].get_widget('chats_vbox')
 		self.users[user.jid] = user
-		self.encrypted[user.jid] = False
+
+		if user.jid in gajim.encrypted_chats[self.account]:
+			self.xmls[user.jid].get_widget('gpg_togglebutton').set_active(True)
 		
 		xm = gtk.glade.XML(GTKGUI_GLADE, 'tabbed_chat_popup_menu', APP)
 		xm.signal_autoconnect(self)
@@ -378,13 +379,15 @@ class TabbedChatWindow(chat.Chat):
 			kind = 'status'
 			name = ''
 		else:
-			if encrypted and not self.encrypted[jid]:
+			ec = gajim.encrypted_chats[self.account]
+			if encrypted and jid not in ec:
 				chat.Chat.print_conversation_line(self, 'Encryption enabled', jid,
 					'status', '', tim)
-			if not encrypted and self.encrypted[jid]:
+				ec.append(jid)
+			if not encrypted and jid in ec:
 				chat.Chat.print_conversation_line(self, 'Encryption disabled', jid,
 					'status', '', tim)
-			self.encrypted[jid] = encrypted
+				ec.remove(jid)
 			self.xmls[jid].get_widget('gpg_togglebutton').set_active(encrypted)
 			if contact:
 				kind = 'outgoing'
-- 
GitLab