mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Add max tab length to statusbar
This commit is contained in:
parent
9f24f6083b
commit
d6e7f389d1
@ -785,6 +785,7 @@ cmd_ac_init(void)
|
|||||||
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");
|
autocomplete_add(statusbar_ac, "maxtabs");
|
||||||
|
autocomplete_add(statusbar_ac, "tablen");
|
||||||
autocomplete_add(statusbar_ac, "self");
|
autocomplete_add(statusbar_ac, "self");
|
||||||
autocomplete_add(statusbar_ac, "chat");
|
autocomplete_add(statusbar_ac, "chat");
|
||||||
autocomplete_add(statusbar_ac, "room");
|
autocomplete_add(statusbar_ac, "room");
|
||||||
|
@ -1361,6 +1361,7 @@ static struct cmd_t command_defs[] =
|
|||||||
"/statusbar show name|number",
|
"/statusbar show name|number",
|
||||||
"/statusbar hide name|number",
|
"/statusbar hide name|number",
|
||||||
"/statusbar maxtabs <value>",
|
"/statusbar maxtabs <value>",
|
||||||
|
"/statusbar tablen <value>",
|
||||||
"/statusbar self user|barejid|fulljid|off",
|
"/statusbar self user|barejid|fulljid|off",
|
||||||
"/statusbar chat user|jid",
|
"/statusbar chat user|jid",
|
||||||
"/statusbar room room|jid",
|
"/statusbar room room|jid",
|
||||||
@ -1370,6 +1371,7 @@ static struct cmd_t command_defs[] =
|
|||||||
"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" },
|
||||||
|
{ "tablen <value>", "Set the maximum number of characters to show as the tab name, 0 sets to unlimited." },
|
||||||
{ "show|hide name", "Show or hide names in tabs." },
|
{ "show|hide name", "Show or hide names in tabs." },
|
||||||
{ "show|hide number", "Show or hide numbers in tabs." },
|
{ "show|hide number", "Show or hide numbers in tabs." },
|
||||||
{ "self user|barejid|fulljid", "Show account user name, barejid, fulljid as status bar title." },
|
{ "self user|barejid|fulljid", "Show account user name, barejid, fulljid as status bar title." },
|
||||||
@ -1379,7 +1381,8 @@ static struct cmd_t command_defs[] =
|
|||||||
{ "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 8",
|
||||||
|
"/statusbar tablen 5",
|
||||||
"/statusbar self user",
|
"/statusbar self user",
|
||||||
"/statusbar chat jid",
|
"/statusbar chat jid",
|
||||||
"/statusbar hide name")
|
"/statusbar hide name")
|
||||||
|
@ -5846,6 +5846,38 @@ cmd_statusbar(ProfWin *window, const char *const command, gchar **args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_strcmp0(args[0], "tablen") == 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) {
|
||||||
|
cons_bad_cmd_usage(command);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
prefs_set_statusbartablen(intval);
|
||||||
|
if (intval == 0) {
|
||||||
|
cons_show("Maximum tab length disabled.");
|
||||||
|
} else {
|
||||||
|
cons_show("Maximum tab length set to %d.", intval);
|
||||||
|
}
|
||||||
|
ui_resize();
|
||||||
|
return TRUE;
|
||||||
|
} else {
|
||||||
|
cons_show(err_msg);
|
||||||
|
cons_bad_cmd_usage(command);
|
||||||
|
free(err_msg);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (g_strcmp0(args[0], "self") == 0) {
|
if (g_strcmp0(args[0], "self") == 0) {
|
||||||
if (g_strcmp0(args[1], "barejid") == 0) {
|
if (g_strcmp0(args[1], "barejid") == 0) {
|
||||||
prefs_set_string(PREF_STATUSBAR_SELF, "barejid");
|
prefs_set_string(PREF_STATUSBAR_SELF, "barejid");
|
||||||
|
@ -680,6 +680,23 @@ prefs_set_statusbartabs(gint value)
|
|||||||
_save_prefs();
|
_save_prefs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gint
|
||||||
|
prefs_get_statusbartablen(void)
|
||||||
|
{
|
||||||
|
if (!g_key_file_has_key(prefs, PREF_GROUP_UI, "statusbar.tablen", NULL)) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return g_key_file_get_integer(prefs, PREF_GROUP_UI, "statusbar.tablen", NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
prefs_set_statusbartablen(gint value)
|
||||||
|
{
|
||||||
|
g_key_file_set_integer(prefs, PREF_GROUP_UI, "statusbar.tablen", value);
|
||||||
|
_save_prefs();
|
||||||
|
}
|
||||||
|
|
||||||
gchar**
|
gchar**
|
||||||
prefs_get_plugins(void)
|
prefs_get_plugins(void)
|
||||||
{
|
{
|
||||||
|
@ -194,6 +194,8 @@ void prefs_set_inpblock(gint value);
|
|||||||
|
|
||||||
void prefs_set_statusbartabs(gint value);
|
void prefs_set_statusbartabs(gint value);
|
||||||
gint prefs_get_statusbartabs(void);
|
gint prefs_get_statusbartabs(void);
|
||||||
|
void prefs_set_statusbartablen(gint value);
|
||||||
|
gint prefs_get_statusbartablen(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);
|
||||||
|
@ -442,6 +442,11 @@ _load_preferences(void)
|
|||||||
prefs_set_statusbartabs(tabs_size);
|
prefs_set_statusbartabs(tabs_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_key_file_has_key(theme, "ui", "statusbar.tablen", NULL)) {
|
||||||
|
gint tab_len = g_key_file_get_integer(theme, "ui", "statusbar.tablen", NULL);
|
||||||
|
prefs_set_statusbartabs(tab_len);
|
||||||
|
}
|
||||||
|
|
||||||
if (g_key_file_has_key(theme, "ui", "occupants.size", NULL)) {
|
if (g_key_file_has_key(theme, "ui", "occupants.size", NULL)) {
|
||||||
gint occupants_size = g_key_file_get_integer(theme, "ui", "occupants.size", NULL);
|
gint occupants_size = g_key_file_get_integer(theme, "ui", "occupants.size", NULL);
|
||||||
prefs_set_occupants_size(occupants_size);
|
prefs_set_occupants_size(occupants_size);
|
||||||
|
@ -1754,6 +1754,13 @@ cons_statusbar_setting(void)
|
|||||||
|
|
||||||
cons_show("Max tabs (/statusbar) : %d", prefs_get_statusbartabs());
|
cons_show("Max tabs (/statusbar) : %d", prefs_get_statusbartabs());
|
||||||
|
|
||||||
|
gint pref_len = prefs_get_statusbartablen();
|
||||||
|
if (pref_len == 0) {
|
||||||
|
cons_show("Max tab length (/statusbar) : OFF");
|
||||||
|
} else {
|
||||||
|
cons_show("Max tab length (/statusbar) : %d", pref_len);
|
||||||
|
}
|
||||||
|
|
||||||
char *pref_self = prefs_get_string(PREF_STATUSBAR_SELF);
|
char *pref_self = prefs_get_string(PREF_STATUSBAR_SELF);
|
||||||
if (g_strcmp0(pref_self, "off") == 0) {
|
if (g_strcmp0(pref_self, "off") == 0) {
|
||||||
cons_show("Self statusbar display (/statusbar) : OFF");
|
cons_show("Self statusbar display (/statusbar) : OFF");
|
||||||
|
@ -511,42 +511,40 @@ _tabs_width(void)
|
|||||||
static char*
|
static char*
|
||||||
_display_name(StatusBarTab *tab)
|
_display_name(StatusBarTab *tab)
|
||||||
{
|
{
|
||||||
|
char *fullname = NULL;
|
||||||
|
|
||||||
if (tab->window_type == WIN_CONSOLE) {
|
if (tab->window_type == WIN_CONSOLE) {
|
||||||
return strdup("console");
|
fullname = strdup("console");
|
||||||
}
|
} else if (tab->window_type == WIN_XML) {
|
||||||
if (tab->window_type == WIN_XML) {
|
fullname = strdup("xmlconsole");
|
||||||
return strdup("xmlconsole");
|
} else if (tab->window_type == WIN_PLUGIN) {
|
||||||
}
|
fullname = strdup(tab->identifier);
|
||||||
if (tab->window_type == WIN_PLUGIN) {
|
} else if (tab->window_type == WIN_CHAT) {
|
||||||
return strdup(tab->identifier);
|
|
||||||
}
|
|
||||||
if (tab->window_type == WIN_CHAT) {
|
|
||||||
PContact contact = roster_get_contact(tab->identifier);
|
PContact contact = roster_get_contact(tab->identifier);
|
||||||
if (contact && p_contact_name(contact)) {
|
if (contact && p_contact_name(contact)) {
|
||||||
return strdup(p_contact_name(contact));
|
fullname = strdup(p_contact_name(contact));
|
||||||
}
|
|
||||||
char *pref = prefs_get_string(PREF_STATUSBAR_CHAT);
|
|
||||||
if (g_strcmp0("user", pref) == 0) {
|
|
||||||
Jid *jidp = jid_create(tab->identifier);
|
|
||||||
char *user = strdup(jidp->localpart);
|
|
||||||
jid_destroy(jidp);
|
|
||||||
return user;
|
|
||||||
} else {
|
} else {
|
||||||
return strdup(tab->identifier);
|
char *pref = prefs_get_string(PREF_STATUSBAR_CHAT);
|
||||||
|
if (g_strcmp0("user", pref) == 0) {
|
||||||
|
Jid *jidp = jid_create(tab->identifier);
|
||||||
|
char *user = strdup(jidp->localpart);
|
||||||
|
jid_destroy(jidp);
|
||||||
|
fullname = user;
|
||||||
|
} else {
|
||||||
|
fullname = strdup(tab->identifier);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (tab->window_type == WIN_MUC) {
|
||||||
if (tab->window_type == WIN_MUC) {
|
|
||||||
char *pref = prefs_get_string(PREF_STATUSBAR_ROOM);
|
char *pref = prefs_get_string(PREF_STATUSBAR_ROOM);
|
||||||
if (g_strcmp0("room", pref) == 0) {
|
if (g_strcmp0("room", pref) == 0) {
|
||||||
Jid *jidp = jid_create(tab->identifier);
|
Jid *jidp = jid_create(tab->identifier);
|
||||||
char *room = strdup(jidp->localpart);
|
char *room = strdup(jidp->localpart);
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
return room;
|
fullname = room;
|
||||||
} else {
|
} else {
|
||||||
return strdup(tab->identifier);
|
fullname = strdup(tab->identifier);
|
||||||
}
|
}
|
||||||
}
|
} else if (tab->window_type == WIN_MUC_CONFIG) {
|
||||||
if (tab->window_type == WIN_MUC_CONFIG) {
|
|
||||||
char *pref = prefs_get_string(PREF_STATUSBAR_ROOM);
|
char *pref = prefs_get_string(PREF_STATUSBAR_ROOM);
|
||||||
GString *display_str = g_string_new("");
|
GString *display_str = g_string_new("");
|
||||||
if (g_strcmp0("room", pref) == 0) {
|
if (g_strcmp0("room", pref) == 0) {
|
||||||
@ -559,9 +557,8 @@ _display_name(StatusBarTab *tab)
|
|||||||
g_string_append(display_str, " conf");
|
g_string_append(display_str, " conf");
|
||||||
char *result = strdup(display_str->str);
|
char *result = strdup(display_str->str);
|
||||||
g_string_free(display_str, TRUE);
|
g_string_free(display_str, TRUE);
|
||||||
return result;
|
fullname = result;
|
||||||
}
|
} else if (tab->window_type == WIN_PRIVATE) {
|
||||||
if (tab->window_type == WIN_PRIVATE) {
|
|
||||||
char *pref = prefs_get_string(PREF_STATUSBAR_ROOM);
|
char *pref = prefs_get_string(PREF_STATUSBAR_ROOM);
|
||||||
if (g_strcmp0("room", pref) == 0) {
|
if (g_strcmp0("room", pref) == 0) {
|
||||||
GString *display_str = g_string_new("");
|
GString *display_str = g_string_new("");
|
||||||
@ -572,10 +569,29 @@ _display_name(StatusBarTab *tab)
|
|||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
char *result = strdup(display_str->str);
|
char *result = strdup(display_str->str);
|
||||||
g_string_free(display_str, TRUE);
|
g_string_free(display_str, TRUE);
|
||||||
return result;
|
fullname = result;
|
||||||
} else {
|
} else {
|
||||||
return strdup(tab->identifier);
|
fullname = strdup(tab->identifier);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fullname = strdup("window");
|
||||||
}
|
}
|
||||||
return strdup("window");
|
|
||||||
|
gint tablen = prefs_get_statusbartablen();
|
||||||
|
if (tablen == 0) {
|
||||||
|
return fullname;
|
||||||
|
}
|
||||||
|
|
||||||
|
int namelen = utf8_display_len(fullname);
|
||||||
|
if (namelen < tablen) {
|
||||||
|
return fullname;
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar *trimmed = g_utf8_substring(fullname, 0, tablen);
|
||||||
|
free(fullname);
|
||||||
|
char *trimmedname = strdup(trimmed);
|
||||||
|
g_free(trimmed);
|
||||||
|
|
||||||
|
return trimmedname;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,7 @@ statusbar.self=user
|
|||||||
statusbar.chat=user
|
statusbar.chat=user
|
||||||
statusbar.room=room
|
statusbar.room=room
|
||||||
statusbar.tabs=8
|
statusbar.tabs=8
|
||||||
|
statusbar.tablen=0
|
||||||
statusbar.show.name=true
|
statusbar.show.name=true
|
||||||
statusbar.show.number=true
|
statusbar.show.number=true
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user