[gnome-software/wip/hughsie/GsPluginEvent] f



commit 16b34b856e4297c89181a05dc0c4ee36cf215b32
Author: Richard Hughes <richard hughsie com>
Date:   Tue Sep 6 21:04:24 2016 +0100

    f

 src/gs-app-private.h          |    3 --
 src/gs-app.c                  |   40 ---------------------
 src/gs-page.c                 |   48 +++++++++++++-------------
 src/gs-plugin-event.c         |   77 ++++++++++++++++++++++++++++++++++++----
 src/gs-plugin-event.h         |    9 +++++
 src/gs-plugin-loader.c        |   29 ++++++++++++----
 src/gs-self-test.c            |   16 +++++++--
 src/gs-shell-updates.c        |   24 ++++++------
 src/gs-shell.c                |    6 +++-
 src/plugins/gs-plugin-dummy.c |    7 +++-
 10 files changed, 160 insertions(+), 99 deletions(-)
---
diff --git a/src/gs-app-private.h b/src/gs-app-private.h
index 9fb8391..0a83c81 100644
--- a/src/gs-app-private.h
+++ b/src/gs-app-private.h
@@ -26,9 +26,6 @@
 
 G_BEGIN_DECLS
 
-GError         *gs_app_get_last_error          (GsApp          *app);
-void            gs_app_set_last_error          (GsApp          *app,
-                                                GError         *error);
 void            gs_app_set_priority            (GsApp          *app,
                                                 guint           priority);
 guint           gs_app_get_priority            (GsApp          *app);
diff --git a/src/gs-app.c b/src/gs-app.c
index 5d57ec0..654e2cc 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -75,7 +75,6 @@ struct _GsApp
        gchar                   *summary_missing;
        gchar                   *description;
        GsAppQuality             description_quality;
-       GError                  *last_error;
        GPtrArray               *screenshots;
        GPtrArray               *categories;
        GPtrArray               *key_colors;
@@ -253,8 +252,6 @@ gs_app_to_string (GsApp *app)
        str = g_string_new ("GsApp:");
        g_string_append_printf (str, " [%p]\n", app);
        gs_app_kv_lpad (str, "kind", as_app_kind_to_string (app->kind));
-       if (app->last_error != NULL)
-               gs_app_kv_lpad (str, "last-error", app->last_error->message);
        gs_app_kv_lpad (str, "state", as_app_state_to_string (app->state));
        if (app->quirk > 0) {
                g_autofree gchar *qstr = _as_app_quirk_to_string (app->quirk);
@@ -793,9 +790,6 @@ gs_app_set_state_internal (GsApp *app, AsAppState state)
                                 app->id, as_app_state_to_string (state));
                        app->state_recover = state;
                }
-
-               /* clear the error as the application has changed state */
-               g_clear_error (&app->last_error);
                break;
        }
 
@@ -3185,38 +3179,6 @@ gs_app_get_priority (GsApp *app)
        return app->priority;
 }
 
-/**
- * gs_app_get_last_error:
- * @app: a #GsApp
- *
- * Get the last error.
- *
- * Returns: a #GError, or %NULL
- *
- * Since: 3.22
- **/
-GError *
-gs_app_get_last_error (GsApp *app)
-{
-       return app->last_error;
-}
-
-/**
- * gs_app_set_last_error:
- * @app: a #GsApp
- * @error: a #GError
- *
- * Sets the last error.
- *
- * Since: 3.22
- **/
-void
-gs_app_set_last_error (GsApp *app, GError *error)
-{
-       g_clear_error (&app->last_error);
-       app->last_error = g_error_copy (error);
-}
-
 static void
 gs_app_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 {
@@ -3365,8 +3327,6 @@ gs_app_finalize (GObject *object)
        g_ptr_array_unref (app->key_colors);
        if (app->keywords != NULL)
                g_ptr_array_unref (app->keywords);
-       if (app->last_error != NULL)
-               g_error_free (app->last_error);
        if (app->local_file != NULL)
                g_object_unref (app->local_file);
        if (app->pixbuf != NULL)
diff --git a/src/gs-page.c b/src/gs-page.c
index 19e5f42..cf8a968 100644
--- a/src/gs-page.c
+++ b/src/gs-page.c
@@ -128,7 +128,7 @@ gs_page_app_installed_cb (GObject *source,
                           gpointer user_data)
 {
        g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data;
-       GError *last_error;
+//     GError *last_error;
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
        GsPage *page = helper->page;
        GsPagePrivate *priv = gs_page_get_instance_private (page);
@@ -177,17 +177,17 @@ gs_page_app_installed_cb (GObject *source,
        }
 
        /* non-fatal error */
-       last_error = gs_app_get_last_error (helper->app);
-       if (last_error != NULL) {
-               g_warning ("failed to install %s: %s",
-                          gs_app_get_id (helper->app),
-                          last_error->message);
-               gs_app_notify_failed_modal (helper->app,
-                                           gs_shell_get_window (priv->shell),
-                                           GS_PLUGIN_LOADER_ACTION_INSTALL,
-                                           last_error);
-               return;
-       }
+//     last_error = gs_app_get_last_error (helper->app);
+//     if (last_error != NULL) {
+//             g_warning ("failed to install %s: %s",
+//                        gs_app_get_id (helper->app),
+//                        last_error->message);
+//             gs_app_notify_failed_modal (helper->app,
+//                                         gs_shell_get_window (priv->shell),
+//                                         GS_PLUGIN_LOADER_ACTION_INSTALL,
+//                                         last_error);
+//             return;
+//     }
 
        /* only show this if the window is not active */
        if (gs_app_get_state (helper->app) != AS_APP_STATE_QUEUED_FOR_INSTALL &&
@@ -204,7 +204,7 @@ gs_page_app_removed_cb (GObject *source,
                         gpointer user_data)
 {
        g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data;
-       GError *last_error;
+//     GError *last_error;
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
        GsPage *page = helper->page;
        GsPagePrivate *priv = gs_page_get_instance_private (page);
@@ -251,17 +251,17 @@ gs_page_app_removed_cb (GObject *source,
        }
 
        /* non-fatal error */
-       last_error = gs_app_get_last_error (helper->app);
-       if (last_error != NULL) {
-               g_warning ("failed to remove %s: %s",
-                          gs_app_get_id (helper->app),
-                          last_error->message);
-               gs_app_notify_failed_modal (helper->app,
-                                           gs_shell_get_window (priv->shell),
-                                           GS_PLUGIN_LOADER_ACTION_REMOVE,
-                                           last_error);
-               return;
-       }
+//     last_error = gs_app_get_last_error (helper->app);
+//     if (last_error != NULL) {
+//             g_warning ("failed to remove %s: %s",
+//                        gs_app_get_id (helper->app),
+//                        last_error->message);
+//             gs_app_notify_failed_modal (helper->app,
+//                                         gs_shell_get_window (priv->shell),
+//                                         GS_PLUGIN_LOADER_ACTION_REMOVE,
+//                                         last_error);
+//             return;
+//     }
 
        if (GS_PAGE_GET_CLASS (page)->app_removed != NULL)
                GS_PAGE_GET_CLASS (page)->app_removed (page, helper->app);
diff --git a/src/gs-plugin-event.c b/src/gs-plugin-event.c
index 173b399..5f52488 100644
--- a/src/gs-plugin-event.c
+++ b/src/gs-plugin-event.c
@@ -36,12 +36,14 @@
 
 #include <glib.h>
 
+#include "gs-plugin.h"
 #include "gs-plugin-event.h"
 
 struct _GsPluginEvent
 {
        GObject                  parent_instance;
        GsApp                   *app;
+       GError                  *gerror;
        GsPluginEventFlag        flags;
 };
 
@@ -85,11 +87,9 @@ gs_plugin_event_get_app (GsPluginEvent *event)
 /**
  * gs_plugin_event_get_kind:
  * @event: A #GsPluginEvent
- * @unique_id: A unique_id
+ * @flag: A #GsPluginEventFlag, e.g. %GS_PLUGIN_EVENT_FLAG_ACTIVE
  *
- * Gets the kind of the event.
- *
- * Returns: a #GsPluginEventKind, e.g. %GS_PLUGIN_EVENT_KIND_WARNING
+ * Adds a flag to the event.
  *
  * Since: 3.22
  **/
@@ -103,11 +103,9 @@ gs_plugin_event_add_flag (GsPluginEvent *event, GsPluginEventFlag flag)
 /**
  * gs_plugin_event_set_kind:
  * @event: A #GsPluginEvent
- * @kind: A #GsPluginEvent, e.g. %GS_PLUGIN_EVENT_KIND_WARNING
- *
- * Sets the kind of the event.
+ * @flag: A #GsPluginEventFlag, e.g. %GS_PLUGIN_EVENT_FLAG_ACTIVE
  *
- * Returns: #GsPluginEventKind, e.g. 
+ * Removes a flag from the event.
  *
  * Since: 3.22
  **/
@@ -118,6 +116,17 @@ gs_plugin_event_remove_flag (GsPluginEvent *event, GsPluginEventFlag flag)
        event->flags &= ~flag;
 }
 
+/**
+ * gs_plugin_event_has_flag:
+ * @event: A #GsPluginEvent
+ * @flag: A #GsPluginEventFlag, e.g. %GS_PLUGIN_EVENT_FLAG_ACTIVE
+ *
+ * Finds out if the event has a specific flag.
+ *
+ * Returns: %TRUE if the flag is set
+ *
+ * Since: 3.22
+ **/
 gboolean
 gs_plugin_event_has_flag (GsPluginEvent *event, GsPluginEventFlag flag)
 {
@@ -125,6 +134,58 @@ gs_plugin_event_has_flag (GsPluginEvent *event, GsPluginEventFlag flag)
        return (event->flags & flag > 0);
 }
 
+/**
+ * gs_plugin_event_set_error:
+ * @event: A #GsPluginEvent
+ * @code: A #GsPluginError, e.g. %GS_PLUGIN_ERROR_NO_NETWORK
+ * @message: A error message
+ *
+ * Sets the event error.
+ *
+ * Since: 3.22
+ **/
+void
+gs_plugin_event_set_error (GsPluginEvent *event, gint code, const gchar *message)
+{
+       g_clear_error (&event->gerror);
+       g_set_error_literal (&event->gerror,
+                            GS_PLUGIN_ERROR,
+                            code,
+                            message);
+}
+
+/**
+ * gs_plugin_event_set_gerror:
+ * @event: A #GsPluginEvent
+ * @error: A #GError
+ *
+ * Sets the event error.
+ *
+ * Since: 3.22
+ **/
+void
+gs_plugin_event_set_gerror (GsPluginEvent *event, const GError *error)
+{
+       g_clear_error (&event->gerror);
+       event->gerror = g_error_copy (error);
+}
+
+/**
+ * gs_plugin_event_get_gerror:
+ * @event: A #GsPluginEvent
+ *
+ * Gets the event error.
+ *
+ * Returns: a #GError, or %NULL for unset
+ *
+ * Since: 3.22
+ **/
+const GError *
+gs_plugin_event_get_gerror (GsPluginEvent *event)
+{
+       return event->gerror;
+}
+
 static void
 gs_plugin_event_finalize (GObject *object)
 {
diff --git a/src/gs-plugin-event.h b/src/gs-plugin-event.h
index 49b5c42..b9acb55 100644
--- a/src/gs-plugin-event.h
+++ b/src/gs-plugin-event.h
@@ -41,9 +41,18 @@ typedef enum {
 } GsPluginEventFlag;
 
 GsPluginEvent          *gs_plugin_event_new            (void);
+
 void                    gs_plugin_event_set_app        (GsPluginEvent          *event,
                                                         GsApp                  *app);
 GsApp                  *gs_plugin_event_get_app        (GsPluginEvent          *event);
+
+void                    gs_plugin_event_set_error      (GsPluginEvent          *event,
+                                                        gint                    code,
+                                                        const gchar            *message);
+void                    gs_plugin_event_set_gerror     (GsPluginEvent          *event,
+                                                        const GError           *error);
+const GError           *gs_plugin_event_get_gerror     (GsPluginEvent          *event);
+
 void                    gs_plugin_event_add_flag       (GsPluginEvent          *event,
                                                         GsPluginEventFlag       flag);
 void                    gs_plugin_event_remove_flag    (GsPluginEvent          *event,
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 1b5f894..89d4ec5 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -904,17 +904,32 @@ gs_plugin_loader_get_app_is_compatible (GsApp *app, gpointer user_data)
 }
 
 static void
-gs_plugin_loader_set_app_error (GsApp *app, GError *error)
+gs_plugin_loader_add_event (GsPluginLoader *plugin_loader, GsPluginEvent *event)
+{
+       GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+       g_ptr_array_add (priv->events, g_object_ref (event));
+       g_object_notify (G_OBJECT (plugin_loader), "events");
+}
+
+static void
+gs_plugin_loader_set_app_error (GsPluginLoader *plugin_loader,
+                               GsApp *app, GError *error)
 {
        if (error == NULL)
                return;
 
        /* random, non-plugin error domains are never shown to the user */
        if (error->domain == GS_PLUGIN_ERROR) {
+               g_autoptr(GsPluginEvent) event = gs_plugin_event_new ();
                g_debug ("saving error for %s: %s",
                         gs_app_get_unique_id (app),
                         error->message);
-               gs_app_set_last_error (app, error);
+
+               /* create and add event */
+               gs_plugin_event_set_app (event, app);
+               gs_plugin_event_set_gerror (event, error);
+               gs_plugin_event_add_flag (event, GS_PLUGIN_EVENT_FLAG_ACTIVE);
+               gs_plugin_loader_add_event (plugin_loader, event);
        } else {
                g_warning ("not saving error for %s: %s",
                           gs_app_get_unique_id (app),
@@ -990,7 +1005,8 @@ gs_plugin_loader_run_action (GsPluginLoader *plugin_loader,
                                   function_name,
                                   gs_plugin_get_name (plugin),
                                   error_local->message);
-                       gs_plugin_loader_set_app_error (app, error_local);
+                       gs_plugin_loader_set_app_error (plugin_loader,
+                                                       app, error_local);
                        continue;
                }
                anything_ran = TRUE;
@@ -3375,9 +3391,7 @@ gs_plugin_loader_add_event_cb (GsPlugin *plugin,
                               GsPluginEvent *event,
                               GsPluginLoader *plugin_loader)
 {
-       GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
-       g_ptr_array_add (priv->events, g_object_ref (event));
-       g_object_notify (G_OBJECT (plugin_loader), "events");
+       gs_plugin_loader_add_event (plugin_loader, event);
 }
 
 static void
@@ -4555,7 +4569,8 @@ gs_plugin_loader_update_thread_cb (GTask *task,
                                           function_name,
                                           gs_plugin_get_name (plugin),
                                           error_local->message);
-                               gs_plugin_loader_set_app_error (app, error_local);
+                               gs_plugin_loader_set_app_error (plugin_loader,
+                                                               app, error_local);
                                continue;
                        }
                }
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 2159948..a05d83d 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -344,10 +344,16 @@ gs_plugin_loader_install_func (GsPluginLoader *plugin_loader)
 static void
 gs_plugin_loader_error_func (GsPluginLoader *plugin_loader)
 {
+       GPtrArray *events;
+       GsPluginEvent *event;
+       const GError *app_error;
        gboolean ret;
        g_autoptr(GsApp) app = NULL;
        g_autoptr(GError) error = NULL;
-       GError *last_error;
+
+       /* remove previous errors */
+       events = gs_plugin_loader_get_events (plugin_loader);
+       g_ptr_array_set_size (events, 0);
 
        /* suppress this */
        g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
@@ -368,8 +374,12 @@ gs_plugin_loader_error_func (GsPluginLoader *plugin_loader)
        g_test_assert_expected_messages ();
 
        /* retrieve the error from the application */
-       last_error = gs_app_get_last_error (app);
-       g_assert_error (last_error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NO_NETWORK);
+       g_assert_cmpint (events->len, ==, 1);
+       event = g_ptr_array_index (events, 0);
+       g_assert (gs_plugin_event_get_app (event) == app);
+       app_error = gs_plugin_event_get_gerror (event);
+       g_assert (app_error != NULL);
+       g_assert_error (app_error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NO_NETWORK);
 }
 
 static void
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 0dd03f7..fd8011f 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -1001,7 +1001,7 @@ upgrade_download_finished_cb (GObject *source,
                               gpointer user_data)
 {
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
-       GError *last_error;
+//     GError *last_error;
        g_autoptr(GError) error = NULL;
        g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data;
 
@@ -1011,17 +1011,17 @@ upgrade_download_finished_cb (GObject *source,
                g_warning ("failed to upgrade-download: %s", error->message);
        }
 
-       last_error = gs_app_get_last_error (helper->app);
-       if (last_error != NULL) {
-               g_warning ("failed to upgrade-download %s: %s",
-                          gs_app_get_id (helper->app),
-                          last_error->message);
-               gs_app_notify_failed_modal (helper->app,
-                                           gs_shell_get_window (helper->self->shell),
-                                           GS_PLUGIN_LOADER_ACTION_UPGRADE_DOWNLOAD,
-                                           last_error);
-               return;
-       }
+//     last_error = gs_app_get_last_error (helper->app);
+//     if (last_error != NULL) {
+//             g_warning ("failed to upgrade-download %s: %s",
+//                        gs_app_get_id (helper->app),
+//                        last_error->message);
+//             gs_app_notify_failed_modal (helper->app,
+//                                         gs_shell_get_window (helper->self->shell),
+//                                         GS_PLUGIN_LOADER_ACTION_UPGRADE_DOWNLOAD,
+//                                         last_error);
+//             return;
+//     }
 }
 
 static void
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 213e511..80f0eb9 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -626,6 +626,7 @@ gs_shell_events_show (GsShell *shell, GsPluginEvent *event)
        GsApp *app = gs_plugin_event_get_app (event);
        GsShellPrivate *priv = gs_shell_get_instance_private (shell);
        GtkWidget *widget;
+       const GError *error;
        const gchar *tmp;
        g_autoptr(GString) header = g_string_new ("");
 
@@ -673,7 +674,10 @@ gs_shell_events_show (GsShell *shell, GsPluginEvent *event)
 
        /* fill in detail */
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "label_events"));
-       gtk_label_set_label (GTK_LABEL (widget), gs_app_get_summary_missing (app));
+       error = gs_plugin_event_get_gerror (event);
+       if (error != NULL)
+               gtk_label_set_label (GTK_LABEL (widget), error->message);
+       gtk_widget_set_visible (widget, error != NULL);
 }
 
 static void
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index 8725d80..44eafac 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -65,13 +65,18 @@ gs_plugin_dummy_add_event (GsPlugin *plugin)
 {
        g_autoptr(GsPluginEvent) event = gs_plugin_event_new ();
        g_autoptr(GsApp) source = gs_app_new ("dummy");
+
+       /* create source */
        gs_app_set_kind (source, AS_APP_KIND_SOURCE);
        gs_app_set_origin_hostname (source, "packages.dummy.org");
        gs_app_set_name (source, GS_APP_QUALITY_NORMAL, "Dummy");
        gs_app_set_state (source, AS_APP_STATE_UNAVAILABLE);
-       gs_app_set_summary_missing (source, "Metadata download failed: Could not reach destination.");
+
+       /* create and add event */
        gs_plugin_event_add_flag (event, GS_PLUGIN_EVENT_FLAG_WARNING);
        gs_plugin_event_set_app (event, source);
+       gs_plugin_event_set_error (event, GS_PLUGIN_ERROR_NO_NETWORK,
+                                  "Metadata download failed: Could not reach destination.");
        gs_plugin_add_event (plugin, event);
 }
 


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