summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2011-09-26 03:56:22 -0400
committerRyan Lortie <desrt@desrt.ca>2011-09-26 16:55:09 -0400
commitd25a6f248654bfa6a8b9593e7315960b3483420d (patch)
treeec2df9267e621d162ba2f38b331f35264c303298
parent9a7f4baf94c41a571afce615d1221f5ccf1efe27 (diff)
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
-rw-r--r--gio/gdesktopappinfo.c66
1 files changed, 27 insertions, 39 deletions
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index 64f03495f..9ad276bdf 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -1533,9 +1533,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;
@@ -1571,8 +1570,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 */
@@ -1597,14 +1594,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);
}
@@ -1675,33 +1668,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);
-
- /* 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_key_file_set_string_list (key_file,
+ ADDED_ASSOCIATIONS_GROUP,
+ content_types[k],
+ (const char * const *)list, i);
- g_list_free_full (system_list, g_free);
- }
- }
-
g_strfreev (list);
}
@@ -3189,6 +3160,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;
@@ -3279,7 +3251,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 */
@@ -3299,6 +3276,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