[evolution-data-server] Replace GcrCertificateWidget with libedataserverui's ECertificateWidget



commit 1385e7259c9a5bf4478ab3a2558dcbaaa63b098e
Author: Milan Crha <mcrha redhat com>
Date:   Thu Aug 11 18:15:55 2022 +0200

    Replace GcrCertificateWidget with libedataserverui's ECertificateWidget
    
    The GcrCertificateWidget will be removed, thus use the one provided
    by the libedataserverui instead. It helps to limit spread of the GCR
    in the code.

 CMakeLists.txt                                 |   9 --
 config.h.in                                    |   3 -
 src/libedataserverui/CMakeLists.txt            |   6 --
 src/libedataserverui/e-trust-prompt.c          | 137 ++-----------------------
 src/modules/trust-prompt/CMakeLists.txt        |   9 +-
 src/modules/trust-prompt/module-trust-prompt.c |  58 +----------
 src/modules/trust-prompt/trust-prompt-gtk.c    |  40 ++------
 src/modules/trust-prompt/trust-prompt.h        |  10 +-
 8 files changed, 23 insertions(+), 249 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8a8a4b370..bd0e4b40c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -116,8 +116,6 @@ add_definitions(-DSOUP_VERSION_MAX_ALLOWED=${soup_encoded_version})
 add_definitions(-DGLIB_VERSION_MIN_REQUIRED=${glib_encoded_version})
 add_definitions(-DSOUP_VERSION_MIN_REQUIRED=${soup_encoded_version})
 
-set(gcr3_minimum_version 3.4)
-set(gcr4_minimum_version 3.90)
 set(libical_glib_minimum_version 3.0.7)
 set(libsecret_minimum_version 0.5)
 set(libxml_minimum_version 2.0.0)
@@ -390,16 +388,10 @@ endif(NOT ICU_FOUND)
 # Check for GTK+
 # *************************
 
-add_printable_option(WITH_GCR3 "Use gcr3, instead of gcr4" OFF)
 add_printable_option(ENABLE_GTK "Enable gtk+ support" ON)
 
 if(ENABLE_GTK)
        pkg_check_modules_for_option(ENABLE_GTK "GTK+ support" GTK gtk+-3.0>=${gdk_minimum_version})
-       if(WITH_GCR3)
-               pkg_check_modules_for_option(ENABLE_GTK "GTK+ support" GCR gcr-3>=${gcr3_minimum_version})
-       else(WITH_GCR3)
-               pkg_check_modules_for_option(ENABLE_GTK "GTK+ support" GCR 
gcr-4-gtk3>=${gcr4_minimum_version})
-       endif(WITH_GCR3)
 
        set(HAVE_GTK 1)
 endif(ENABLE_GTK)
@@ -407,7 +399,6 @@ endif(ENABLE_GTK)
 add_printable_option(ENABLE_GTK4 "Enable gtk4 support" ON)
 if(ENABLE_GTK4)
        pkg_check_modules_for_option(ENABLE_GTK4 "gtk4 support" GTK4 gtk4>=${gdk4_minimum_version})
-       pkg_check_modules_for_option(ENABLE_GTK4 "gtk4 support" GCR4 gcr-4-gtk4>=${gcr4_minimum_version})
 
        set(HAVE_GTK4 1)
 endif(ENABLE_GTK4)
diff --git a/config.h.in b/config.h.in
index fbb74c50c..9019d65dc 100644
--- a/config.h.in
+++ b/config.h.in
@@ -199,6 +199,3 @@
 
 /* Defined, when time_t is of the 32bit size */
 #cmakedefine HAVE_32BIT_TIME_T 1
-
-/* Defined, when using gcr3, not gcr4 */
-#cmakedefine WITH_GCR3 1
diff --git a/src/libedataserverui/CMakeLists.txt b/src/libedataserverui/CMakeLists.txt
index cef206bed..c2d250c0e 100644
--- a/src/libedataserverui/CMakeLists.txt
+++ b/src/libedataserverui/CMakeLists.txt
@@ -75,7 +75,6 @@ target_compile_options(edataserverui PUBLIC
        ${CAMEL_CFLAGS}
        ${CODE_COVERAGE_CFLAGS}
        ${GNOME_PLATFORM_CFLAGS}
-       ${GCR_CFLAGS}
        ${GTK_CFLAGS}
        ${JSON_GLIB_CFLAGS}
        ${OAUTH2_WEBKITGTK_CFLAGS}
@@ -90,7 +89,6 @@ target_include_directories(edataserverui PUBLIC
        ${CAMEL_INCLUDE_DIRS}
        ${CODE_COVERAGE_INCLUDE_DIRS}
        ${GNOME_PLATFORM_INCLUDE_DIRS}
-       ${GCR_INCLUDE_DIRS}
        ${GTK_INCLUDE_DIRS}
        ${JSON_GLIB_INCLUDE_DIRS}
        ${OAUTH2_WEBKITGTK_INCLUDE_DIRS}
@@ -102,7 +100,6 @@ target_link_libraries(edataserverui
        ${CAMEL_LDFLAGS}
        ${CODE_COVERAGE_LDFLAGS}
        ${GNOME_PLATFORM_LDFLAGS}
-       ${GCR_LDFLAGS}
        ${GTK_LDFLAGS}
        ${JSON_GLIB_LDFLAGS}
        ${OAUTH2_WEBKITGTK_LDFLAGS}
@@ -236,7 +233,6 @@ target_compile_options(edataserverui${UI_VERSION} PUBLIC
        ${CAMEL_CFLAGS}
        ${CODE_COVERAGE_CFLAGS}
        ${GNOME_PLATFORM_CFLAGS}
-       ${GCR4_CFLAGS}
        ${GTK4_CFLAGS}
        ${JSON_GLIB_CFLAGS}
        ${OAUTH2_WEBKITGTK4_CFLAGS}
@@ -251,7 +247,6 @@ target_include_directories(edataserverui${UI_VERSION} PUBLIC
        ${CAMEL_INCLUDE_DIRS}
        ${CODE_COVERAGE_INCLUDE_DIRS}
        ${GNOME_PLATFORM_INCLUDE_DIRS}
-       ${GCR4_INCLUDE_DIRS}
        ${GTK4_INCLUDE_DIRS}
        ${JSON_GLIB_INCLUDE_DIRS}
        ${OAUTH2_WEBKITGTK4_INCLUDE_DIRS}
@@ -263,7 +258,6 @@ target_link_libraries(edataserverui${UI_VERSION}
        ${CAMEL_LDFLAGS}
        ${CODE_COVERAGE_LDFLAGS}
        ${GNOME_PLATFORM_LDFLAGS}
-       ${GCR4_LDFLAGS}
        ${GTK4_LDFLAGS}
        ${JSON_GLIB_LDFLAGS}
        ${OAUTH2_WEBKITGTK4_LDFLAGS}
diff --git a/src/libedataserverui/e-trust-prompt.c b/src/libedataserverui/e-trust-prompt.c
index f0dd7ee00..a6caf1418 100644
--- a/src/libedataserverui/e-trust-prompt.c
+++ b/src/libedataserverui/e-trust-prompt.c
@@ -23,23 +23,10 @@
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 
-#define GCR_API_SUBJECT_TO_CHANGE
-#define GCK_API_SUBJECT_TO_CHANGE
-#if GTK_CHECK_VERSION(4, 0, 0)
-#include <gcr-gtk4/gcr-certificate-widget.h>
-#else
-#ifdef WITH_GCR3
-#include <gcr/gcr.h>
-#else
-#include <gcr-gtk3/gcr-gtk3.h>
-#endif
-#endif
-#undef GCK_API_SUBJECT_TO_CHANGE
-#undef GCR_API_SUBJECT_TO_CHANGE
-
 #include "camel/camel.h"
 #include "libedataserver/libedataserver.h"
 #include "libedataserverui-private.h"
+#include "e-certificate-widget.h"
 
 #include "e-trust-prompt.h"
 
@@ -112,19 +99,13 @@ trust_prompt_show (GtkWindow *parent,
                   const gchar *source_display_name,
                   const gchar *host,
                   const gchar *error_text,
-                  GcrParsed *parsed,
+                  const gchar *certificate_pem,
                   const gchar *reason,
                   void (* dialog_ready_cb) (GtkDialog *dialog, gpointer user_data),
                   gpointer user_data)
 {
        ETrustPromptResponse response;
-       GcrCertificate *certificate;
-       const guchar *data;
-       gsize length;
        GtkWidget *dialog, *widget;
-#if !defined(WITH_GCR3) || GTK_CHECK_VERSION(4, 0, 0)
-       GtkWidget *scrolled_window;
-#endif
        GtkGrid *grid;
        gchar *bhost, *tmp;
        gint row = 0;
@@ -251,67 +232,10 @@ trust_prompt_show (GtkWindow *parent,
        if (error_text)
                trust_prompt_add_info_line (grid, _("Detailed error:"), error_text, FALSE, TRUE, FALSE, &row);
 
-#if defined(WITH_GCR3) && !GTK_CHECK_VERSION(4, 0, 0)
-       /* the certificate widget has its own scrollbars */
-#else /* defined(WITH_GCR3) && !GTK_CHECK_VERSION(4, 0, 0) */
-#if GTK_CHECK_VERSION(4, 0, 0)
-       scrolled_window = gtk_scrolled_window_new ();
-#else
-       scrolled_window = gtk_scrolled_window_new (NULL, NULL);
-#endif
-       g_object_set (G_OBJECT (scrolled_window),
-               "halign", GTK_ALIGN_FILL,
-               "hexpand", TRUE,
-               "valign", GTK_ALIGN_FILL,
-               "vexpand", TRUE,
-               "hscrollbar-policy", GTK_POLICY_NEVER,
-               "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
-               "propagate-natural-height", TRUE,
-#if GTK_CHECK_VERSION(4, 0, 0)
-               "has-frame", FALSE,
-#else
-               "shadow-type", GTK_SHADOW_NONE,
-#endif
-               NULL);
-
-       gtk_grid_attach (grid, scrolled_window, 1, row, 2, 1);
-#endif /* defined(WITH_GCR3) && !GTK_CHECK_VERSION(4, 0, 0) */
-
-       data = gcr_parsed_get_data (parsed, &length);
-       certificate = gcr_simple_certificate_new (data, length);
-       #if defined(WITH_GCR3) && !GTK_CHECK_VERSION(4, 0, 0)
-       {
-               GcrCertificateWidget *certificate_widget;
-               GckAttributes *attributes;
-
-               attributes = gcr_parsed_get_attributes (parsed);
-               certificate_widget = gcr_certificate_widget_new (certificate);
-               gcr_certificate_widget_set_attributes (certificate_widget, attributes);
-
-               widget = GTK_WIDGET (certificate_widget);
-
-               g_object_set (G_OBJECT (widget),
-                       "halign", GTK_ALIGN_FILL,
-                       "hexpand", TRUE,
-                       "valign", GTK_ALIGN_FILL,
-                       "vexpand", TRUE,
-                       NULL);
-       }
-       #else /* defined(WITH_GCR3) && !GTK_CHECK_VERSION(4, 0, 0) */
-       widget = gcr_certificate_widget_new (certificate);
-       #endif /* defined(WITH_GCR3) && !GTK_CHECK_VERSION(4, 0, 0) */
+       widget = e_certificate_widget_new ();
+       e_certificate_widget_set_pem (E_CERTIFICATE_WIDGET (widget), certificate_pem);
 
-#if defined(WITH_GCR3) && !GTK_CHECK_VERSION(4, 0, 0)
        gtk_grid_attach (grid, widget, 1, row, 2, 1);
-#else /* defined(WITH_GCR3) && !GTK_CHECK_VERSION(4, 0, 0) */
-#if GTK_CHECK_VERSION(4, 0, 0)
-       gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), widget);
-#else
-       gtk_container_add (GTK_CONTAINER (scrolled_window), widget);
-#endif
-#endif /* defined(WITH_GCR3) && !GTK_CHECK_VERSION(4, 0, 0) */
-
-       g_clear_object (&certificate);
 
 #if !GTK_CHECK_VERSION(4, 0, 0)
        gtk_widget_show_all (GTK_WIDGET (grid));
@@ -393,18 +317,6 @@ e_trust_prompt_describe_certificate_errors (GTlsCertificateFlags flags)
        return g_string_free (reason, FALSE);
 }
 
-static void
-trust_prompt_parser_parsed_cb (GcrParser *parser,
-                              GcrParsed **out_parsed)
-{
-       GcrParsed *parsed;
-
-       parsed = gcr_parser_get_parsed (parser);
-       g_return_if_fail (parsed != NULL);
-
-       *out_parsed = gcr_parsed_ref (parsed);
-}
-
 static ETrustPromptResponse
 e_trust_prompt_run_with_dialog_ready_callback (GtkWindow *parent,
                                               const gchar *source_extension,
@@ -417,51 +329,18 @@ e_trust_prompt_run_with_dialog_ready_callback (GtkWindow *parent,
                                               gpointer user_data)
 {
        ETrustPromptResponse response = E_TRUST_PROMPT_RESPONSE_UNKNOWN;
-       GcrParser *parser;
-       GcrParsed *parsed = NULL;
-       GError *local_error = NULL;
+       gchar *reason;
 
        if (parent)
                g_return_val_if_fail (GTK_IS_WINDOW (parent), E_TRUST_PROMPT_RESPONSE_UNKNOWN);
        g_return_val_if_fail (host != NULL, E_TRUST_PROMPT_RESPONSE_UNKNOWN);
        g_return_val_if_fail (certificate_pem != NULL, E_TRUST_PROMPT_RESPONSE_UNKNOWN);
 
-       /* Continue even if PKCS#11 module registration fails.
-        * Certificate details won't display correctly but the
-        * user can still respond to the prompt. */
-       gcr_pkcs11_initialize (NULL, &local_error);
-       if (local_error != NULL) {
-               g_warning ("%s: gcr_pkcs11_initialize() call failed: %s", G_STRFUNC, local_error->message);
-               g_clear_error (&local_error);
-       }
-
-       parser = gcr_parser_new ();
-
-       g_signal_connect (
-               parser, "parsed",
-               G_CALLBACK (trust_prompt_parser_parsed_cb), &parsed);
-
-       gcr_parser_parse_data (parser, (const guchar *) certificate_pem, strlen (certificate_pem), 
&local_error);
-
-       g_object_unref (parser);
+       reason = e_trust_prompt_describe_certificate_errors (certificate_errors);
 
-       /* Sanity check. */
-       g_warn_if_fail (
-               ((parsed != NULL) && (local_error == NULL)) ||
-               ((parsed == NULL) && (local_error != NULL)));
-
-       if (parsed != NULL) {
-               gchar *reason;
-
-               reason = e_trust_prompt_describe_certificate_errors (certificate_errors);
-
-               response = trust_prompt_show (parent, source_extension, source_display_name, host, 
error_text, parsed, reason, dialog_ready_cb, user_data);
-
-               gcr_parsed_unref (parsed);
-               g_free (reason);
-       }
+       response = trust_prompt_show (parent, source_extension, source_display_name, host, error_text, 
certificate_pem, reason, dialog_ready_cb, user_data);
 
-       g_clear_error (&local_error);
+       g_free (reason);
 
        return response;
 }
diff --git a/src/modules/trust-prompt/CMakeLists.txt b/src/modules/trust-prompt/CMakeLists.txt
index 7aed5125a..f39034642 100644
--- a/src/modules/trust-prompt/CMakeLists.txt
+++ b/src/modules/trust-prompt/CMakeLists.txt
@@ -5,27 +5,20 @@ set(TRUST_PROMPT_SOURCES
 set(TRUST_PROMPT_CFLAGS
        ${GNOME_PLATFORM_CFLAGS}
        ${GTK_CFLAGS}
-       ${GCR_CFLAGS}
 )
 
 set(TRUST_PROMPT_INCLUDE_DIRS
        ${GNOME_PLATFORM_INCLUDE_DIRS}
        ${GTK_INCLUDE_DIRS}
-       ${GCR_INCLUDE_DIRS}
 )
 
 set(TRUST_PROMPT_LDFLAGS
        ${GNOME_PLATFORM_LDFLAGS}
        ${GTK_LDFLAGS}
-       ${GCR_LDFLAGS}
 )
 
 set(extra_defines)
-if(WITH_GCR3)
-       set(extra_defines -DWITH_GCR3=1)
-endif(WITH_GCR3)
-
-set(extra_deps)
+set(extra_deps edataserverui)
 set(sources
        module-trust-prompt.c
        trust-prompt.h
diff --git a/src/modules/trust-prompt/module-trust-prompt.c b/src/modules/trust-prompt/module-trust-prompt.c
index b2379e581..151b97019 100644
--- a/src/modules/trust-prompt/module-trust-prompt.c
+++ b/src/modules/trust-prompt/module-trust-prompt.c
@@ -105,18 +105,6 @@ cert_errors_to_reason (GTlsCertificateFlags flags)
        return g_string_free (reason, FALSE);
 }
 
-static void
-parser_parsed_cb (GcrParser *parser,
-                  GcrParsed **out_parsed)
-{
-       GcrParsed *parsed;
-
-       parsed = gcr_parser_get_parsed (parser);
-       g_return_if_fail (parsed != NULL);
-
-       *out_parsed = gcr_parsed_ref (parsed);
-}
-
 static gboolean
 trust_prompt_show_trust_prompt (EUserPrompterServerExtension *extension,
                                 gint prompt_id,
@@ -125,25 +113,11 @@ trust_prompt_show_trust_prompt (EUserPrompterServerExtension *extension,
        const gchar *host, *markup, *base64_cert, *cert_errs_str;
        gchar *reason;
        gint64 cert_errs;
-       GcrParser *parser;
-       GcrParsed *parsed = NULL;
-       guchar *data;
-       gsize data_length;
-       gboolean success = FALSE;
-       GError *local_error = NULL;
+       gboolean success;
 
        g_return_val_if_fail (extension != NULL, FALSE);
        g_return_val_if_fail (parameters != NULL, FALSE);
 
-       /* Continue even if PKCS#11 module registration fails.
-        * Certificate details won't display correctly but the
-        * user can still respond to the prompt. */
-       gcr_pkcs11_initialize (NULL, &local_error);
-       if (local_error != NULL) {
-               g_warning ("%s: %s", G_STRFUNC, local_error->message);
-               g_clear_error (&local_error);
-       }
-
        host = e_named_parameters_get (parameters, "host");
        markup = e_named_parameters_get (parameters, "markup");
        base64_cert = e_named_parameters_get (parameters, "certificate");
@@ -156,39 +130,13 @@ trust_prompt_show_trust_prompt (EUserPrompterServerExtension *extension,
        cert_errs = g_ascii_strtoll (cert_errs_str, NULL, 16);
        reason = cert_errors_to_reason (cert_errs);
 
-       parser = gcr_parser_new ();
-
-       g_signal_connect (
-               parser, "parsed",
-               G_CALLBACK (parser_parsed_cb), &parsed);
-
-       data = g_base64_decode (base64_cert, &data_length);
-       gcr_parser_parse_data (parser, data, data_length, &local_error);
-       g_free (data);
-
-       g_object_unref (parser);
-
-       /* Sanity check. */
-       g_warn_if_fail (
-               ((parsed != NULL) && (local_error == NULL)) ||
-               ((parsed == NULL) && (local_error != NULL)));
-
-       if (parsed != NULL) {
-               success = trust_prompt_show (
-                       extension, prompt_id, host, markup, parsed, reason);
-               gcr_parsed_unref (parsed);
-       }
-
-       if (local_error != NULL) {
-               g_warning ("%s: %s", G_STRFUNC, local_error->message);
-               g_clear_error (&local_error);
-               success = FALSE;
-       }
+       success = trust_prompt_show (extension, prompt_id, host, markup, base64_cert, reason);
 
        g_free (reason);
 
        return success;
 }
+
 static void
 trust_prompt_register_dialogs (EExtension *extension,
                                EUserPrompterServer *server)
diff --git a/src/modules/trust-prompt/trust-prompt-gtk.c b/src/modules/trust-prompt/trust-prompt-gtk.c
index bcacdbeb2..a7b6c6b6c 100644
--- a/src/modules/trust-prompt/trust-prompt-gtk.c
+++ b/src/modules/trust-prompt/trust-prompt-gtk.c
@@ -21,14 +21,7 @@
 #include <glib/gi18n-lib.h>
 
 #include <libebackend/libebackend.h>
-
-#define GCR_API_SUBJECT_TO_CHANGE
-#ifdef WITH_GCR3
-#include <gcr/gcr.h>
-#else
-#include <gcr-gtk3/gcr-gtk3.h>
-#endif
-#undef GCR_API_SUBJECT_TO_CHANGE
+#include <libedataserverui/libedataserverui.h>
 
 #include "trust-prompt.h"
 
@@ -120,14 +113,13 @@ trust_prompt_show (EUserPrompterServerExtension *extension,
                    gint prompt_id,
                    const gchar *host,
                    const gchar *markup,
-                   GcrParsed *parsed,
+                   const gchar *base64_certificate_der,
                    const gchar *reason)
 {
-       GcrCertificate *certificate;
+       guchar *certificate_der;
+       gsize certificate_der_len = 0;
        GtkWidget *dialog, *widget;
        GtkGrid *grid;
-       const guchar *data;
-       gsize length;
        gchar *tmp;
        gint row = 0;
 
@@ -191,29 +183,17 @@ trust_prompt_show (EUserPrompterServerExtension *extension,
 
        trust_prompt_add_info_line (grid, _("Reason:"), reason, FALSE, &row);
 
-       data = gcr_parsed_get_data (parsed, &length);
-
-       certificate = gcr_simple_certificate_new (data, length);
-
-       #ifdef WITH_GCR3
-       {
-               GcrCertificateWidget *certificate_widget;
-               GckAttributes *attributes;
+       widget = e_certificate_widget_new ();
 
-               attributes = gcr_parsed_get_attributes (parsed);
-               certificate_widget = gcr_certificate_widget_new (certificate);
-               gcr_certificate_widget_set_attributes (certificate_widget, attributes);
-
-               widget = GTK_WIDGET (certificate_widget);
+       certificate_der = g_base64_decode (base64_certificate_der, &certificate_der_len);
+       if (certificate_der) {
+               e_certificate_widget_set_der (E_CERTIFICATE_WIDGET (widget), certificate_der, 
certificate_der_len);
+               g_free (certificate_der);
        }
-       #else
-       widget = gcr_certificate_widget_new (certificate);
-       #endif
+
        gtk_grid_attach (grid, widget, 1, row, 2, 1);
        gtk_widget_show (widget);
 
-       g_clear_object (&certificate);
-
        g_object_set_data (G_OBJECT (dialog), TRUST_PROMP_ID_KEY, GINT_TO_POINTER (prompt_id));
 
        g_signal_connect (dialog, "response", G_CALLBACK (trust_prompt_response_cb), extension);
diff --git a/src/modules/trust-prompt/trust-prompt.h b/src/modules/trust-prompt/trust-prompt.h
index 0bdf4e959..965753578 100644
--- a/src/modules/trust-prompt/trust-prompt.h
+++ b/src/modules/trust-prompt/trust-prompt.h
@@ -18,14 +18,6 @@
 #ifndef TRUST_PROMPT_H
 #define TRUST_PROMPT_H
 
-#define GCR_API_SUBJECT_TO_CHANGE
-#ifdef WITH_GCR3
-#include <gcr/gcr.h>
-#else
-#include <gcr-gtk3/gcr-gtk3.h>
-#endif
-#undef GCR_API_SUBJECT_TO_CHANGE
-
 #include <libebackend/libebackend.h>
 
 G_BEGIN_DECLS
@@ -45,7 +37,7 @@ trust_prompt_show (EUserPrompterServerExtension *extension,
                   gint prompt_id,
                   const gchar *host,
                   const gchar *markup,
-                  GcrParsed *parsed,
+                  const gchar *base64_certificate_der,
                   const gchar *reason);
 
 G_END_DECLS


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