[gnome-shell] Add shell_app_system_get_app_for_path



commit fe52a9e1a17b26f2dc36894f9fddd1c95695b3c3
Author: Colin Walters <walters verbum org>
Date:   Thu Mar 25 17:45:28 2010 -0400

    Add shell_app_system_get_app_for_path
    
    Allows looking up an app given an absolute path to its
    desktop file; will be used for startup-notification.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=612833

 src/shell-app-system.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 src/shell-app-system.h |    1 +
 2 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
index 2d0d3db..c2d0025 100644
--- a/src/shell-app-system.c
+++ b/src/shell-app-system.c
@@ -485,6 +485,49 @@ shell_app_system_get_app (ShellAppSystem   *self,
 }
 
 /**
+ * shell_app_system_get_app_for_path:
+ * @system: a #ShellAppSystem
+ * @desktop_path: (utf8): UTF-8 encoded absolute file name
+ *
+ * Find or create a #ShellApp corresponding to a given absolute
+ * file name which must be in the standard paths (XDG_DATA_DIRS).
+ * For files outside the datadirs, this function returns %NULL.
+ *
+ * If already cached elsewhere in memory, return that instance.
+ * Otherwise, create a new one.
+ *
+ * Return value: (transfer full): The #ShellApp for id, or %NULL if none
+ */
+ShellApp *
+shell_app_system_get_app_for_path (ShellAppSystem   *system,
+                                   const char       *desktop_path)
+{
+  const char *basename;
+  ShellAppInfo *info;
+
+  basename = g_strrstr (desktop_path, "/");
+  if (basename)
+    basename += 1;
+  else
+    basename = desktop_path;
+
+  info = g_hash_table_lookup (system->priv->app_id_to_info, basename);
+  if (!info)
+    return NULL;
+
+  if (info->type == SHELL_APP_INFO_TYPE_ENTRY)
+    {
+      const char *full_path = gmenu_tree_entry_get_desktop_file_path ((GMenuTreeEntry*) info->entry);
+      if (strcmp (desktop_path, full_path) != 0)
+        return NULL;
+    }
+  else
+    return NULL;
+
+  return shell_app_system_get_app (system, basename);
+}
+
+/**
  * shell_app_system_get_app_for_window:
  * @self: A #ShellAppSystem
  * @window: A #MetaWindow
diff --git a/src/shell-app-system.h b/src/shell-app-system.h
index be7efeb..2f3dda7 100644
--- a/src/shell-app-system.h
+++ b/src/shell-app-system.h
@@ -70,6 +70,7 @@ gboolean shell_app_info_launch (ShellAppInfo *info,
 ShellAppInfo *shell_app_system_load_from_desktop_file (ShellAppSystem *system, const char *filename, GError **error);
 
 ShellApp *shell_app_system_get_app (ShellAppSystem *system, const char *id);
+ShellApp *shell_app_system_get_app_for_path (ShellAppSystem *system, const char *desktop_path);
 ShellApp *shell_app_system_get_app_for_window (ShellAppSystem *self, MetaWindow *window);
 
 void _shell_app_system_register_app (ShellAppSystem *self, ShellApp *app);



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