[gtk+] GtkIconCache: Add api to find if directories are empty



commit b4d12fff4e5f6206e9ba33f25cb00cb31d7c7ee3
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jun 20 12:11:22 2014 -0400

    GtkIconCache: Add api to find if directories are empty
    
    This will help in not creating structs for tons of empty
    directories.

 gtk/gtkiconcache.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkiconcache.h |    2 ++
 2 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkiconcache.c b/gtk/gtkiconcache.c
index 4eaff97..d19c0a9 100644
--- a/gtk/gtkiconcache.c
+++ b/gtk/gtkiconcache.c
@@ -300,6 +300,48 @@ _gtk_icon_cache_get_icon_flags (GtkIconCache *cache,
   return GET_UINT16 (cache->buffer, image_offset + 2);
 }
 
+gboolean
+_gtk_icon_cache_has_icons (GtkIconCache *cache,
+                          const gchar  *directory)
+{
+  int directory_index;
+  guint32 hash_offset, n_buckets;
+  guint32 chain_offset;
+  guint32 image_list_offset, n_images;
+  int i, j;
+
+  directory_index = get_directory_index (cache, directory);
+
+  if (directory_index == -1)
+    return FALSE;
+
+  hash_offset = GET_UINT32 (cache->buffer, 4);
+  n_buckets = GET_UINT32 (cache->buffer, hash_offset);
+
+  for (i = 0; i < n_buckets; i++)
+    {
+      chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * i);
+      while (chain_offset != 0xffffffff)
+       {
+         guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
+
+         image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8);
+         n_images = GET_UINT32 (cache->buffer, image_list_offset);
+
+         for (j = 0; j < n_images; j++)
+           {
+             if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * j) ==
+                 directory_index)
+               return TRUE;
+           }
+
+         chain_offset = GET_UINT32 (cache->buffer, chain_offset);
+       }
+    }
+
+  return FALSE;
+}
+
 void
 _gtk_icon_cache_add_icons (GtkIconCache *cache,
                           const gchar  *directory,
diff --git a/gtk/gtkiconcache.h b/gtk/gtkiconcache.h
index 767e2b6..1ec47b0 100644
--- a/gtk/gtkiconcache.h
+++ b/gtk/gtkiconcache.h
@@ -44,6 +44,8 @@ gboolean      _gtk_icon_cache_has_icon       (GtkIconCache *cache,
 gboolean      _gtk_icon_cache_has_icon_in_directory (GtkIconCache *cache,
                                                     const gchar  *icon_name,
                                                     const gchar  *directory);
+gboolean      _gtk_icon_cache_has_icons      (GtkIconCache *cache,
+                                              const gchar  *directory);
 void         _gtk_icon_cache_add_icons      (GtkIconCache *cache,
                                              const gchar  *directory,
                                              GHashTable   *hash_table);


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