Commit 7c2d40e5 authored by Ray Strode's avatar Ray Strode

daemon: switch to using accounts service for language and session

Control center now uses accounts service, so we should, too.
parent e280e791
......@@ -51,6 +51,7 @@ LIBCANBERRA_GTK_REQUIRED_VERSION=0.4
#FONTCONFIG_REQUIRED_VERSION=2.6.0
FONTCONFIG_REQUIRED_VERSION=2.5.0
UPOWER_REQUIRED_VERSION=0.9.0
ACCOUNTS_SERVICE_REQUIRED_VERSION=0.6.3
EXTRA_COMPILE_WARNINGS(yes)
......@@ -70,6 +71,7 @@ PKG_CHECK_MODULES(DAEMON,
dbus-glib-1 >= $DBUS_GLIB_REQUIRED_VERSION
gobject-2.0 >= $GLIB_REQUIRED_VERSION
gio-2.0 >= $GLIB_REQUIRED_VERSION
accountsservice >= $ACCOUNTS_SERVICE_REQUIRED_VERSION
)
AC_SUBST(DAEMON_CFLAGS)
AC_SUBST(DAEMON_LIBS)
......
......@@ -32,8 +32,11 @@
#include <glib-object.h>
#include <glib/gi18n.h>
#include <act/act-user-manager.h>
struct _GdmSessionSettingsPrivate
{
ActUserManager *user_manager;
char *session_name;
char *language_name;
};
......@@ -102,6 +105,8 @@ gdm_session_settings_init (GdmSessionSettings *settings)
GDM_TYPE_SESSION_SETTINGS,
GdmSessionSettingsPrivate);
settings->priv->user_manager = act_user_manager_get_default ();
}
static void
......@@ -230,122 +235,67 @@ gdm_session_settings_is_loaded (GdmSessionSettings *settings)
gboolean
gdm_session_settings_load (GdmSessionSettings *settings,
const char *username,
GError **error)
const char *username)
{
GKeyFile *key_file;
GError *load_error;
gboolean is_loaded;
char *session_name;
char *language_name;
char *filename;
ActUser *user;
const char *session_name;
const char *language_name;
g_return_val_if_fail (settings != NULL, FALSE);
g_return_val_if_fail (username != NULL, FALSE);
g_return_val_if_fail (!gdm_session_settings_is_loaded (settings), FALSE);
filename = g_build_filename (GDM_CACHE_DIR, username, "dmrc", NULL);
user = act_user_manager_get_user (settings->priv->user_manager,
username);
is_loaded = FALSE;
key_file = g_key_file_new ();
load_error = NULL;
if (!g_key_file_load_from_file (key_file, filename,
G_KEY_FILE_NONE, &load_error)) {
g_propagate_error (error, load_error);
goto out;
if (!act_user_is_loaded (user)) {
g_object_unref (user);
return FALSE;
}
session_name = g_key_file_get_string (key_file, "Desktop", "Session",
&load_error);
session_name = act_user_get_x_session (user);
if (session_name != NULL) {
gdm_session_settings_set_session_name (settings, session_name);
g_free (session_name);
} else if (g_error_matches (load_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
g_error_free (load_error);
load_error = NULL;
} else {
g_propagate_error (error, load_error);
goto out;
}
language_name = g_key_file_get_string (key_file, "Desktop", "Language",
&load_error);
language_name = act_user_get_language (user);
if (language_name != NULL) {
gdm_session_settings_set_language_name (settings, language_name);
g_free (language_name);
} else if (g_error_matches (load_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
g_error_free (load_error);
load_error = NULL;
} else {
g_propagate_error (error, load_error);
goto out;
}
g_object_unref (user);
is_loaded = TRUE;
out:
g_key_file_free (key_file);
g_free (filename);
return is_loaded;
return TRUE;
}
gboolean
gdm_session_settings_save (GdmSessionSettings *settings,
const char *home_directory,
GError **error)
const char *username)
{
GKeyFile *key_file;
GError *file_error;
gboolean is_saved;
char *filename;
gsize length;
gchar *contents;
ActUser *user;
g_return_val_if_fail (GDM_IS_SESSION_SETTINGS (settings), FALSE);
g_return_val_if_fail (home_directory != NULL, FALSE);
g_return_val_if_fail (username != NULL, FALSE);
g_return_val_if_fail (gdm_session_settings_is_loaded (settings), FALSE);
filename = g_build_filename (home_directory, ".dmrc", NULL);
is_saved = FALSE;
key_file = g_key_file_new ();
user = act_user_manager_get_user (settings->priv->user_manager,
username);
file_error = NULL;
g_key_file_load_from_file (key_file, filename,
G_KEY_FILE_KEEP_COMMENTS |
G_KEY_FILE_KEEP_TRANSLATIONS,
NULL);
if (settings->priv->session_name != NULL) {
g_key_file_set_string (key_file, "Desktop", "Session",
settings->priv->session_name);
if (!act_user_is_loaded (user)) {
g_object_unref (user);
return FALSE;
}
if (settings->priv->language_name != NULL) {
g_key_file_set_string (key_file, "Desktop", "Language",
settings->priv->language_name);
}
contents = g_key_file_to_data (key_file, &length, &file_error);
if (contents == NULL) {
g_propagate_error (error, file_error);
goto out;
if (settings->priv->session_name != NULL) {
act_user_set_x_session (user, settings->priv->session_name);
}
if (!g_file_set_contents (filename, contents, length, &file_error)) {
g_free (contents);
g_propagate_error (error, file_error);
goto out;
if (settings->priv->language_name != NULL) {
act_user_set_language (user, settings->priv->language_name);
}
g_free (contents);
is_saved = TRUE;
out:
g_key_file_free (key_file);
g_free (filename);
g_object_unref (user);
return is_saved;
return TRUE;
}
......@@ -54,11 +54,9 @@ GType gdm_session_settings_get_type (void);
GdmSessionSettings *gdm_session_settings_new (void);
gboolean gdm_session_settings_load (GdmSessionSettings *settings,
const char *username,
GError **error);
const char *username);
gboolean gdm_session_settings_save (GdmSessionSettings *settings,
const char *home_directory,
GError **error);
const char *username);
gboolean gdm_session_settings_is_loaded (GdmSessionSettings *settings);
char *gdm_session_settings_get_language_name (GdmSessionSettings *settings);
char *gdm_session_settings_get_session_name (GdmSessionSettings *settings);
......
......@@ -592,8 +592,7 @@ attempt_to_load_user_settings (GdmSessionWorker *worker,
const char *username)
{
gdm_session_settings_load (worker->priv->user_settings,
username,
NULL);
username);
}
static void
......@@ -1933,8 +1932,6 @@ static void
_save_user_settings (GdmSessionWorker *worker,
const char *home_dir)
{
GError *error;
if (!gdm_session_settings_is_loaded (worker->priv->user_settings)) {
/*
* Even if the user did not change the defaults, there may
......@@ -1943,12 +1940,9 @@ _save_user_settings (GdmSessionWorker *worker,
goto out;
}
error = NULL;
if (!gdm_session_settings_save (worker->priv->user_settings,
home_dir, &error)) {
g_warning ("could not save session and language settings: %s",
error->message);
g_error_free (error);
home_dir)) {
g_warning ("could not save session and language settings");
}
out:
......
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