[gnome-software] Avoid empty folders



commit 247dafdcaefe3c989507f9ed869f9e09177a1cb2
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Dec 18 15:42:36 2013 -0500

    Avoid empty folders
    
    Discard empty folders both on load and on save. They are not
    interesting - the shell won't show them, and you can just
    recreate them when you need them.

 src/gs-folders.c |   31 +++++++++++++++++--------------
 1 files changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/src/gs-folders.c b/src/gs-folders.c
index 718c9eb..e9bc038 100644
--- a/src/gs-folders.c
+++ b/src/gs-folders.c
@@ -128,18 +128,19 @@ load (GsFolders *folders)
        g_variant_iter_init (&iter, v);
        while (g_variant_iter_next (&iter, "{&sas}", &id, &apps)) {
 
-               name = lookup_folder_name (folders, id);
-               folder = gs_folder_new (id, name ? name : id);
-               g_free (name);
-               while (g_variant_iter_next (apps, "s", &app)) {
-                       g_ptr_array_add (folder->apps, app);
-               }
+               if (g_variant_iter_n_children (apps) > 0) {
+                       name = lookup_folder_name (folders, id);
+                       folder = gs_folder_new (id, name ? name : id);
+                       g_free (name);
+                       while (g_variant_iter_next (apps, "s", &app)) {
+                               g_ptr_array_add (folder->apps, app);
+                       }
                
-               g_hash_table_insert (folders->priv->folders, (gpointer)folder->id, folder);
-               for (i = 0; i < folder->apps->len; i++) {
-                       g_hash_table_insert (folders->priv->apps, g_ptr_array_index (folder->apps, i), 
folder);
+                       g_hash_table_insert (folders->priv->folders, (gpointer)folder->id, folder);
+                       for (i = 0; i < folder->apps->len; i++) {
+                               g_hash_table_insert (folders->priv->apps, g_ptr_array_index (folder->apps, 
i), folder);
+                       }
                }
-
                g_variant_iter_free (apps);
        }
        g_variant_unref (v);
@@ -155,10 +156,12 @@ save (GsFolders *folders)
        g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sas}"));
        g_hash_table_iter_init (&iter, folders->priv->folders);
        while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&folder)) {
-               g_ptr_array_add (folder->apps, NULL);
-               g_variant_builder_add (&builder, "{s^as}",
-                                      folder->id, folder->apps->pdata);
-               g_ptr_array_remove (folder->apps, NULL);
+               if (folder->apps->len > 0) {
+                       g_ptr_array_add (folder->apps, NULL);
+                       g_variant_builder_add (&builder, "{s^as}",
+                                              folder->id, folder->apps->pdata);
+                       g_ptr_array_remove (folder->apps, NULL);
+               }
        }
 
        g_settings_set_value (folders->priv->settings, "app-folders", g_variant_builder_end (&builder));


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