[gnome-shell/wip/carlosg/less-get-all-calls: 2/3] shell-app-system: Cache GAppInfos around



commit 9905210f520fe235940e03860e31652fb37bf75d
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Dec 19 13:13:42 2018 +0100

    shell-app-system: Cache GAppInfos around
    
    This was called here just to end up emitting ::installed-changed,
    which would trigger other g_app_info_get_all() calls. Cache it here
    so it may be reused later on.

 src/shell-app-system.c | 30 +++++++++++++++++++++++++-----
 src/shell-app-system.h |  2 ++
 2 files changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
index 71fc2f89a..1a8d4219e 100644
--- a/src/shell-app-system.c
+++ b/src/shell-app-system.c
@@ -50,6 +50,7 @@ struct _ShellAppSystemPrivate {
   GHashTable *running_apps;
   GHashTable *id_to_app;
   GHashTable *startup_wm_class_to_id;
+  GList *all_apps;
 };
 
 static void shell_app_system_finalize (GObject *object);
@@ -82,12 +83,14 @@ static void
 scan_startup_wm_class_to_id (ShellAppSystem *self)
 {
   ShellAppSystemPrivate *priv = self->priv;
-  GList *apps, *l;
+  GList *l;
 
   g_hash_table_remove_all (priv->startup_wm_class_to_id);
 
-  apps = g_app_info_get_all ();
-  for (l = apps; l != NULL; l = l->next)
+  g_list_free_full (priv->all_apps, g_object_unref);
+  priv->all_apps = g_app_info_get_all ();
+
+  for (l = priv->all_apps; l != NULL; l = l->next)
     {
       GAppInfo *info = l->data;
       const char *startup_wm_class, *id, *old_id;
@@ -105,8 +108,6 @@ scan_startup_wm_class_to_id (ShellAppSystem *self)
         g_hash_table_insert (priv->startup_wm_class_to_id,
                              g_strdup (startup_wm_class), g_strdup (id));
     }
-
-  g_list_free_full (apps, g_object_unref);
 }
 
 static gboolean
@@ -198,6 +199,7 @@ shell_app_system_finalize (GObject *object)
   g_hash_table_destroy (priv->running_apps);
   g_hash_table_destroy (priv->id_to_app);
   g_hash_table_destroy (priv->startup_wm_class_to_id);
+  g_list_free_full (priv->all_apps, g_object_unref);
 
   G_OBJECT_CLASS (shell_app_system_parent_class)->finalize (object);
 }
@@ -436,3 +438,21 @@ shell_app_system_search (const char *search_string)
 
   return results;
 }
+
+/**
+ * shell_app_system_get_all_apps:
+ * @self: the #ShellAppSystem
+ *
+ * Returns all known apps, as a list of #GAppInfo
+ *
+ * Returns: (transfer none) (element-type GAppInfo): a list of #GAppInfo
+ *   describing all known applications. This memory is owned by the
+ *   #ShellAppSystem and should not be freed.
+ **/
+GList *
+shell_app_system_get_all_apps (ShellAppSystem *self)
+{
+  ShellAppSystemPrivate *priv = self->priv;
+
+  return priv->all_apps;
+}
diff --git a/src/shell-app-system.h b/src/shell-app-system.h
index 445671f5b..bf0cb3cd3 100644
--- a/src/shell-app-system.h
+++ b/src/shell-app-system.h
@@ -27,4 +27,6 @@ ShellApp       *shell_app_system_lookup_desktop_wmclass       (ShellAppSystem *s
 GSList         *shell_app_system_get_running               (ShellAppSystem  *self);
 char         ***shell_app_system_search                    (const char *search_string);
 
+GList          *shell_app_system_get_all_apps              (ShellAppSystem  *self);
+
 #endif /* __SHELL_APP_SYSTEM_H__ */


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