From ac1164a3fa6f4c388399af06612e16eade16e46b Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 29 Sep 2015 21:51:04 +0100 Subject: [PATCH 1/2] Use more specific messages for last activity responses --- src/event/server_events.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index ea181865..74e5cf75 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -740,15 +740,39 @@ sv_ev_lastactivity_response(const char * const from, const int seconds, const ch return; } - // full jid or bare jid - if (jidp->resourcepart || jidp->localpart) { - if (msg) { - cons_show("%s last active %d seconds ago, status: %s", from, seconds, msg); + // full jid - last activity + if (jidp->resourcepart) { + if (seconds == 0) { + if (msg) { + cons_show("%s currently active, status: %s", from, msg); + } else { + cons_show("%s currently active.", from); + } } else { - cons_show("%s last active %d seconds ago.", from, seconds); + if (msg) { + cons_show("%s last active %d seconds ago, status: %s", from, seconds, msg); + } else { + cons_show("%s last active %d seconds ago.", from, seconds); + } } - // domain only + // barejid - last logged in + } else if (jidp->localpart) { + if (seconds == 0) { + if (msg) { + cons_show("%s currently logged in, status: %s", from, msg); + } else { + cons_show("%s currently loggrd in.", from); + } + } else { + if (msg) { + cons_show("%s last logged in %d seconds ago, status: %s", from, seconds, msg); + } else { + cons_show("%s last logged in %d seconds ago.", from, seconds); + } + } + + // domain only - uptime } else { cons_show("%s uptime %d seconds", from, seconds); } From 99fc70bd9283280bdb6056634c759196f549a4c6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 29 Sep 2015 23:30:23 +0100 Subject: [PATCH 2/2] Added last activity time format option --- src/command/command.c | 21 +++++++++++++++------ src/command/commands.c | 19 ++++++++++++++++++- src/config/preferences.c | 5 +++++ src/config/preferences.h | 1 + src/config/theme.c | 1 + src/event/server_events.c | 36 +++++++++++++++++++++++++++++------- src/ui/console.c | 4 ++++ src/ui/window.c | 21 +++++++-------------- themes/boothj5 | 1 + 9 files changed, 81 insertions(+), 28 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 603b0f12..2203b398 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -950,7 +950,8 @@ static struct cmd_t command_defs[] = "/time main set ", "/time main off", "/time statusbar set ", - "/time statusbar off") + "/time statusbar off", + "/time lastactivity set ") CMD_DESC( "Configure time display preferences. " "Time formats are strings supported by g_date_time_format. " @@ -958,14 +959,16 @@ static struct cmd_t command_defs[] = "Setting the format to an unsupported string, will display the string. " "If the format contains spaces, it must be surrounded with double quotes.") CMD_ARGS( - { "main set ", "Change time format in main window." }, - { "main off", "Do not show time in main window." }, - { "statusbar set ", "Change time format in statusbar." }, - { "statusbar off", "Change time format in status bar." }) + { "main set ", "Change time format in main window." }, + { "main off", "Do not show time in main window." }, + { "statusbar set ", "Change time format in statusbar." }, + { "statusbar off", "Do not show time in status bar." }, + { "lastactivity set ", "Change time format for last activity." }) CMD_EXAMPLES( "/time main set \"%d-%m-%y %H:%M\"", "/time main off", - "/time statusbar set %H:%M") + "/time statusbar set %H:%M", + "/time lastactivity set \"%d-%m-%y %H:%M\"") }, { "/inpblock", @@ -2098,6 +2101,7 @@ cmd_init(void) time_ac = autocomplete_new(); autocomplete_add(time_ac, "main"); autocomplete_add(time_ac, "statusbar"); + autocomplete_add(time_ac, "lastactivity"); time_format_ac = autocomplete_new(); autocomplete_add(time_format_ac, "set"); @@ -3367,6 +3371,11 @@ _time_autocomplete(ProfWin *window, const char * const input) return found; } + found = autocomplete_param_with_ac(input, "/time lastactivity", time_format_ac, TRUE); + if (found) { + return found; + } + found = autocomplete_param_with_ac(input, "/time main", time_format_ac, TRUE); if (found) { return found; diff --git a/src/command/commands.c b/src/command/commands.c index 6b301057..2e4332b2 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3569,7 +3569,24 @@ cmd_wrap(ProfWin *window, const char * const command, gchar **args) gboolean cmd_time(ProfWin *window, const char * const command, gchar **args) { - if (g_strcmp0(args[0], "statusbar") == 0) { + if (g_strcmp0(args[0], "lastactivity") == 0) { + if (args[1] == NULL) { + cons_show("Current last activity time format is '%s'.", prefs_get_string(PREF_TIME_LASTACTIVITY)); + return TRUE; + } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { + prefs_set_string(PREF_TIME_LASTACTIVITY, args[2]); + cons_show("Last activity time format set to '%s'.", args[2]); + ui_redraw(); + return TRUE; + } else if (g_strcmp0(args[1], "off") == 0) { + cons_show("Last activity time cannot be disabled."); + ui_redraw(); + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } + } else if (g_strcmp0(args[0], "statusbar") == 0) { if (args[1] == NULL) { cons_show("Current status bar time format is '%s'.", prefs_get_string(PREF_TIME_STATUSBAR)); return TRUE; diff --git a/src/config/preferences.c b/src/config/preferences.c index e594e9f6..c53c09bc 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -602,6 +602,7 @@ _get_group(preference_t pref) case PREF_WINS_AUTO_TIDY: case PREF_TIME: case PREF_TIME_STATUSBAR: + case PREF_TIME_LASTACTIVITY: case PREF_ROSTER: case PREF_ROSTER_OFFLINE: case PREF_ROSTER_RESOURCE: @@ -756,6 +757,8 @@ _get_key(preference_t pref) return "time"; case PREF_TIME_STATUSBAR: return "time.statusbar"; + case PREF_TIME_LASTACTIVITY: + return "time.lastactivity"; case PREF_ROSTER: return "roster"; case PREF_ROSTER_OFFLINE: @@ -845,6 +848,8 @@ _get_default_string(preference_t pref) return "%H:%M:%S"; case PREF_TIME_STATUSBAR: return "%H:%M"; + case PREF_TIME_LASTACTIVITY: + return "%d-%m-%y %H:%M:%S"; case PREF_PGP_LOG: return "redact"; default: diff --git a/src/config/preferences.h b/src/config/preferences.h index 1879c7d3..875db253 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -72,6 +72,7 @@ typedef enum { PREF_WINS_AUTO_TIDY, PREF_TIME, PREF_TIME_STATUSBAR, + PREF_TIME_LASTACTIVITY, PREF_STATUSES, PREF_STATUSES_CONSOLE, PREF_STATUSES_CHAT, diff --git a/src/config/theme.c b/src/config/theme.c index c4b25c73..588a3a42 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -434,6 +434,7 @@ _load_preferences(void) _set_boolean_preference("wins.autotidy", PREF_WINS_AUTO_TIDY); _set_string_preference("time", PREF_TIME); _set_string_preference("time.statusbar", PREF_TIME_STATUSBAR); + _set_string_preference("time.lastactivity", PREF_TIME_LASTACTIVITY); _set_boolean_preference("resource.title", PREF_RESOURCE_TITLE); _set_boolean_preference("resource.message", PREF_RESOURCE_MESSAGE); diff --git a/src/event/server_events.c b/src/event/server_events.c index 74e5cf75..91e1ca7b 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -34,6 +34,7 @@ #include #include +#include #include "config.h" @@ -740,19 +741,28 @@ sv_ev_lastactivity_response(const char * const from, const int seconds, const ch return; } + GDateTime *now = g_date_time_new_now_local(); + GDateTime *active = g_date_time_add_seconds(now, 0 - seconds); + + gchar *date_fmt = NULL; + char *time_pref = prefs_get_string(PREF_TIME_LASTACTIVITY); + date_fmt = g_date_time_format(active, time_pref); + prefs_free_string(time_pref); + assert(date_fmt != NULL); + // full jid - last activity if (jidp->resourcepart) { if (seconds == 0) { if (msg) { cons_show("%s currently active, status: %s", from, msg); } else { - cons_show("%s currently active.", from); + cons_show("%s currently active", from); } } else { if (msg) { - cons_show("%s last active %d seconds ago, status: %s", from, seconds, msg); + cons_show("%s last active %s, status: %s", from, date_fmt, msg); } else { - cons_show("%s last active %d seconds ago.", from, seconds); + cons_show("%s last active %s", from, date_fmt); } } @@ -762,20 +772,32 @@ sv_ev_lastactivity_response(const char * const from, const int seconds, const ch if (msg) { cons_show("%s currently logged in, status: %s", from, msg); } else { - cons_show("%s currently loggrd in.", from); + cons_show("%s currently loggrd in", from); } } else { if (msg) { - cons_show("%s last logged in %d seconds ago, status: %s", from, seconds, msg); + cons_show("%s last logged in %s, status: %s", from, date_fmt, msg); } else { - cons_show("%s last logged in %d seconds ago.", from, seconds); + cons_show("%s last logged in %s", from, date_fmt); } } // domain only - uptime } else { - cons_show("%s uptime %d seconds", from, seconds); + int left = seconds; + int days = seconds / 86400; + left = left - days * 86400; + int hours = left / 3600; + left = left - hours * 3600; + int minutes = left / 60; + left = left - minutes * 60; + int seconds = left; + + cons_show("%s up since %s, uptime %d days, %d hrs, %d mins, %d secs", from, date_fmt, days, hours, minutes, seconds); } + g_date_time_unref(now); + g_date_time_unref(active); + g_free(date_fmt); jid_destroy(jidp); } diff --git a/src/ui/console.c b/src/ui/console.c index 666f7015..1bbaac38 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1010,6 +1010,10 @@ cons_time_setting(void) else cons_show("Time statusbar (/time) : %s", pref_time_statusbar); prefs_free_string(pref_time_statusbar); + + char *pref_time_lastactivity = prefs_get_string(PREF_TIME_LASTACTIVITY); + cons_show("Time last activity (/time) : %s", pref_time_lastactivity); + prefs_free_string(pref_time_lastactivity); } void diff --git a/src/ui/window.c b/src/ui/window.c index a78b0e15..5a2196f2 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -852,22 +852,15 @@ win_show_status_string(ProfWin *window, const char * const from, win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", " is %s", default_show); if (last_activity) { - GDateTime *now = g_date_time_new_now_local(); - GTimeSpan span = g_date_time_difference(now, last_activity); - g_date_time_unref(now); + gchar *date_fmt = NULL; + char *time_pref = prefs_get_string(PREF_TIME_LASTACTIVITY); + date_fmt = g_date_time_format(last_activity, time_pref); + prefs_free_string(time_pref); + assert(date_fmt != NULL); - int hours = span / G_TIME_SPAN_HOUR; - span = span - hours * G_TIME_SPAN_HOUR; - int minutes = span / G_TIME_SPAN_MINUTE; - span = span - minutes * G_TIME_SPAN_MINUTE; - int seconds = span / G_TIME_SPAN_SECOND; + win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", last activity: %s", date_fmt); - if (hours > 0) { - win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dh%dm%ds", hours, minutes, seconds); - } - else { - win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, presence_colour, "", ", idle %dm%ds", minutes, seconds); - } + g_free(date_fmt); } if (status) diff --git a/themes/boothj5 b/themes/boothj5 index a408d3b5..dfbb0192 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -56,6 +56,7 @@ splash=true wrap=true time=%d-%m-%y %H:%M time.statusbar=%H:%M:%S +time.lastactivity=%d/%m/%y %H:%M:%S privileges=true presence=true intype=true