[glib] GDesktopAppInfo: Add g_desktop_app_info_get_show_in()



commit ae7c48b955cd6979a799574bb92e654081769c62
Author: Vincent Untz <vuntz gnome org>
Date:   Thu Jul 21 15:23:00 2011 +0200

    GDesktopAppInfo: Add g_desktop_app_info_get_show_in()
    
    Necessary for rebasing gnome-menus on top of GDesktopAppInfo.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=655044

 docs/reference/gio/gio-sections.txt |    1 +
 gio/gdesktopappinfo.c               |  111 ++++++++++++++++++++++------------
 gio/gdesktopappinfo.h               |    2 +
 gio/gio.symbols                     |    1 +
 4 files changed, 76 insertions(+), 39 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index 29f10c1..879f521 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -1402,6 +1402,7 @@ g_desktop_app_info_new
 g_desktop_app_info_get_filename
 g_desktop_app_info_get_is_hidden
 g_desktop_app_info_get_nodisplay
+g_desktop_app_info_get_show_in
 g_desktop_app_info_get_generic_name
 g_desktop_app_info_get_categories
 g_desktop_app_info_set_desktop_env
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index 9761895..996acdf 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -127,6 +127,9 @@ G_DEFINE_TYPE_WITH_CODE (GDesktopAppInfo, g_desktop_app_info, G_TYPE_OBJECT,
 			 G_IMPLEMENT_INTERFACE (G_TYPE_APP_INFO,
 						g_desktop_app_info_iface_init))
 
+G_LOCK_DEFINE_STATIC (g_desktop_env);
+static gchar *g_desktop_env = NULL;
+
 static gpointer
 search_path_init (gpointer data)
 {
@@ -691,6 +694,72 @@ g_desktop_app_info_get_nodisplay (GDesktopAppInfo *info)
   return info->nodisplay;
 }
 
+/**
+ * g_desktop_app_info_get_show_in:
+ * @info: a #GDesktopAppInfo
+ * @desktop_env: a string specifying a desktop name
+ *
+ * Checks if the application info should be shown in menus that list available
+ * applications for a specific name of the desktop, based on the
+ * <literal>OnlyShowIn</literal> and <literal>NotShowIn</literal> keys.
+ *
+ * If @desktop_env is %NULL, then the name of the desktop set with
+ * g_desktop_app_info_set_desktop_env() is used.
+ *
+ * Note that g_app_info_should_show() for @info will include this check (with
+ * %NULL for @desktop_env) as well as additional checks.
+ *
+ * Returns: %TRUE if the @info should be shown in @desktop_env according to the
+ * <literal>OnlyShowIn</literal> and <literal>NotShowIn</literal> keys, %FALSE
+ * otherwise.
+ *
+ * Since: 2.30
+ */
+gboolean
+g_desktop_app_info_get_show_in (GDesktopAppInfo *info,
+                                const gchar     *desktop_env)
+{
+  gboolean found;
+  int i;
+
+  g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE);
+
+  if (!desktop_env) {
+    G_LOCK (g_desktop_env);
+    desktop_env = g_desktop_env;
+    G_UNLOCK (g_desktop_env);
+  }
+
+  if (info->only_show_in)
+    {
+      if (desktop_env == NULL)
+	return FALSE;
+
+      found = FALSE;
+      for (i = 0; info->only_show_in[i] != NULL; i++)
+	{
+	  if (strcmp (info->only_show_in[i], desktop_env) == 0)
+	    {
+	      found = TRUE;
+	      break;
+	    }
+	}
+      if (!found)
+	return FALSE;
+    }
+
+  if (info->not_show_in && desktop_env)
+    {
+      for (i = 0; info->not_show_in[i] != NULL; i++)
+	{
+	  if (strcmp (info->not_show_in[i], desktop_env) == 0)
+	    return FALSE;
+	}
+    }
+
+  return TRUE;
+}
+
 static char *
 expand_macro_single (char macro, char *uri)
 {
@@ -1376,15 +1445,13 @@ g_desktop_app_info_launch_uris_as_manager (GDesktopAppInfo            *appinfo,
 						   error);
 }
 
-G_LOCK_DEFINE_STATIC (g_desktop_env);
-static gchar *g_desktop_env = NULL;
-
 /**
  * g_desktop_app_info_set_desktop_env:
  * @desktop_env: a string specifying what desktop this is
  *
  * Sets the name of the desktop that the application is running in.
- * This is used by g_app_info_should_show() to evaluate the
+ * This is used by g_app_info_should_show() and
+ * g_desktop_app_info_get_show_in() to evaluate the
  * <literal>OnlyShowIn</literal> and <literal>NotShowIn</literal>
  * desktop entry fields.
  *
@@ -1413,45 +1480,11 @@ static gboolean
 g_desktop_app_info_should_show (GAppInfo *appinfo)
 {
   GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
-  gboolean found;
-  const gchar *desktop_env;
-  int i;
 
   if (info->nodisplay)
     return FALSE;
 
-  G_LOCK (g_desktop_env);
-  desktop_env = g_desktop_env;
-  G_UNLOCK (g_desktop_env);
-
-  if (info->only_show_in)
-    {
-      if (desktop_env == NULL)
-	return FALSE;
-      
-      found = FALSE;
-      for (i = 0; info->only_show_in[i] != NULL; i++)
-	{
-	  if (strcmp (info->only_show_in[i], desktop_env) == 0)
-	    {
-	      found = TRUE;
-	      break;
-	    }
-	}
-      if (!found)
-	return FALSE;
-    }
-
-  if (info->not_show_in && desktop_env)
-    {
-      for (i = 0; info->not_show_in[i] != NULL; i++)
-	{
-	  if (strcmp (info->not_show_in[i], desktop_env) == 0)
-	    return FALSE;
-	}
-    }
-  
-  return TRUE;
+  return g_desktop_app_info_get_show_in (info, NULL);
 }
 
 typedef enum {
diff --git a/gio/gdesktopappinfo.h b/gio/gdesktopappinfo.h
index 8939189..9e45a25 100644
--- a/gio/gdesktopappinfo.h
+++ b/gio/gdesktopappinfo.h
@@ -53,6 +53,8 @@ const char *     g_desktop_app_info_get_filename      (GDesktopAppInfo *info);
 const char *     g_desktop_app_info_get_generic_name  (GDesktopAppInfo *info);
 const char *     g_desktop_app_info_get_categories    (GDesktopAppInfo *info);
 gboolean         g_desktop_app_info_get_nodisplay     (GDesktopAppInfo *info);
+gboolean         g_desktop_app_info_get_show_in       (GDesktopAppInfo *info,
+                                                       const gchar     *desktop_env);
 
 GDesktopAppInfo *g_desktop_app_info_new               (const char      *desktop_id);
 gboolean         g_desktop_app_info_get_is_hidden     (GDesktopAppInfo *info);
diff --git a/gio/gio.symbols b/gio/gio.symbols
index e5f96e9..5189d56 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -98,6 +98,7 @@ g_desktop_app_info_get_filename
 g_desktop_app_info_get_generic_name
 g_desktop_app_info_get_is_hidden
 g_desktop_app_info_get_nodisplay
+g_desktop_app_info_get_show_in
 g_desktop_app_info_get_type
 g_desktop_app_info_launch_uris_as_manager
 g_desktop_app_info_lookup_get_type



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