Commit 081f2939 authored by Felix Zhang's avatar Felix Zhang Committed by Ray Strode

common: Support runtime configurations

Add runtime configuration file /run/gdm/custom.conf, making device
dependent configurations possible.

https://bugzilla.gnome.org/show_bug.cgi?id=789081
parent 17a9f382
......@@ -20,6 +20,8 @@ AM_CPPFLAGS = \
-DGDM_DEFAULTS_CONF=\"$(GDM_DEFAULTS_CONF)\" \
-DGDM_CUSTOM_CONF=\"$(GDM_CUSTOM_CONF)\" \
-DGDM_OLD_CONF=\"$(GDM_OLD_CONF)\" \
-DGDM_RUN_DIR=\"$(GDM_RUN_DIR)\" \
-DGDM_RUNTIME_CONF=\"$(GDM_RUNTIME_CONF)\" \
-DGDM_SESSION_DEFAULT_PATH=\"$(GDM_SESSION_DEFAULT_PATH)\" \
$(COMMON_CFLAGS) \
$(NULL)
......
......@@ -46,12 +46,90 @@ struct GdmSettingsDesktopBackendPrivate
guint save_id;
};
enum {
PROP_0,
PROP_FILENAME,
};
static void gdm_settings_desktop_backend_class_init (GdmSettingsDesktopBackendClass *klass);
static void gdm_settings_desktop_backend_init (GdmSettingsDesktopBackend *settings_desktop_backend);
static void gdm_settings_desktop_backend_finalize (GObject *object);
G_DEFINE_TYPE (GdmSettingsDesktopBackend, gdm_settings_desktop_backend, GDM_TYPE_SETTINGS_BACKEND)
static void
_gdm_settings_desktop_backend_set_file_name (GdmSettingsDesktopBackend *backend,
const char *filename)
{
gboolean res;
GError *error;
char *contents;
backend->priv = GDM_SETTINGS_DESKTOP_BACKEND_GET_PRIVATE (backend);
g_free (backend->priv->filename);
backend->priv->filename = g_strdup (filename);
backend->priv->key_file = g_key_file_new ();
error = NULL;
res = g_key_file_load_from_file (backend->priv->key_file,
backend->priv->filename,
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
&error);
if (! res) {
g_warning ("Unable to load file '%s': %s", backend->priv->filename, error->message);
}
contents = g_key_file_to_data (backend->priv->key_file, NULL, NULL);
if (contents != NULL) {
g_debug ("GdmSettings: %s is:\n%s\n", backend->priv->filename, contents);
g_free (contents);
}
}
static void
gdm_settings_desktop_backend_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GdmSettingsDesktopBackend *self;
self = GDM_SETTINGS_DESKTOP_BACKEND (object);
switch (prop_id) {
case PROP_FILENAME:
_gdm_settings_desktop_backend_set_file_name (self, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gdm_settings_desktop_backend_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GdmSettingsDesktopBackend *self;
self = GDM_SETTINGS_DESKTOP_BACKEND (object);
switch (prop_id) {
case PROP_FILENAME:
g_value_set_string (value, self->priv->filename);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
parse_key_string (const char *keystring,
char **group,
......@@ -308,41 +386,27 @@ gdm_settings_desktop_backend_class_init (GdmSettingsDesktopBackendClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GdmSettingsBackendClass *backend_class = GDM_SETTINGS_BACKEND_CLASS (klass);
object_class->get_property = gdm_settings_desktop_backend_get_property;
object_class->set_property = gdm_settings_desktop_backend_set_property;
object_class->finalize = gdm_settings_desktop_backend_finalize;
backend_class->get_value = gdm_settings_desktop_backend_get_value;
backend_class->set_value = gdm_settings_desktop_backend_set_value;
g_type_class_add_private (klass, sizeof (GdmSettingsDesktopBackendPrivate));
g_object_class_install_property (object_class,
PROP_FILENAME,
g_param_spec_string ("filename",
"File Name",
"The name of the configuration file",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
static void
gdm_settings_desktop_backend_init (GdmSettingsDesktopBackend *backend)
{
gboolean res;
GError *error;
char *contents;
backend->priv = GDM_SETTINGS_DESKTOP_BACKEND_GET_PRIVATE (backend);
backend->priv->key_file = g_key_file_new ();
backend->priv->filename = g_strdup (GDM_CUSTOM_CONF);
error = NULL;
res = g_key_file_load_from_file (backend->priv->key_file,
backend->priv->filename,
G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
&error);
if (! res) {
g_warning ("Unable to load file '%s': %s", backend->priv->filename, error->message);
}
contents = g_key_file_to_data (backend->priv->key_file, NULL, NULL);
if (contents != NULL) {
g_debug ("GdmSettings: %s is:\n%s\n", backend->priv->filename, contents);
g_free (contents);
}
}
static void
......@@ -365,11 +429,15 @@ gdm_settings_desktop_backend_finalize (GObject *object)
}
GdmSettingsBackend *
gdm_settings_desktop_backend_new (void)
gdm_settings_desktop_backend_new (const char* filename)
{
GObject *object;
object = g_object_new (GDM_TYPE_SETTINGS_DESKTOP_BACKEND, NULL);
if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR))
return NULL;
object = g_object_new (GDM_TYPE_SETTINGS_DESKTOP_BACKEND,
"filename", filename,
NULL);
return GDM_SETTINGS_BACKEND (object);
}
......@@ -49,7 +49,7 @@ typedef struct
GType gdm_settings_desktop_backend_get_type (void);
GdmSettingsBackend *gdm_settings_desktop_backend_new (void);
GdmSettingsBackend *gdm_settings_desktop_backend_new (const char* filename);
G_END_DECLS
......
......@@ -43,7 +43,7 @@
struct GdmSettingsPrivate
{
GdmSettingsBackend *backend;
GList *backends;
};
enum {
......@@ -80,15 +80,28 @@ gdm_settings_get_value (GdmSettings *settings,
{
GError *local_error;
gboolean res;
GList *l;
g_return_val_if_fail (GDM_IS_SETTINGS (settings), FALSE);
g_return_val_if_fail (key != NULL, FALSE);
local_error = NULL;
res = gdm_settings_backend_get_value (settings->priv->backend,
key,
value,
&local_error);
for (l = settings->priv->backends; l; l = g_list_next (l)) {
GdmSettingsBackend *backend = l->data;
if (local_error) {
g_error_free (local_error);
local_error = NULL;
}
res = gdm_settings_backend_get_value (backend,
key,
value,
&local_error);
if (res)
break;
}
if (! res) {
g_propagate_error (error, local_error);
}
......@@ -104,6 +117,7 @@ gdm_settings_set_value (GdmSettings *settings,
{
GError *local_error;
gboolean res;
GList *l;
g_return_val_if_fail (GDM_IS_SETTINGS (settings), FALSE);
g_return_val_if_fail (key != NULL, FALSE);
......@@ -111,10 +125,23 @@ gdm_settings_set_value (GdmSettings *settings,
g_debug ("Setting value %s", key);
local_error = NULL;
res = gdm_settings_backend_set_value (settings->priv->backend,
key,
value,
&local_error);
for (l = settings->priv->backends; l; l = g_list_next (l)) {
GdmSettingsBackend *backend = l->data;
if (local_error) {
g_error_free (local_error);
local_error = NULL;
}
res = gdm_settings_backend_set_value (backend,
key,
value,
&local_error);
if (res)
break;
}
if (! res) {
g_propagate_error (error, local_error);
}
......@@ -162,13 +189,27 @@ backend_value_changed (GdmSettingsBackend *backend,
static void
gdm_settings_init (GdmSettings *settings)
{
GList *l;
GdmSettingsBackend *backend;
settings->priv = GDM_SETTINGS_GET_PRIVATE (settings);
settings->priv->backend = gdm_settings_desktop_backend_new ();
g_signal_connect (settings->priv->backend,
"value-changed",
G_CALLBACK (backend_value_changed),
settings);
backend = gdm_settings_desktop_backend_new (GDM_CUSTOM_CONF);
if (backend)
settings->priv->backends = g_list_prepend (NULL, backend);
backend = gdm_settings_desktop_backend_new (GDM_RUNTIME_CONF);
if (backend)
settings->priv->backends = g_list_prepend (settings->priv->backends, backend);
for (l = settings->priv->backends; l; l = g_list_next (l)) {
backend = l->data;
g_signal_connect (backend,
"value-changed",
G_CALLBACK (backend_value_changed),
settings);
}
}
static void
......@@ -183,9 +224,9 @@ gdm_settings_finalize (GObject *object)
g_return_if_fail (settings->priv != NULL);
if (settings->priv->backend != NULL) {
g_object_unref (settings->priv->backend);
}
g_list_foreach (settings->priv->backends, (GFunc) g_object_unref, NULL);
g_list_free (settings->priv->backends);
settings->priv->backends = NULL;
settings_object = NULL;
......
......@@ -1423,6 +1423,24 @@ fi
AC_SUBST(GDM_SCREENSHOT_DIR)
dnl ---------------------------------------------------------------------------
dnl - runtime conf
dnl ---------------------------------------------------------------------------
withval=""
AC_ARG_WITH(runtime_conf,
AS_HELP_STRING([--with-runtime-conf=<FILENAME>],
[FILENAME to give to runtime configuration file @<:@default=GDM_RUN_DIR/custom.conf@:>@]))
if test x$withval != x; then
GDM_RUNTIME_CONF="$withval"
else
GDM_RUNTIME_CONF="$GDM_RUN_DIR/custom.conf"
fi
AC_SUBST(GDM_RUNTIME_CONF)
dnl ---------------------------------------------------------------------------
dnl - Finish
dnl ---------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment