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

Re: default email client from gsettings



On Mon, 04 May 2020 at 11:23:24 +0200, Jeff wrote:
> The Fedora maintainer for a package for which I am upstream has pointed
> out that it still uses gconftool or gconftool-2, which is way out of
> date and should use gsettings[1].

Taking a step back from "tell me the default email client", what are
you actually trying to do, at a high level? I suspect that rather
than manipulating the default email client (which is a job for desktop
configuration applications like gnome-control-center), you probably want
to compose an email?

It's often best to start from your application's high-level goal, ask
what you want to achieve, and look for (or ask about) APIs to do exactly
that, rather than immediately homing in on a particular lower-level
implementation detail.

If your goal is to pre-fill the To/Subject/body of an email in the user's
preferred email composition application, you would probably be better
off building a mailto: URI and asking your preferred library (in your
case that seems to be GLib/GTK?) to launch the preferred handler for that
URI. In GLib/GTK, try using APIs like g_app_info_launch_default_for_uri().

Or you could use xdg-email(1) from the xdg-utils package. It's a large
shell script that tries to do various legacy desktop-specific and/or
client-specific things in addition to the freedesktop.org URI-handler code
path, so might work better in legacy environments, at the cost that if
a desktop has moved from legacy desktop-specific APIs to freedesktop.org
APIs and xdg-utils hasn't been updated, it will continue to do the legacy
thing (even if that's now wrong).

> Unfortunately, my search engine foo is failing me and I can't find the
> right incantation to get gsettings to tell me the default email client.

That's probably because it isn't stored in gsettings.

GNOME 2 had GNOME-specific configuration for the preferred email client,
stored in gconf. The most direct equivalent of gconf in GNOME 3 is
indeed gsettings. However, there is not a 1:1 equivalence between
configuration items in gconf and configuration items in gsettings.

Instead of gconf or gsettings, GNOME 3 uses the freedesktop.org content
type (MIME type) handlers as a way to store/choose application defaults,
which is hopefully cross-desktop. Specifically, email is tracked as
the handler of the pseudo-MIME-type "x-scheme-handler/mailto". It
looks as though recent versions of at least KDE, MATE and Cinnamon
do the same. XFCE might still have its own desktop-specific mechanism
(or maybe it uses the freedesktop.org handlers now and xdg-utils just
hasn't caught up).

If you really need to manipulate the preferred handler for a URI
scheme like mailto (which you probably don't, because again,
this is a job for desktop configuration applications like
gnome-control-center), the way to do it in GNOME/KDE/etc. is
with C APIs like g_app_info_get_default_for_uri_scheme() and
g_app_info_set_as_default_for_type() (or their bindings into various non-C
languages), or with 'gio mime x-scheme-handler/mailto' from libglib2.0-bin
(which is just a CLI binding for those APIs), or with Qt/KDE equivalents
if you're closer to the Qt/KDE ecosystem than the GLib/GNOME ecosystem.

Or you could use xdg-settings(1) and/or xdg-mime(1) from the xdg-utils
package. Again, these are large shell scripts that try to do various
legacy desktop-specific and/or client-specific things, so they might work
better in legacy environments, but they might also do the wrong thing if
they have got out of sync with how their supported desktop environments
actually work.

    smcv


Reply to: