[gnome-shell/T27795: 46/138] shell-app-system: Add support for X-Endless-Alias key in desktop files
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/T27795: 46/138] shell-app-system: Add support for X-Endless-Alias key in desktop files
- Date: Tue, 1 Oct 2019 23:33:11 +0000 (UTC)
commit 870274b9f87ec578d7e3bb333fa0a19e8139c160
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
src/shell-app-system.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/shell-app-system.h | 2 ++
2 files changed, 83 insertions(+)
---
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
index fad1639f91..3ba25f27fb 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,34 @@ static void shell_app_system_class_init(ShellAppSystemClass *klass)
G_TYPE_NONE, 0);
}
+
+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)
+ {
+ GAppInfo *info = l->data;
+ const char *alias, *id;
+ g_autofree char *desktop_alias = NULL;
+
+ id = g_app_info_get_id (info);
+ alias = g_desktop_app_info_get_string (G_DESKTOP_APP_INFO (info), X_ENDLESS_ALIAS_KEY);
+ if (alias == NULL)
+ continue;
+
+ desktop_alias = g_strconcat (alias, ".desktop", NULL);
+ g_hash_table_insert (priv->alias_to_id, g_strdup (desktop_alias), g_strdup (id));
+ }
+
+ g_list_free_full (apps, g_object_unref);
+}
+
static void
scan_startup_wm_class_to_id (ShellAppSystem *self)
{
@@ -226,6 +262,8 @@ installed_changed (GAppInfoMonitor *monitor,
ShellAppSystem *self = user_data;
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);
@@ -247,6 +285,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);
monitor = g_app_info_monitor_get ();
g_signal_connect (monitor, "changed", G_CALLBACK (installed_changed), self);
@@ -264,6 +303,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);
}
@@ -298,6 +338,7 @@ shell_app_system_lookup_app (ShellAppSystem *self,
ShellAppSystemPrivate *priv = self->priv;
ShellApp *app;
GDesktopAppInfo *info;
+ g_autofree char *alias = NULL;
app = g_hash_table_lookup (priv->id_to_app, id);
if (app)
@@ -310,6 +351,14 @@ 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);
g_object_unref (info);
+
+ alias = g_desktop_app_info_get_string (info, X_ENDLESS_ALIAS_KEY);
+ if (alias != NULL && g_hash_table_lookup (priv->alias_to_id, alias) == NULL)
+ {
+ g_autofree char *desktop_alias = g_strconcat (alias, ".desktop", NULL);
+ g_hash_table_insert (priv->alias_to_id, g_strdup (desktop_alias), g_strdup (id));
+ }
+
return app;
}
@@ -347,6 +396,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]