summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2020-12-31 12:40:41 +0100
committerTimm Bäder <mail@baedert.org>2021-01-03 11:01:29 +0100
commit34ea99006ffdbe1a4eab34e2c6db793ca75dd160 (patch)
tree07ac177745b0d6b82bd38e9db5002d7131270de4
parent06cce81a97e8cf5ef2ab78eec2d5c7c05d5de8b8 (diff)
downloadgtk+-34ea99006ffdbe1a4eab34e2c6db793ca75dd160.tar.gz
settings: Load keyfiles ourselves
This does not change anything in the case where the .init file does not exist. We still hit the disk once. Otherwise, we now only hit it once instead of twice and avoid a potential race-condition.
-rw-r--r--gtk/gtksettings.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c
index 5bde1e547c..02b02c3911 100644
--- a/gtk/gtksettings.c
+++ b/gtk/gtksettings.c
@@ -275,27 +275,23 @@ gtk_settings_init (GtkSettings *settings)
g_free (pspecs);
path = g_build_filename (_gtk_get_data_prefix (), "share", "gtk-4.0", "settings.ini", NULL);
- if (g_file_test (path, G_FILE_TEST_EXISTS))
- gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
+ gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
g_free (path);
path = g_build_filename (_gtk_get_sysconfdir (), "gtk-4.0", "settings.ini", NULL);
- if (g_file_test (path, G_FILE_TEST_EXISTS))
- gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
+ gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
g_free (path);
config_dirs = g_get_system_config_dirs ();
for (i = 0; config_dirs[i] != NULL; i++)
{
path = g_build_filename (config_dirs[i], "gtk-4.0", "settings.ini", NULL);
- if (g_file_test (path, G_FILE_TEST_EXISTS))
- gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
+ gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
g_free (path);
}
path = g_build_filename (g_get_user_config_dir (), "gtk-4.0", "settings.ini", NULL);
- if (g_file_test (path, G_FILE_TEST_EXISTS))
- gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
+ gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_DEFAULT);
g_free (path);
g_object_thaw_notify (G_OBJECT (settings));
@@ -1690,8 +1686,7 @@ settings_update_theme (GtkSettings *settings)
if (theme_dir)
{
path = g_build_filename (theme_dir, "settings.ini", NULL);
- if (g_file_test (path, G_FILE_TEST_EXISTS))
- gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
+ gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
g_free (path);
}
@@ -1728,13 +1723,18 @@ gtk_settings_load_from_key_file (GtkSettings *settings,
char **keys;
gsize n_keys;
int i;
+ char *contents;
+ gsize contents_len;
+
+ if (!g_file_get_contents (path, &contents, &contents_len, NULL))
+ return;
error = NULL;
keys = NULL;
keyfile = g_key_file_new ();
- if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, &error))
+ if (!g_key_file_load_from_data (keyfile, contents, contents_len, G_KEY_FILE_NONE, &error))
{
g_warning ("Failed to parse %s: %s", path, error->message);
@@ -1845,6 +1845,7 @@ gtk_settings_load_from_key_file (GtkSettings *settings,
}
out:
+ g_free (contents);
g_strfreev (keys);
g_key_file_free (keyfile);
}