From 4b7f789ddf83ef459e91aca16007b4722e3a2c9e Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Fri, 12 Oct 2012 14:29:24 +0200 Subject: [PATCH 2/2] accountsservice: Add User.LoginTime property https://bugzilla.gnome.org/show_bug.cgi?id=681772 --- data/org.freedesktop.Accounts.User.xml | 10 ++++++++++ src/daemon.c | 8 ++++++-- src/libaccountsservice/act-user.c | 36 ++++++++++++++++++++++++++++++++++ src/libaccountsservice/act-user.h | 1 + src/user.c | 15 ++++++++++++++ 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/data/org.freedesktop.Accounts.User.xml b/data/org.freedesktop.Accounts.User.xml index 9065ce1..94ccd52 100644 --- a/data/org.freedesktop.Accounts.User.xml +++ b/data/org.freedesktop.Accounts.User.xml @@ -653,6 +653,16 @@ + + + + + The last login time. + + + + + diff --git a/src/daemon.c b/src/daemon.c index f7fdad0..b31d5da 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -219,6 +219,7 @@ entry_generator_wtmp (GHashTable *users, struct hash_data { int frequency; + gint64 time; GVariantBuilder *times; }; @@ -256,15 +257,17 @@ entry_generator_wtmp (GHashTable *users, &key, &value)) { data = g_new (struct hash_data, 1); data->frequency = 1; + data->time = wtmp_entry->ut_tv.tv_sec; data->times = g_variant_builder_new (G_VARIANT_TYPE ("ax")); - g_variant_builder_add (data->times, "x", (gint64)wtmp_entry->ut_tv.tv_sec); + g_variant_builder_add (data->times, "x", data->time); g_hash_table_insert (login_frequency_hash, g_strdup (wtmp_entry->ut_user), data); } else { data = value; data->frequency++; - g_variant_builder_add (data->times, "x", (gint64)wtmp_entry->ut_tv.tv_sec); + data->time = wtmp_entry->ut_tv.tv_sec; + g_variant_builder_add (data->times, "x", data->time); } return pwent; @@ -283,6 +286,7 @@ entry_generator_wtmp (GHashTable *users, } g_object_set (user, "login-frequency", data->frequency, NULL); + g_object_set (user, "login-time", data->time, NULL); g_object_set (user, "login-times", g_variant_new ("ax", data->times), NULL); g_variant_builder_unref (data->times); diff --git a/src/libaccountsservice/act-user.c b/src/libaccountsservice/act-user.c index 3611b51..1fb0b43 100644 --- a/src/libaccountsservice/act-user.c +++ b/src/libaccountsservice/act-user.c @@ -57,6 +57,7 @@ enum { PROP_SYSTEM_ACCOUNT, PROP_LOCAL_ACCOUNT, PROP_LOGIN_FREQUENCY, + PROP_LOGIN_TIME, PROP_LOGIN_TIMES, PROP_ICON_FILE, PROP_LANGUAGE, @@ -92,6 +93,7 @@ struct _ActUser { char *x_session; GList *sessions; int login_frequency; + gint64 login_time; GVariant *login_times; ActUserAccountType account_type; @@ -208,6 +210,9 @@ act_user_get_property (GObject *object, case PROP_LOGIN_FREQUENCY: g_value_set_int (value, user->login_frequency); break; + case PROP_LOGIN_TIME: + g_value_set_int64 (value, user->login_time); + break; case PROP_LOGIN_TIMES: g_value_set_variant (value, user->login_times); break; @@ -348,6 +353,15 @@ act_user_class_init (ActUserClass *class) 0, G_PARAM_READABLE)); g_object_class_install_property (gobject_class, + PROP_LOGIN_TIME, + g_param_spec_int64 ("login-time", + "Login time", + "The last login time for this user.", + 0, + G_MAXINT64, + 0, + G_PARAM_READABLE)); + g_object_class_install_property (gobject_class, PROP_LOGIN_TIMES, g_param_spec_variant ("login-times", "Login times", @@ -692,6 +706,21 @@ act_user_get_login_frequency (ActUser *user) } /** + * act_user_get_login_time: + * @user: a #ActUser + * + * Returns the last login time for @user. + * + * Returns: (transfer none): the login time + */ +gint64 +act_user_get_login_time (ActUser *user) { + g_return_val_if_fail (ACT_IS_USER (user), 0); + + return user->login_time; +} + +/** * act_user_get_login_times: * @user: a #ActUser * @@ -1067,6 +1096,13 @@ collect_props (const gchar *key, user->login_frequency = new_login_frequency; g_object_notify (G_OBJECT (user), "login-frequency"); } + } else if (strcmp (key, "LoginTime") == 0) { + gint64 new_login_time = value; + + if (user->login_time != new_login_time) { + user->login_time = new_login_time; + g_object_notify (G_OBJECT (user), "login-time"); + } } else if (strcmp (key, "LoginTimes") == 0) { GVariant *new_login_times = value; diff --git a/src/libaccountsservice/act-user.h b/src/libaccountsservice/act-user.h index bd30b20..4ed2780 100644 --- a/src/libaccountsservice/act-user.h +++ b/src/libaccountsservice/act-user.h @@ -66,6 +66,7 @@ const char *act_user_get_location (ActUser *user); guint act_user_get_num_sessions (ActUser *user); gboolean act_user_is_logged_in (ActUser *user); int act_user_get_login_frequency (ActUser *user); +gint64 act_user_get_login_time (ActUser *user); const GVariant*act_user_get_login_times (ActUser *user); gboolean act_user_get_locked (ActUser *user); gboolean act_user_get_automatic_login (ActUser *user); diff --git a/src/user.c b/src/user.c index 35c1de3..49b1885 100644 --- a/src/user.c +++ b/src/user.c @@ -59,6 +59,7 @@ enum { PROP_X_SESSION, PROP_LOCATION, PROP_LOGIN_FREQUENCY, + PROP_LOGIN_TIME, PROP_LOGIN_TIMES, PROP_ICON_FILE, PROP_LOCKED, @@ -91,6 +92,7 @@ struct User { gchar *x_session; gchar *location; guint64 login_frequency; + gint64 login_time; GVariant *login_times; gchar *icon_file; gchar *default_icon_file; @@ -1685,6 +1687,12 @@ user_real_get_login_frequency (AccountsUser *user) return USER (user)->login_frequency; } +static gint64 +user_real_get_login_time (AccountsUser *user) +{ + return USER (user)->login_time; +} + static const GVariant * user_real_get_login_times (AccountsUser *user) { @@ -1778,6 +1786,9 @@ user_set_property (GObject *object, case PROP_LOGIN_FREQUENCY: user->login_frequency = g_value_get_uint64 (value); break; + case PROP_LOGIN_TIME: + user->login_time = g_value_get_int64 (value); + break; case PROP_LOGIN_TIMES: user->login_times = g_variant_ref (g_value_get_variant (value)); break; @@ -1851,6 +1862,9 @@ user_get_property (GObject *object, case PROP_LOGIN_FREQUENCY: g_value_set_uint64 (value, user->login_frequency); break; + case PROP_LOGIN_TIME: + g_value_set_int64 (value, user->login_time); + break; case PROP_LOGIN_TIMES: g_value_set_variant (value, user->login_times); break; @@ -1914,6 +1928,7 @@ user_accounts_user_iface_init (AccountsUserIface *iface) iface->get_xsession = user_real_get_xsession; iface->get_location = user_real_get_location; iface->get_login_frequency = user_real_get_login_frequency; + iface->get_login_time = user_real_get_login_time; iface->get_login_times = user_real_get_login_times; iface->get_icon_file = user_real_get_icon_file; iface->get_locked = user_real_get_locked; -- 1.7.11.4