[balsa/gtk4: 192/311] libbalsa-gpgme: Build with gtk4




commit 8db2f9fa3d7222b2e9056d64ac929cf296d63fef
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Thu Oct 8 21:33:10 2020 -0400

    libbalsa-gpgme: Build with gtk4

 libbalsa/libbalsa-gpgme-keys.c    | 44 +++++++++++++++++-
 libbalsa/libbalsa-gpgme-widgets.c | 96 +++++++++++++++++++--------------------
 2 files changed, 90 insertions(+), 50 deletions(-)
---
diff --git a/libbalsa/libbalsa-gpgme-keys.c b/libbalsa/libbalsa-gpgme-keys.c
index ebd11dd7c..b3a2ff973 100644
--- a/libbalsa/libbalsa-gpgme-keys.c
+++ b/libbalsa/libbalsa-gpgme-keys.c
@@ -61,7 +61,6 @@ static gboolean gpgme_import_key(gpgme_ctx_t   ctx,
                                                                 GError      **error);
 static gchar *gpgme_import_res_to_gchar(gpgme_import_result_t import_result)
        G_GNUC_WARN_UNUSED_RESULT;
-static gboolean show_keyserver_dialog(gpointer user_data);
 static void keyserver_op_free(keyserver_op_t *keyserver_op);
 
 
@@ -457,6 +456,49 @@ check_key(const gpgme_key_t key,
  * returned and call gpgme_import_key() as to import or update it in this case.  Call 
show_keyserver_dialog() as idle callback to
  * present the user the results.
  */
+
+typedef struct {
+    keyserver_op_t *keyserver_op;
+    GList *keys;
+} gpgme_keyserver_data;
+
+static gboolean
+gpgme_keyserver_idle(gpointer user_data)
+{
+    gpgme_keyserver_data *data = user_data;
+    GtkWidget *dialog;
+
+    if (data->keys == NULL) {
+        dialog = gtk_message_dialog_new(data->keyserver_op->parent,
+                                        GTK_DIALOG_DESTROY_WITH_PARENT | libbalsa_dialog_flags(),
+                                        GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
+                                        _
+                                        ("Cannot find a key with fingerprint %s on the key server."),
+                                        data->keyserver_op->fingerprint);
+    } else if (data->keys->next != NULL) {
+        /* more than one key found */
+        dialog = gtk_message_dialog_new(data->keyserver_op->parent,
+                                        GTK_DIALOG_DESTROY_WITH_PARENT | libbalsa_dialog_flags(),
+                                        GTK_MESSAGE_WARNING,
+                                        GTK_BUTTONS_CLOSE,
+                                        ngettext
+                                        ("Found %u key with fingerprint %s on the key server. Please check 
and import the proper key manually.",
+                                         "Found %u keys with fingerprint %s on the key server. Please check 
and import the proper key manually.",
+                                         g_list_length(data->keys)), g_list_length(data->keys),
+                                        data->keyserver_op->fingerprint);
+    } else {
+        dialog = gpgme_keyserver_do_import(data->keyserver_op, (gpgme_key_t) data->keys->data);
+    }
+
+    g_list_free_full(data->keys, (GDestroyNotify) gpgme_key_unref);
+    g_free(data);
+
+    g_signal_connect(dialog, "response", G_CALLBACK(gtk_window_destroy), NULL);
+    gtk_widget_show(dialog);
+
+    return G_SOURCE_REMOVE;
+}
+
 static gpointer
 gpgme_keyserver_run(gpointer user_data)
 {
diff --git a/libbalsa/libbalsa-gpgme-widgets.c b/libbalsa/libbalsa-gpgme-widgets.c
index 244499f30..b04b43120 100644
--- a/libbalsa/libbalsa-gpgme-widgets.c
+++ b/libbalsa/libbalsa-gpgme-widgets.c
@@ -132,9 +132,9 @@ libbalsa_gpgme_key(const gpgme_key_t     key,
 
                uid_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
                gtk_widget_set_margin_start(uid_box, 12);
-               gtk_container_add(GTK_CONTAINER(uid_expander), uid_box);
+               gtk_expander_set_child(GTK_EXPANDER(uid_expander), uid_box);
                for (uid = key->uids->next; uid != NULL; uid = uid->next) {
-                       gtk_container_add(GTK_CONTAINER(uid_box), create_key_uid_widget(uid));
+                       gtk_box_append(GTK_BOX(uid_box), create_key_uid_widget(uid));
                }
        }
 
@@ -151,7 +151,7 @@ libbalsa_gpgme_key(const gpgme_key_t     key,
                issuer_grid = gtk_grid_new();
                gtk_widget_set_margin_start(issuer_grid, 12);
                gtk_grid_set_column_spacing(GTK_GRID(issuer_grid), 6);
-               gtk_container_add(GTK_CONTAINER(issuer_expander), issuer_grid);
+               gtk_expander_set_child(GTK_EXPANDER(issuer_expander), issuer_grid);
 
                if (key->issuer_name != NULL) {
                        uid_readable = libbalsa_cert_subject_readable(key->issuer_name);
@@ -209,7 +209,7 @@ libbalsa_gpgme_key(const gpgme_key_t     key,
 
                subkey_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
                gtk_widget_set_margin_start(subkey_box, 12);
-               gtk_container_add(GTK_CONTAINER(subkey_expander), subkey_box);
+               gtk_expander_set_child(GTK_EXPANDER(subkey_expander), subkey_box);
 
                for (subkey = key->subkeys; subkey != NULL; subkey = subkey->next) {
                        if (fingerprint != NULL) {
@@ -222,7 +222,7 @@ libbalsa_gpgme_key(const gpgme_key_t     key,
 
                                     gtk_widget_set_margin_top(subkey_widget, 2);
                                     gtk_widget_set_margin_bottom(subkey_widget, 2);
-                                    gtk_container_add(GTK_CONTAINER(subkey_box), subkey_widget);
+                                    gtk_box_append(GTK_BOX(subkey_box), subkey_widget);
                                }
                        } else if ((((subkey_capa & GPG_SUBKEY_CAP_SIGN) != 0U) && (subkey->can_sign != 0)) ||
                                           (((subkey_capa & GPG_SUBKEY_CAP_ENCRYPT) != 0U) && 
(subkey->can_encrypt != 0)) ||
@@ -232,7 +232,7 @@ libbalsa_gpgme_key(const gpgme_key_t     key,
 
                             gtk_widget_set_margin_top(subkey_widget, 2);
                             gtk_widget_set_margin_bottom(subkey_widget, 2);
-                            gtk_container_add(GTK_CONTAINER(subkey_box), subkey_widget);
+                            gtk_box_append(GTK_BOX(subkey_box), subkey_widget);
                        } else {
                                /* do not print this subkey */
                        }
@@ -412,21 +412,21 @@ libbalsa_key_dialog(GtkWindow            *parent,
        content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
 
        hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
-       gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
+       g_object_set(hbox, "margin", 6, NULL);
         gtk_widget_set_vexpand(hbox, TRUE);
         gtk_widget_set_valign(hbox, GTK_ALIGN_FILL);
-       gtk_container_add(GTK_CONTAINER(content_area), hbox);
+       gtk_box_append(GTK_BOX(content_area), hbox);
        gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
 
        /* standard key icon; "application-certificate" would be an alternative... */
-       icon = gtk_image_new_from_icon_name("dialog-password", GTK_ICON_SIZE_DIALOG);
-       gtk_container_add(GTK_CONTAINER(hbox), icon);
+       icon = gtk_image_new_from_icon_name("dialog-password");
+       gtk_box_append(GTK_BOX(hbox), icon);
        gtk_widget_set_valign(icon, GTK_ALIGN_START);
 
        vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
         gtk_widget_set_hexpand(vbox, TRUE);
         gtk_widget_set_halign(vbox, GTK_ALIGN_FILL);
-       gtk_container_add(GTK_CONTAINER(hbox), vbox);
+       gtk_box_append(GTK_BOX(hbox), vbox);
        gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE);
 
        if (message1 != NULL) {
@@ -436,27 +436,25 @@ libbalsa_key_dialog(GtkWindow            *parent,
                markup = g_markup_printf_escaped("<b><big>%s</big></b>", message1);
                gtk_label_set_markup(GTK_LABEL(label), markup);
                g_free(markup);
-               gtk_container_add(GTK_CONTAINER(vbox), label);
+               gtk_box_append(GTK_BOX(vbox), label);
        }
 
        if (message2 != NULL) {
                label = libbalsa_create_wrap_label(message2, FALSE);
-               gtk_container_add(GTK_CONTAINER(vbox), label);
+               gtk_box_append(GTK_BOX(vbox), label);
        }
 
-       scrolledw = gtk_scrolled_window_new(NULL, NULL);
+       scrolledw = gtk_scrolled_window_new();
         gtk_widget_set_vexpand(scrolledw, TRUE);
         gtk_widget_set_valign(scrolledw, GTK_ALIGN_FILL);
         gtk_widget_set_margin_top(scrolledw, 6);
         gtk_widget_set_margin_bottom(scrolledw, 6);
-       gtk_container_add(GTK_CONTAINER(vbox), scrolledw);
+       gtk_box_append(GTK_BOX(vbox), scrolledw);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledw), GTK_POLICY_NEVER, 
GTK_POLICY_AUTOMATIC);
        gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scrolledw), 120);
 
        key_data = libbalsa_gpgme_key(key, NULL, subkey_capa, TRUE);
-       gtk_container_add(GTK_CONTAINER(scrolledw), key_data);
-
-       gtk_widget_show_all(hbox);
+       gtk_box_append(GTK_BOX(scrolledw), key_data);
 
        return dialog;
 }
@@ -606,33 +604,34 @@ create_key_uid_widget(const gpgme_user_id_t uid)
  * a warning icon prepended.  In both cases, the label is start-justified, selectable and line-wrappable.
  */
 static GtkWidget *
-create_key_label_with_warn(const gchar *text,
-                                                  gboolean     warn)
+create_key_label_with_warn(const gchar * text, gboolean warn)
 {
-       GtkWidget *result;
-
-       if (warn) {
-               GtkWidget *icon;
-               GtkWidget *label;
-               gchar *buf;
-
-               result = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
-               icon = gtk_image_new_from_icon_name("dialog-warning", GTK_ICON_SIZE_MENU);
-               gtk_container_add(GTK_CONTAINER(result), icon);
-               buf = g_markup_printf_escaped("<span fgcolor=\"red\">%s</span>", text);
-               label = libbalsa_create_wrap_label(buf, TRUE);
-               g_free(buf);
-               gtk_label_set_selectable(GTK_LABEL(label), TRUE);
-               gtk_widget_set_hexpand(label, TRUE);
-                gtk_widget_set_halign(label, GTK_ALIGN_FILL);
-               gtk_container_add(GTK_CONTAINER(result), label);
-       } else {
-               result = libbalsa_create_wrap_label(text, FALSE);
-               gtk_widget_set_hexpand(result, TRUE);
-               gtk_label_set_selectable(GTK_LABEL(result), TRUE);
-       }
-
-       return result;
+    GtkWidget *result;
+
+    if (warn) {
+        GtkWidget *icon;
+        GtkWidget *label;
+        gchar *buf;
+
+        result = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
+        icon = gtk_image_new_from_icon_name("dialog-warning");
+        gtk_box_append(GTK_BOX(result), icon);
+
+        buf = g_markup_printf_escaped("<span fgcolor=\"red\">%s</span>", text);
+        label = libbalsa_create_wrap_label(buf, TRUE);
+        g_free(buf);
+
+        gtk_label_set_selectable(GTK_LABEL(label), TRUE);
+        gtk_widget_set_hexpand(label, TRUE);
+        gtk_widget_set_halign(label, GTK_ALIGN_FILL);
+        gtk_box_append(GTK_BOX(result), label);
+    } else {
+        result = libbalsa_create_wrap_label(text, FALSE);
+        gtk_widget_set_hexpand(result, TRUE);
+        gtk_label_set_selectable(GTK_LABEL(result), TRUE);
+    }
+
+    return result;
 }
 
 
@@ -781,7 +780,7 @@ smime_show_chain(GtkWidget *button, gpointer G_GNUC_UNUSED user_data)
        GtkWidget *chain;
 
        dialog = gtk_dialog_new_with_buttons("Certificate Chain",
-               GTK_WINDOW(gtk_widget_get_toplevel(button)),
+               GTK_WINDOW(gtk_widget_get_root(button)),
                GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | libbalsa_dialog_flags(),
                _("_Close"), GTK_RESPONSE_CLOSE, NULL);
        geometry_manager_attach(GTK_WINDOW(dialog), "CertChain");
@@ -791,9 +790,8 @@ smime_show_chain(GtkWidget *button, gpointer G_GNUC_UNUSED user_data)
         gtk_widget_set_valign(chain, GTK_ALIGN_FILL);
         gtk_widget_set_margin_top(chain, 6);
         gtk_widget_set_margin_bottom(chain, 6);
-       gtk_container_add(GTK_CONTAINER(vbox), chain);
+       gtk_box_append(GTK_BOX(vbox), chain);
 
-       gtk_widget_show_all(vbox);
-       gtk_dialog_run(GTK_DIALOG(dialog));
-       gtk_widget_destroy(dialog);
+        g_signal_connect(dialog, "response", G_CALLBACK(gtk_window_destroy), NULL);
+        gtk_widget_show(dialog);
 }


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