From f838c2faa2a382c32e664aea51be530c968779db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philipp=20H=C3=B6rist?= <philipp@hoerist.com>
Date: Wed, 27 Mar 2019 23:32:40 +0100
Subject: [PATCH] MUC: Use NewConfirmationDialog for file transfer

---
 gajim/chat_control_base.py | 52 +++++++++++++++++++++++---------------
 gajim/groupchat_control.py |  6 ++---
 2 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/gajim/chat_control_base.py b/gajim/chat_control_base.py
index 3fcc68053e..b0e87730f2 100644
--- a/gajim/chat_control_base.py
+++ b/gajim/chat_control_base.py
@@ -51,7 +51,8 @@ from gajim.message_control import MessageControl
 from gajim.conversation_textview import ConversationTextview
 from gajim.message_textview import MessageTextView
 
-from gajim.gtk.dialogs import NonModalConfirmationDialog
+from gajim.gtk.dialogs import NewConfirmationDialog
+from gajim.gtk.dialogs import DialogButton
 from gajim.gtk import util
 from gajim.gtk.util import convert_rgb_to_hex
 from gajim.gtk.util import at_the_end
@@ -1042,29 +1043,38 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
         """
         def _on_ok(c):
             app.interface.instances['file_transfers'].show_file_send_request(
-                    self.account, c)
+                self.account, c)
         if self.type_id == message_control.TYPE_PM:
             gc_contact = self.gc_contact
-        if gc_contact:
-            # gc or pm
-            gc_control = app.interface.msg_win_mgr.get_gc_control(
-                    gc_contact.room_jid, self.account)
-            self_contact = app.contacts.get_gc_contact(self.account,
-                    gc_control.room_jid, gc_control.nick)
-            if gc_control.is_anonymous and gc_contact.affiliation.value not in ['admin',
-            'owner'] and self_contact.affiliation.value in ['admin', 'owner']:
-                contact = app.contacts.get_contact(self.account, gc_contact.jid)
-                if not contact or contact.sub not in ('both', 'to'):
-                    prim_text = _('Really send file?')
-                    sec_text = _('If you send a file to %s, your real JID will '
-                        'be revealed.') % gc_contact.name
-                    dialog = NonModalConfirmationDialog(prim_text,
-                        sec_text, on_response_ok=(_on_ok, gc_contact))
-                    dialog.popup()
-                    return
-            _on_ok(gc_contact)
+
+        if not gc_contact:
+            _on_ok(self.contact)
             return
-        _on_ok(self.contact)
+
+        # gc or pm
+        gc_control = app.interface.msg_win_mgr.get_gc_control(
+            gc_contact.room_jid, self.account)
+        self_contact = app.contacts.get_gc_contact(self.account,
+                                                   gc_control.room_jid,
+                                                   gc_control.nick)
+        if (gc_control.is_anonymous and
+                gc_contact.affiliation.value not in ['admin', 'owner'] and
+                self_contact.affiliation.value in ['admin', 'owner']):
+            contact = app.contacts.get_contact(self.account, gc_contact.jid)
+            if not contact or contact.sub not in ('both', 'to'):
+
+                NewConfirmationDialog(
+                    _('Privacy'),
+                    _('Warning'),
+                    _('If you send a file to <b>%s</b>, '
+                      'your real JID will be revealed.' % gc_contact.name),
+                    [DialogButton.make('Cancel'),
+                     DialogButton.make(
+                         'OK',
+                         text=_('Continue'),
+                         callback=lambda: _on_ok(gc_contact))]).show()
+                return
+        _on_ok(gc_contact)
 
     def on_notify_menuitem_toggled(self, widget):
         app.config.set_per('rooms', self.contact.jid, 'notify_on_all_messages',
diff --git a/gajim/groupchat_control.py b/gajim/groupchat_control.py
index f8ea8cf453..a0bdb0808b 100644
--- a/gajim/groupchat_control.py
+++ b/gajim/groupchat_control.py
@@ -2786,12 +2786,12 @@ class GroupchatControl(ChatControlBase):
         self.handlers[id_] = item
 
         item = xml.get_object('send_file_menuitem')
-        if not c.resource:
+        if not c.jid:
             item.set_sensitive(False)
         else:
-            item.set_sensitive(False)
+            item.set_sensitive(True)
             # ToDo: integrate HTTP File Upload
-            id_ = item.connect('activate', self._on_send_file_jingle, c)
+            id_ = item.connect('activate', lambda x: self._on_send_file_jingle(c))
             self.handlers[id_] = item
 
         # show the popup now!
-- 
GitLab