[gnome-software] category page: Make state keeping more robust



commit 4a5b422e8c47ee3172e79963c6b03b47cd43153a
Author: Kalev Lember <klember redhat com>
Date:   Mon Jun 29 15:53:42 2015 +0200

    category page: Make state keeping more robust
    
    Previously, we would use priv->category for storing either the main
    category or the subcategory, depending on the sitation. This made it
    more difficult than neccessary to figure out the main category:
    sometimes we would have to walk the parent tree, sometimes it would be
    NULL, sometimes the parent would already have been destroyed.
    
    Instead, simplify the code to always store the main category and rely on
    the fact that we always have the current subcategory available on the
    currently selected row.
    
    This fixes a bunch of criticals and incorrect state when going back to
    the category view after installing an app.

 src/gs-shell-category.c |   41 +++++++++++++++--------------------------
 1 files changed, 15 insertions(+), 26 deletions(-)
---
diff --git a/src/gs-shell-category.c b/src/gs-shell-category.c
index 464bbc1..3890d38 100644
--- a/src/gs-shell-category.c
+++ b/src/gs-shell-category.c
@@ -60,14 +60,10 @@ gs_shell_category_switch_to (GsShellCategory *shell)
 {
        GsShellCategoryPrivate *priv = shell->priv;
        GtkWidget *widget;
-       GsCategory *category;
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "application_details_header"));
        gtk_widget_show (widget);
-       category = priv->category;
-       if (gs_category_get_parent (category))
-               category = gs_category_get_parent (category);
-       gtk_label_set_label (GTK_LABEL (widget), gs_category_get_name (category));
+       gtk_label_set_label (GTK_LABEL (widget), gs_category_get_name (priv->category));
 }
 
 static void
@@ -126,33 +122,28 @@ out:
 }
 
 static void
-gs_shell_category_populate_filtered (GsShellCategory *shell)
+gs_shell_category_populate_filtered (GsShellCategory *shell, GsCategory *subcategory)
 {
        GsShellCategoryPrivate *priv = shell->priv;
-       GsCategory *parent;
        GtkWidget *tile;
        guint i;
 
+       g_assert (subcategory != NULL);
+
        if (priv->cancellable != NULL) {
                g_cancellable_cancel (priv->cancellable);
                g_object_unref (priv->cancellable);
        }
        priv->cancellable = g_cancellable_new ();
 
-       parent = gs_category_get_parent (priv->category);
-       if (parent == NULL) {
-               g_debug ("search using %s",
-                        gs_category_get_id (priv->category));
-       } else {
-               g_debug ("search using %s/%s",
-                        gs_category_get_id (parent),
-                        gs_category_get_id (priv->category));
-       }
+       g_debug ("search using %s/%s",
+                gs_category_get_id (priv->category),
+                gs_category_get_id (subcategory));
 
        gtk_grid_remove_column (GTK_GRID (priv->category_detail_grid), 1);
        gtk_grid_remove_column (GTK_GRID (priv->category_detail_grid), 0);
 
-       for (i = 0; i < MIN (30, gs_category_get_size (priv->category)); i++) {
+       for (i = 0; i < MIN (30, gs_category_get_size (subcategory)); i++) {
                tile = gs_app_tile_new (NULL);
                gtk_grid_attach (GTK_GRID (priv->category_detail_grid), tile, (i % 2), i / 2, 1, 1);
        }
@@ -161,7 +152,7 @@ gs_shell_category_populate_filtered (GsShellCategory *shell)
        gtk_grid_attach (GTK_GRID (priv->category_detail_grid), priv->col1_placeholder, 1, 0, 1, 1);
 
        gs_plugin_loader_get_category_apps_async (priv->plugin_loader,
-                                                 priv->category,
+                                                 subcategory,
                                                  GS_PLUGIN_REFINE_FLAGS_DEFAULT |
                                                  GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING,
                                                  priv->cancellable,
@@ -179,9 +170,7 @@ filter_selected (GtkListBox *filters, GtkListBoxRow *row, gpointer data)
                return;
 
        category = g_object_get_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (row))), "category");
-       g_clear_object (&shell->priv->category);
-       shell->priv->category = g_object_ref (category);
-       gs_shell_category_populate_filtered (shell);
+       gs_shell_category_populate_filtered (shell, category);
 }
 
 static void
@@ -230,9 +219,13 @@ gs_shell_category_set_category (GsShellCategory *shell, GsCategory *category)
        GList *l;
 
        /* this means we've come from the app-view -> back */
-       if (gs_category_get_parent (category) != NULL)
+       if (priv->category == category)
                return;
 
+       /* save this */
+       g_clear_object (&priv->category);
+       priv->category = g_object_ref (category);
+
        /* select favourites by default */
        list = gs_category_get_subcategories (category);
        for (l = list; l != NULL; l = l->next) {
@@ -247,10 +240,6 @@ gs_shell_category_set_category (GsShellCategory *shell, GsCategory *category)
        if (selected == NULL && list != NULL)
                selected = GS_CATEGORY (list->data);
 
-       /* save this */
-       g_clear_object (&priv->category);
-       priv->category = g_object_ref (selected);
-
        /* find apps in this group */
        gs_shell_category_create_filter_list (shell, category, selected);
        g_list_free (list);


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