After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 729813 - AppInfo: use XDG_CURRENT_DESKTOP for OnlyShowIn
AppInfo: use XDG_CURRENT_DESKTOP for OnlyShowIn
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-05-08 13:04 UTC by Allison Karlitskaya (desrt)
Modified: 2014-05-08 20:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
AppInfo: use XDG_CURRENT_DESKTOP for OnlyShowIn (6.18 KB, patch)
2014-05-08 13:04 UTC, Allison Karlitskaya (desrt)
reviewed Details | Review
AppInfo: use XDG_CURRENT_DESKTOP for OnlyShowIn (6.13 KB, patch)
2014-05-08 20:17 UTC, Allison Karlitskaya (desrt)
committed Details | Review
tests: add testcase for {Only,Not}ShowIn (5.98 KB, patch)
2014-05-08 20:17 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Allison Karlitskaya (desrt) 2014-05-08 13:04:39 UTC
Expand the functionality of g_desktop_app_info_set_desktop_env() to
include the possibility of passing strings containing ':' characters (as
some apps, such as gnome-session, are directly passing the value of
XDG_CURRENT_DESKTOP).  At the same time, deprecate it, since now we get
the list from the environment variable for ourselves.

Modify the checks in g_desktop_app_info_get_show_in() to deal with
multiple items listed in XDG_CURRENT_DESKTOP.  For example, if we find
that we have

  XDG_CURRENT_DESKTOP=GNOME-Classic:GNOME

and a desktop file contains:

  OnlyShowIn=GNOME

then we will show this file because of the fallback to GNOME.  If the
file _also_ contains the line:

  NotShowIn=GNOME-Classic

Then we will not show it, because GNOME-Classic comes before GNOME in
XDG_CURRENT_DESKTOP.
Comment 1 Allison Karlitskaya (desrt) 2014-05-08 13:04:40 UTC
Created attachment 276156 [details] [review]
AppInfo: use XDG_CURRENT_DESKTOP for OnlyShowIn
Comment 2 Lars Karlitski 2014-05-08 13:50:52 UTC
Review of attachment 276156 [details] [review]:

There's a small regression: calling g_desktop_app_info_get_show_in() before g_desktop_app_info_set_desktop_env() will make the latter call not work. I don't think that will be an issue in practice, or will it?
Comment 3 Ray Strode [halfline] 2014-05-08 14:52:59 UTC
Review of attachment 276156 [details] [review]:

Seems pretty much okay to me, a couple of comments, but I don't see any obvious show-stopping bugs.

::: gio/gdesktopappinfo.c
@@ +246,3 @@
+  static gchar **result;
+
+  if (g_once_init_enter (&result))

As mentioned by Lars, maybe this shouldn't be GOnce since set_desktop_env might be called after get_show_in (though that's sort of questionable behavior on the apps part since set_desktop_env can only be called once)

@@ +254,3 @@
+
+      if (value)
+        tmp = g_strsplit (value, G_SEARCHPATH_SEPARATOR_S, 0);

shouldn't this be the literal ":" ?  XDG_CURRENT_DESKTOP doesn't use ";" on windows right? (Granted, I guess, it's not used at all on windows at the moment)

@@ +256,3 @@
+        tmp = g_strsplit (value, G_SEARCHPATH_SEPARATOR_S, 0);
+      else
+        tmp = g_new0 (gchar *, 0 + 1);

I think the "0 + 1" is supposed to mean "0 elements + NULL terminator" but it's a little confusing to read.  What might be clearer is to unconditionally call g_strsplit, but pass it ' value? value : "" ' or above it have:

if (!value)
   value = "";

and then let g_strsplit handle it for you. Just an idea, take it or leave it :-)
Comment 4 Allison Karlitskaya (desrt) 2014-05-08 16:49:38 UTC
Review of attachment 276156 [details] [review]:

::: gio/gdesktopappinfo.c
@@ +246,3 @@
+  static gchar **result;
+
+  if (g_once_init_enter (&result))

This was intentional.  I think this is correct, for a couple of reasons.

First is that the call is deprecated.

Second is that the only reasonable argument that you might make here is that you have a process that contains two entities and one of them manages to call _get_show_in() before the other has a chance to call set_desktop_env().  In that case, though, the one that calls _get_show_in() could notice inconsistent behaviour later (apps appearing or disappearing, effectively), despite not having received a signal from the appinfo monitor.

@@ +254,3 @@
+
+      if (value)
+        tmp = g_strsplit (value, G_SEARCHPATH_SEPARATOR_S, 0);

Ya.  That would probably read easier.

@@ +256,3 @@
+        tmp = g_strsplit (value, G_SEARCHPATH_SEPARATOR_S, 0);
+      else
+        tmp = g_new0 (gchar *, 0 + 1);

I really like "0 + 1" because although it is "a little confusing to read" it catches the eye and makes you think about it, after which you invariably come to the correct conclusion about what is going on here (as you just did).

In any case, I think your suggestion to unconditionally call split() is a good one.
Comment 5 Allison Karlitskaya (desrt) 2014-05-08 20:17:16 UTC
Created attachment 276199 [details] [review]
AppInfo: use XDG_CURRENT_DESKTOP for OnlyShowIn

Expand the functionality of g_desktop_app_info_set_desktop_env() to
include the possibility of passing strings containing ':' characters (as
some apps, such as gnome-session, are directly passing the value of
XDG_CURRENT_DESKTOP).  At the same time, deprecate it, since now we get
the list from the environment variable for ourselves.

Modify the checks in g_desktop_app_info_get_show_in() to deal with
multiple items listed in XDG_CURRENT_DESKTOP.  For example, if we find
that we have

  XDG_CURRENT_DESKTOP=GNOME-Classic:GNOME

and a desktop file contains:

  OnlyShowIn=GNOME

then we will show this file because of the fallback to GNOME.  If the
file _also_ contains the line:

  NotShowIn=GNOME-Classic

Then we will not show it, because GNOME-Classic comes before GNOME in
XDG_CURRENT_DESKTOP.
Comment 6 Allison Karlitskaya (desrt) 2014-05-08 20:17:27 UTC
Created attachment 276200 [details] [review]
tests: add testcase for {Only,Not}ShowIn
Comment 7 Allison Karlitskaya (desrt) 2014-05-08 20:33:19 UTC
Attachment 276199 [details] pushed as 5a5e16e - AppInfo: use XDG_CURRENT_DESKTOP for OnlyShowIn
Attachment 276200 [details] pushed as 079d20f - tests: add testcase for {Only,Not}ShowIn