[gnome-keysign: 11/15] send: allow for pasting the email into the result box




commit efef0415ebe7a1ea5f8e058739bb3bbad84141ac
Author: Tobias Mueller <muelli cryptobitch de>
Date:   Fri Apr 8 14:38:39 2022 +0200

    send: allow for pasting the email into the result box
    
    Now you can import the signatures after having sent your key.

 keysign/send.py |  60 +++++++++++++++-
 keysign/send.ui | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 251 insertions(+), 19 deletions(-)
---
diff --git a/keysign/send.py b/keysign/send.py
index 65d09a8..710416f 100644
--- a/keysign/send.py
+++ b/keysign/send.py
@@ -114,11 +114,42 @@ class SendApp:
         self.label.drag_dest_add_text_targets()
         self.label.drag_dest_add_uri_targets()
 
+        self.rb.connect('drag-data-received', self.on_rb_drag_data_received)
+        # We should probably only accept drag data when we have successfully sent the key.
+        # Now we're unconditionally accepting drags.
+        self.rb.drag_dest_set(Gtk.DestDefaults.ALL, [], DRAG_ACTION)
+        self.rb.drag_dest_set_target_list(None)
+        self.rb.drag_dest_add_text_targets()
+        self.rb.drag_dest_add_uri_targets()
+        self.rb_import_okay = builder.get_object('rb_infobar_import_okay')
+        self.rb_button_ib_return_signature = builder.get_object('rb_return_signature')
+        self.rb_import_error = builder.get_object('rb_infobar_import_error')
+        assert self.rb_import_error
+        self.button_rb_import_error = builder.get_object('rb_import_error_details_button')
+
+
+
     def on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
         if self.notify is not None:
             log.debug("We are trying to send a key, no imports at this stage")
             return
+        try:
+            self.decrypt_and_import_certifications(data)
+        except errors.GPGMEError as e:
+            self.signature_import_error(e)
+        else:
+            self.signature_imported(decrypted_certifications, sender)
 
+    def on_rb_drag_data_received(self, widget, drag_context, x, y, data, info, time):
+        try:
+            decrypted_certifications = self.decrypt_and_import_certifications(data)
+        except errors.GPGMEError as e:
+            self.rb_signature_import_error(e)
+        else:
+            self.rb_signature_imported(decrypted_certifications)
+
+
+    def decrypt_and_import_certifications(self, data):
         filename = data.get_text()
         # If we don't have a filename it means that the user maybe dropped
         # an attachment or an entire email.
@@ -140,17 +171,17 @@ class SendApp:
         # and then try to find that key in our keyring.
         sender = None
 
+        decrypted_certifications = []
         try:
-            decrypted_certifications = []
             for signature in signatures:
                 decrypted_certification = gpgmeh.decrypt_signature(signature)
                 import_result = gpgmeh.import_signature(decrypted_certification)
                 decrypted_certifications.append(decrypted_certification)
         except errors.GPGMEError as e:
             log.exception("Could not import signatures")
-            self.signature_import_error(e)
+            raise
         else:
-            self.signature_imported(decrypted_certifications, sender)
+            return decrypted_certifications
 
     @inlineCallbacks
     def on_key_activated(self, widget, key):
@@ -255,6 +286,28 @@ class SendApp:
         self.klw.button_ib_import_error.hide()
         log.info("Signature import error")
 
+    def rb_signature_imported(self, decrypted_certifications):
+        self.rb_import_okay.show()
+        sender = None
+        if not sender:
+            # We do not know where to return the certification to, so we hide the button
+            self.rb_button_ib_return_signature.hide()
+        else:
+            def return_certification(button):
+                log.info("Return certification to %s (%d)",
+                    sender, len(decrypted_certifications))
+
+            self.rb_button_ib_return_signature.connect('clicked', return_certification)
+            self.rb_button_ib_return_signature.show()
+
+        log.info("Signature imported")
+
+    def rb_signature_import_error(self, e):
+        self.rb_import_error.show()
+        # We hide the error details button, because we don't have that functionality just yet
+        self.button_rb_import_error.hide()
+        log.info("Signature import error")
+
     def create_keypresent(self, discovery_code, discovery_data):
         self._deactivate_timer()
         log.info("Use this for discovering the other key: %r", discovery_data)
@@ -330,6 +383,7 @@ class SendApp:
             log.debug("Stopped network services")
 
 
+
 class App(Gtk.Application):
     def __init__(self, *args, **kwargs):
         super(App, self).__init__(*args, **kwargs)
diff --git a/keysign/send.ui b/keysign/send.ui
index 8fc28c5..cc315d7 100644
--- a/keysign/send.ui
+++ b/keysign/send.ui
@@ -713,14 +713,189 @@ FDFB F70A 0290 6C30 1813</property>
             <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
-              <object class="GtkLabel" id="success_label">
-                <property name="visible">True</property>
+              <object class="GtkInfoBar" id="rb_infobar_import_okay">
+                <property name="app-paintable">True</property>
                 <property name="can-focus">False</property>
-                <property name="label" translatable="yes">Key successfully sent.
-You should receive an email with the signature soon.
-You can drag and drop the email here to import your certification.</property>
+                <property name="no-show-all">True</property>
+                <property name="margin-bottom">5</property>
+                <property name="show-close-button">True</property>
+                <child internal-child="action_area">
+                  <object class="GtkButtonBox">
+                    <property name="can-focus">False</property>
+                    <property name="spacing">6</property>
+                    <property name="layout-style">end</property>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child internal-child="content_area">
+                  <object class="GtkBox">
+                    <property name="can-focus">False</property>
+                    <property name="spacing">16</property>
+                    <child>
+                      <object class="GtkLabel" id="rb_label_import_okay">
+                        <property name="visible">True</property>
+                        <property name="can-focus">False</property>
+                        <property name="label" translatable="yes">The signature has been successfully 
imported!</property>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkImage" id="image_import_okay1">
+                        <property name="visible">True</property>
+                        <property name="can-focus">False</property>
+                        <property name="stock">gtk-dialog-ok</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="rb_return_signature">
+                        <property name="label">gtk-undo</property>
+                        <property name="visible">True</property>
+                        <property name="can-focus">True</property>
+                        <property name="receives-default">True</property>
+                        <property name="tooltip-text" translatable="yes">Returns the received certification 
back to the sender, so that the sender can make use of your OpenPGP certificate</property>
+                        <property name="use-stock">True</property>
+                        <property name="always-show-image">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkInfoBar" id="rb_infobar_import_error">
+                <property name="app-paintable">True</property>
+                <property name="can-focus">False</property>
+                <property name="no-show-all">True</property>
+                <property name="margin-bottom">5</property>
+                <property name="show-close-button">True</property>
+                <child internal-child="action_area">
+                  <object class="GtkButtonBox">
+                    <property name="can-focus">False</property>
+                    <property name="spacing">6</property>
+                    <property name="layout-style">end</property>
+                    <child>
+                      <object class="GtkButton" id="rb_import_error_details_button">
+                        <property name="label">gtk-info</property>
+                        <property name="visible">True</property>
+                        <property name="can-focus">True</property>
+                        <property name="receives-default">True</property>
+                        <property name="tooltip-text" translatable="yes">Display more details for the 
error.</property>
+                        <property name="use-stock">True</property>
+                        <property name="always-show-image">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child internal-child="content_area">
+                  <object class="GtkBox">
+                    <property name="can-focus">False</property>
+                    <property name="spacing">16</property>
+                    <child>
+                      <object class="GtkLabel" id="rb_label_import_error">
+                        <property name="visible">True</property>
+                        <property name="can-focus">False</property>
+                        <property name="label" translatable="yes">An error occurred while trying to import 
the signature.</property>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkImage" id="image_import_error1">
+                        <property name="visible">True</property>
+                        <property name="can-focus">False</property>
+                        <property name="stock">gtk-dialog-error</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="password_error_label">
+                <property name="can-focus">False</property>
+                <property name="label" translatable="yes">Could not establish a secure connection.
+Either your partner has entered a wrong code or someone tried to intercept your connection.</property>
                 <property name="justify">center</property>
-                <property name="selectable">True</property>
                 <attributes>
                   <attribute name="weight" value="heavy"/>
                 </attributes>
@@ -728,17 +903,17 @@ You can drag and drop the email here to import your certification.</property>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">0</property>
+                <property name="position">2</property>
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="result_label">
+              <object class="GtkLabel" id="success_label">
                 <property name="visible">True</property>
                 <property name="can-focus">False</property>
-                <property name="label" translatable="yes">An unexpected error occurred.</property>
+                <property name="label" translatable="yes">Key successfully sent.
+You should receive an email with the signature soon.
+You can drag and drop the email here to import your certification.</property>
                 <property name="justify">center</property>
-                <property name="wrap">True</property>
-                <property name="wrap-mode">char</property>
                 <property name="selectable">True</property>
                 <attributes>
                   <attribute name="weight" value="heavy"/>
@@ -747,15 +922,18 @@ You can drag and drop the email here to import your certification.</property>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">1</property>
+                <property name="position">3</property>
               </packing>
             </child>
             <child>
-              <object class="GtkLabel" id="password_error_label">
+              <object class="GtkLabel" id="result_label">
+                <property name="visible">True</property>
                 <property name="can-focus">False</property>
-                <property name="label" translatable="yes">Could not establish a secure connection.
-Either your partner has entered a wrong code or someone tried to intercept your connection.</property>
+                <property name="label" translatable="yes">An unexpected error occurred.</property>
                 <property name="justify">center</property>
+                <property name="wrap">True</property>
+                <property name="wrap-mode">char</property>
+                <property name="selectable">True</property>
                 <attributes>
                   <attribute name="weight" value="heavy"/>
                 </attributes>
@@ -763,7 +941,7 @@ Either your partner has entered a wrong code or someone tried to intercept your
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">2</property>
+                <property name="position">4</property>
               </packing>
             </child>
           </object>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]