[gnome-software] Folders: hide empty folders



commit 3b0f48a7d281adbeedaf9864aa9142f85159cc48
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jan 24 05:58:10 2014 -0500

    Folders: hide empty folders

 src/gs-app-folder-dialog.c |    2 +-
 src/gs-folders.c           |   26 ++++++++++++++++++++++++++
 src/gs-folders.h           |    1 +
 3 files changed, 28 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-app-folder-dialog.c b/src/gs-app-folder-dialog.c
index 2e051b7..e82803a 100644
--- a/src/gs-app-folder-dialog.c
+++ b/src/gs-app-folder-dialog.c
@@ -245,7 +245,7 @@ populate_list (GsAppFolderDialog *dialog)
        gchar **folders;
        guint i;
 
-       folders = gs_folders_get_folders (priv->folders);
+       folders = gs_folders_get_nonempty_folders (priv->folders);
        for (i = 0; folders[i]; i++) {
                gtk_list_box_insert (GTK_LIST_BOX (priv->app_folder_list), 
                                      create_row (dialog, folders[i]), -1);
diff --git a/src/gs-folders.c b/src/gs-folders.c
index a76c3b3..e91328e 100644
--- a/src/gs-folders.c
+++ b/src/gs-folders.c
@@ -343,6 +343,32 @@ gs_folders_get_folders (GsFolders *folders)
        return (gchar**) g_hash_table_get_keys_as_array (folders->priv->folders, NULL);
 }
 
+gchar **
+gs_folders_get_nonempty_folders (GsFolders *folders)
+{
+       GHashTable *tmp;
+       GHashTableIter iter;
+       GsFolder *folder;
+       gchar **keys;
+
+       tmp = g_hash_table_new (g_str_hash, g_str_equal);
+
+       g_hash_table_iter_init (&iter, folders->priv->apps);
+       while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&folder)) {
+               g_hash_table_add (tmp, folder->id);
+       }
+
+       g_hash_table_iter_init (&iter, folders->priv->categories);
+       while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&folder)) {
+               g_hash_table_add (tmp, folder->id);
+       }
+
+       keys = (gchar **) g_hash_table_get_keys_as_array (tmp, NULL);
+       g_hash_table_destroy (tmp);
+
+       return keys;
+}
+
 static void
 canonicalize_key (gchar *key)
 {
diff --git a/src/gs-folders.h b/src/gs-folders.h
index 38b332d..03d1576 100644
--- a/src/gs-folders.h
+++ b/src/gs-folders.h
@@ -52,6 +52,7 @@ GType           gs_folders_get_type           (void);
 GsFolders       *gs_folders_get                (void);
 
 gchar          **gs_folders_get_folders        (GsFolders      *folders);
+gchar          **gs_folders_get_nonempty_folders (GsFolders    *folders);
 const gchar     *gs_folders_add_folder         (GsFolders      *folders,
                                                 const gchar    *id);
 void             gs_folders_remove_folder      (GsFolders      *folders,


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