Bug 30214 - [PATCH] smart defaults per MIME heuristic
Summary: [PATCH] smart defaults per MIME heuristic
Status: NEW
Alias: None
Product: desktop-file-utils
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: All All
: medium enhancement
Assignee: Hans Petter Jansson
QA Contact:
Depends on:
Reported: 2010-09-15 08:20 UTC by Stanislav Brabec
Modified: 2015-09-18 09:50 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:

desktop-file-utils-generate-defaults-list.patch (22.57 KB, patch)
2010-09-15 08:20 UTC, Stanislav Brabec
Details | Splinter Review
desktop-file-utils-generate-defaults-list.patch (22.69 KB, patch)
2011-01-27 08:22 UTC, Stanislav Brabec
Details | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Stanislav Brabec 2010-09-15 08:20:25 UTC
Created attachment 38726 [details] [review]

In the default system, the defaults.list has to be created manually. Keeping it up to date requires lot of maintenance time. That is why I implemented a heuristic that allows to define defaults in a simple and straighforward way:

1. If desktop file is assigned to a particular MIME type, it is used.

2. If any desktop file is marked as Preferred, it will be used, if 1. cannot apply.

3. If any desktop file is marked as Default, it will be used, if 1. and 2. cannot apply.

4. If any desktop file matches defined Categories and supports particular MIME type, it will be used if 1.-3. cannot apply.

Such heuristic allows to define smart defaults in just a few lines.


- The implementation supports {ENVIRONMENT}-defaults.list. These per-environment defaults are not yet supported by any application, but I am working on a patch for GLib.

- The implementation is just a rewrite of SUSEconfig.glib2 heuristic to C language. It was used in openSUSE and SLE for creating of defaults.list for several year.

- See TODO file for ideas for possible improvements.
Comment 1 Vincent Untz 2010-09-15 09:00:45 UTC
Review of attachment 38726 [details] [review]:

Here's just a small review, without looking at the code in detail.

::: TODO
@@ +7,3 @@
+Make possible to define per-user desktop-defaults.conf as the way user
+selects defaults.

Well, that wouldn't be part of desktop-file-utils: that should be handled by glib.

::: man/update-desktop-database.1
@@ +115,3 @@
+This file contains preferences for the defaults list generator.
+.B ${XDG_DATA_DIRS[0]}/${ENVIRONMENT}defaults.list

The code doesn't use ENVIRONMENT, but XDG_DESKTOP_PREFIX, iirc.

::: src/Makefile.am
@@ +12,3 @@
+xdgconfigdir = $(sysconfdir)/xdg
+xdgconfig_DATA =				\
+	desktop-defaults.conf

I would name the file mime.defaults.

::: src/desktop-defaults.conf
@@ +1,2 @@
+#Desktop defaults for update-desktop-database.

I wonder if we should really ship data here: it's a bit weird that desktop-file-utils needs to be updated for each desktop.

Thinking about it, we might want to have a /etc/xdg/mime directory, where desktops can put a file. So you'd have /etc/xdg/mime/gnome.defaults, for example. Which would be shipped by GNOME. And then we can keep the generic defaults shipped here.

::: src/update-desktop-database.c
@@ +97,3 @@
+g_list_index_custom (GList         *list,
+		     gconstpointer  data,
+		     GCompareFunc   func)

Do not name it g_list_index_custom, but dfu_list_index_custom. And it might be worth putting it in a new file: dfu-glib.[ch], where we put some useful extensions to glib.

@@ +115,3 @@
+static inline gint
+g_string_compare_equal (gconstpointer a,
+			gconstpointer b)

Probably same comment than for g_list_index_custom.

@@ +148,2 @@
 static GHashTable *mime_types_map = NULL;
+static GList *enviro_list = NULL;

enviro_list? Either env_list or environment_list :-)

@@ +851,3 @@
+    {
+      desktop_dirs = get_default_search_path ();
+      defaults = TRUE;

Hrm, doesn't this mean that the --defaults-list is always used?
Comment 2 Stanislav Brabec 2010-09-15 09:29:56 UTC
>+Make possible to define per-user desktop-defaults.conf as the way user
>+selects defaults.
>Well, that wouldn't be part of desktop-file-utils: that should be handled by

It would need to collect all desktop files. I was thinking about creating user desktop-defaults.conf and then calling update-desktop-database --defaults-list with user privileges.

But yes, it would mean much more:
- It would require "I like Totem everywhere" and "I like Totem in GNOME" as an optional way to configure in addition to the current "Use Totem for opening of this MIME type".

Yes, having multiple mime preferences definitions may be a good idea. I planned to write it to the TODO, but forgot about it.

g_list_index_custom may be a candidate for GLib. It needs to be renamed if it stays in desktop-file-utils.

Yes, rename enviro_list -> env_list may be a good idea.

defaults = TRUE

Yes, I forgot to revert this chunk from the testing phase.

Should I prepare new patch or an incremental patch?

Well, I also wanted to discuss, which name is better:


GNOME: Matches value in g_desktop_app_info_set_desktop_env().
gnome: Matches $DESKTOP_SESSION

prepending env_name: Prepending is already used in gnome-menus (XDG_MENU_PREFIX).
appending env_name: Looks more comfortable in ls -al.
Comment 3 Stanislav Brabec 2010-09-16 07:43:26 UTC
I was thinking about the heuristic and it looks to me that Preferred key is probably superfluous.

The new implementation considers Default values as ordered list, so I guess it should be sufficient to do everything we need just by correct order of values.
Comment 4 Stanislav Brabec 2010-09-20 08:08:37 UTC
The GIO patch supporting desktop specific MIME defaults is available: https://bugzilla.gnome.org/show_bug.cgi?id=630171

Somebody should review KDE defaults definition.
Comment 5 Stanislav Brabec 2010-09-20 08:31:52 UTC
Feature announced in the XDG list: http://lists.freedesktop.org/archives/xdg/2010-September/011625.html
Comment 6 Stanislav Brabec 2010-09-23 08:26:21 UTC
Talking with Luboš Luňák, it seems, that easy KDE configuration would need wildcards for MIME types, e. g.:

Something like this:


The default configuration should also contain office applications. It is questionable, whether GNOME should default to AbiWord+Gnumeric and KDE to KOffice or both to OpenOffice. (Well, the same problem affects Epiphany x Konqueror x Firefox). Probably the default should be environment specific, and distro maintainers will customize.
Comment 7 Stanislav Brabec 2011-01-27 08:22:39 UTC
Created attachment 42598 [details] [review]

Patch ported to desktop-file-utils-0.18. No new changes were done there yet.
Comment 8 Cé! 2013-02-08 14:41:18 UTC
ex-falso.desktop (from quod-libet) has mime-type inode/directory. After generating /usr/share/applications/mimeinfo.cache with update-desktop-database (if I am not wrong), ex-falso.desktop precedes nautilus.desktop as the default inode/directory as a system wide setting. Annoying.

I don't know what to do to override this behavior. I hope this patch will solve the problem in the near future.

Keep up the good job!
Comment 9 Stanislav Brabec 2013-02-11 14:41:30 UTC
Regarding comment 8: GNOME 3 does not contain nautilus-folder-handler.desktop any longer, and nautilus.desktop now handles the inode/directory. But nautilus.desktop is not listed in the list of preferred applications. The algorithm cannot discriminate between "this is an application to view folder contents" and "by the way, this application can do something with directories".

desktop-defaults.conf needs update. Replace nautilus-folder-handler.desktop by nautilus.desktop.
Comment 10 Stanislav Brabec 2015-04-02 13:30:22 UTC
The latest "Association between MIME types and applications" specification finally started to support different defaults for different desktops:

Maybe there is a time to to port and update this patch.
Comment 11 Vincent Untz 2015-09-18 09:50:42 UTC
Sorry for the noise, reassigning to new maintainer.

bug/show.html.tmpl processed on Jul 02, 2016 at 05:35:32.
(provided by the Example extension).