1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-08 19:34:14 -04:00

Added /time statusbar preference

This commit is contained in:
James Booth 2015-03-10 23:35:08 +00:00
parent 0269129d17
commit e5bb12a0d6
10 changed files with 144 additions and 36 deletions

View File

@ -102,6 +102,7 @@ static char * _role_autocomplete(const char * const input);
static char * _resource_autocomplete(const char * const input);
static char * _titlebar_autocomplete(const char * const input);
static char * _inpblock_autocomplete(const char * const input);
static char * _time_autocomplete(const char * const input);
GHashTable *commands = NULL;
@ -681,11 +682,18 @@ static struct cmd_t command_defs[] =
NULL } } },
{ "/time",
cmd_time, parse_args, 1, 1, &cons_time_setting,
{ "/time minutes|seconds", "Time display.",
{ "/time minutes|seconds",
"---------------------",
"Configure time precision for the main window.",
cmd_time, parse_args, 1, 2, &cons_time_setting,
{ "/time setting|statusbar [setting]", "Time display.",
{ "/time setting|statusbar [setting]",
"---------------------------------",
"Configure time display preferences.",
"",
"minutes : Use minutes precision in main window.",
"seconds : Use seconds precision in main window.",
"off : Do not show time in main window.",
"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.",
NULL } } },
{ "/inpblock",
@ -1180,6 +1188,7 @@ static Autocomplete form_field_multi_ac;
static Autocomplete occupants_ac;
static Autocomplete occupants_default_ac;
static Autocomplete time_ac;
static Autocomplete time_statusbar_ac;
static Autocomplete resource_ac;
static Autocomplete inpblock_ac;
@ -1523,6 +1532,12 @@ cmd_init(void)
autocomplete_add(time_ac, "minutes");
autocomplete_add(time_ac, "seconds");
autocomplete_add(time_ac, "off");
autocomplete_add(time_ac, "statusbar");
time_statusbar_ac = autocomplete_new();
autocomplete_add(time_statusbar_ac, "minutes");
autocomplete_add(time_statusbar_ac, "seconds");
autocomplete_add(time_statusbar_ac, "off");
resource_ac = autocomplete_new();
autocomplete_add(resource_ac, "set");
@ -1587,6 +1602,7 @@ cmd_uninit(void)
autocomplete_free(occupants_ac);
autocomplete_free(occupants_default_ac);
autocomplete_free(time_ac);
autocomplete_free(time_statusbar_ac);
autocomplete_free(resource_ac);
autocomplete_free(inpblock_ac);
}
@ -1752,6 +1768,7 @@ cmd_reset_autocomplete()
autocomplete_reset(occupants_ac);
autocomplete_reset(occupants_default_ac);
autocomplete_reset(time_ac);
autocomplete_reset(time_statusbar_ac);
autocomplete_reset(resource_ac);
autocomplete_reset(inpblock_ac);
@ -2067,8 +2084,8 @@ _cmd_complete_parameters(const char * const input)
}
}
gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room", "/time" };
Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac, time_ac };
gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room" };
Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac };
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE);
@ -2103,6 +2120,7 @@ _cmd_complete_parameters(const char * const input)
g_hash_table_insert(ac_funcs, "/resource", _resource_autocomplete);
g_hash_table_insert(ac_funcs, "/titlebar", _titlebar_autocomplete);
g_hash_table_insert(ac_funcs, "/inpblock", _inpblock_autocomplete);
g_hash_table_insert(ac_funcs, "/time", _time_autocomplete);
int len = strlen(input);
char parsed[len+1];
@ -2739,6 +2757,24 @@ _occupants_autocomplete(const char * const input)
return NULL;
}
static char *
_time_autocomplete(const char * const input)
{
char *found = NULL;
found = autocomplete_param_with_ac(input, "/time statusbar", time_statusbar_ac, TRUE);
if (found != NULL) {
return found;
}
found = autocomplete_param_with_ac(input, "/time", time_ac, TRUE);
if (found != NULL) {
return found;
}
return NULL;
}
static char *
_kick_autocomplete(const char * const input)
{

View File

@ -3270,24 +3270,46 @@ cmd_wrap(gchar **args, struct cmd_help_t help)
gboolean
cmd_time(gchar **args, struct cmd_help_t help)
{
if (g_strcmp0(args[0], "minutes") == 0) {
prefs_set_string(PREF_TIME, "minutes");
cons_show("Time precision set to minutes.");
wins_resize_all();
return TRUE;
} else if (g_strcmp0(args[0], "seconds") == 0) {
prefs_set_string(PREF_TIME, "seconds");
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.");
wins_resize_all();
return TRUE;
if (g_strcmp0(args[0], "statusbar") == 0) {
if (g_strcmp0(args[1], "minutes") == 0) {
prefs_set_string(PREF_TIME_STATUSBAR, "minutes");
cons_show("Status bar time precision set to minutes.");
ui_redraw();
return TRUE;
} else if (g_strcmp0(args[1], "seconds") == 0) {
prefs_set_string(PREF_TIME_STATUSBAR, "seconds");
cons_show("Status bar time precision set to seconds.");
ui_redraw();
return TRUE;
} else if (g_strcmp0(args[1], "off") == 0) {
prefs_set_string(PREF_TIME_STATUSBAR, "off");
cons_show("Status bar time display disabled.");
ui_redraw();
return TRUE;
} else {
cons_show("Usage: %s", help.usage);
return TRUE;
}
} else {
cons_show("Usage: %s", help.usage);
return TRUE;
if (g_strcmp0(args[0], "minutes") == 0) {
prefs_set_string(PREF_TIME, "minutes");
cons_show("Time precision set to minutes.");
wins_resize_all();
return TRUE;
} else if (g_strcmp0(args[0], "seconds") == 0) {
prefs_set_string(PREF_TIME, "seconds");
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.");
wins_resize_all();
return TRUE;
} else {
cons_show("Usage: %s", help.usage);
return TRUE;
}
}
}

View File

@ -507,6 +507,7 @@ _get_group(preference_t pref)
case PREF_PRESENCE:
case PREF_WRAP:
case PREF_TIME:
case PREF_TIME_STATUSBAR:
case PREF_ROSTER:
case PREF_ROSTER_OFFLINE:
case PREF_ROSTER_RESOURCE:
@ -646,6 +647,8 @@ _get_key(preference_t pref)
return "wrap";
case PREF_TIME:
return "time";
case PREF_TIME_STATUSBAR:
return "time.statusbar";
case PREF_ROSTER:
return "roster";
case PREF_ROSTER_OFFLINE:
@ -722,6 +725,8 @@ _get_default_string(preference_t pref)
return "presence";
case PREF_TIME:
return "seconds";
case PREF_TIME_STATUSBAR:
return "minutes";
default:
return NULL;
}

View File

@ -72,6 +72,7 @@ typedef enum {
PREF_PRESENCE,
PREF_WRAP,
PREF_TIME,
PREF_TIME_STATUSBAR,
PREF_STATUSES,
PREF_STATUSES_CONSOLE,
PREF_STATUSES_CHAT,

View File

@ -426,6 +426,7 @@ _load_preferences(void)
_set_boolean_preference("splash", PREF_SPLASH);
_set_boolean_preference("wrap", PREF_WRAP);
_set_string_preference("time", PREF_TIME);
_set_string_preference("time.statusbar", PREF_TIME_STATUSBAR);
_set_boolean_preference("resource.title", PREF_RESOURCE_TITLE);
_set_boolean_preference("resource.message", PREF_RESOURCE_MESSAGE);

View File

@ -934,6 +934,16 @@ cons_time_setting(void)
cons_show("Time (/time) : seconds");
prefs_free_string(pref_time);
char *pref_time_statusbar = prefs_get_string(PREF_TIME_STATUSBAR);
if (g_strcmp0(pref_time_statusbar, "minutes") == 0)
cons_show("Time statusbar (/time) : minutes");
else if (g_strcmp0(pref_time_statusbar, "off") == 0)
cons_show("Time statusbar (/time) : OFF");
else
cons_show("Time statusbar (/time) : seconds");
prefs_free_string(pref_time_statusbar);
}
void

View File

@ -48,6 +48,7 @@
#include "ui/ui.h"
#include "ui/statusbar.h"
#include "ui/inputwin.h"
#include "config/preferences.h"
#define TIME_CHECK 60000000
@ -127,7 +128,14 @@ status_bar_resize(void)
wattroff(status_bar, bracket_attrs);
if (message != NULL) {
mvwprintw(status_bar, 0, 10, message);
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
if (g_strcmp0(time_pref, "minutes") == 0) {
mvwprintw(status_bar, 0, 10, message);
} else if (g_strcmp0(time_pref, "seconds") == 0) {
mvwprintw(status_bar, 0, 13, message);
} else {
mvwprintw(status_bar, 0, 1, message);
}
}
if (last_time != NULL) {
g_date_time_unref(last_time);
@ -293,7 +301,15 @@ status_bar_print_message(const char * const msg)
free(message);
}
message = strdup(msg);
mvwprintw(status_bar, 0, 10, message);
char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
if (g_strcmp0(time_pref, "minutes") == 0) {
mvwprintw(status_bar, 0, 10, message);
} else if (g_strcmp0(time_pref, "seconds") == 0) {
mvwprintw(status_bar, 0, 13, message);
} else {
mvwprintw(status_bar, 0, 1, message);
}
int cols = getmaxx(stdscr);
int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);
@ -416,19 +432,33 @@ _status_bar_draw(void)
g_date_time_unref(last_time);
}
last_time = g_date_time_new_now_local();
gchar *date_fmt = g_date_time_format(last_time, "%H:%M");
assert(date_fmt != NULL);
int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);
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, 7, ']');
wattroff(status_bar, bracket_attrs);
g_free(date_fmt);
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, "%H:%M");
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, 7, ']');
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);
g_free(date_fmt);
}
_update_win_statuses();
wnoutrefresh(status_bar);

View File

@ -54,6 +54,7 @@ flash=false
splash=true
wrap=true
time=seconds
time.statusbar=seconds
privileges=true
presence=true
intype=true

View File

@ -4,6 +4,7 @@ flash=false
splash=true
wrap=true
time=seconds
time.statusbar=seconds
resource.title=true
resource.message=true
statuses.console=all

View File

@ -4,6 +4,7 @@ flash=false
splash=true
wrap=true
time=minutes
time.statusbar=off
resource.title=false
resource.message=false
statuses.console=none