[seahorse/wip/nielsdg/export-secret-and-public-key] pgp: Allow exporting both public & secret key



commit e993a56b8eb7eedb64cfbc7c6a8ee682ae7cd3e9
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sat Feb 15 00:58:02 2020 +0100

    pgp: Allow exporting both public & secret key
    
    The UI made it a bit unclear, but Seahorse can export both the public
    and the private key of a GPG key. The former happened by clicking the
    "Export..." button when right-clicking it in the key list, the latter
    had its own dedicated button in the key properties dialog.
    
    This commit changes the "Export secret key" button to show a popover
    instead, where the user can choose between exporting their secret and
    their public key, which makes all of this a bit more intuitive.
    
    Fixes https://gitlab.gnome.org/GNOME/seahorse/issues/208

 pgp/seahorse-pgp-key-properties.c          | 22 ++++++++++--
 pgp/seahorse-pgp-private-key-properties.ui | 54 ++++++++++--------------------
 2 files changed, 36 insertions(+), 40 deletions(-)
---
diff --git a/pgp/seahorse-pgp-key-properties.c b/pgp/seahorse-pgp-key-properties.c
index b2fd7c1a..3cf566e4 100644
--- a/pgp/seahorse-pgp-key-properties.c
+++ b/pgp/seahorse-pgp-key-properties.c
@@ -1084,9 +1084,8 @@ on_export_complete (GObject *source, GAsyncResult *result, gpointer user_data)
 }
 
 static void
-on_export_secret (GSimpleAction *action, GVariant *param, gpointer user_data)
+export_key_to_file (SeahorsePgpKeyProperties *self, gboolean secret)
 {
-    SeahorsePgpKeyProperties *self = SEAHORSE_PGP_KEY_PROPERTIES (user_data);
     GList *exporters = NULL;
     GtkWindow *window;
     g_autofree gchar *directory = NULL;
@@ -1094,7 +1093,7 @@ on_export_secret (GSimpleAction *action, GVariant *param, gpointer user_data)
     SeahorseExporter *exporter = NULL;
 
     exporters = g_list_append (exporters,
-                               seahorse_gpgme_exporter_new (G_OBJECT (self->key), TRUE, TRUE));
+                               seahorse_gpgme_exporter_new (G_OBJECT (self->key), TRUE, secret));
 
     window = GTK_WINDOW (self);
     if (seahorse_exportable_prompt (exporters, window, &directory, &file, &exporter)) {
@@ -1106,6 +1105,22 @@ on_export_secret (GSimpleAction *action, GVariant *param, gpointer user_data)
     g_list_free_full (exporters, g_object_unref);
 }
 
+static void
+on_export_secret (GSimpleAction *action, GVariant *param, gpointer user_data)
+{
+    SeahorsePgpKeyProperties *self = SEAHORSE_PGP_KEY_PROPERTIES (user_data);
+
+    export_key_to_file (self, TRUE);
+}
+
+static void
+on_export_public (GSimpleAction *action, GVariant *param, gpointer user_data)
+{
+    SeahorsePgpKeyProperties *self = SEAHORSE_PGP_KEY_PROPERTIES (user_data);
+
+    export_key_to_file (self, FALSE);
+}
+
 static void
 on_change_expires (GSimpleAction *action, GVariant *param, gpointer user_data)
 {
@@ -1622,6 +1637,7 @@ static const GActionEntry PRIVATE_KEY_ACTIONS[] = {
     { "change-password",  on_change_password  },
     { "change-expires",   on_change_expires   },
     { "export-secret",    on_export_secret    },
+    { "export-public",    on_export_public    },
     { "uids.add",           on_uids_add           },
     { "uids.delete",        on_uids_delete        },
     { "uids.make-primary",  on_uids_make_primary  },
diff --git a/pgp/seahorse-pgp-private-key-properties.ui b/pgp/seahorse-pgp-private-key-properties.ui
index e99ed3fa..071a1e95 100644
--- a/pgp/seahorse-pgp-private-key-properties.ui
+++ b/pgp/seahorse-pgp-private-key-properties.ui
@@ -24,6 +24,18 @@
       </row>
     </data>
   </object>
+  <menu id="export_menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">Export _secret key</attribute>
+        <attribute name="action">props.export-secret</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Export _public key</attribute>
+        <attribute name="action">props.export-public</attribute>
+      </item>
+    </section>
+  </menu>
           <object class="GtkNotebook" id="window-content">
             <property name="visible">True</property>
             <property name="vexpand">True</property>
@@ -873,49 +885,17 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkLabel">
+                                  <object class="GtkMenuButton">
                                     <property name="visible">True</property>
-                                    <property name="xalign">0</property>
-                                    <property name="label" translatable="yes">_Export Secret Key:</property>
+                                    <property name="label" translatable="yes">_Export to file</property>
+                                    <property name="halign">start</property>
                                     <property name="use_underline">True</property>
-                                    <property name="mnemonic_widget">details-export-button</property>
+                                    <property name="menu-model">export_menu</property>
                                   </object>
                                   <packing>
                                     <property name="top_attach">1</property>
                                     <property name="left_attach">0</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <object class="GtkButton" id="details-export-button">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">True</property>
-                                    <property name="receives_default">False</property>
-                                    <property name="action-name">props.export-secret</property>
-                                    <child>
-                                      <object class="GtkBox">
-                                        <property name="visible">True</property>
-                                        <property name="orientation">horizontal</property>
-                                        <property name="halign">center</property>
-                                        <property name="spacing">2</property>
-                                        <child>
-                                          <object class="GtkImage">
-                                            <property name="visible">True</property>
-                                            <property name="stock">gtk-save</property>
-                                          </object>
-                                        </child>
-                                        <child>
-                                          <object class="GtkLabel">
-                                            <property name="visible">True</property>
-                                            <property name="label" translatable="yes">Export</property>
-                                            <property name="use_underline">True</property>
-                                          </object>
-                                        </child>
-                                      </object>
-                                    </child>
-                                  </object>
-                                  <packing>
-                                    <property name="top_attach">1</property>
-                                    <property name="left_attach">1</property>
+                                    <property name="width">2</property>
                                   </packing>
                                 </child>
                               </object>


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