[glib] GDesktopAppInfo: simplify how defaults work
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GDesktopAppInfo: simplify how defaults work
- Date: Mon, 26 Sep 2011 20:54:36 +0000 (UTC)
commit 104ea17125aa70f926bddb3889d594b6f5642a21
Author: Ryan Lortie <desrt desrt ca>
Date: Mon Sep 26 03:56:22 2011 -0400
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
gio/gdesktopappinfo.c | 66 ++++++++++++++++++++-----------------------------
1 files changed, 27 insertions(+), 39 deletions(-)
---
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index 7f099d2..9b83662 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -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);
-
- /* 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);
}
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]