user-accounts: Add last login field
https://bugzilla.gnome.org/show_bug.cgi?id=681772
This commit is contained in:
parent
ff186736dc
commit
691a258232
6 changed files with 132 additions and 1 deletions
|
@ -437,6 +437,41 @@
|
|||
<property name="height">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="last-login-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">Last Login</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="mnemonic_widget">last-login-value-label</property>
|
||||
<style>
|
||||
<class name="dim-label"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">7</property>
|
||||
<property name="width">1</property>
|
||||
<property name="height">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="last-login-value-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">6</property>
|
||||
<property name="margin_top">6</property>
|
||||
<property name="margin_bottom">6</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">7</property>
|
||||
<property name="width">1</property>
|
||||
<property name="height">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
|
|
@ -553,6 +553,35 @@ autologin_changed (GObject *object,
|
|||
g_object_unref (user);
|
||||
}
|
||||
|
||||
static gchar *
|
||||
get_login_time_text (UmUser *user)
|
||||
{
|
||||
gchar *text, *date_str, *time_str;
|
||||
GDateTime *date_time;
|
||||
gint64 time;
|
||||
|
||||
time = um_user_get_login_time (user);
|
||||
if (um_user_is_logged_in (user)) {
|
||||
text = g_strdup (_("Logged in"));
|
||||
}
|
||||
else if (time > 0) {
|
||||
date_time = g_date_time_new_from_unix_local (time);
|
||||
date_str = get_smart_date (date_time);
|
||||
time_str = g_date_time_format (date_time, "%k:%M");
|
||||
|
||||
text = g_strconcat (date_str, ", ", time_str, NULL);
|
||||
|
||||
g_date_time_unref (date_time);
|
||||
g_free (date_str);
|
||||
g_free (time_str);
|
||||
}
|
||||
else {
|
||||
text = g_strdup ("—");
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
static void
|
||||
show_user (UmUser *user, UmUserPanelPrivate *d)
|
||||
{
|
||||
|
@ -561,11 +590,12 @@ show_user (UmUser *user, UmUserPanelPrivate *d)
|
|||
GtkWidget *label2;
|
||||
GtkWidget *label3;
|
||||
GdkPixbuf *pixbuf;
|
||||
gchar *lang;
|
||||
gchar *lang, *text;
|
||||
GtkWidget *widget;
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
gboolean show, enable;
|
||||
UmUser *current;
|
||||
|
||||
pixbuf = um_user_render_icon (user, UM_ICON_STYLE_NONE, 48);
|
||||
image = get_widget (d, "user-icon-image");
|
||||
|
@ -624,6 +654,21 @@ show_user (UmUser *user, UmUserPanelPrivate *d)
|
|||
show = um_user_is_local_account (user);
|
||||
gtk_widget_set_visible (widget, show);
|
||||
gtk_widget_set_visible (label, show);
|
||||
|
||||
/* Last login: show when administrator or current user */
|
||||
widget = get_widget (d, "last-login-value-label");
|
||||
label = get_widget (d, "last-login-label");
|
||||
|
||||
current = um_user_manager_get_user_by_id (d->um, getuid ());
|
||||
show = um_user_get_uid (user) == getuid () ||
|
||||
um_user_get_account_type (current) == UM_ACCOUNT_TYPE_ADMINISTRATOR;
|
||||
if (show) {
|
||||
text = get_login_time_text (user);
|
||||
gtk_label_set_text (GTK_LABEL (widget), text);
|
||||
g_free (text);
|
||||
}
|
||||
gtk_widget_set_visible (widget, show);
|
||||
gtk_widget_set_visible (label, show);
|
||||
}
|
||||
|
||||
static void on_permission_changed (GPermission *permission, GParamSpec *pspec, gpointer data);
|
||||
|
|
|
@ -60,6 +60,7 @@ typedef struct {
|
|||
gchar *language;
|
||||
gchar *location;
|
||||
guint64 login_frequency;
|
||||
gint64 login_time;
|
||||
gchar *icon_file;
|
||||
gboolean locked;
|
||||
gboolean automatic_login;
|
||||
|
@ -138,6 +139,9 @@ user_properties_get (GDBusConnection *bus,
|
|||
else if (strcmp (key, "LoginFrequency") == 0) {
|
||||
g_variant_get (value, "t", &props->login_frequency);
|
||||
}
|
||||
else if (strcmp (key, "LoginTime") == 0) {
|
||||
g_variant_get (value, "x", &props->login_time);
|
||||
}
|
||||
else if (strcmp (key, "IconFile") == 0) {
|
||||
g_variant_get (value, "s", &props->icon_file);
|
||||
}
|
||||
|
@ -304,6 +308,14 @@ um_user_get_login_frequency (UmUser *user)
|
|||
return user->props->login_frequency;
|
||||
}
|
||||
|
||||
gint64
|
||||
um_user_get_login_time (UmUser *user)
|
||||
{
|
||||
g_return_val_if_fail (UM_IS_USER (user), 0);
|
||||
|
||||
return user->props->login_time;
|
||||
}
|
||||
|
||||
gint
|
||||
um_user_collate (UmUser *user1,
|
||||
UmUser *user2)
|
||||
|
|
|
@ -69,6 +69,7 @@ const gchar *um_user_get_location (UmUser *user);
|
|||
const gchar *um_user_get_home_directory (UmUser *user);
|
||||
const gchar *um_user_get_shell (UmUser *user);
|
||||
gulong um_user_get_login_frequency (UmUser *user);
|
||||
gint64 um_user_get_login_time (UmUser *user);
|
||||
gint um_user_get_password_mode (UmUser *user);
|
||||
const gchar *um_user_get_password_hint (UmUser *user);
|
||||
const gchar *um_user_get_icon_file (UmUser *user);
|
||||
|
|
|
@ -746,3 +746,39 @@ generate_username_choices (const gchar *name,
|
|||
g_string_free (item3, TRUE);
|
||||
g_string_free (item4, TRUE);
|
||||
}
|
||||
|
||||
gchar *
|
||||
get_smart_date (GDateTime *date)
|
||||
{
|
||||
gchar *label;
|
||||
GDateTime *today, *local;
|
||||
GTimeSpan span;
|
||||
|
||||
/* Set today date */
|
||||
local = g_date_time_new_now_local ();
|
||||
today = g_date_time_new_local (g_date_time_get_year (local),
|
||||
g_date_time_get_month (local),
|
||||
g_date_time_get_day_of_month (local),
|
||||
0, 0, 0);
|
||||
|
||||
span = g_date_time_difference (today, date);
|
||||
if (span <= 0) {
|
||||
label = g_strdup (_("Today"));
|
||||
}
|
||||
else if (span <= G_TIME_SPAN_DAY) {
|
||||
label = g_strdup (_("Yesterday"));
|
||||
}
|
||||
else {
|
||||
if (g_date_time_get_year (date) == g_date_time_get_year (today)) {
|
||||
label = g_date_time_format (date, "%b %e");
|
||||
}
|
||||
else {
|
||||
label = g_date_time_format (date, "%b %e, %Y");
|
||||
}
|
||||
}
|
||||
|
||||
g_date_time_unref (local);
|
||||
g_date_time_unref (today);
|
||||
|
||||
return label;
|
||||
}
|
||||
|
|
|
@ -65,6 +65,8 @@ gboolean is_valid_username (const gchar *name,
|
|||
void generate_username_choices (const gchar *name,
|
||||
GtkListStore *store);
|
||||
|
||||
gchar * get_smart_date (GDateTime *date);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue