[seahorse/wip/nielsdg/bye-seahorsewidget] keyserver-sync: Port to GtkTemplate




commit c13de7920fd0b725535e2212a804ec17223357e5
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Wed Feb 24 23:00:43 2021 +0100

    keyserver-sync: Port to GtkTemplate
    
    Get rid of SeahorseWidget once more.

 pgp/seahorse-keyserver-sync.c  | 293 +++++++++++++++++++++++++++--------------
 pgp/seahorse-keyserver-sync.h  |  11 +-
 pgp/seahorse-keyserver-sync.ui | 219 ++++++++++--------------------
 pgp/seahorse-pgp-actions.c     |  45 +++----
 4 files changed, 294 insertions(+), 274 deletions(-)
---
diff --git a/pgp/seahorse-keyserver-sync.c b/pgp/seahorse-keyserver-sync.c
index 7d8f1ea5..1b5a92ba 100644
--- a/pgp/seahorse-keyserver-sync.c
+++ b/pgp/seahorse-keyserver-sync.c
@@ -33,153 +33,226 @@
 
 #include <glib/gi18n.h>
 
-void            on_sync_ok_clicked                (GtkButton *button,
-                                                   SeahorseWidget *swidget);
+struct _SeahorseKeyserverSync {
+    GtkDialog parent_instance;
 
-void            on_sync_configure_clicked         (GtkButton *button,
-                                                   SeahorseWidget *swidget);
+    GList *keys;
+
+    GtkWidget *detail_message;
+    GtkWidget *publish_message;
+    GtkWidget *sync_message;
+    GtkWidget *sync_button;
+};
+
+enum {
+    PROP_0,
+    PROP_KEYS,
+    N_PROPS
+};
+
+G_DEFINE_TYPE (SeahorseKeyserverSync, seahorse_keyserver_sync, GTK_TYPE_DIALOG)
 
 static void
-on_transfer_upload_complete (GObject *object,
+on_transfer_upload_complete (GObject      *object,
                              GAsyncResult *result,
-                             gpointer user_data)
+                             gpointer      user_data)
 {
-       SeahorsePlace *place = SEAHORSE_PLACE (user_data);
-       GError *error = NULL;
-       gchar *publish_to;
-
-       if (!seahorse_pgp_backend_transfer_finish (SEAHORSE_PGP_BACKEND (object), result, &error)) {
-               publish_to = seahorse_app_settings_get_server_publish_to (seahorse_app_settings_instance ());
-               seahorse_util_handle_error (&error, NULL,
-                                           _("Couldn’t publish keys to server"), publish_to);
-               g_free (publish_to);
-       }
-
-       g_object_unref (place);
+    SeahorsePgpBackend *backend = SEAHORSE_PGP_BACKEND (object);
+    SeahorseAppSettings *app_settings;
+    GError *error = NULL;
+    g_autofree char *publish_to = NULL;
+
+    if (seahorse_pgp_backend_transfer_finish (backend, result, &error))
+        return;
+
+    app_settings = seahorse_app_settings_instance ();
+    publish_to = seahorse_app_settings_get_server_publish_to (app_settings);
+    seahorse_util_handle_error (&error, NULL,
+                                _("Couldn’t publish keys to server"), publish_to);
 }
 
 static void
-on_transfer_download_complete (GObject *object,
+on_transfer_download_complete (GObject      *object,
                                GAsyncResult *result,
-                               gpointer user_data)
+                               gpointer      user_data)
 {
-       SeahorsePlace *place = SEAHORSE_PLACE (user_data);
-       GError *error = NULL;
-       gchar *keyserver;
-
-       if (!seahorse_transfer_finish (result, &error)) {
-               g_object_get (place, "key-server", &keyserver, NULL);
-               seahorse_util_handle_error (&error, NULL,
-                                           _("Couldn’t retrieve keys from server: %s"), keyserver);
-               g_free (keyserver);
-       }
-
-       g_object_unref (place);
+    g_autoptr(SeahorseServerSource) ssrc = SEAHORSE_SERVER_SOURCE (user_data);
+    GError *error = NULL;
+
+    if (!seahorse_transfer_finish (result, &error)) {
+        g_autofree char *uri = NULL;
+
+        uri = seahorse_place_get_uri (SEAHORSE_PLACE (ssrc));
+        seahorse_util_handle_error (&error, NULL,
+                                    _("Couldn’t retrieve keys from server: %s"),
+                                    uri);
+    }
 }
 
-G_MODULE_EXPORT void
-on_sync_ok_clicked (GtkButton *button, SeahorseWidget *swidget)
+static void
+update_message (SeahorseKeyserverSync *self)
 {
-    GList *keys;
+    SeahorseAppSettings *app_settings;
+    g_autofree char *text = NULL;
+    gboolean should_publish;
+
+    app_settings = seahorse_app_settings_instance ();
+    text = seahorse_app_settings_get_server_publish_to (app_settings);
 
-    keys = (GList*)g_object_get_data (G_OBJECT (swidget), "publish-keys");
-    keys = g_list_copy (keys);
+    should_publish = (text && *text);
+    gtk_widget_set_visible (self->publish_message, should_publish);
+    gtk_widget_set_visible (self->sync_message, !should_publish);
+    gtk_widget_set_sensitive (self->sync_button, should_publish);
+}
 
-    seahorse_widget_destroy (swidget);
+static void
+on_settings_publish_to_changed (GSettings  *settings,
+                                const char *key,
+                                gpointer    user_data)
+{
+    SeahorseKeyserverSync *self = SEAHORSE_KEYSERVER_SYNC (user_data);
 
-    seahorse_keyserver_sync (keys);
-    g_list_free (keys);
+    update_message (self);
 }
 
-G_MODULE_EXPORT void
-on_sync_configure_clicked (GtkButton *button, SeahorseWidget *swidget)
+static void
+on_sync_ok_clicked (GtkButton *button, gpointer user_data)
 {
-    SeahorsePrefs *prefs = seahorse_prefs_new (GTK_WINDOW (seahorse_widget_get_widget (swidget, 
swidget->name)));
+    SeahorseKeyserverSync *self = SEAHORSE_KEYSERVER_SYNC (user_data);
+    g_autoptr(GList) keys = NULL;
+
+    keys = g_list_copy (self->keys);
+    seahorse_keyserver_sync_do_sync (keys);
+}
+
+static void
+on_sync_configure_clicked (GtkButton *button, gpointer user_data)
+{
+    SeahorseKeyserverSync *self = SEAHORSE_KEYSERVER_SYNC (user_data);
+    SeahorsePrefs *prefs;
+
+    prefs = seahorse_prefs_new (GTK_WINDOW (self));
     gtk_window_present (GTK_WINDOW (prefs));
 }
 
 static void
-update_message (SeahorseWidget *swidget)
+seahorse_keyserver_sync_get_property (GObject    *object,
+                                      guint       prop_id,
+                                      GValue     *value,
+                                      GParamSpec *pspec)
 {
-       GtkWidget *widget;
-       GtkWidget *widget2;
-       GtkWidget *sync_button;
-       gchar *text;
-
-       widget = seahorse_widget_get_widget (swidget, "publish-message");
-       widget2 = seahorse_widget_get_widget (swidget, "sync-message");
-       sync_button = seahorse_widget_get_widget (swidget, "sync-button");
-
-       text = seahorse_app_settings_get_server_publish_to (seahorse_app_settings_instance ());
-       if (text && text[0]) {
-               gtk_widget_show (widget);
-               gtk_widget_hide (widget2);
-               gtk_widget_set_sensitive (sync_button, TRUE);
-       } else {
-               gtk_widget_hide (widget);
-               gtk_widget_show (widget2);
-               gtk_widget_set_sensitive (sync_button, FALSE);
-       }
-       g_free (text);
+    SeahorseKeyserverSync *self = SEAHORSE_KEYSERVER_SYNC (object);
+
+    switch (prop_id) {
+    case PROP_KEYS:
+        g_value_set_pointer (value, self->keys);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
 }
 
 static void
-on_settings_publish_to_changed (GSettings *settings, const gchar *key, gpointer user_data)
+seahorse_keyserver_sync_set_property (GObject      *object,
+                                      guint         prop_id,
+                                      const GValue *value,
+                                      GParamSpec   *pspec)
 {
-       SeahorseWidget *swidget = SEAHORSE_WIDGET (user_data);
-       update_message (swidget);
+    SeahorseKeyserverSync *self = SEAHORSE_KEYSERVER_SYNC (object);
+
+    switch (prop_id) {
+    case PROP_KEYS:
+        g_list_free (self->keys);
+        self->keys = g_list_copy (g_value_get_pointer (value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
 }
 
-/**
- * seahorse_keyserver_sync_show
- * @keys: The keys to synchronize
- *
- * Shows a synchronize window.
- *
- * Returns the new window.
- **/
-GtkWindow*
-seahorse_keyserver_sync_show (GList *keys, GtkWindow *parent)
+static void
+seahorse_keyserver_sync_finalize (GObject *obj)
 {
-    SeahorseWidget *swidget;
-    GtkWindow *win;
-    GtkWidget *w;
-    guint n;
-    gchar *t;
+    SeahorseKeyserverSync *self = SEAHORSE_KEYSERVER_SYNC (obj);
 
-    swidget = seahorse_widget_new_allow_multiple ("keyserver-sync", parent);
-    g_return_val_if_fail (swidget != NULL, NULL);
+    g_clear_pointer (&self->keys, g_list_free);
 
-    win = GTK_WINDOW (seahorse_widget_get_widget (swidget, swidget->name));
+    G_OBJECT_CLASS (seahorse_keyserver_sync_parent_class)->finalize (obj);
+}
+
+static void
+seahorse_keyserver_sync_constructed (GObject *obj)
+{
+    SeahorseKeyserverSync *self = SEAHORSE_KEYSERVER_SYNC (obj);
+    SeahorseAppSettings *app_settings;
+    unsigned int n_keys;
+    g_autofree char *t = NULL;
+
+    G_OBJECT_CLASS (seahorse_keyserver_sync_parent_class)->constructed (obj);
 
     /* The details message */
-    n = g_list_length (keys);
+    n_keys = g_list_length (self->keys);
     t = g_strdup_printf (ngettext ("<b>%d key is selected for synchronizing</b>",
-                                   "<b>%d keys are selected for synchronizing</b>", n), n);
-
-    w = GTK_WIDGET (seahorse_widget_get_widget (swidget, "detail-message"));
-    g_return_val_if_fail (swidget != NULL, win);
-    gtk_label_set_markup (GTK_LABEL (w), t);
-    g_free (t);
+                                   "<b>%d keys are selected for synchronizing</b>",
+                                   n_keys),
+                         n_keys);
+    gtk_label_set_markup (GTK_LABEL (self->detail_message), t);
 
     /* The right help message */
-    update_message (swidget);
-    g_signal_connect_object (seahorse_app_settings_instance (), "changed::server-publish-to",
-                             G_CALLBACK (on_settings_publish_to_changed), swidget, 0);
+    app_settings = seahorse_app_settings_instance ();
+    g_signal_connect_object (app_settings, "changed::server-publish-to",
+                             G_CALLBACK (on_settings_publish_to_changed),
+                             self, 0);
+    update_message (self);
+}
+
+static void
+seahorse_keyserver_sync_init (SeahorseKeyserverSync *self)
+{
+    gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+static void
+seahorse_keyserver_sync_class_init (SeahorseKeyserverSyncClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+    gobject_class->constructed = seahorse_keyserver_sync_constructed;
+    gobject_class->get_property = seahorse_keyserver_sync_get_property;
+    gobject_class->set_property = seahorse_keyserver_sync_set_property;
+    gobject_class->finalize = seahorse_keyserver_sync_finalize;
+
+    g_object_class_install_property (gobject_class, PROP_KEYS,
+        g_param_spec_pointer ("keys", "Keys",
+                              "A GList of keys which should be synced",
+                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+    gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Seahorse/seahorse-keyserver-sync.ui");
 
-    keys = g_list_copy (keys);
-    g_return_val_if_fail (!keys || SEAHORSE_IS_OBJECT (keys->data), win);
-    g_object_set_data_full (G_OBJECT (swidget), "publish-keys", keys,
-                            (GDestroyNotify)g_list_free);
+    gtk_widget_class_bind_template_child (widget_class, SeahorseKeyserverSync, detail_message);
+    gtk_widget_class_bind_template_child (widget_class, SeahorseKeyserverSync, publish_message);
+    gtk_widget_class_bind_template_child (widget_class, SeahorseKeyserverSync, sync_message);
+    gtk_widget_class_bind_template_child (widget_class, SeahorseKeyserverSync, sync_button);
 
-    return win;
+    gtk_widget_class_bind_template_callback (widget_class, on_sync_ok_clicked);
+    gtk_widget_class_bind_template_callback (widget_class, on_sync_configure_clicked);
 }
 
+/**
+ * seahorse_keyserver_sync_do_sync:
+ * @keys: (element-type SeahorsePgpKey): List of keys that need to be synced
+ *
+ * Non-interactively synchronizes the given @keys with the chosen keyserver.
+ */
 void
-seahorse_keyserver_sync (GList *keys)
+seahorse_keyserver_sync_do_sync (GList *keys)
 {
     SeahorseServerSource *source;
     SeahorseGpgmeKeyring *keyring;
+    SeahorseAppSettings *app_settings;
     SeahorsePgpSettings *pgp_settings;
     g_autofree char *keyserver = NULL;
     g_autoptr(GCancellable) cancellable = NULL;
@@ -216,7 +289,8 @@ seahorse_keyserver_sync (GList *keys)
     }
 
     /* Publishing keys online */
-    keyserver = seahorse_app_settings_get_server_publish_to (seahorse_app_settings_instance ());
+    app_settings = seahorse_app_settings_instance ();
+    keyserver = seahorse_app_settings_get_server_publish_to (app_settings);
     if (keyserver && keyserver[0]) {
         source = seahorse_pgp_backend_lookup_remote (NULL, keyserver);
 
@@ -230,3 +304,18 @@ seahorse_keyserver_sync (GList *keys)
 
     seahorse_progress_show (cancellable, _("Synchronizing keys…"), FALSE);
 }
+
+SeahorseKeyserverSync *
+seahorse_keyserver_sync_new (GList     *keys,
+                             GtkWindow *parent)
+{
+    g_return_val_if_fail (keys, NULL);
+    g_return_val_if_fail (keys->data, NULL);
+    g_return_val_if_fail (!parent || GTK_IS_WINDOW (parent), NULL);
+
+    return g_object_new (SEAHORSE_TYPE_KEYSERVER_SYNC,
+                         "keys", keys,
+                         "transient-for", parent,
+                         "use-header-bar", 1,
+                         NULL);
+}
diff --git a/pgp/seahorse-keyserver-sync.h b/pgp/seahorse-keyserver-sync.h
index 43bf5394..6b6679d7 100644
--- a/pgp/seahorse-keyserver-sync.h
+++ b/pgp/seahorse-keyserver-sync.h
@@ -2,6 +2,7 @@
  * Seahorse
  *
  * Copyright (C) 2006 Adam Schreiber
+ * Copyright (C) 2020 Niels De Graef
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,8 +22,12 @@
 
 #include <gtk/gtk.h>
 
-void        seahorse_keyserver_sync             (GList *keys);
+#define SEAHORSE_TYPE_KEYSERVER_SYNC (seahorse_keyserver_sync_get_type ())
+G_DECLARE_FINAL_TYPE (SeahorseKeyserverSync, seahorse_keyserver_sync,
+                      SEAHORSE, KEYSERVER_SYNC,
+                      GtkDialog)
 
+SeahorseKeyserverSync *    seahorse_keyserver_sync_new          (GList     *keys,
+                                                                 GtkWindow *parent);
 
-GtkWindow*  seahorse_keyserver_sync_show        (GList *keys,
-                                                 GtkWindow *parent);
+void                       seahorse_keyserver_sync_do_sync      (GList *keys);
diff --git a/pgp/seahorse-keyserver-sync.ui b/pgp/seahorse-keyserver-sync.ui
index 70aa2c93..70e52582 100644
--- a/pgp/seahorse-keyserver-sync.ui
+++ b/pgp/seahorse-keyserver-sync.ui
@@ -1,180 +1,105 @@
 <?xml version="1.0"?>
 <interface>
-  <requires lib="gtk+" version="2.16"/>
-  <!-- interface-naming-policy toplevel-contextual -->
-  <object class="GtkImage" id="configure-image">
-    <property name="stock">gtk-properties</property>
-  </object>
-  <object class="GtkImage" id="sync-image">
-    <property name="stock">gtk-refresh</property>
-  </object>
-  <object class="GtkDialog" id="keyserver-sync">
-    <property name="visible">True</property>
-    <property name="border_width">5</property>
+  <requires lib="gtk+" version="3.24"/>
+  <template class="SeahorseKeyserverSync" parent="GtkDialog">
     <property name="title" translatable="yes">Sync Keys</property>
-    <property name="window_position">center</property>
-    <property name="type_hint">dialog</property>
+    <property name="border_width">6</property>
+    <property name="use_header_bar">1</property>
     <child internal-child="vbox">
-      <object class="GtkVBox" id="dialog-vbox1">
+      <object class="GtkBox">
         <property name="visible">True</property>
-        <property name="spacing">2</property>
+        <property name="orientation">vertical</property>
+        <property name="border_width">5</property>
+        <property name="spacing">12</property>
         <child>
-          <object class="GtkVBox" id="vbox1">
+          <object class="GtkBox">
             <property name="visible">True</property>
-            <property name="border_width">5</property>
+            <property name="orientation">horizontal</property>
             <property name="spacing">12</property>
             <child>
-              <object class="GtkHBox" id="hbox2">
+              <object class="GtkImage">
                 <property name="visible">True</property>
+                <property name="icon-name">network-transmit-receive-symbolic</property>
+                <property name="icon-size">5</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
                 <property name="spacing">12</property>
                 <child>
-                  <object class="GtkImage" id="image2">
+                  <object class="GtkLabel" id="publish_message">
                     <property name="visible">True</property>
                     <property name="xalign">0</property>
                     <property name="yalign">0</property>
-                    <property name="stock">gtk-network</property>
-                    <property name="icon-size">5</property>
+                    <property name="label" translatable="yes">This will publish the keys in your key ring so 
they’re available for others to use. You’ll also get any changes others have made since you received their 
keys.</property>
+                    <property name="max-width-chars">80</property>
+                    <property name="wrap">True</property>
                   </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="position">0</property>
-                  </packing>
                 </child>
                 <child>
-                  <object class="GtkVBox" id="vbox2">
+                  <object class="GtkLabel" id="sync_message">
+                    <property name="xalign">0</property>
+                    <property name="yalign">0</property>
+                    <property name="label" translatable="yes">This will retrieve any changes others have 
made since you received their keys. No key server has been chosen for publishing, so your keys will not be 
made available to others.</property>
+                    <property name="wrap">True</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="detail_message">
                     <property name="visible">True</property>
-                    <property name="spacing">12</property>
-                    <child>
-                      <object class="GtkLabel" id="publish-message">
-                        <property name="visible">True</property>
-                        <property name="xalign">0</property>
-                        <property name="yalign">0</property>
-                        <property name="label" translatable="yes">This will publish the keys in your key 
ring so they’re available for others to use. You’ll also get any changes others have made since you received 
their keys.</property>
-                        <property name="wrap">True</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="sync-message">
-                        <property name="xalign">0</property>
-                        <property name="yalign">0</property>
-                        <property name="label" translatable="yes">This will retrieve any changes others have 
made since you received their keys. No key server has been chosen for publishing, so your keys will not be 
made available to others.</property>
-                        <property name="wrap">True</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="detail-message">
-                        <property name="visible">True</property>
-                        <property name="xalign">0</property>
-                        <property name="yalign">0</property>
-                        <property name="label"></property>
-                        <property name="use_markup">True</property>
-                        <property name="wrap">True</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">False</property>
-                        <property name="position">2</property>
-                      </packing>
-                    </child>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0</property>
+                    <property name="label"></property>
+                    <property name="use_markup">True</property>
+                    <property name="wrap">True</property>
                   </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">1</property>
-                  </packing>
                 </child>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
             </child>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="position">1</property>
-          </packing>
         </child>
-        <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="dialog-action_area1">
+        <child>
+          <object class="GtkButton" id="configure">
+            <property name="label" translatable="yes">_Key Servers</property>
             <property name="visible">True</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="configure">
-                <property name="label" translatable="yes">_Key Servers</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="image">configure-image</property>
-                <property name="use_underline">True</property>
-                <signal name="clicked" handler="on_sync_configure_clicked"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="button3">
-                <property name="label">gtk-cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-                <signal name="clicked" handler="on_widget_closed"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="sync-button">
-                <property name="label" translatable="yes">_Sync</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="has_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="has_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="image">sync-image</property>
-                <property name="use_underline">True</property>
-                <signal name="clicked" handler="on_sync_ok_clicked"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
+            <property name="halign">end</property>
+            <property name="can_focus">True</property>
+            <property name="can_default">True</property>
+            <property name="receives_default">False</property>
+            <property name="use_underline">True</property>
+            <signal name="clicked" handler="on_sync_configure_clicked"/>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
         </child>
       </object>
     </child>
+    <child type="action">
+      <object class="GtkButton" id="cancel_button">
+        <property name="label" translatable="yes">_Cancel</property>
+        <property name="visible">True</property>
+        <property name="use-underline">True</property>
+        <property name="can_focus">True</property>
+        <property name="can_default">True</property>
+        <property name="receives_default">False</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="sync_button">
+        <property name="label" translatable="yes">_Sync</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="has_focus">True</property>
+        <property name="can_default">True</property>
+        <property name="has_default">True</property>
+        <property name="receives_default">False</property>
+        <property name="use_underline">True</property>
+        <signal name="clicked" handler="on_sync_ok_clicked"/>
+      </object>
+    </child>
     <action-widgets>
-      <action-widget response="-6">configure</action-widget>
-      <action-widget response="-6">button3</action-widget>
-      <action-widget response="-5">sync-button</action-widget>
+      <action-widget response="cancel">cancel_button</action-widget>
+      <action-widget response="accept">sync_button</action-widget>
     </action-widgets>
-  </object>
+  </template>
 </interface>
diff --git a/pgp/seahorse-pgp-actions.c b/pgp/seahorse-pgp-actions.c
index 4daedd07..c4e36e2b 100644
--- a/pgp/seahorse-pgp-actions.c
+++ b/pgp/seahorse-pgp-actions.c
@@ -99,31 +99,32 @@ on_remote_sync (GSimpleAction *action,
                 GVariant *param,
                 gpointer user_data)
 {
-  SeahorseActionGroup *actions = SEAHORSE_ACTION_GROUP (user_data);
-  SeahorseGpgmeKeyring *keyring;
-  SeahorseCatalog *catalog;
-  GList *objects = NULL;
-  GList *keys = NULL;
-  GList *l;
-
-  catalog = seahorse_action_group_get_catalog (actions);
-  if (catalog != NULL) {
-    objects = seahorse_catalog_get_selected_objects (catalog);
-    for (l = objects; l != NULL; l = g_list_next (l)) {
-      if (SEAHORSE_PGP_IS_KEY (l->data))
-        keys = g_list_prepend (keys, l->data);
+    SeahorseActionGroup *actions = SEAHORSE_ACTION_GROUP (user_data);
+    g_autoptr(SeahorseCatalog) catalog = NULL;
+    g_autoptr(GList) keys = NULL;
+    SeahorseKeyserverSync *dialog = NULL;
+
+    catalog = seahorse_action_group_get_catalog (actions);
+    if (catalog != NULL) {
+        g_autoptr(GList) objects = NULL;
+
+        objects = seahorse_catalog_get_selected_objects (catalog);
+        for (GList *l = objects; l != NULL; l = g_list_next (l)) {
+            if (SEAHORSE_PGP_IS_KEY (l->data))
+                keys = g_list_prepend (keys, l->data);
+        }
     }
-    g_list_free (objects);
-  }
-  g_object_unref (catalog);
 
-  if (keys == NULL) {
-    keyring = seahorse_pgp_backend_get_default_keyring (NULL);
-    keys = gcr_collection_get_objects (GCR_COLLECTION (keyring));
-  }
+    if (keys == NULL) {
+        SeahorseGpgmeKeyring *keyring;
+
+        keyring = seahorse_pgp_backend_get_default_keyring (NULL);
+        keys = gcr_collection_get_objects (GCR_COLLECTION (keyring));
+    }
 
-  seahorse_keyserver_sync_show (keys, GTK_WINDOW (catalog));
-  g_list_free (keys);
+    dialog = seahorse_keyserver_sync_new (keys, GTK_WINDOW (catalog));
+    gtk_dialog_run (GTK_DIALOG (dialog));
+    gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
 #endif /* WITH_KEYSERVER */


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