From 5f5afab1e236b0f8abb6318ce637f951cbf2a4d6 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Thu, 18 Jul 2013 20:32:45 +0200
Subject: [PATCH] make the Ok button of Insecure connection dialog insensitive
 when yes checkbox is not checked. Fixes #7373

---
 src/dialogs.py       | 25 +++++++++++++++++++++++++
 src/gui_interface.py | 14 +-------------
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/dialogs.py b/src/dialogs.py
index 21af116f67..f200b56369 100644
--- a/src/dialogs.py
+++ b/src/dialogs.py
@@ -1826,6 +1826,31 @@ class ConfirmationDialogDoubleCheck(ConfirmationDialog):
             is_checked_2 = False
         return [is_checked_1, is_checked_2]
 
+class PlainConnectionDialog(ConfirmationDialogDoubleCheck):
+    """
+    Dialog that is shown when using an insecure connection
+    """
+    def __init__(self, account, on_ok, on_cancel):
+        pritext = _('Insecure connection')
+        sectext = _('You are about to connect to the account %(account)s '
+            '(%(server)s) with an insecure connection. This means all your '
+            'conversations will be exchanged unencrypted. This type of '
+            'connection is really discouraged.\nAre you sure you want to do '
+            'that?') % {'account': account,
+            'server': gajim.get_hostname_from_account(account)}
+        checktext1 = _('Yes, I really want to connect insecurely')
+        tooltip1 = _('Gajim will NOT connect unless you check this box')
+        checktext2 = _('_Do not ask me again')
+        ConfirmationDialogDoubleCheck.__init__(self, pritext, sectext,
+            checktext1, checktext2, tooltip1=tooltip1, on_response_ok=on_ok,
+            on_response_cancel=on_cancel, is_modal=False)
+        self.ok_button = self.action_area.get_children()[0] # right to left
+        self.ok_button.set_sensitive(False)
+        self.checkbutton1.connect('clicked', self.on_checkbutton_clicked)
+
+    def on_checkbutton_clicked(self, widget):
+        self.ok_button.set_sensitive(widget.get_active())
+
 class ConfirmationDialogDoubleRadio(ConfirmationDialog):
     """
     HIG compliant confirmation dialog with 2 radios
diff --git a/src/gui_interface.py b/src/gui_interface.py
index cf5192a089..122895bb3b 100644
--- a/src/gui_interface.py
+++ b/src/gui_interface.py
@@ -1409,23 +1409,11 @@ class Interface:
             gajim.nec.push_incoming_event(OurShowEvent(None, conn=obj.conn,
                 show='offline'))
 
-        pritext = _('Insecure connection')
-        sectext = _('You are about to connect to the account %(account)s '
-            '(%(server)s) with an insecure connection. This means all your '
-            'conversations will be exchanged unencrypted. This type of '
-            'connection is really discouraged.\nAre you sure you want to do '
-            'that?') % {'account': obj.conn.name,
-            'server': gajim.get_hostname_from_account(obj.conn.name)}
-        checktext1 = _('Yes, I really want to connect insecurely')
-        tooltip1 = _('Gajim will NOT connect unless you check this box')
-        checktext2 = _('_Do not ask me again')
         if 'plain_connection' in self.instances[obj.conn.name]['online_dialog']:
             self.instances[obj.conn.name]['online_dialog']['plain_connection'].\
                 destroy()
         self.instances[obj.conn.name]['online_dialog']['plain_connection'] = \
-            dialogs.ConfirmationDialogDoubleCheck(pritext, sectext, checktext1,
-            checktext2, tooltip1=tooltip1, on_response_ok=on_ok,
-            on_response_cancel=on_cancel, is_modal=False)
+            dialogs.PlainConnectionDialog(obj.conn.name, on_ok, on_cancel)
 
     def handle_event_insecure_ssl_connection(self, obj):
         # ('INSECURE_SSL_CONNECTION', account, (connection, connection_type))
-- 
GitLab