Commit Graph

293 Commits

Author SHA1 Message Date
Emmanuel Fleury
08f73f8187 Fix signedness warning in gio/gdesktopappinfo.c:g_desktop_app_info_launch_uris_with_spawn()
gio/gdesktopappinfo.c: In function ‘g_desktop_app_info_launch_uris_with_spawn’:
gio/gdesktopappinfo.c:2804:21: error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’
 2804 |       for (i = 0; i < G_N_ELEMENTS (wrapper_argv); i++)
      |                     ^
2021-01-12 19:25:26 +01:00
Emmanuel Fleury
04a05ff016 Fix signedness warning in gio/gdesktopappinfo.c:desktop_file_dirs_lock()
gio/gdesktopappinfo.c: In function ‘desktop_file_dirs_lock’:
gio/gdesktopappinfo.c:1564:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1564 |   for (i = 0; i < desktop_file_dirs->len; i++)
      |                 ^
2021-01-12 19:16:56 +01:00
Emmanuel Fleury
ce2446ddfd Fix signedness warning in gio/gdesktopappinfo.c:array_contains()
gio/gdesktopappinfo.c: In function ‘array_contains’:
gio/gdesktopappinfo.c:1193:17: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘guint’ {aka ‘unsigned int’}
 1193 |   for (i = 0; i < array->len; i++)
      |                 ^
2021-01-12 19:16:56 +01:00
Emmanuel Fleury
5940d51167 Fix signedness warning in gio/gdesktopappinfo.c:desktop_file_dir_unindexed_setup_search()
gio/gdesktopappinfo.c: In function ‘desktop_file_dir_unindexed_setup_search’:
gio/gdesktopappinfo.c:1114:25: error: comparison of integer expressions of different signedness: ‘gint’ {aka ‘int’} and ‘long unsigned int’
 1114 |           for (i = 0; i < G_N_ELEMENTS (desktop_key_match_category); i++)
      |                         ^
2021-01-12 19:16:56 +01:00
Krzesimir Nowak
cdf0a50c69 gdesktopappinfo: Fix validation of XDG_CURRENT_DESKTOP
Split out XDG_CURRENT_DESKTOP handling to a separate function and make
sure that it drops all the invalid entries properly. Earlier a bad
entry could slip through the checks by sitting just after another bad
entry, like in env being set to `invalid1!:invalid2!`, where
`invalid2!` could slip the checks.
2021-01-09 15:39:09 +01:00
Philip Withnall
45d01e5aa9 gdesktopappinfo: Validate XDG_CURRENT_DESKTOP before using it
Its components are used to build filenames, so if the value of
`XDG_CURRENT_DESKTOP` comes from an untrusted caller (as can happen in
setuid programs), using it unvalidated may be unsafe.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2168
2021-01-07 15:02:25 +00:00
Sebastian Dröge
705a59a315 gio: Add missing nullable annotations 2020-11-11 13:15:21 +02:00
Philip Withnall
648986a290 glib: Avoid redefining GLIB_DISABLE_DEPRECATION_WARNINGS
It may be defined by the environment (we document that as being allowed)
— if so, individual files should not try to redefine it, as that causes
a preprocessor warning.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-27 15:41:09 +01:00
Philip Withnall
3b6460b94c glib: Use g_file_set_contents_full() throughout GLib and GIO
Where applicable. Where the current use of `g_file_set_contents()` seems
the most appropriate, leave that in place.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1302
2020-07-26 21:37:46 +01:00
Felix Riemann
88fe78137d gdesktopappinfo: Fix unnecessarily copied and leaked URI list
When an app is spawned using g_desktop_app_info_launch_uris_with_spawn
it will expand the various token in the app's commandline with the
URIs of the files to open. The expand_macro() function that is used for
this advances the pointer to the URI list to show up to which entries
it used.

To not loose the pointer to the list head a duplicate of the URI list
was actually passed to expand_macro(). However, it's not necessary to
create a copy of the URI list for that as expand_macro() will only
change which element the pointer will point to.

This behaviour actually caused the duplicated list to be leaked as the
the list pointer is NULL once all URIs are used up by expand_macro()
and thus nothing was freed at the end of the function.
2020-07-04 20:20:42 +02:00
Philip Withnall
00bfb3ab44 tree: Fix various typos and outdated terminology
This was mostly machine generated with the following command:
```
codespell \
    --builtin clear,rare,usage \
    --skip './po/*' --skip './.git/*' --skip './NEWS*' \
    --write-changes .
```
using the latest git version of `codespell` as per [these
instructions](https://github.com/codespell-project/codespell#user-content-updating).

Then I manually checked each change using `git add -p`, made a few
manual fixups and dropped a load of incorrect changes.

There are still some outdated or loaded terms used in GLib, mostly to do
with git branch terminology. They will need to be changed later as part
of a wider migration of git terminology.

If I’ve missed anything, please file an issue!

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-06-12 15:01:08 +01:00
Corentin Noël
0663a9bd56 gdesktopappinfo: Add several nullable annotation to GAppInfo getters
Some functions can return a NULL GAppInfo when the conditions given as arguments are not met.
2020-05-07 10:30:39 +01:00
Philip Withnall
5314a20389 gdesktopappinfo: Note that search results are not filtered
Mention in the documentation that (presumably for performance reasons)
the search results from `g_desktop_app_info_search()` are not filtered
by executable presence or hidden attribute.

Perhaps they should be in future, but for now we should at least
document it.

Spotted by Will Thompson.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-05-05 09:29:50 +01:00
Philip Withnall
2b533ca99a gdesktopappinfo: Use sh rather than gio-launch-desktop
There were some problems about where to install `gio-launch-desktop` to
support multiarch systems without circular dependencies. Simon McVittie
suggested that, actually, given the current set of platforms supported
by `GDesktopAppInfo` (they’re all POSIX), we could just use `sh`.

That simplifies things nicely. `gio-launch-desktop` can always be
resurrected (and the multiarch debate continued and resolved) if needed
in future.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1633
2020-02-14 18:09:18 +00:00
Philip Withnall
5b07fc98e0 gdesktopappinfo: Cancel file monitor when resetting a DesktopFileDir
It’s not enough to unref the monitor, since the GLib worker thread might
still hold a reference to it.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1903
2019-10-11 22:31:24 +01:00
Philip Withnall
bffe058550 gdesktopappinfo: Allocate DesktopFileDir structs dynamically
`DesktopFileDir` pointers are passed around between threads: they are
initially created on the main thread, but a pointer to them is passed to
the GLib worker thread in the file monitor callback
(`desktop_file_dir_changed()`).

Accordingly, the `DesktopFileDir` objects either have to be
 (1) immutable;
 (2) reference counted; or
 (3) synchronised between the two threads
to avoid one of them being used by one thread after being freed on
another. Option (1) changed with commit 99bc33b6 and is no longer an
option. Option (3) would mean blocking the main thread on the worker
thread, which would be hard to achieve and is against the point of
having a worker thread. So that leaves option (2), which is implemented
here.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1903
2019-10-11 22:31:24 +01:00
Philip Withnall
d55f6fb5fe gdesktopappinfo: Update calling convention for gnome-terminal
For several years now (I haven’t looked up the exact date),
`gnome-terminal` has preferred being called as `gnome-terminal
--terminal-args -- /some/other/program --its-args` rather than as
`gnome-terminal --terminal-args -x /some/other/program --its-args`.
Since 2017 it has warned about uses of `-x` (see
ad4edbd118).

So we should change our calling convention for it.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-06-28 13:05:07 +01:00
Philip Withnall
40ff475977 Annotate various types and macros as deprecated
These have all been documented as deprecated for a long time, but we’ve
never had a way to programmatically mark them as deprecated. Do that
now.

This is based on the list of deprecations from the reverted commit
80fcb1bc2.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #638
2019-05-30 10:39:11 +01:00
Philip Withnall
70c8a7ef8d gdesktopappinfo: Improve documentation formatting slightly
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-05-30 10:38:45 +01:00
Philip Withnall
9bfd7e2a9d gdesktopappinfo: Add deprecation version to GDesktopAppInfoLookup
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-05-30 10:38:45 +01:00
Colomban Wendling
292cb2cb1b gdesktopappinfo: Add support for MATE and Xfce4 terminals
Add support for mate-terminal and xfce4-terminal with higher precedence
over xterm as it's likely people that have those want to use them.
They both use the gnome-terminal `-x` switch instead of xterm's `-e`.
2019-04-25 16:10:49 +02:00
Philip Withnall
d55ed6755e gdesktopappinfo: Fix an overly-specific ‘Since’ documentation line
This was causing gtk-doc to try and link to an API deprecation index
which doesn’t exist.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-03-15 11:09:32 +00:00
Ondrej Holy
cec5778cad gappinfo: Add launch_uris_async() and launch_uris_finish() vfuncs
The g_app_info_launch_uris_async() and g_app_info_launch_uris_finish()
functions are crucial to fix g_app_info_launch_default_for_uri_async()
to be really asynchronous.

This patch also adds GDesktopAppInfo implementation of that vfuncs.
The implementation may still use some synchronous calls to local MIME DB.

https://gitlab.gnome.org/GNOME/glib/issues/1347
https://gitlab.gnome.org/GNOME/glib/issues/1249
2019-01-28 16:42:34 +01:00
Philip Withnall
99bc33b632 gdesktopappinfo: Reload the desktop dirs if the $XDG_CONFIG_HOME changes
This causes the desktop directory cache to be correctly reloaded between
unit tests if G_TEST_OPTION_ISOLATE_DIRS is in use.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-12-17 17:16:04 +00:00
Philip Withnall
3f2a5ee1cc docs: Fix ‘Since’ line for new function to reference stable release
We only build API ‘since’ indexes for stable releases, so 2.59 needs to
be rounded up to 2.60.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-11-23 13:30:33 +00:00
Will Thompson
5ca9eca632 gdesktopappinfo: add get_string_list() function
The X-Flatpak-RenamedFrom key is used in .desktop files to identify past
names for the desktop file. It is defined to be a list of strings.
However, there was previously no correct way to retrieve a list of
strings from the GKeyFile wrapped by GDesktopAppInfo, short of
re-parsing the file with GKeyFile.

Note that doing something like:

    g_strsplit (g_desktop_app_info_get_string (...), ";", -1)

is not correct: the raw value "a\;b;" represents the one-element list
["a;b"], but g_key_file_get_string() rejects the sequence "\;", and so
g_desktop_app_info_get_string() returns NULL in this case. (Of course, a
.desktop file with a semicolon in its name is a pathological case.)

Add g_desktop_app_info_get_string_list(), a trivial wrapper around
g_key_file_get_string_list(), similar to g_desktop_app_info_get_string()
and co.

The change from g_key_file_free() to g_key_file_unref() in the test is
needed because g_key_file_free() clears the contents of the keyfile.
This is fine for all the fields which are eagerly loaded and copied into
GDesktopAppInfo, but not when we want to access arbitrary stuff from the
keyfile.
2018-10-01 20:03:55 +01:00
Philip Withnall
6db2412b41 gdesktopappinfo: Fix a minor command line leak
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2018-06-27 15:01:09 +01:00
Daniel Drake
156d009696 gdesktopappinfo: add g_desktop_app_info_launch_uris_as_manager_with_fds variant
Add an app-launching function which allows standard file descriptors
to be passed to the child process.

This will be used by gnome-shell to pass systemd journal descriptors
as stdout/stderr. gnome-shell's child_setup function can then be
eliminated, which will enable use of the posix_spawn optimized
gspawn codepath for desktop app launching.
2018-06-21 11:44:59 -05:00
Daniel Drake
742efe6232 gdesktopappinfo: enable fast posix_spawn gspawn codepath
In order to use the new posix_spawn gspawn codepath, for more robust
app launching when available memory is low, we need to meet some
conditions.

child_setup needs to be NULL for this optimization to work, so drop
the internal child_setup that is used here. Replace it with a lightweight
wrapper binary (gio-launch-desktop) that sets GIO_LAUNCHED_DESKTOP_FILE_PID
before executing the app.

Adjust PATH for gio tests so that it can execute the new binary from the
build directory.
2018-06-21 11:44:28 -05:00
Tomasz Miąsko
9d40f64960 gdesktopappinfo: Mark GDesktopAppInfo constructors as nullable.
GDesktopAppInfo constructors return NULL on error without having
separate **GError parameter.

https://bugzilla.gnome.org/show_bug.cgi?id=795152
2018-05-04 17:13:39 +01:00
Florian Müllner
1e2579da2c gdesktopappinfo: Filter out some binary names in search
The executable name can be a useful bit of information to match on in
searches where it differs from the name (for example because the latter
is localised), but will produce surprising results where the real appli-
cation is executed by a shared binary (for example interpretors like
gjs or python, or sandboxes like flatpak).

Address this by adding a blacklist of binary names that are ignored
in search.

https://bugzilla.gnome.org/show_bug.cgi?id=795488
2018-04-24 13:11:00 +02:00
Emmanuele Bassi
07731ff3fc Do not use g_autofree
The g_auto macros are available only with GCC-compatible compilers on
Unix, but having __attribute__((cleanup)) is not part of our toolchain
requirements, so we shouldn't use it — even if we are building on
Unix-compatible systems.

https://bugzilla.gnome.org/show_bug.cgi?id=794732
2018-03-28 11:49:59 +01:00
Florian Müllner
a55bfeee41 gdesktopappinfo: Add g_desktop_app_info_get_locale_string()
Custom desktop file fields may be translated, but there is currently
no non-hacky way to look up the localized value; fill get gap with
a small wrapper around g_key_file_get_locale_string().

https://bugzilla.gnome.org/show_bug.cgi?id=779413
2018-01-08 16:28:34 +01:00
Mario Sanchez Prada
d501bd0dbe gdesktopappinfo: Gracefully handle NULL URIs when passed to expand_macro()
If an application calls g_app_info_launch_uris() with a GList that includes
NULL values in some of its data members, and GIO ends up internally calling
g_desktop_app_info_launch_uris_with_spawn() for whatever reason (e.g. no
D-Bus session available), expand_macro() will crash due to the invalid data.

As this is considered a programmer error, use g_return_val_if_fail() in those
situations to prevent the crash from happening, but printing a warning anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=791337
2017-12-08 13:47:23 +00:00
Mario Sanchez Prada
fbed9c8b85 gdesktopappinfo: Pass a copy of the URIs list to expand_application_parameters()
This list will be modified in-place when calling expand_macro(), so pass a copy
of it instead the original pointer, that is supposed to be an input parameter
only for g_desktop_app_info_launch_uris_with_spawn().

https://bugzilla.gnome.org/show_bug.cgi?id=791337
2017-12-08 13:47:23 +00:00
Philip Withnall
181eb900d5 gdesktopappinfo: Downgrade a warning to a debug message
Bug #786580 triggered this warning to show up in the appinfo tests if
run on a machine where no terminal except xterm is installed (for
example, a build machine). Since we didn’t warn before if xterm but no
other terminals were installed, it seems reasonable to downgrade the
warning to a debug message.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=790914
2017-11-28 14:12:40 +00:00
Christoph Reiter
fed574a0c8 introspection: Add more filename type annotations for strings which can contain filenames
This continues the changes done in https://bugzilla.gnome.org/show_bug.cgi?id=767245

This makes it possible to pass Python path types as process arguments and env vars
in PyGObject and and makes it clear that the values are not strictly utf-8 and need
to be validated/converted first.

https://bugzilla.gnome.org/show_bug.cgi?id=788863
2017-10-26 18:51:51 +02:00
Mikhail Zabaluev
48cf1d32c6 Fix up closure annotations for GSpawnChildSetupFunc
https://bugzilla.gnome.org/show_bug.cgi?id=738176
2017-09-11 21:07:08 +01:00
Cj Malone
926db3174a gdesktopappinfo.c: Drop disregarded xterm check
https://bugzilla.gnome.org/show_bug.cgi?id=786580
2017-08-23 23:55:43 +01:00
Matthias Clasen
d3b4f7c9f6 Make dbus activation sandbox-aware
When we call org.freedesktop.Application.Open to activate
an application and pass file uris, the application may not
be able to see the files due to a flatpak sandbox.

Flatpak puts the flatpak app-id in the  X-Flatpak key in
desktop files that it exports, so we can easily recognize
applications that may be affected by this.

In this case, call the document portal to export the files
and pass the resulting uri's instead of the original ones.

https://bugzilla.gnome.org/show_bug.cgi?id=783130
2017-05-29 17:57:39 -04:00
Sébastien Wilmet
3bf4a720c3 gio/: LGPLv2+ -> LGPLv2.1+
Sub-directories inside gio/ already processed in a previous commit:
- fam/
- gdbus-2.0/ (which contains only codegen/)
- gvdb/
- inotify/
- tests/
- win32/
- xdgmime/

Other sub-directories inside gio/:
- completion/: no license headers
- kqueue/: not LGPL, BSD-style license

https://bugzilla.gnome.org/show_bug.cgi?id=776504
2017-05-29 19:53:34 +02:00
Simon McVittie
e5ed410c8c Avoid calling Standard C string/array functions with NULL arguments
glibc string.h declares memcpy() with attribute(nonnull(1,2)), causing
calls with NULL arguments to be treated as undefined behaviour.
This is consistent with ISO C99 and C11, which state that passing 0
to string functions as an array length does not remove the requirement
that the pointer to the array is a valid pointer.
gcc -fsanitize=undefined catches this while running OSTree's test suite.

Similarly, running the GLib test suite reports similar issues for
qsort(), memmove(), memcmp().

Signed-off-by: Simon McVittie <smcv@debian.org>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=775510
Reviewed-by: Colin Walters
2016-12-02 19:10:39 +00:00
Christian Hergert
18a33f72db introspection: use (nullable) or (optional) instead of (allow-none)
If we have an input parameter (or return value) we need to use (nullable).
However, if it is an (inout) or (out) parameter, (optional) is sufficient.

It looks like (nullable) could be used for everything according to the
Annotation documentation, but (optional) is more specific.
2016-11-22 14:14:37 -08:00
Piotr Drąg
10c490cdfe Use Unicode in translatable strings
See https://developer.gnome.org/hig/stable/typography.html

https://bugzilla.gnome.org/show_bug.cgi?id=772221
2016-10-12 21:30:42 +02:00
Christoph Reiter
9ec74d20a7 Partly revert "gio: Add filename type annotations"
Revert all annotation changes for environment variables and command line
arguments.

See commit f8189ddf98.
2016-06-07 19:50:03 +02:00
Christoph Reiter
f8189ddf98 gio: Add filename type annotations
https://bugzilla.gnome.org/show_bug.cgi?id=767245
2016-06-04 20:38:42 +02:00
Allison Ryan Lortie
3301b852a2 GDesktopAppInfo: support bus activation with '-'
GApplication has accepted any valid bus name as an application ID since
before the time of D-Bus activation.  This includes bus names with '-'.
Several applications have even attempted support bus activation with
these names, going as far as installing D-Bus service files, without
realising that they are silently falling back to fork()/exec() on
account of the name containing a dash.

The reason for the problem is that D-Bus object paths cannot contain
dashes.  We solved this problem privately in an unspecified way inside
of GApplication but substituting '_' in this case, but never made this
part of the Desktop Entry Specification.

The fact that these apps with '-' in the desktop file names aren't
actually using D-Bus activation is beside the point: their intent here
was clear.  Let's avoid forcing them to rename their desktop files again
by simply accepting '-' in desktop file names and munging the path in
the way that GApplication did so historically.

The new path escaping code here has been copied more or less verbatim
from GApplication's own code for the same purpose, with only the removal
of one irrelevant part.

An update to the desktop entry specification will follow.

https://bugzilla.gnome.org/show_bug.cgi?id=764754
2016-04-25 09:19:23 +02:00
Philip Withnall
27660b178e gio: Fix a GError memory leak in GDesktopAppInfo
Spotted by Coverity (CID: #1352961).
2016-03-15 18:03:00 +00:00
Olivier Fourdan
4919c25d49 GDesktopAppInfo: Do not set the DISPLAY in gio
The environment variable DISPLAY makes sense only for X11, it should
not be set in gio.

Beside, if the backend is not X11 but Wayland, forcing the value of
DISPLAY to the Wayland display will confuse the backend selection and
possibly crash the applications.

https://bugzilla.gnome.org/show_bug.cgi?id=754983
2015-10-05 23:21:43 -04:00
Ryan Lortie
2bb898c60f app info: tweak default application algorithm
Always run the full algorithm for a given mime type before considering
fallback types.

This includes considering installed applications capable of handling a
particular mimetype, even if such an app is not explicitly marked as
default, and there is a default app for a less-specific type.

Specifically, this often helps with cases of installing apps that can
handle a particular subtype of text/plain.  We want to take those apps
in preference to a generic text editor, even if that editor is listed as
the default for text/plain and there is no default listed for the more
specific type.

Because of the more holistic approach taken by the algorithm, it is now
more complicated, but it also means that we can do more work while
holding the lock.  In turn, that lets us avoid duplicating some strings,
which is nice.

https://bugzilla.gnome.org/show_bug.cgi?id=744282
2015-04-22 10:52:10 +01:00
Ryan Lortie
2737ab3201 substantially rework file monitors
Remove all event merging and dispatch logic from GFileMonitor.  The only
implementation of GFileMonitor outside of glib is in gvfs and it already
does these things properly.

Get rid of GLocalDirectoryMonitor.  We will use a single class,
GLocalFileMonitor, for both directory and file monitoring.  This will
prevent every single backend from having to create two objects
separately (eg: ginotifydirectorymonitor.c and ginotifyfilemonitor.c).

Introduce GFileMonitorSource as a thread-safe cross-context dispatch
mechanism.  Put it in GLocalFileMonitor.  All backends will be expected
to dispatch via the source and not touch the GFileMonitor object at all
from the worker thread.

Remove all construct properties from GLocalFileMonitor and remove the
"context" construct property from GFileMonitor.  All backends must now
get the information about what file to monitor from the ->start() call
which is mandatory to implement.

Remove the implementation of rate limiting in GFileMonitor and add an
implementation in GLocalFileMonitor.  gvfs never did anything with this
anyway, but if it wanted to, it would have to implement it for itself.
This was done in order to get the rate_limit field into the
GFileMonitorSource so that it could be safely accessed from the worker
thread.

Expose g_local_file_is_remote() internally for NFS detection.

With the "is_remote" functionality exposed, we can now move all
functions for creating local file monitors to a proper location in
glocalfilemonitor.c

Port the inotify backend to adjust to the changes above.  None of the
other backends are ported yet.  Those will come in future commits.
2015-03-20 11:59:47 -04:00
Xavier Claessens
74c22150cf docs: fix up docs issues in gio/ 2015-02-05 16:20:43 +01:00
Jasper St. Pierre
5a0a85e444 gdesktopappinfo: Fix copy/paste typo from e24e89b
Commit e24e89b accidentally ironically introduced a typo when replacing
the code with symbolic contents. Specifically, "Added Associations" was
replaced with "Default Applications" when reading defaults.list, giving
a warning about the file containing a "Default Applications" group.

If this was intended, it should have not been lumped in with a cleanup.
2014-10-14 19:17:53 -07:00
Bastien Nocera
e24e89bc07 gdesktopappinfo: Use symbolic names in the code
We have #defines for the key file groups, so use them to avoid typos.

https://bugzilla.gnome.org/show_bug.cgi?id=736273
2014-09-30 14:41:43 +02:00
Jasper St. Pierre
4482977238 Fix some introspection warnings 2014-09-16 14:52:21 -06:00
Ryan Lortie
3b8bc8bacf GDesktopAppInfo: avoid inotify on missing dirs
Some desktop file directories, like /usr/local/share/applications may be
missing on some systems.

When we try to inotify on these directories, this will result in a
every-4-seconds poll being setup which is quite bad.

This is an issue that should be fixed in inotify itself but the problem
is much larger there.  For now, we can work around it in GDesktopAppInfo
by refusing to monitor missing directories.

We may get some spurious notifications of changes in the case that
/usr/local/share or /usr/local/share/applications is created without
actually adding desktop files, but spurious changes can already be
reported in other cases, so that's OK.  We won't get (user-visible)
notification for a simple case of a completely unrelated file being
created (however we cannot avoid the wakeup in this case due to how
inotify works).  That's probably pretty theoretical, though, since files
in /usr don't change much and for the home directory we're likely to
have at least ~/.config and ~/.local existing.

https://bugzilla.gnome.org/show_bug.cgi?id=736350
2014-09-09 14:11:38 -04:00
Ryan Lortie
08efbda733 GDesktopAppInfo: fix default app logic
We use "tweaks" structures to track how a particular directory impacts
the list of added, removed and default applications.  We maintain this
set of tweaks for each directory, in a hash table, keyed by unaliased
mime type name, in order to facilitate fast lookups.

A typo in the logic for creating and maintaining the uniqueness of these
structures was causing the default app to be selected incorrectly from
time to time.  Fix that.
2014-09-04 14:48:05 -04:00
Ryan Lortie
5a5e16e93c 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.

https://bugzilla.gnome.org/show_bug.cgi?id=729813
2014-05-08 16:19:56 -04:00
Ryan Lortie
9aaf990960 Add g_desktop_app_info_get_implementations()
This provides support for the draft addition of 'Implements=' to the Desktop
Entry specification.

https://bugzilla.gnome.org/show_bug.cgi?id=712391
2014-05-08 16:19:05 -04:00
Ryan Lortie
afaee8dc6a gdesktopappinfo: fix a crasher
During the time that we are expanding the strv, it is not
null-terminated.  Use the strv_len variable instead to bound the search
for duplicates.
2014-04-15 14:12:58 -04:00
Ryan Lortie
6fd5a8cdaa GDesktopAppInfo: rewrite content type code
Redo the code for type-based selection of applications (all,
recommended, default, fallback) based on the new DesktopFileDir
structures that we introduced last cycle.

At the same time, we expand the functionality to add support for the new
features of the specification:

 - moving ~/.local/share/applications/mimeapps.list to ~/.config/

 - per-desktop default applications (via XDG_CURRENT_DESKTOP)

 - sysadmin customisation of defaults (via /etc/xdg/mimeapps.list)

 - deprecation of the old defaults.list, favouring the use of
   /usr/share/applications/mimeapps.list (or gnome-mimeapps.list) to
   accomplish the same

We modify the mimeapps testcase to check for mimeapps.list having been
created in XDG_CONFIG_HOME instead of XDG_DATA_HOME.

The modification is a net reduction of code (due to less duplication in
bookkeeping).  It is also an increase in performance and reduction in
memory consumption (due to simplified data structures).  Finally, it
removes the stat-based timestamp checking in favour of the
GFileMonitor-based approach that was already being used in the
implementation of DesktopFileDir (in order to know if we had to rescan
the desktop files themselves).

https://bugzilla.gnome.org/show_bug.cgi?id=728040
2014-04-15 11:36:39 -04:00
Colin Walters
2d96503898 gdesktopappinfo: Don't double free sn_id
Not sure why mclasen added a g_free() in that path, it was just wrong.
We free it correctly later.
2014-04-12 13:26:29 -04:00
Colin Walters
af1772b642 gdesktopappinfo: Initialize sn_id to NULL
Otherwise we'll be freeing a random stack pointer.
2014-04-12 13:21:20 -04:00
Matthias Clasen
94e5dafbc9 Deal with startup notify id being NULL
The app launch context may just not support startup notification,
in which case, g_app_launch_context_get_startup_notify_id() will
return NULL.

Failure to take this into account leads to criticals like this:
gnome-session[8489]: GLib-CRITICAL: g_variant_new_take_string: assertion 'string != NULL' failed
gnome-session[8489]: GLib-CRITICAL: g_variant_new_variant: assertion 'value != NULL' failed
gnome-session[8489]: GLib-CRITICAL: g_variant_get_type: assertion 'value != NULL' failed
gnome-session[8489]: GLib-CRITICAL: g_variant_type_is_subtype_of: assertion 'g_variant_type_check (type)' failed

https://bugzilla.gnome.org/show_bug.cgi?id=728066
2014-04-11 19:00:12 -07:00
Ryan Lortie
5d5ea495b5 desktopappinfo: add Exec to searchable keys
Add the basename from the first component of the Exec line to the list of
strings to search for via g_desktop_app_info_search().

We treat Exec as a fairly strong match -- just below the visible name.

Add a testcase to make sure everything is working OK.

https://bugzilla.gnome.org/show_bug.cgi?id=725023
2014-03-03 16:01:27 -05:00
William Jon McCann
20f4d1820b docs: use "Returns:" consistently
Instead of "Return value:".
2014-02-19 19:41:52 -05:00
Matthias Clasen
35066ed6c6 Docs: Drop entities, switch away from sgml mode
Since all element markup is now gone from the doc comments,
we can turn off the gtk-doc sgml mode, which means that from
now on, docbook markup is no longer allowed in doc comments.

To make this possible, we have to replace all remaining
entities in doc comments by their replacement text, &amp; -> &
and so on.
2014-02-09 02:07:26 -05:00
Matthias Clasen
3232425785 Docs: replace <literal> by ` 2014-02-06 08:07:16 -05:00
Matthias Clasen
cb588d4532 Convert external links to markdown syntax 2014-02-05 21:23:28 -05:00
Matthias Clasen
0cc20b7e0b Don't use <filename> in docs
Switch to simpler markdown, `foo`.
2014-02-05 20:17:46 -05:00
Matthias Clasen
111803030d Don't use <envar> in docs
Switch to simpler markdown, `foo`.
2014-02-05 19:32:41 -05:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Rico Tzschichholz
60cca82c9d gdesktopinfo: Fix typo in "Since" annotation of has_key 2014-01-13 12:33:35 +01:00
Martin Pitt
e6c86d58f2 gdesktopappinfo: Add missing annotations
Add missing (allow-none) annotations to
g_desktop_app_info_launch_uris_as_manager(). Tested with

  python -c "from gi.repository import GLib, Gio; Gio.DesktopAppInfo.new('gcalctool.desktop').launch_uris_as_manager([], None, GLib.SpawnFlags.SEARCH_PATH|GLib.SpawnFlags.STDOUT_TO_DEV_NULL, None, None, None, None)"

which is necessary to do a launch_uris() without leaking stdout.

https://launchpad.net/bugs/1259721
2013-12-11 13:17:10 +01:00
Florian Müllner
2fb8901b64 gdesktopappinfo: Rank Keywords matches higher than GenericName
It makes sense to match on GenericName in case an application does
not provide any keywords, but the Keywords field has been added
to explicitly support the search case, while GenericName was used
to be displayed in menus, so it makes more sense to consider
Keywords more (or equally) relevant for search.

https://bugzilla.gnome.org/show_bug.cgi?id=711640
2013-11-13 16:54:02 +01:00
Ryan Lortie
3d32d5359a Add g_desktop_app_info_search()
The first time this function is called we load all of the keyfiles in
the directory, ignoring the 'Hidden' ones and build an index out of the
interesting fields using g_str_tokenize_and_fold().

We do prefix matching on the tokens to find relevent desktop files.

Right now this is implemented as a hashtable that we iterate over,
checking prefixes on each token.  This could possibly be sped up by
creating an array, but it's already pretty fast...

https://bugzilla.gnome.org/show_bug.cgi?id=711557
2013-11-07 12:41:27 -05:00
Ryan Lortie
e55d33edc1 Add GAppInfoMonitor
This is a simple object that emits a "change" signal when the installed
applications may have changed in some way.

https://bugzilla.gnome.org/show_bug.cgi?id=711556
2013-11-06 11:26:53 -05:00
Ryan Lortie
86ce3bf48e gdesktopappinfo: keep a list of files in the dirs
In each DesktopFileDir, store a list of desktop files for that
directory.  This speeds up opening desktop files by name because we can
skip statting in directories that we know don't have the file and also
speeds up _get_all() because we can avoid enumeration.

This also improves our support for dealing with names like
'kde4/kate.desktop' (equivalent to kde4-kate.desktop) since we find out
about all of these files are the start and don't need to guess about
which '-' to change to a '/'.  It also means that we can easily deal
with more than one level of such prefixes.

We use a file monitor to watch for changes, invalidating our lists when
we notice them.

https://bugzilla.gnome.org/show_bug.cgi?id=711520
2013-11-06 10:56:25 -05:00
Ryan Lortie
e0ffd5c184 appinfo: Don't try DBusActivatable with load_from_keyfile
We can't get the name of the filename, so we can't determine the application
ID.  We'll have to fallback on Exec= for this case.

https://bugzilla.gnome.org/show_bug.cgi?id=709326
2013-10-04 12:19:03 -04:00
Ryan Lortie
c8e1dbb106 gdesktopappinfo: Large-scale whitespace fixup
Fix up a lot of whitespace issues in this file since we're about to do
some pretty serious rewriting here anyway...

Add some fold markers while we're at it.
2013-10-03 10:40:25 -04:00
Ryan Lortie
b0601e7558 gdesktopappinfo: rework search path
Change the search path to be a global array of 'DesktopFileDir' structures and
change the 'get' function to an 'ensure' function.

This is just a straight-up refactor.  Future patches will expand the
DesktopFileDir structure.
2013-10-03 10:40:25 -04:00
Ryan Lortie
5e59ab8e8c gdesktopappinfo: remove global_defaults_cache
...and some related functions.

This variable is also used for nothing at all.
2013-10-03 10:40:25 -04:00
Ryan Lortie
b95ef4aad4 gdesktopappinfo: remove should_ping_mime_monitor
This variable is used for nothing...
2013-10-03 10:40:25 -04:00
Bastien Nocera
2d8e5ef81e gdesktopappinfo: Call g_file_get_path() on demand
Rather than always calling out to g_file_get_path() (which
might block, whatever the documentation might say), postpone
the call until we actually need it.

https://bugzilla.gnome.org/show_bug.cgi?id=708753
2013-09-27 09:52:57 +02:00
Daniel Svensson
8a1b553728 gdesktopappinfo: Add missing return value 2013-07-30 18:20:44 -04:00
Ryan Lortie
9ec8ab62b2 GDesktopAppInfo: remove note about OnlyShowIn
A previous version of the patch had OnlyShowIn support for desktop file
actions.  This was removed from the spec and the patch rewritten, but
this bit of documentation slipped through.  Remove it.
2013-07-11 13:04:23 -04:00
Ryan Lortie
6dc5c118e4 Implement the Desktop Action specification
For some time, the desktop file specification has supported "additional
application actions".  This is intended to allow for additional methods
of starting an app, such as a mail client having a "Compose New Message"
action that brings up the compose window instead of the folder list.

This patch adds support for this with a relatively minimal API.

In the case that the application is a GApplication and DBusActivatable,
desktop actions are translated into GActions that have been added to the
application with g_action_map_add_action().  This more or less closes
the loop on being able to activate an application with an action
invocation (instead of 'activate').

https://bugzilla.gnome.org/show_bug.cgi?id=664444
2013-07-11 12:48:08 -04:00
Ryan Lortie
afc8b1020a GDesktopAppInfo: support DBusActivatable
Support the sender-side of the freedesktop application specification for
cases that we find 'DBusActivatable=true' in the desktop file.

https://bugzilla.gnome.org/show_bug.cgi?id=699259
2013-06-07 18:36:55 -04:00
Tim Lunn
daf7f56491 gio: fix small leak
https://bugzilla.gnome.org/show_bug.cgi?id=699361
2013-05-01 11:15:13 +10:00
Jasper St. Pierre
c0af442909 gdesktopappinfo: Allow getting the desktop ID from the filename 2013-04-21 00:09:47 -04:00
Cosimo Cecchi
f641699299 desktopappinfo: check whether the specified executable is valid
Before declaring the desktop file as valid, make sure the referenced
application actually exists in path and the commandline is not
malformed.

https://bugzilla.gnome.org/show_bug.cgi?id=675333
2013-03-04 14:40:36 -05:00
Colin Walters
f398bec5bc Add g_close(), use it
There are two benefits to this:

1) We can centralize any operating system specific knowledge of
   close-vs-EINTR handling.  For example, while on Linux we should never
   retry, if someone cared enough later about HP-UX, they could come by
   and change this one spot.
2) For places that do care about the return value and want to provide
   the caller with a GError, this function makes it convenient to do so.

Note that gspawn.c had an incorrect EINTR loop-retry around close().

https://bugzilla.gnome.org/show_bug.cgi?id=682819
2013-01-29 09:46:04 -05:00
Matthias Clasen
bace1822d7 GAppLaunchContext: make it possible ot get the effective startup id
gnome-session needs to know the startup id that was given to
a started app; this was not available via GAppLaunchContext.
This commit adds a ::launched signal to get this information.
At the same time, turn the launch_failed vfunc into a signal
as well.

https://bugzilla.gnome.org/show_bug.cgi?id=688497
2012-11-21 21:20:25 -05:00
Matthias Clasen
4adbc7aa42 GDesktopAppInfo: add enough api to make autostart implementable
gnome-session still uses EggDesktopFile, since GDesktopAppInfo is
missing a handful of APIs that are needed to implement the
autostart spec. This patch adds the minimum that is required.

https://bugzilla.gnome.org/show_bug.cgi?id=688497
2012-11-21 21:12:45 -05:00
Matthias Clasen
344066e0c1 Fix gio docs 2012-09-23 02:18:56 -04:00
Dan Winship
fa58cef826 GDesktopAppInfo: fix leaks
g_desktop_app_info_ensure_saved() was leaking the file contents.

_g_desktop_app_info_launch_uris_internal() was leaking the session bus
on error.

https://bugzilla.gnome.org/show_bug.cgi?id=682560
2012-09-03 08:36:10 -04:00
Colin Walters
f7abd3ce13 Add g_spawn_check_exit_status()
Many (if not "almost all") programs that spawn other programs via
g_spawn_sync() or the like simply want to check whether or not the
child exited successfully, but doing so requires use of
platform-specific functionality and there's actually a fair amount of
boilerplate involved.

This new API will help drain a *lot* of mostly duplicated code in
GNOME, from gnome-session to gdm.  And we can see that some bits even
inside GLib were doing it wrong; for example checking the exit status
on Unix, but ignoring it on Windows.

https://bugzilla.gnome.org/show_bug.cgi?id=679691
2012-07-10 18:03:56 -04:00
Alexander Larsson
c35106fcc4 Fix the mimetype default fix
We need to ignore the defaults.list item only when there
was a mimetype handler found in a previous mimetype, not
if one was found for the same mimetype as the one that
is listed in defaults.list (same for the new-style defaults).
2012-06-28 15:38:06 +02:00
Alexander Larsson
f14c0112d0 Fix default app lookup wrt parent types and defaults.list
There was an issue when looking up the default handler
for a type where a supertype was listed in defaults.list.
We would pick the default for the parent type even if
there was a handler for the more specific type.

In the case of the new-style defaults marking (
"Default Applications" in mimeapps.list) we were already
checking for a more specific handler befor using a default,
but we also need to do a similar check for the defaults.list
case.

https://bugzilla.gnome.org/show_bug.cgi?id=678944
2012-06-28 15:05:03 +02:00
Holger Berndt
0e6d9df35c Document that g_app_info_create_from_commandline() does unquoting according to fd.o
https://bugzilla.gnome.org/show_bug.cgi?id=676277
2012-05-18 15:20:40 +02:00