[gnome-software/603-gnome-software-reports-unknown-error-when-there-is-a-signing-issue: 24/27] gs-plugin: Add 'ask-untrusted' signal




commit 9896132c63855a2dd74b16460794e4c070f46128
Author: Milan Crha <mcrha redhat com>
Date:   Mon Sep 20 14:12:50 2021 +0200

    gs-plugin: Add 'ask-untrusted' signal
    
    It can be used to ask the user, whether he/she accepts a download,
    install or update of an untrusted software.

 lib/gs-plugin-loader.c | 25 +++++++++++++++++++++++++
 lib/gs-plugin.c        | 43 +++++++++++++++++++++++++++++++++++++++++++
 lib/gs-plugin.h        | 12 +++++++++++-
 3 files changed, 79 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 7f5859a05..08ef04fd9 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -92,6 +92,7 @@ enum {
        SIGNAL_UPDATES_CHANGED,
        SIGNAL_RELOAD,
        SIGNAL_BASIC_AUTH_START,
+       SIGNAL_ASK_UNTRUSTED,
        SIGNAL_LAST
 };
 
@@ -2186,6 +2187,22 @@ gs_plugin_loader_basic_auth_start_cb (GsPlugin *plugin,
                       user_data);
 }
 
+static gboolean
+gs_plugin_loader_ask_untrusted_cb (GsPlugin *plugin,
+                                  const gchar *title,
+                                  const gchar *msg,
+                                  const gchar *details,
+                                  const gchar *accept_label,
+                                  GsPluginLoader *plugin_loader)
+{
+       gboolean accepts = FALSE;
+       g_debug ("emitting ask-untrusted title:'%s', msg:'%s' details:'%s' aaccept-label:'%s'", title, msg, 
details, accept_label);
+       g_signal_emit (plugin_loader,
+                      signals[SIGNAL_ASK_UNTRUSTED], 0,
+                      title, msg, details, accept_label, &accepts);
+       return accepts;
+}
+
 static gboolean
 gs_plugin_loader_job_actions_changed_delay_cb (gpointer user_data)
 {
@@ -2293,6 +2310,9 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        g_signal_connect (plugin, "repository-changed",
                          G_CALLBACK (gs_plugin_loader_repository_changed_cb),
                          plugin_loader);
+       g_signal_connect (plugin, "ask-untrusted",
+                         G_CALLBACK (gs_plugin_loader_ask_untrusted_cb),
+                         plugin_loader);
        gs_plugin_set_soup_session (plugin, plugin_loader->soup_session);
        gs_plugin_set_language (plugin, plugin_loader->language);
        gs_plugin_set_scale (plugin, gs_plugin_loader_get_scale (plugin_loader));
@@ -2936,6 +2956,11 @@ gs_plugin_loader_class_init (GsPluginLoaderClass *klass)
                              G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
                              0, NULL, NULL, g_cclosure_marshal_generic,
                              G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER);
+       signals [SIGNAL_ASK_UNTRUSTED] =
+               g_signal_new ("ask-untrusted",
+                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+                             0, NULL, NULL, g_cclosure_marshal_generic,
+                             G_TYPE_BOOLEAN, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
 }
 
 static void
diff --git a/lib/gs-plugin.c b/lib/gs-plugin.c
index 186bf3159..d9d53bae1 100644
--- a/lib/gs-plugin.c
+++ b/lib/gs-plugin.c
@@ -90,6 +90,7 @@ enum {
        SIGNAL_ALLOW_UPDATES,
        SIGNAL_BASIC_AUTH_START,
        SIGNAL_REPOSITORY_CHANGED,
+       SIGNAL_ASK_UNTRUSTED,
        SIGNAL_LAST
 };
 
@@ -2011,6 +2012,13 @@ gs_plugin_class_init (GsPluginClass *klass)
                              G_STRUCT_OFFSET (GsPluginClass, repository_changed),
                              NULL, NULL, g_cclosure_marshal_generic,
                              G_TYPE_NONE, 1, GS_TYPE_APP);
+
+       signals [SIGNAL_ASK_UNTRUSTED] =
+               g_signal_new ("ask-untrusted",
+                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (GsPluginClass, ask_untrusted),
+                             NULL, NULL, g_cclosure_marshal_generic,
+                             G_TYPE_BOOLEAN, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
 }
 
 static void
@@ -2169,3 +2177,38 @@ gs_plugin_get_action_supported (GsPlugin *plugin,
 
        return gs_plugin_get_symbol (plugin, function_name) != NULL;
 }
+
+/**
+ * gs_plugin_ask_untrusted:
+ * @plugin: a #GsPlugin
+ * @title: the title for the question
+ * @msg: the message for the question
+ * @details: (nullable): the detailed error message, or %NULL for none
+ * @accept_label: (nullable): a label of the 'accept' button, or %NULL to use 'Accept'
+ *
+ * Asks the user whether he/she accepts an untrusted package install/download/update,
+ * as described by @title and @msg, eventually with the @details.
+ *
+ * Note: This is a blocking call and can be called only from the main/GUI thread.
+ *
+ * Returns: whether the user accepted the question
+ *
+ * Since: 42
+ **/
+gboolean
+gs_plugin_ask_untrusted (GsPlugin *plugin,
+                        const gchar *title,
+                        const gchar *msg,
+                        const gchar *details,
+                        const gchar *accept_label)
+{
+       gboolean accepts = FALSE;
+       g_signal_emit (plugin,
+                      signals[SIGNAL_ASK_UNTRUSTED], 0,
+                      title,
+                      msg,
+                      details,
+                      accept_label,
+                      &accepts);
+       return accepts;
+}
diff --git a/lib/gs-plugin.h b/lib/gs-plugin.h
index fbd64ee27..8ed99237c 100644
--- a/lib/gs-plugin.h
+++ b/lib/gs-plugin.h
@@ -45,7 +45,12 @@ struct _GsPluginClass
                                                         gpointer        user_data);
        void                    (*repository_changed)   (GsPlugin       *plugin,
                                                         GsApp          *repository);
-       gpointer                 padding[24];
+       gboolean                (*ask_untrusted)        (GsPlugin       *plugin,
+                                                        const gchar    *title,
+                                                        const gchar    *msg,
+                                                        const gchar    *details,
+                                                        const gchar    *accept_label);
+       gpointer                 padding[23];
 };
 
 typedef struct GsPluginData    GsPluginData;
@@ -138,5 +143,10 @@ void               gs_plugin_update_cache_state_for_repository
                                                         GsApp *repository);
 gboolean       gs_plugin_get_action_supported          (GsPlugin       *plugin,
                                                         GsPluginAction  action);
+gboolean       gs_plugin_ask_untrusted                 (GsPlugin       *plugin,
+                                                        const gchar    *title,
+                                                        const gchar    *msg,
+                                                        const gchar    *details,
+                                                        const gchar    *accept_label);
 
 G_END_DECLS


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