[gnome-software/wip/hughsie/upgrades: 3/4] Show a modal dialog when downloading the distro-upgrade failed



commit c5a3bd65bebd88a23ffef5a321f7f8c6fbd7a837
Author: Richard Hughes <richard hughsie com>
Date:   Fri Apr 22 12:52:10 2016 +0100

    Show a modal dialog when downloading the distro-upgrade failed

 src/gs-page.c          |   20 +++++++-----------
 src/gs-self-test.c     |    6 +++++
 src/gs-shell-updates.c |   51 ++++++++++++++++++++++++++++++++++++++++++++---
 src/gs-utils.c         |    5 ++++
 4 files changed, 66 insertions(+), 16 deletions(-)
---
diff --git a/src/gs-page.c b/src/gs-page.c
index 7be141a..5e8d2dc 100644
--- a/src/gs-page.c
+++ b/src/gs-page.c
@@ -55,14 +55,16 @@ gs_page_helper_free (GsPageHelper *helper)
        g_slice_free (GsPageHelper, helper);
 }
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GsPageHelper, gs_page_helper_free);
+
 static void
 gs_page_app_installed_cb (GObject *source,
                           GAsyncResult *res,
                           gpointer user_data)
 {
+       g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data;
        GError *last_error;
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
-       GsPageHelper *helper = (GsPageHelper *) user_data;
        GsPage *page = helper->page;
        GsPagePrivate *priv = gs_page_get_instance_private (page);
        gboolean ret;
@@ -79,7 +81,7 @@ gs_page_app_installed_cb (GObject *source,
                                            gs_shell_get_window (priv->shell),
                                            GS_PLUGIN_LOADER_ACTION_INSTALL,
                                            error);
-               goto out;
+               return;
        }
 
        /* non-fatal error */
@@ -92,7 +94,7 @@ gs_page_app_installed_cb (GObject *source,
                                            gs_shell_get_window (priv->shell),
                                            GS_PLUGIN_LOADER_ACTION_INSTALL,
                                            last_error);
-               goto out;
+               return;
        }
 
        /* only show this if the window is not active */
@@ -102,9 +104,6 @@ gs_page_app_installed_cb (GObject *source,
 
        if (GS_PAGE_GET_CLASS (page)->app_installed != NULL)
                GS_PAGE_GET_CLASS (page)->app_installed (page, helper->app);
-
-out:
-       gs_page_helper_free (helper);
 }
 
 static void
@@ -112,9 +111,9 @@ gs_page_app_removed_cb (GObject *source,
                         GAsyncResult *res,
                         gpointer user_data)
 {
+       g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data;
        GError *last_error;
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
-       GsPageHelper *helper = (GsPageHelper *) user_data;
        GsPage *page = helper->page;
        GsPagePrivate *priv = gs_page_get_instance_private (page);
        gboolean ret;
@@ -129,7 +128,7 @@ gs_page_app_removed_cb (GObject *source,
                                            gs_shell_get_window (priv->shell),
                                            GS_PLUGIN_LOADER_ACTION_REMOVE,
                                            error);
-               goto out;
+               return;
        }
 
        /* non-fatal error */
@@ -142,14 +141,11 @@ gs_page_app_removed_cb (GObject *source,
                                            gs_shell_get_window (priv->shell),
                                            GS_PLUGIN_LOADER_ACTION_REMOVE,
                                            last_error);
-               goto out;
+               return;
        }
 
        if (GS_PAGE_GET_CLASS (page)->app_removed != NULL)
                GS_PAGE_GET_CLASS (page)->app_removed (page, helper->app);
-
-out:
-       gs_page_helper_free (helper);
 }
 
 GtkWidget *
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 365d034..a1a8799 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -139,6 +139,12 @@ gs_app_func (void)
        g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_REMOVING);
        gs_app_set_state_recover (app); // simulate an error
        g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
+
+       /* try again */
+       gs_app_set_state (app, AS_APP_STATE_REMOVING);
+       g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_REMOVING);
+       gs_app_set_state_recover (app); // simulate an error
+       g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_INSTALLED);
 }
 
 static guint _status_changed_cnt = 0;
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index c4552eb..2a4ecb8 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -1023,16 +1023,54 @@ gs_shell_updates_button_update_all_cb (GtkButton      *button,
                                       self);
 }
 
+typedef struct {
+       GsApp           *app;
+       GsShellUpdates  *self;
+} GsPageHelper;
+
+static void
+gs_page_helper_free (GsPageHelper *helper)
+{
+       if (helper->app != NULL)
+               g_object_unref (helper->app);
+       if (helper->self != NULL)
+               g_object_unref (helper->self);
+       g_slice_free (GsPageHelper, helper);
+}
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GsPageHelper, gs_page_helper_free);
+
 static void
 upgrade_download_finished_cb (GObject *source,
                               GAsyncResult *res,
                               gpointer user_data)
 {
-       GsShellUpdates *self = (GsShellUpdates *) user_data;
+       GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
+       GError *last_error;
        g_autoptr(GError) error = NULL;
+       g_autoptr(GsPageHelper) helper = (GsPageHelper *) user_data;
 
-       if (!gs_plugin_loader_app_action_finish (self->plugin_loader, res, &error)) {
-               g_warning ("failed to download upgrade: %s", error->message);
+       if (!gs_plugin_loader_app_action_finish (plugin_loader, res, &error)) {
+               g_warning ("failed to upgrade-download: %s", error->message);
+               if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+                       return;
+               gs_app_notify_failed_modal (helper->app,
+                                           gs_shell_get_window (helper->self->shell),
+                                           GS_PLUGIN_LOADER_ACTION_UPGRADE_DOWNLOAD,
+                                           error);
+               return;
+       }
+
+       /* non-fatal error */
+       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;
        }
 }
@@ -1042,6 +1080,7 @@ gs_shell_updates_upgrade_download_cb (GsUpgradeBanner *upgrade_banner,
                                       GsShellUpdates *self)
 {
        GsApp *app;
+       GsPageHelper *helper;
 
        app = gs_upgrade_banner_get_app (upgrade_banner);
        if (app == NULL) {
@@ -1049,6 +1088,10 @@ gs_shell_updates_upgrade_download_cb (GsUpgradeBanner *upgrade_banner,
                return;
        }
 
+       helper = g_slice_new0 (GsPageHelper);
+       helper->app = g_object_ref (app);
+       helper->self = g_object_ref (self);
+
        if (self->cancellable_upgrade_download != NULL)
                g_object_unref (self->cancellable_upgrade_download);
        self->cancellable_upgrade_download = g_cancellable_new ();
@@ -1057,7 +1100,7 @@ gs_shell_updates_upgrade_download_cb (GsUpgradeBanner *upgrade_banner,
                                           GS_PLUGIN_LOADER_ACTION_UPGRADE_DOWNLOAD,
                                           self->cancellable_upgrade_download,
                                           upgrade_download_finished_cb,
-                                          self);
+                                          helper);
 }
 
 static void
diff --git a/src/gs-utils.c b/src/gs-utils.c
index f727b72..7964fb6 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -180,6 +180,11 @@ gs_app_notify_failed_modal (GsApp *app,
                g_string_append_printf (msg, _("Removal of %s failed."),
                                        gs_app_get_name (app));
                break;
+       case GS_PLUGIN_LOADER_ACTION_UPGRADE_DOWNLOAD:
+               /* TRANSLATORS: this is when the upgrade download fails */
+               g_string_append_printf (msg, _("Upgrade to %s failed."),
+                                       gs_app_get_name (app));
+               break;
        default:
                g_assert_not_reached ();
                break;


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