[gnome-software] Allow plugins to report events directly



commit 4a94e4e7828c032afb506f3a39266cc5022b7151
Author: Richard Hughes <richard hughsie com>
Date:   Wed Oct 26 14:20:44 2016 +0100

    Allow plugins to report events directly

 src/gs-plugin-loader.c |   11 +++++++++++
 src/gs-plugin.c        |   27 +++++++++++++++++++++++++++
 src/gs-plugin.h        |    2 ++
 3 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index ffd991c..9d7826a 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -3701,6 +3701,14 @@ gs_plugin_loader_remove_events (GsPluginLoader *plugin_loader)
 }
 
 static void
+gs_plugin_loader_report_event_cb (GsPlugin *plugin,
+                                 GsPluginEvent *event,
+                                 GsPluginLoader *plugin_loader)
+{
+       gs_plugin_loader_add_event (plugin_loader, event);
+}
+
+static void
 gs_plugin_loader_status_changed_cb (GsPlugin *plugin,
                                    GsApp *app,
                                    GsPluginStatus status,
@@ -3809,6 +3817,9 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        g_signal_connect (plugin, "status-changed",
                          G_CALLBACK (gs_plugin_loader_status_changed_cb),
                          plugin_loader);
+       g_signal_connect (plugin, "report-event",
+                         G_CALLBACK (gs_plugin_loader_report_event_cb),
+                         plugin_loader);
        gs_plugin_set_soup_session (plugin, priv->soup_session);
        gs_plugin_set_auth_array (plugin, priv->auth_array);
        gs_plugin_set_profile (plugin, priv->profile);
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index 57af366..9b2d318 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -90,6 +90,7 @@ enum {
        SIGNAL_UPDATES_CHANGED,
        SIGNAL_STATUS_CHANGED,
        SIGNAL_RELOAD,
+       SIGNAL_REPORT_EVENT,
        SIGNAL_LAST
 };
 
@@ -1272,6 +1273,25 @@ gs_plugin_cache_invalidate (GsPlugin *plugin)
 }
 
 /**
+ * gs_plugin_report_event:
+ * @plugin: a #GsPlugin
+ * @event: a #GsPluginEvent
+ *
+ * Report a non-fatal event to the UI. Plugins should not assume that a
+ * specific event is actually shown to the user as it may be ignored
+ * automatically.
+ *
+ * Since: 3.24
+ **/
+void
+gs_plugin_report_event (GsPlugin *plugin, GsPluginEvent *event)
+{
+       g_return_if_fail (GS_IS_PLUGIN (plugin));
+       g_return_if_fail (GS_IS_PLUGIN_EVENT (event));
+       g_signal_emit (plugin, signals[SIGNAL_REPORT_EVENT], 0, event);
+}
+
+/**
  * gs_plugin_error_to_string:
  * @error: a #GsPluginError, e.g. %GS_PLUGIN_ERROR_NO_NETWORK
  *
@@ -1469,6 +1489,13 @@ gs_plugin_class_init (GsPluginClass *klass)
                              G_STRUCT_OFFSET (GsPluginClass, reload),
                              NULL, NULL, g_cclosure_marshal_VOID__VOID,
                              G_TYPE_NONE, 0);
+
+       signals [SIGNAL_REPORT_EVENT] =
+               g_signal_new ("report-event",
+                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (GsPluginClass, report_event),
+                             NULL, NULL, g_cclosure_marshal_generic,
+                             G_TYPE_NONE, 1, GS_TYPE_PLUGIN_EVENT);
 }
 
 static void
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index 4f60470..72ff9ec 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -117,6 +117,8 @@ gboolean     gs_plugin_app_launch                   (GsPlugin       *plugin,
 void            gs_plugin_updates_changed              (GsPlugin       *plugin);
 void            gs_plugin_reload                       (GsPlugin       *plugin);
 const gchar    *gs_plugin_status_to_string             (GsPluginStatus  status);
+void            gs_plugin_report_event                 (GsPlugin       *plugin,
+                                                        GsPluginEvent  *event);
 
 G_END_DECLS
 


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