diff options
-rw-r--r-- | src/ck-session.c | 49 | ||||
-rw-r--r-- | src/ck-session.h | 5 | ||||
-rw-r--r-- | src/ck-session.xml | 7 | ||||
-rw-r--r-- | tools/list-sessions.c | 17 |
4 files changed, 76 insertions, 2 deletions
diff --git a/src/ck-session.c b/src/ck-session.c index 5f44bac..b028baa 100644 --- a/src/ck-session.c +++ b/src/ck-session.c @@ -58,7 +58,10 @@ struct CkSessionPrivate gboolean active; gboolean is_local; + GTimeVal creation_time; + gboolean idle; + GTimeVal idle_since; DBusGConnection *connection; DBusGProxy *bus_proxy; @@ -216,6 +219,10 @@ session_set_idle_internal (CkSession *session, { if (session->priv->idle != idle) { session->priv->idle = idle; + + /* FIXME: can we get a time from the dbus message? */ + g_get_current_time (&session->priv->idle_since); + ck_debug ("Emitting idle-changed for session %s", session->priv->id); g_signal_emit (session, signals [IDLE_CHANGED], 0); } @@ -223,6 +230,13 @@ session_set_idle_internal (CkSession *session, return TRUE; } +/* + Example: + dbus-send --system --dest=org.freedesktop.ConsoleKit \ + --type=method_call --print-reply --reply-timeout=2000 \ + /org/freedesktop/ConsoleKit/Session1 \ + org.freedesktop.ConsoleKit.Session.SetIdle boolean:TRUE +*/ gboolean ck_session_set_idle (CkSession *session, gboolean idle, @@ -283,6 +297,25 @@ ck_session_get_idle (CkSession *session, } gboolean +ck_session_get_idle_since (CkSession *session, + DBusGMethodInvocation *context) +{ + char *date_str; + + g_return_val_if_fail (CK_IS_SESSION (session), FALSE); + + date_str = NULL; + if (session->priv->idle) { + date_str = g_time_val_to_iso8601 (&session->priv->idle_since); + } + + dbus_g_method_return (context, date_str); + g_free (date_str); + + return TRUE; +} + +gboolean ck_session_activate (CkSession *session, DBusGMethodInvocation *context) { @@ -425,6 +458,20 @@ ck_session_get_host_name (CkSession *session, } gboolean +ck_session_get_creation_time (CkSession *session, + char **iso8601_datetime, + GError **error) +{ + g_return_val_if_fail (CK_IS_SESSION (session), FALSE); + + if (iso8601_datetime != NULL) { + *iso8601_datetime = g_time_val_to_iso8601 (&session->priv->creation_time); + } + + return TRUE; +} + +gboolean ck_session_get_session_type (CkSession *session, char **type, GError **error) @@ -808,6 +855,8 @@ ck_session_init (CkSession *session) { session->priv = CK_SESSION_GET_PRIVATE (session); + /* FIXME: should we have a property for this? */ + g_get_current_time (&session->priv->creation_time); } static void diff --git a/src/ck-session.h b/src/ck-session.h index e2f68bf..c0c1d22 100644 --- a/src/ck-session.h +++ b/src/ck-session.h @@ -135,10 +135,15 @@ gboolean ck_session_get_session_type (CkSession *sessi gboolean ck_session_get_host_name (CkSession *session, char **host_name, GError **error); +gboolean ck_session_get_creation_time (CkSession *session, + char **iso8601_datetime, + GError **error); /* Non-authoritative properties */ gboolean ck_session_get_idle (CkSession *session, DBusGMethodInvocation *context); +gboolean ck_session_get_idle_since (CkSession *session, + DBusGMethodInvocation *context); gboolean ck_session_set_idle (CkSession *session, gboolean idle, DBusGMethodInvocation *context); diff --git a/src/ck-session.xml b/src/ck-session.xml index f3faae1..e1102fb 100644 --- a/src/ck-session.xml +++ b/src/ck-session.xml @@ -30,6 +30,9 @@ <method name="IsLocal"> <arg name="local" direction="out" type="b"/> </method> + <method name="GetCreationTime"> + <arg name="iso8601_datetime" type="s" direction="out"/> + </method> <method name="Activate"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> @@ -45,6 +48,10 @@ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="idle" type="b" direction="out"/> </method> + <method name="GetIdleSince"> + <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> + <arg name="iso8601_datetime" type="s" direction="out"/> + </method> <method name="SetIdle"> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <arg name="idle" type="b" direction="in"/> diff --git a/tools/list-sessions.c b/tools/list-sessions.c index 7fcb76e..e386b15 100644 --- a/tools/list-sessions.c +++ b/tools/list-sessions.c @@ -167,6 +167,8 @@ list_session (DBusGConnection *connection, char *xdisplay; char *display_device; char *host_name; + char *creation_time; + char *idle_since; gboolean is_active; gboolean is_local; char *short_sid; @@ -184,6 +186,8 @@ list_session (DBusGConnection *connection, session_type = NULL; xdisplay = NULL; host_name = NULL; + creation_time = NULL; + idle_since = NULL; get_int (proxy, "GetUser", &uid); get_path (proxy, "GetSeatId", &sid); @@ -193,6 +197,8 @@ list_session (DBusGConnection *connection, get_string (proxy, "GetHostName", &host_name); get_boolean (proxy, "IsActive", &is_active); get_boolean (proxy, "IsLocal", &is_local); + get_string (proxy, "GetCreationTime", &creation_time); + get_string (proxy, "GetIdleSince", &idle_since); realname = get_real_name (uid); @@ -206,9 +212,16 @@ list_session (DBusGConnection *connection, short_ssid = ssid + strlen (CK_PATH) + 1; } - printf ("uid='%d' realname='%s' seat='%s' session='%s' session-type='%s' active=%s x11-display='%s' display-device='%s' host-name='%s' is-local=%s\n", - uid, realname, short_sid, short_ssid, session_type, is_active ? "TRUE" : "FALSE", xdisplay, display_device, host_name, is_local ? "TRUE" : "FALSE"); + printf ("uid='%d' realname='%s' seat='%s' session='%s' session-type='%s' active=%s x11-display='%s' display-device='%s' host-name='%s' is-local=%s on-since='%s'", + uid, realname, short_sid, short_ssid, session_type, is_active ? "TRUE" : "FALSE", xdisplay, display_device, host_name, is_local ? "TRUE" : "FALSE", creation_time); + if (idle_since != NULL && idle_since[0] != '\0') { + printf (" idle-since='%s'", idle_since); + } + printf ("\n"); + g_free (idle_since); + g_free (creation_time); + g_free (host_name); g_free (realname); g_free (sid); g_free (session_type); |