[gnome-shell/eos3.8: 34/255] shell-app-system: Add support for X-Endless-Alias key in desktop files



commit bcdbbabc074e94cfc58513a8f7da4ac55a158f04
Author: Mario Sanchez Prada <mario endlessm com>
Date:   Mon Jun 5 17:15:18 2017 +0100

    shell-app-system: Add support for X-Endless-Alias key in desktop files
    
     * 2020-03-23: Squash with 730800ea3

 src/shell-app-system.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++-
 src/shell-app-system.h |  2 ++
 2 files changed, 80 insertions(+), 1 deletion(-)
---
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
index 08db745e93..a80986fe39 100644
--- a/src/shell-app-system.c
+++ b/src/shell-app-system.c
@@ -33,6 +33,12 @@
  */
 #define SHELL_APP_IS_OPEN_EVENT "b5e11a3d-13f8-4219-84fd-c9ba0bf3d1f0"
 
+/* Additional key used to map a renamed desktop file to its previous name;
+ * for instance, org.gnome.Totem.desktop would use this key to point to
+ * 'totem.desktop'
+ */
+#define X_ENDLESS_ALIAS_KEY     "X-Endless-Alias"
+
 /* Vendor prefixes are something that can be preprended to a .desktop
  * file name.  Undo this.
  */
@@ -72,6 +78,8 @@ struct _ShellAppSystemPrivate {
 
   guint rescan_icons_timeout_id;
   guint n_rescan_retries;
+
+  GHashTable *alias_to_id;
 };
 
 static void shell_app_system_finalize (GObject *object);
@@ -100,6 +108,37 @@ static void shell_app_system_class_init(ShellAppSystemClass *klass)
                  G_TYPE_NONE, 0);
 }
 
+static void
+add_aliases (ShellAppSystem  *self,
+             GDesktopAppInfo *info)
+{
+  ShellAppSystemPrivate *priv = self->priv;
+  const char *id = g_app_info_get_id (G_APP_INFO (info));
+  const char *alias;
+
+  alias = g_desktop_app_info_get_string (info, X_ENDLESS_ALIAS_KEY);
+  if (alias != NULL)
+    {
+      char *desktop_alias = g_strconcat (alias, ".desktop", NULL);
+      g_hash_table_insert (priv->alias_to_id, desktop_alias, g_strdup (id));
+    }
+}
+
+static void
+scan_alias_to_id (ShellAppSystem *self)
+{
+  ShellAppSystemPrivate *priv = self->priv;
+  GList *apps, *l;
+
+  g_hash_table_remove_all (priv->alias_to_id);
+
+  apps = g_app_info_get_all ();
+  for (l = apps; l != NULL; l = l->next)
+    add_aliases (self, G_DESKTOP_APP_INFO (l->data));
+
+  g_list_free_full (apps, g_object_unref);
+}
+
 static void
 scan_startup_wm_class_to_id (ShellAppSystem *self)
 {
@@ -224,6 +263,8 @@ installed_changed (ShellAppCache  *cache,
                    ShellAppSystem *self)
 {
   rescan_icon_theme (self);
+  scan_alias_to_id (self);
+
   scan_startup_wm_class_to_id (self);
 
   g_hash_table_foreach_remove (self->priv->id_to_app, stale_app_remove_func, NULL);
@@ -245,6 +286,7 @@ shell_app_system_init (ShellAppSystem *self)
                                            (GDestroyNotify)g_object_unref);
 
   priv->startup_wm_class_to_id = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+  priv->alias_to_id = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 
   cache = shell_app_cache_get_default ();
   g_signal_connect (cache, "changed", G_CALLBACK (installed_changed), self);
@@ -262,6 +304,7 @@ shell_app_system_finalize (GObject *object)
   g_hash_table_destroy (priv->startup_wm_class_to_id);
   g_list_free_full (priv->installed_apps, g_object_unref);
   g_clear_handle_id (&priv->rescan_icons_timeout_id, g_source_remove);
+  g_hash_table_destroy (priv->alias_to_id);
 
   G_OBJECT_CLASS (shell_app_system_parent_class)->finalize (object);
 }
@@ -295,7 +338,8 @@ shell_app_system_lookup_app (ShellAppSystem   *self,
 {
   ShellAppSystemPrivate *priv = self->priv;
   ShellApp *app;
-  GDesktopAppInfo *info;
+  g_autoptr(GDesktopAppInfo) info = NULL;
+  g_autofree char *alias = NULL;
 
   app = g_hash_table_lookup (priv->id_to_app, id);
   if (app)
@@ -307,6 +351,7 @@ shell_app_system_lookup_app (ShellAppSystem   *self,
 
   app = _shell_app_new (info);
   g_hash_table_insert (priv->id_to_app, (char *) shell_app_get_id (app), app);
+
   return app;
 }
 
@@ -344,6 +389,38 @@ shell_app_system_lookup_heuristic_basename (ShellAppSystem *system,
   return NULL;
 }
 
+/**
+ * shell_app_system_lookup_alias:
+ * @system: a #ShellAppSystem
+ * @alias: alternative application id
+ *
+ * Find a valid application corresponding to a given
+ * alias string, or %NULL if none.
+ *
+ * Returns: (transfer none): A #ShellApp for @alias
+ */
+ShellApp *
+shell_app_system_lookup_alias (ShellAppSystem *system,
+                               const char     *alias)
+{
+  ShellApp *result;
+  const char *id;
+
+  g_return_val_if_fail (alias != NULL, NULL);
+
+  result = shell_app_system_lookup_app (system, alias);
+  if (result != NULL)
+    return result;
+
+  id = g_hash_table_lookup (system->priv->alias_to_id, alias);
+  if (id == NULL)
+    return NULL;
+
+  result = shell_app_system_lookup_app (system, id);
+
+  return result;
+}
+
 /**
  * shell_app_system_lookup_desktop_wmclass:
  * @system: a #ShellAppSystem
diff --git a/src/shell-app-system.h b/src/shell-app-system.h
index 8719dbcf2d..d236b3b5f3 100644
--- a/src/shell-app-system.h
+++ b/src/shell-app-system.h
@@ -23,6 +23,8 @@ ShellApp       *shell_app_system_lookup_startup_wmclass       (ShellAppSystem *s
                                                                const char     *wmclass);
 ShellApp       *shell_app_system_lookup_desktop_wmclass       (ShellAppSystem *system,
                                                                const char     *wmclass);
+ShellApp       *shell_app_system_lookup_alias                 (ShellAppSystem  *system,
+                                                               const char      *alias);
 
 GSList         *shell_app_system_get_running               (ShellAppSystem  *self);
 char         ***shell_app_system_search                    (const char *search_string);


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