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




commit 42210e51b8ee9bec1fca6021fce654ac0af96d99
Author: Milan Crha <mcrha redhat com>
Date:   Thu Oct 14 15:48:04 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 8278bc2e9..633ddefee 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
 };
 
@@ -2177,6 +2178,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)
 {
@@ -2284,6 +2301,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));
@@ -2907,6 +2927,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 767bb2332..da8c5e75c 100644
--- a/lib/gs-plugin.c
+++ b/lib/gs-plugin.c
@@ -89,6 +89,7 @@ enum {
        SIGNAL_ALLOW_UPDATES,
        SIGNAL_BASIC_AUTH_START,
        SIGNAL_REPOSITORY_CHANGED,
+       SIGNAL_ASK_UNTRUSTED,
        SIGNAL_LAST
 };
 
@@ -1952,6 +1953,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
@@ -2110,3 +2118,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 b4c529324..0f1e3e9d3 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];
 };
 
 /* helpers */
@@ -133,5 +138,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]