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

Add max tabs preference for statusbar

This commit is contained in:
James Booth 2018-03-08 23:11:49 +00:00
parent 720dce866e
commit a957c545d3
7 changed files with 111 additions and 59 deletions

View File

@ -783,6 +783,7 @@ cmd_ac_init(void)
autocomplete_add(statusbar_ac, "down"); autocomplete_add(statusbar_ac, "down");
autocomplete_add(statusbar_ac, "show"); autocomplete_add(statusbar_ac, "show");
autocomplete_add(statusbar_ac, "hide"); autocomplete_add(statusbar_ac, "hide");
autocomplete_add(statusbar_ac, "maxtabs");
statusbar_show_ac = autocomplete_new(); statusbar_show_ac = autocomplete_new();
autocomplete_add(statusbar_show_ac, "empty"); autocomplete_add(statusbar_show_ac, "empty");

View File

@ -1366,19 +1366,19 @@ static struct cmd_t command_defs[] =
CMD_SYN( CMD_SYN(
"/statusbar show empty|name", "/statusbar show empty|name",
"/statusbar hide empty|name", "/statusbar hide empty|name",
// "/statusbar maxtabs <value>", "/statusbar maxtabs <value>",
"/statusbar up", "/statusbar up",
"/statusbar down") "/statusbar down")
CMD_DESC( CMD_DESC(
"Manage statusbar display preferences.") "Manage statusbar display preferences.")
CMD_ARGS( CMD_ARGS(
// { "maxtabs <value>", "Set the maximum number of tabs to display, <value> must be between 0 and 10" }, { "maxtabs <value>", "Set the maximum number of tabs to display, <value> must be between 0 and 10" },
{ "show|hide empty", "Show or hide empty tabs." }, { "show|hide empty", "Show or hide empty tabs." },
{ "show|hide name", "Show or hide names in tabs." }, { "show|hide name", "Show or hide names in tabs." },
{ "up", "Move the status bar up the screen." }, { "up", "Move the status bar up the screen." },
{ "down", "Move the status bar down the screen." }) { "down", "Move the status bar down the screen." })
CMD_EXAMPLES( CMD_EXAMPLES(
// "/statusbar maxtabs 5", "/statusbar maxtabs 5",
"/statusbar show empty", "/statusbar show empty",
"/statusbar hide name") "/statusbar hide name")
}, },

View File

@ -5827,7 +5827,34 @@ cmd_statusbar(ProfWin *window, const char *const command, gchar **args)
} }
if (g_strcmp0(args[0], "maxtabs") == 0) { if (g_strcmp0(args[0], "maxtabs") == 0) {
if (args[1] == NULL) {
cons_bad_cmd_usage(command);
return TRUE;
}
char *value = args[1];
int intval = 0;
char *err_msg = NULL;
gboolean res = strtoi_range(value, &intval, 0, INT_MAX, &err_msg);
if (res) {
if (intval < 0 || intval > 10) {
cons_bad_cmd_usage(command);
return TRUE;
}
prefs_set_statusbartabs(intval);
if (intval == 0) {
cons_show("Status bar tabs disabled.");
} else {
cons_show("Status bar tabs set to %d.", intval);
}
return TRUE;
} else {
cons_show(err_msg);
cons_bad_cmd_usage(command);
free(err_msg);
return TRUE;
}
} }
if (g_strcmp0(args[0], "up") == 0) { if (g_strcmp0(args[0], "up") == 0) {

View File

@ -663,6 +663,23 @@ prefs_get_tray_timer(void)
} }
} }
gint
prefs_get_statusbartabs(void)
{
if (!g_key_file_has_key(prefs, PREF_GROUP_UI, "statusbar.tabs", NULL)) {
return 10;
} else {
return g_key_file_get_integer(prefs, PREF_GROUP_UI, "statusbar.tabs", NULL);
}
}
void
prefs_set_statusbartabs(gint value)
{
g_key_file_set_integer(prefs, PREF_GROUP_UI, "statusbar.tabs", value);
_save_prefs();
}
gchar** gchar**
prefs_get_plugins(void) prefs_get_plugins(void)
{ {

View File

@ -190,6 +190,9 @@ gint prefs_get_autoping_timeout(void);
gint prefs_get_inpblock(void); gint prefs_get_inpblock(void);
void prefs_set_inpblock(gint value); void prefs_set_inpblock(gint value);
void prefs_set_statusbartabs(gint value);
gint prefs_get_statusbartabs(void);
void prefs_set_occupants_size(gint value); void prefs_set_occupants_size(gint value);
gint prefs_get_occupants_size(void); gint prefs_get_occupants_size(void);
void prefs_set_roster_size(gint value); void prefs_set_roster_size(gint value);

View File

@ -1544,6 +1544,7 @@ cons_show_ui_prefs(void)
cons_presence_setting(); cons_presence_setting();
cons_inpblock_setting(); cons_inpblock_setting();
cons_tlsshow_setting(); cons_tlsshow_setting();
cons_statusbar_setting();
cons_alert(); cons_alert();
} }
@ -1750,7 +1751,6 @@ cons_inpblock_setting(void)
void void
cons_statusbar_setting(void) cons_statusbar_setting(void)
{ {
cons_winpos_setting();
if (prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY)) { if (prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY)) {
cons_show("Show empty tabs (/statusbar) : ON"); cons_show("Show empty tabs (/statusbar) : ON");
} else { } else {
@ -1761,6 +1761,8 @@ cons_statusbar_setting(void)
} else { } else {
cons_show("Show tab names (/statusbar) : OFF"); cons_show("Show tab names (/statusbar) : OFF");
} }
cons_show("Max tabs (/statusbar) : %d", prefs_get_statusbartabs());
} }
void void

View File

@ -63,24 +63,13 @@ typedef struct _status_bar_t {
int current_tab; int current_tab;
} StatusBar; } StatusBar;
#define MAX_TABS 10
static GTimeZone *tz; static GTimeZone *tz;
static StatusBar *statusbar; static StatusBar *statusbar;
static WINDOW *statusbar_win; static WINDOW *statusbar_win;
static void _status_bar_draw(void); static void _status_bar_draw(void);
static void _destroy_tab(StatusBarTab *tab);
void static int _tabs_width(void);
_destroy_tab(StatusBarTab *tab)
{
if (tab) {
if (tab->display_name) {
free(tab->display_name);
}
free(tab);
}
}
void void
status_bar_init(void) status_bar_init(void)
@ -241,47 +230,6 @@ status_bar_clear_message(void)
_status_bar_draw(); _status_bar_draw();
} }
static int
_tabs_width(void)
{
gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY);
gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME);
if (show_name) {
if (show_empty) {
int width = 4;
int i = 0;
for (i = 1; i <= MAX_TABS; i++) {
StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i));
if (tab) {
width += strlen(tab->display_name);
width += 4;
} else {
width += 3;
}
}
return width;
} else {
int width = 4;
int i = 0;
for (i = 1; i <= MAX_TABS; i++) {
StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i));
if (tab) {
width += strlen(tab->display_name);
width += 4;
}
}
return width;
}
} else {
if (show_empty) {
return MAX_TABS * 3 + 4;
} else {
return g_hash_table_size(statusbar->tabs) * 3 + 4;
}
}
}
static void static void
_status_bar_draw(void) _status_bar_draw(void)
{ {
@ -339,9 +287,10 @@ _status_bar_draw(void)
gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY); gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY);
gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME); gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME);
gint max_tabs = prefs_get_statusbartabs();
int i = 1; int i = 1;
for (i = 1; i <= MAX_TABS; i++) { for (i = 1; i <= max_tabs; i++) {
int display_num = i == 10 ? 0 : i; int display_num = i == 10 ? 0 : i;
StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i));
@ -409,3 +358,56 @@ _status_bar_draw(void)
wnoutrefresh(statusbar_win); wnoutrefresh(statusbar_win);
inp_put_back(); inp_put_back();
} }
static void
_destroy_tab(StatusBarTab *tab)
{
if (tab) {
if (tab->display_name) {
free(tab->display_name);
}
free(tab);
}
}
static int
_tabs_width(void)
{
gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY);
gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME);
gint max_tabs = prefs_get_statusbartabs();
if (show_name) {
if (show_empty) {
int width = 4;
int i = 0;
for (i = 1; i <= max_tabs; i++) {
StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i));
if (tab) {
width += strlen(tab->display_name);
width += 4;
} else {
width += 3;
}
}
return width;
} else {
int width = 4;
int i = 0;
for (i = 1; i <= max_tabs; i++) {
StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i));
if (tab) {
width += strlen(tab->display_name);
width += 4;
}
}
return width;
}
} else {
if (show_empty) {
return max_tabs * 3 + 4;
} else {
return g_hash_table_size(statusbar->tabs) * 3 + 4;
}
}
}