1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into osx-functional

This commit is contained in:
James Booth 2015-09-29 23:30:59 +01:00
commit 2a30e342d7
9 changed files with 105 additions and 28 deletions

View File

@ -950,7 +950,8 @@ static struct cmd_t command_defs[] =
"/time main set <format>",
"/time main off",
"/time statusbar set <format>",
"/time statusbar off")
"/time statusbar off",
"/time lastactivity set <format>")
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 <format>", "Change time format in main window." },
{ "main off", "Do not show time in main window." },
{ "statusbar set <format>", "Change time format in statusbar." },
{ "statusbar off", "Change time format in status bar." })
{ "main set <format>", "Change time format in main window." },
{ "main off", "Do not show time in main window." },
{ "statusbar set <format>", "Change time format in statusbar." },
{ "statusbar off", "Do not show time in status bar." },
{ "lastactivity set <format>", "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;

View File

@ -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;

View File

@ -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:

View File

@ -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,

View File

@ -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);

View File

@ -34,6 +34,7 @@
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "config.h"
@ -740,18 +741,63 @@ 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);
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);
}
} else {
cons_show("%s last active %d seconds ago.", from, seconds);
if (msg) {
cons_show("%s last active %s, status: %s", from, date_fmt, msg);
} else {
cons_show("%s last active %s", from, date_fmt);
}
}
// 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 %s, status: %s", from, date_fmt, msg);
} else {
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);
}

View File

@ -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

View File

@ -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)

View File

@ -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