[gnome-software] Notify about the correct application when installing from the details panel



commit 0bca23e1d0e489ef29a23d390c28cf3c23c6b31a
Author: Richard Hughes <richard hughsie com>
Date:   Tue Oct 15 16:08:37 2013 +0100

    Notify about the correct application when installing from the details panel
    
    If the user switches the details view to another application, we have to notify
    about the thing we're installing, not the new application we're showing.
    
    Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=710192

 src/gs-shell-details.c |   37 +++++++++++++++++++++++++++----------
 1 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 1c08421..bc21fd1 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -562,6 +562,11 @@ gs_shell_details_get_app (GsShellDetails *shell_details)
        return shell_details->priv->app;
 }
 
+typedef struct {
+       GsShellDetails  *shell_details;
+       GsApp           *app;
+} GsShellDetailsHelper;
+
 /**
  * gs_shell_details_app_installed_cb:
  **/
@@ -572,8 +577,7 @@ gs_shell_details_app_installed_cb (GObject *source,
 {
        GError *error = NULL;
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
-       GsShellDetails *shell_details = GS_SHELL_DETAILS (user_data);
-       GsShellDetailsPrivate *priv = shell_details->priv;
+       GsShellDetailsHelper *helper = (GsShellDetailsHelper *) user_data;
        gboolean ret;
 
        ret = gs_plugin_loader_app_action_finish (plugin_loader,
@@ -581,12 +585,15 @@ gs_shell_details_app_installed_cb (GObject *source,
                                                  &error);
        if (!ret) {
                g_warning ("failed to install %s: %s",
-                          gs_app_get_id (priv->app),
+                          gs_app_get_id (helper->app),
                           error->message);
                g_error_free (error);
                return;
        }
-       gs_app_notify_installed (priv->app);
+       gs_app_notify_installed (helper->app);
+       g_object_unref (helper->shell_details);
+       g_object_unref (helper->app);
+       g_free (helper);
 }
 
 /**
@@ -599,8 +606,7 @@ gs_shell_details_app_removed_cb (GObject *source,
 {
        GError *error = NULL;
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
-       GsShellDetails *shell_details = GS_SHELL_DETAILS (user_data);
-       GsShellDetailsPrivate *priv = shell_details->priv;
+       GsShellDetailsHelper *helper = (GsShellDetailsHelper *) user_data;
        gboolean ret;
 
        ret = gs_plugin_loader_app_action_finish (plugin_loader,
@@ -608,12 +614,15 @@ gs_shell_details_app_removed_cb (GObject *source,
                                                  &error);
        if (!ret) {
                g_warning ("failed to remove %s: %s",
-                          gs_app_get_id (priv->app),
+                          gs_app_get_id (helper->app),
                           error->message);
                g_error_free (error);
                return;
        }
-       gs_shell_details_refresh (shell_details);
+       gs_shell_details_refresh (helper->shell_details);
+       g_object_unref (helper->shell_details);
+       g_object_unref (helper->app);
+       g_free (helper);
 }
 
 /**
@@ -622,6 +631,7 @@ gs_shell_details_app_removed_cb (GObject *source,
 static void
 gs_shell_details_app_remove_button_cb (GtkWidget *widget, GsShellDetails *shell_details)
 {
+       GsShellDetailsHelper *helper;
        GsShellDetailsPrivate *priv = shell_details->priv;
        GString *markup;
        GtkResponseType response;
@@ -652,12 +662,15 @@ gs_shell_details_app_remove_button_cb (GtkWidget *widget, GsShellDetails *shell_
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        if (response == GTK_RESPONSE_OK) {
                g_debug ("remove %s", gs_app_get_id (priv->app));
+               helper = g_new0 (GsShellDetailsHelper, 1);
+               helper->shell_details = g_object_ref (shell_details);
+               helper->app = g_object_ref (priv->app);
                gs_plugin_loader_app_action_async (priv->plugin_loader,
                                                   priv->app,
                                                   GS_PLUGIN_LOADER_ACTION_REMOVE,
                                                   priv->cancellable,
                                                   gs_shell_details_app_removed_cb,
-                                                  shell_details);
+                                                  helper);
        }
        g_string_free (markup, TRUE);
        gtk_widget_destroy (dialog);
@@ -670,12 +683,16 @@ static void
 gs_shell_details_app_install_button_cb (GtkWidget *widget, GsShellDetails *shell_details)
 {
        GsShellDetailsPrivate *priv = shell_details->priv;
+       GsShellDetailsHelper *helper;
+       helper = g_new0 (GsShellDetailsHelper, 1);
+       helper->shell_details = g_object_ref (shell_details);
+       helper->app = g_object_ref (priv->app);
        gs_plugin_loader_app_action_async (priv->plugin_loader,
                                           priv->app,
                                           GS_PLUGIN_LOADER_ACTION_INSTALL,
                                           priv->cancellable,
                                           gs_shell_details_app_installed_cb,
-                                          shell_details);
+                                          helper);
 }
 
 /**


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