GDesktopAppInfo: simplify how defaults work

Previously, we took the default application for a particular mimetype
from the system and copied it into the user's configuration as the
default there.

Instead of doing that we leave the user's default unset, and at time of
use, if the user has no explicitly-set default value, we use the system
default.

This avoids complicated situations where inappropriate applications were
being set as the default in the user's configuration.

https://bugzilla.gnome.org/show_bug.cgi?id=658188
This commit is contained in:
Ryan Lortie 2011-09-26 03:56:22 -04:00
parent 5b2c809dda
commit 104ea17125

View File

@ -1535,9 +1535,8 @@ update_mimeapps_list (const char *desktop_id,
{ {
char *dirname, *filename, *string; char *dirname, *filename, *string;
GKeyFile *key_file; GKeyFile *key_file;
gboolean load_succeeded, res, explicit_default; gboolean load_succeeded, res;
char **old_list, **list; char **old_list, **list;
GList *system_list;
gsize length, data_size; gsize length, data_size;
char *data; char *data;
int i, j, k; int i, j, k;
@ -1573,8 +1572,6 @@ update_mimeapps_list (const char *desktop_id,
content_types = g_key_file_get_keys (key_file, DEFAULT_APPLICATIONS_GROUP, NULL, NULL); content_types = g_key_file_get_keys (key_file, DEFAULT_APPLICATIONS_GROUP, NULL, NULL);
} }
explicit_default = FALSE;
for (k = 0; content_types && content_types[k]; k++) for (k = 0; content_types && content_types[k]; k++)
{ {
/* set as default, if requested so */ /* set as default, if requested so */
@ -1599,15 +1596,11 @@ update_mimeapps_list (const char *desktop_id,
content_types[k], content_types[k],
NULL); NULL);
else else
{
g_key_file_set_string (key_file, g_key_file_set_string (key_file,
DEFAULT_APPLICATIONS_GROUP, DEFAULT_APPLICATIONS_GROUP,
content_types[k], content_types[k],
string); string);
explicit_default = TRUE;
}
g_free (string); g_free (string);
} }
@ -1677,33 +1670,11 @@ update_mimeapps_list (const char *desktop_id,
content_types[k], content_types[k],
NULL); NULL);
else else
{
g_key_file_set_string_list (key_file, g_key_file_set_string_list (key_file,
ADDED_ASSOCIATIONS_GROUP, ADDED_ASSOCIATIONS_GROUP,
content_types[k], content_types[k],
(const char * const *)list, i); (const char * const *)list, i);
/* if we had no explicit default set, we should add the system default to the
* list, to avoid overriding it with applications from this list.
*/
if (!explicit_default)
{
system_list = get_all_desktop_entries_for_mime_type (content_type, (const char **) list, FALSE, NULL);
if (system_list != NULL)
{
string = system_list->data;
g_key_file_set_string (key_file,
DEFAULT_APPLICATIONS_GROUP,
content_types[k],
string);
}
g_list_free_full (system_list, g_free);
}
}
g_strfreev (list); g_strfreev (list);
} }
@ -3195,6 +3166,7 @@ get_all_desktop_entries_for_mime_type (const char *base_mime_type,
GList *desktop_entries, *removed_entries, *list, *dir_list, *tmp; GList *desktop_entries, *removed_entries, *list, *dir_list, *tmp;
MimeInfoCacheDir *dir; MimeInfoCacheDir *dir;
char *mime_type, *default_entry = NULL; char *mime_type, *default_entry = NULL;
char *old_default_entry = NULL;
const char *entry; const char *entry;
char **mime_types; char **mime_types;
char **default_entries; char **default_entries;
@ -3285,8 +3257,13 @@ get_all_desktop_entries_for_mime_type (const char *base_mime_type,
/* Then system defaults (or old per-user config) (using removed associations from this dir or earlier) */ /* Then system defaults (or old per-user config) (using removed associations from this dir or earlier) */
default_entries = g_hash_table_lookup (dir->defaults_list_map, mime_type); default_entries = g_hash_table_lookup (dir->defaults_list_map, mime_type);
for (j = 0; default_entries != NULL && default_entries[j] != NULL; j++) for (j = 0; default_entries != NULL && default_entries[j] != NULL; j++)
{
if (default_entry == NULL && old_default_entry == NULL)
old_default_entry = g_strdup (default_entries[j]);
desktop_entries = append_desktop_entry (desktop_entries, default_entries[j], removed_entries); desktop_entries = append_desktop_entry (desktop_entries, default_entries[j], removed_entries);
} }
}
/* Go through all entries that support the mimetype */ /* Go through all entries that support the mimetype */
for (dir_list = mime_info_cache->dirs; for (dir_list = mime_info_cache->dirs;
@ -3305,6 +3282,17 @@ get_all_desktop_entries_for_mime_type (const char *base_mime_type,
g_strfreev (mime_types); g_strfreev (mime_types);
/* If we have no default from mimeapps.list, take it from
* defaults.list intead.
*
* If we do have a default from mimeapps.list, free any one that came
* from defaults.list.
*/
if (default_entry == NULL)
default_entry = old_default_entry;
else
g_free (old_default_entry);
if (explicit_default != NULL) if (explicit_default != NULL)
*explicit_default = default_entry; *explicit_default = default_entry;
else else