mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
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:
parent
5b2c809dda
commit
104ea17125
@ -1535,9 +1535,8 @@ update_mimeapps_list (const char *desktop_id,
|
||||
{
|
||||
char *dirname, *filename, *string;
|
||||
GKeyFile *key_file;
|
||||
gboolean load_succeeded, res, explicit_default;
|
||||
gboolean load_succeeded, res;
|
||||
char **old_list, **list;
|
||||
GList *system_list;
|
||||
gsize length, data_size;
|
||||
char *data;
|
||||
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);
|
||||
}
|
||||
|
||||
explicit_default = FALSE;
|
||||
|
||||
for (k = 0; content_types && content_types[k]; k++)
|
||||
{
|
||||
/* set as default, if requested so */
|
||||
@ -1599,14 +1596,10 @@ update_mimeapps_list (const char *desktop_id,
|
||||
content_types[k],
|
||||
NULL);
|
||||
else
|
||||
{
|
||||
g_key_file_set_string (key_file,
|
||||
DEFAULT_APPLICATIONS_GROUP,
|
||||
content_types[k],
|
||||
string);
|
||||
|
||||
explicit_default = TRUE;
|
||||
}
|
||||
g_key_file_set_string (key_file,
|
||||
DEFAULT_APPLICATIONS_GROUP,
|
||||
content_types[k],
|
||||
string);
|
||||
|
||||
g_free (string);
|
||||
}
|
||||
@ -1677,33 +1670,11 @@ update_mimeapps_list (const char *desktop_id,
|
||||
content_types[k],
|
||||
NULL);
|
||||
else
|
||||
{
|
||||
g_key_file_set_string_list (key_file,
|
||||
ADDED_ASSOCIATIONS_GROUP,
|
||||
content_types[k],
|
||||
(const char * const *)list, i);
|
||||
g_key_file_set_string_list (key_file,
|
||||
ADDED_ASSOCIATIONS_GROUP,
|
||||
content_types[k],
|
||||
(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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
MimeInfoCacheDir *dir;
|
||||
char *mime_type, *default_entry = NULL;
|
||||
char *old_default_entry = NULL;
|
||||
const char *entry;
|
||||
char **mime_types;
|
||||
char **default_entries;
|
||||
@ -3285,7 +3257,12 @@ 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) */
|
||||
default_entries = g_hash_table_lookup (dir->defaults_list_map, mime_type);
|
||||
for (j = 0; default_entries != NULL && default_entries[j] != NULL; j++)
|
||||
desktop_entries = append_desktop_entry (desktop_entries, default_entries[j], removed_entries);
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/* Go through all entries that support the mimetype */
|
||||
@ -3305,6 +3282,17 @@ get_all_desktop_entries_for_mime_type (const char *base_mime_type,
|
||||
|
||||
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)
|
||||
*explicit_default = default_entry;
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user