mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Merge remote-tracking branch 'incertia/time'
Conflicts: src/config/preferences.c
This commit is contained in:
commit
106e909fbd
@ -701,18 +701,21 @@ static struct cmd_t command_defs[] =
|
|||||||
NULL } } },
|
NULL } } },
|
||||||
|
|
||||||
{ "/time",
|
{ "/time",
|
||||||
cmd_time, parse_args, 1, 2, &cons_time_setting,
|
cmd_time, parse_args, 1, 3, &cons_time_setting,
|
||||||
{ "/time setting|statusbar [setting]", "Time display.",
|
{ "/time main|statusbar set|off [format]", "Time display.",
|
||||||
{ "/time setting|statusbar [setting]",
|
{ "/time main|statusbar set|off [format]",
|
||||||
"---------------------------------",
|
"-------------------------------------",
|
||||||
"Configure time display preferences.",
|
"Configure time display preferences.",
|
||||||
"",
|
"",
|
||||||
"minutes : Use minutes precision in main window.",
|
"main set <format> : Change time format to <format> in main window.",
|
||||||
"seconds : Use seconds precision in main window.",
|
"main off : Do not show time in main window.",
|
||||||
"off : Do not show time in main window.",
|
"statusbar set <format> : Change time format to <format> in statusbar.",
|
||||||
"statusbar minutes : Show minutes precision in status bar.",
|
|
||||||
"statusbar seconds : Show seconds precision in status bar.",
|
|
||||||
"statusbar off : Do not show time in status bar.",
|
"statusbar off : Do not show time in status bar.",
|
||||||
|
"",
|
||||||
|
"Time formats are strings supported by g_date_time_format.",
|
||||||
|
"See https://developer.gnome.org/glib/stable/glib-GDateTime.html#g-date-time-format for more details.",
|
||||||
|
"Example: /time main set %H:%M (main time will be set to HH:MM)",
|
||||||
|
"Example: /time statusbar set yolo (statusbar time will all be changed to a static yolo)",
|
||||||
NULL } } },
|
NULL } } },
|
||||||
|
|
||||||
{ "/inpblock",
|
{ "/inpblock",
|
||||||
@ -1235,7 +1238,7 @@ static Autocomplete occupants_ac;
|
|||||||
static Autocomplete occupants_default_ac;
|
static Autocomplete occupants_default_ac;
|
||||||
static Autocomplete occupants_show_ac;
|
static Autocomplete occupants_show_ac;
|
||||||
static Autocomplete time_ac;
|
static Autocomplete time_ac;
|
||||||
static Autocomplete time_statusbar_ac;
|
static Autocomplete time_format_ac;
|
||||||
static Autocomplete resource_ac;
|
static Autocomplete resource_ac;
|
||||||
static Autocomplete inpblock_ac;
|
static Autocomplete inpblock_ac;
|
||||||
static Autocomplete receipts_ac;
|
static Autocomplete receipts_ac;
|
||||||
@ -1585,15 +1588,12 @@ cmd_init(void)
|
|||||||
autocomplete_add(occupants_show_ac, "jid");
|
autocomplete_add(occupants_show_ac, "jid");
|
||||||
|
|
||||||
time_ac = autocomplete_new();
|
time_ac = autocomplete_new();
|
||||||
autocomplete_add(time_ac, "minutes");
|
autocomplete_add(time_ac, "main");
|
||||||
autocomplete_add(time_ac, "seconds");
|
|
||||||
autocomplete_add(time_ac, "off");
|
|
||||||
autocomplete_add(time_ac, "statusbar");
|
autocomplete_add(time_ac, "statusbar");
|
||||||
|
|
||||||
time_statusbar_ac = autocomplete_new();
|
time_format_ac = autocomplete_new();
|
||||||
autocomplete_add(time_statusbar_ac, "minutes");
|
autocomplete_add(time_format_ac, "set");
|
||||||
autocomplete_add(time_statusbar_ac, "seconds");
|
autocomplete_add(time_format_ac, "off");
|
||||||
autocomplete_add(time_statusbar_ac, "off");
|
|
||||||
|
|
||||||
resource_ac = autocomplete_new();
|
resource_ac = autocomplete_new();
|
||||||
autocomplete_add(resource_ac, "set");
|
autocomplete_add(resource_ac, "set");
|
||||||
@ -1677,7 +1677,7 @@ cmd_uninit(void)
|
|||||||
autocomplete_free(occupants_default_ac);
|
autocomplete_free(occupants_default_ac);
|
||||||
autocomplete_free(occupants_show_ac);
|
autocomplete_free(occupants_show_ac);
|
||||||
autocomplete_free(time_ac);
|
autocomplete_free(time_ac);
|
||||||
autocomplete_free(time_statusbar_ac);
|
autocomplete_free(time_format_ac);
|
||||||
autocomplete_free(resource_ac);
|
autocomplete_free(resource_ac);
|
||||||
autocomplete_free(inpblock_ac);
|
autocomplete_free(inpblock_ac);
|
||||||
autocomplete_free(receipts_ac);
|
autocomplete_free(receipts_ac);
|
||||||
@ -1851,7 +1851,7 @@ cmd_reset_autocomplete(ProfWin *window)
|
|||||||
autocomplete_reset(occupants_default_ac);
|
autocomplete_reset(occupants_default_ac);
|
||||||
autocomplete_reset(occupants_show_ac);
|
autocomplete_reset(occupants_show_ac);
|
||||||
autocomplete_reset(time_ac);
|
autocomplete_reset(time_ac);
|
||||||
autocomplete_reset(time_statusbar_ac);
|
autocomplete_reset(time_format_ac);
|
||||||
autocomplete_reset(resource_ac);
|
autocomplete_reset(resource_ac);
|
||||||
autocomplete_reset(inpblock_ac);
|
autocomplete_reset(inpblock_ac);
|
||||||
autocomplete_reset(receipts_ac);
|
autocomplete_reset(receipts_ac);
|
||||||
@ -2763,7 +2763,12 @@ _time_autocomplete(ProfWin *window, const char * const input)
|
|||||||
{
|
{
|
||||||
char *found = NULL;
|
char *found = NULL;
|
||||||
|
|
||||||
found = autocomplete_param_with_ac(input, "/time statusbar", time_statusbar_ac, TRUE);
|
found = autocomplete_param_with_ac(input, "/time statusbar", time_format_ac, TRUE);
|
||||||
|
if (found) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
found = autocomplete_param_with_ac(input, "/time main", time_format_ac, TRUE);
|
||||||
if (found) {
|
if (found) {
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
@ -3407,18 +3407,16 @@ gboolean
|
|||||||
cmd_time(ProfWin *window, gchar **args, struct cmd_help_t help)
|
cmd_time(ProfWin *window, gchar **args, struct cmd_help_t help)
|
||||||
{
|
{
|
||||||
if (g_strcmp0(args[0], "statusbar") == 0) {
|
if (g_strcmp0(args[0], "statusbar") == 0) {
|
||||||
if (g_strcmp0(args[1], "minutes") == 0) {
|
if (args[1] == NULL) {
|
||||||
prefs_set_string(PREF_TIME_STATUSBAR, "minutes");
|
cons_show("Current status bar time format is '%s'.", prefs_get_string(PREF_TIME_STATUSBAR));
|
||||||
cons_show("Status bar time precision set to minutes.");
|
|
||||||
ui_redraw();
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (g_strcmp0(args[1], "seconds") == 0) {
|
} else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
|
||||||
prefs_set_string(PREF_TIME_STATUSBAR, "seconds");
|
prefs_set_string(PREF_TIME_STATUSBAR, args[2]);
|
||||||
cons_show("Status bar time precision set to seconds.");
|
cons_show("Status bar time format set to '%s'.", args[2]);
|
||||||
ui_redraw();
|
ui_redraw();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (g_strcmp0(args[1], "off") == 0) {
|
} else if (g_strcmp0(args[1], "off") == 0) {
|
||||||
prefs_set_string(PREF_TIME_STATUSBAR, "off");
|
prefs_set_string(PREF_TIME_STATUSBAR, "");
|
||||||
cons_show("Status bar time display disabled.");
|
cons_show("Status bar time display disabled.");
|
||||||
ui_redraw();
|
ui_redraw();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -3426,19 +3424,17 @@ cmd_time(ProfWin *window, gchar **args, struct cmd_help_t help)
|
|||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (g_strcmp0(args[0], "main") == 0) {
|
||||||
if (g_strcmp0(args[0], "minutes") == 0) {
|
if (args[1] == NULL) {
|
||||||
prefs_set_string(PREF_TIME, "minutes");
|
cons_show("Current time format is '%s'.", prefs_get_string(PREF_TIME));
|
||||||
cons_show("Time precision set to minutes.");
|
return TRUE;
|
||||||
|
} else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) {
|
||||||
|
prefs_set_string(PREF_TIME, args[2]);
|
||||||
|
cons_show("Time format set to '%s'.", args[2]);
|
||||||
wins_resize_all();
|
wins_resize_all();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (g_strcmp0(args[0], "seconds") == 0) {
|
} else if (g_strcmp0(args[1], "off") == 0) {
|
||||||
prefs_set_string(PREF_TIME, "seconds");
|
prefs_set_string(PREF_TIME, "");
|
||||||
cons_show("Time precision set to seconds.");
|
|
||||||
wins_resize_all();
|
|
||||||
return TRUE;
|
|
||||||
} else if (g_strcmp0(args[0], "off") == 0) {
|
|
||||||
prefs_set_string(PREF_TIME, "off");
|
|
||||||
cons_show("Time display disabled.");
|
cons_show("Time display disabled.");
|
||||||
wins_resize_all();
|
wins_resize_all();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -3446,6 +3442,9 @@ cmd_time(ProfWin *window, gchar **args, struct cmd_help_t help)
|
|||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
cons_show("Usage: %s", help.usage);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -725,9 +725,9 @@ _get_default_string(preference_t pref)
|
|||||||
case PREF_ROSTER_BY:
|
case PREF_ROSTER_BY:
|
||||||
return "presence";
|
return "presence";
|
||||||
case PREF_TIME:
|
case PREF_TIME:
|
||||||
return "seconds";
|
return "%H:%M:%S";
|
||||||
case PREF_TIME_STATUSBAR:
|
case PREF_TIME_STATUSBAR:
|
||||||
return "minutes";
|
return "%H:%M";
|
||||||
case PREF_PGP_LOG:
|
case PREF_PGP_LOG:
|
||||||
return "redact";
|
return "redact";
|
||||||
default:
|
default:
|
||||||
|
@ -954,12 +954,10 @@ void
|
|||||||
cons_time_setting(void)
|
cons_time_setting(void)
|
||||||
{
|
{
|
||||||
char *pref_time = prefs_get_string(PREF_TIME);
|
char *pref_time = prefs_get_string(PREF_TIME);
|
||||||
if (g_strcmp0(pref_time, "minutes") == 0)
|
if (g_strcmp0(pref_time, "off") == 0)
|
||||||
cons_show("Time (/time) : minutes");
|
|
||||||
else if (g_strcmp0(pref_time, "off") == 0)
|
|
||||||
cons_show("Time (/time) : OFF");
|
cons_show("Time (/time) : OFF");
|
||||||
else
|
else
|
||||||
cons_show("Time (/time) : seconds");
|
cons_show("Time (/time) : %s", pref_time);
|
||||||
|
|
||||||
prefs_free_string(pref_time);
|
prefs_free_string(pref_time);
|
||||||
|
|
||||||
|
@ -129,10 +129,14 @@ status_bar_resize(void)
|
|||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
|
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
|
||||||
if (g_strcmp0(time_pref, "minutes") == 0) {
|
gchar *date_fmt = g_date_time_format(last_time, time_pref);
|
||||||
mvwprintw(status_bar, 0, 10, message);
|
assert(date_fmt != NULL);
|
||||||
} else if (g_strcmp0(time_pref, "seconds") == 0) {
|
size_t len = strlen(date_fmt);
|
||||||
mvwprintw(status_bar, 0, 13, message);
|
g_free(date_fmt);
|
||||||
|
if (g_strcmp0(time_pref, "") != 0) {
|
||||||
|
/* 01234567890123456
|
||||||
|
* [HH:MM] message */
|
||||||
|
mvwprintw(status_bar, 0, 5 + len, message);
|
||||||
} else {
|
} else {
|
||||||
mvwprintw(status_bar, 0, 1, message);
|
mvwprintw(status_bar, 0, 1, message);
|
||||||
}
|
}
|
||||||
@ -304,10 +308,12 @@ status_bar_print_message(const char * const msg)
|
|||||||
message = strdup(msg);
|
message = strdup(msg);
|
||||||
|
|
||||||
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
|
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
|
||||||
if (g_strcmp0(time_pref, "minutes") == 0) {
|
gchar *date_fmt = g_date_time_format(last_time, time_pref);
|
||||||
mvwprintw(status_bar, 0, 10, message);
|
assert(date_fmt != NULL);
|
||||||
} else if (g_strcmp0(time_pref, "seconds") == 0) {
|
size_t len = strlen(date_fmt);
|
||||||
mvwprintw(status_bar, 0, 13, message);
|
g_free(date_fmt);
|
||||||
|
if (g_strcmp0(time_pref, "") != 0) {
|
||||||
|
mvwprintw(status_bar, 0, 5 + len, message);
|
||||||
} else {
|
} else {
|
||||||
mvwprintw(status_bar, 0, 1, message);
|
mvwprintw(status_bar, 0, 1, message);
|
||||||
}
|
}
|
||||||
@ -438,26 +444,16 @@ _status_bar_draw(void)
|
|||||||
int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);
|
int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);
|
||||||
|
|
||||||
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
|
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
|
||||||
if (g_strcmp0(time_pref, "minutes") == 0) {
|
if (g_strcmp0(time_pref, "") != 0) {
|
||||||
gchar *date_fmt = g_date_time_format(last_time, "%H:%M");
|
gchar *date_fmt = g_date_time_format(last_time, time_pref);
|
||||||
assert(date_fmt != NULL);
|
assert(date_fmt != NULL);
|
||||||
|
size_t len = strlen(date_fmt);
|
||||||
wattron(status_bar, bracket_attrs);
|
wattron(status_bar, bracket_attrs);
|
||||||
mvwaddch(status_bar, 0, 1, '[');
|
mvwaddch(status_bar, 0, 1, '[');
|
||||||
wattroff(status_bar, bracket_attrs);
|
wattroff(status_bar, bracket_attrs);
|
||||||
mvwprintw(status_bar, 0, 2, date_fmt);
|
mvwprintw(status_bar, 0, 2, date_fmt);
|
||||||
wattron(status_bar, bracket_attrs);
|
wattron(status_bar, bracket_attrs);
|
||||||
mvwaddch(status_bar, 0, 7, ']');
|
mvwaddch(status_bar, 0, 2 + len, ']');
|
||||||
wattroff(status_bar, bracket_attrs);
|
|
||||||
g_free(date_fmt);
|
|
||||||
} else if (g_strcmp0(time_pref, "seconds") == 0) {
|
|
||||||
gchar *date_fmt = g_date_time_format(last_time, "%H:%M:%S");
|
|
||||||
assert(date_fmt != NULL);
|
|
||||||
wattron(status_bar, bracket_attrs);
|
|
||||||
mvwaddch(status_bar, 0, 1, '[');
|
|
||||||
wattroff(status_bar, bracket_attrs);
|
|
||||||
mvwprintw(status_bar, 0, 2, date_fmt);
|
|
||||||
wattron(status_bar, bracket_attrs);
|
|
||||||
mvwaddch(status_bar, 0, 10, ']');
|
|
||||||
wattroff(status_bar, bracket_attrs);
|
wattroff(status_bar, bracket_attrs);
|
||||||
g_free(date_fmt);
|
g_free(date_fmt);
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
|
||||||
@ -60,7 +61,7 @@
|
|||||||
|
|
||||||
static void _win_print(ProfWin *window, const char show_char, GDateTime *time,
|
static void _win_print(ProfWin *window, const char show_char, GDateTime *time,
|
||||||
int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt);
|
int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt);
|
||||||
static void _win_print_wrapped(WINDOW *win, const char * const message);
|
static void _win_print_wrapped(WINDOW *win, const char * const message, size_t indent);
|
||||||
|
|
||||||
int
|
int
|
||||||
win_roster_cols(void)
|
win_roster_cols(void)
|
||||||
@ -1016,18 +1017,20 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time,
|
|||||||
gboolean me_message = FALSE;
|
gboolean me_message = FALSE;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int colour = theme_attrs(THEME_ME);
|
int colour = theme_attrs(THEME_ME);
|
||||||
|
size_t indent = 0;
|
||||||
|
|
||||||
if ((flags & NO_DATE) == 0) {
|
|
||||||
gchar *date_fmt = NULL;
|
gchar *date_fmt = NULL;
|
||||||
char *time_pref = prefs_get_string(PREF_TIME);
|
char *time_pref = prefs_get_string(PREF_TIME);
|
||||||
if (g_strcmp0(time_pref, "minutes") == 0) {
|
date_fmt = g_date_time_format(time, time_pref);
|
||||||
date_fmt = g_date_time_format(time, "%H:%M");
|
|
||||||
} else if (g_strcmp0(time_pref, "seconds") == 0) {
|
|
||||||
date_fmt = g_date_time_format(time, "%H:%M:%S");
|
|
||||||
}
|
|
||||||
free(time_pref);
|
free(time_pref);
|
||||||
|
assert(date_fmt != NULL);
|
||||||
|
|
||||||
if (date_fmt) {
|
if(strlen(date_fmt) != 0){
|
||||||
|
indent = 3 + strlen(date_fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((flags & NO_DATE) == 0) {
|
||||||
|
if (date_fmt && strlen(date_fmt)) {
|
||||||
if ((flags & NO_COLOUR_DATE) == 0) {
|
if ((flags & NO_COLOUR_DATE) == 0) {
|
||||||
wattron(window->layout->win, theme_attrs(THEME_TIME));
|
wattron(window->layout->win, theme_attrs(THEME_TIME));
|
||||||
}
|
}
|
||||||
@ -1072,7 +1075,7 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_WRAP)) {
|
if (prefs_get_boolean(PREF_WRAP)) {
|
||||||
_win_print_wrapped(window->layout->win, message+offset);
|
_win_print_wrapped(window->layout->win, message+offset, indent);
|
||||||
} else {
|
} else {
|
||||||
wprintw(window->layout->win, "%s", message+offset);
|
wprintw(window->layout->win, "%s", message+offset);
|
||||||
}
|
}
|
||||||
@ -1102,20 +1105,11 @@ _win_indent(WINDOW *win, int size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_win_print_wrapped(WINDOW *win, const char * const message)
|
_win_print_wrapped(WINDOW *win, const char * const message, size_t indent)
|
||||||
{
|
{
|
||||||
int wordi = 0;
|
int wordi = 0;
|
||||||
char *word = malloc(strlen(message) + 1);
|
char *word = malloc(strlen(message) + 1);
|
||||||
|
|
||||||
char *time_pref = prefs_get_string(PREF_TIME);
|
|
||||||
int indent = 0;
|
|
||||||
if (g_strcmp0(time_pref, "minutes") == 0) {
|
|
||||||
indent = 8;
|
|
||||||
} else if (g_strcmp0(time_pref, "seconds") == 0) {
|
|
||||||
indent = 11;
|
|
||||||
}
|
|
||||||
free(time_pref);
|
|
||||||
|
|
||||||
gchar *curr_ch = g_utf8_offset_to_pointer(message, 0);
|
gchar *curr_ch = g_utf8_offset_to_pointer(message, 0);
|
||||||
|
|
||||||
while (*curr_ch != '\0') {
|
while (*curr_ch != '\0') {
|
||||||
|
Loading…
Reference in New Issue
Block a user