[gnome-software/603-gnome-software-reports-unknown-error-when-there-is-a-signing-issue: 386/389] gs-plugin: Add 'ask-user-accepts' signal




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

    gs-plugin: Add 'ask-user-accepts' signal
    
    It can be used for general questions to the user, usually about
    confirmation for the next operation.

 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 4d5240c32..c991f739d 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_USER_ACCEPTS,
        SIGNAL_LAST
 };
 
@@ -2167,6 +2168,22 @@ gs_plugin_loader_basic_auth_start_cb (GsPlugin *plugin,
                       user_data);
 }
 
+static gboolean
+gs_plugin_loader_ask_user_accepts_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-user-accepts title:'%s', msg:'%s' details:'%s'", title, msg, details);
+       g_signal_emit (plugin_loader,
+                      signals[SIGNAL_ASK_USER_ACCEPTS], 0,
+                      title, msg, details, accept_label, &accepts);
+       return accepts;
+}
+
 static gboolean
 gs_plugin_loader_job_actions_changed_delay_cb (gpointer user_data)
 {
@@ -2274,6 +2291,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-user-accepts",
+                         G_CALLBACK (gs_plugin_loader_ask_user_accepts_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));
@@ -2917,6 +2937,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_USER_ACCEPTS] =
+               g_signal_new ("ask-user-accepts",
+                             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..4e48f063d 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_USER_ACCEPTS,
        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_USER_ACCEPTS] =
+               g_signal_new ("ask-user-accepts",
+                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (GsPluginClass, ask_user_accepts),
+                             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_user_accepts:
+ * @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 what is 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_user_accepts (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_USER_ACCEPTS], 0,
+                      title,
+                      msg,
+                      details,
+                      accept_label,
+                      &accepts);
+       return accepts;
+}
diff --git a/lib/gs-plugin.h b/lib/gs-plugin.h
index fbd64ee27..e6ad87965 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_user_accepts)     (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_user_accepts              (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]