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

WIP add self prefs for statusbar

This commit is contained in:
James Booth 2018-03-10 22:16:52 +00:00
parent b38f6ba512
commit 95b639a21f
10 changed files with 107 additions and 76 deletions

View File

@ -201,6 +201,7 @@ static Autocomplete presence_ac;
static Autocomplete presence_setting_ac;
static Autocomplete winpos_ac;
static Autocomplete statusbar_ac;
static Autocomplete statusbar_self_ac;
static Autocomplete statusbar_chat_ac;
static Autocomplete statusbar_room_ac;
static Autocomplete statusbar_show_ac;
@ -784,9 +785,16 @@ cmd_ac_init(void)
autocomplete_add(statusbar_ac, "show");
autocomplete_add(statusbar_ac, "hide");
autocomplete_add(statusbar_ac, "maxtabs");
autocomplete_add(statusbar_ac, "self");
autocomplete_add(statusbar_ac, "chat");
autocomplete_add(statusbar_ac, "room");
statusbar_self_ac = autocomplete_new();
autocomplete_add(statusbar_self_ac, "user");
autocomplete_add(statusbar_self_ac, "barejid");
autocomplete_add(statusbar_self_ac, "fulljid");
autocomplete_add(statusbar_self_ac, "off");
statusbar_chat_ac = autocomplete_new();
autocomplete_add(statusbar_chat_ac, "user");
autocomplete_add(statusbar_chat_ac, "jid");
@ -1080,6 +1088,7 @@ cmd_ac_reset(ProfWin *window)
autocomplete_reset(presence_setting_ac);
autocomplete_reset(winpos_ac);
autocomplete_reset(statusbar_ac);
autocomplete_reset(statusbar_self_ac);
autocomplete_reset(statusbar_chat_ac);
autocomplete_reset(statusbar_room_ac);
autocomplete_reset(statusbar_show_ac);
@ -1211,6 +1220,7 @@ cmd_ac_uninit(void)
autocomplete_free(presence_setting_ac);
autocomplete_free(winpos_ac);
autocomplete_free(statusbar_ac);
autocomplete_free(statusbar_self_ac);
autocomplete_free(statusbar_chat_ac);
autocomplete_free(statusbar_room_ac);
autocomplete_free(statusbar_show_ac);
@ -3230,6 +3240,11 @@ _statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previ
return found;
}
found = autocomplete_param_with_ac(input, "/statusbar self", statusbar_self_ac, TRUE, previous);
if (found) {
return found;
}
found = autocomplete_param_with_ac(input, "/statusbar chat", statusbar_chat_ac, TRUE, previous);
if (found) {
return found;

View File

@ -1361,6 +1361,7 @@ static struct cmd_t command_defs[] =
"/statusbar show name|number",
"/statusbar hide name|number",
"/statusbar maxtabs <value>",
"/statusbar self user|barejid|fulljid|off",
"/statusbar chat user|jid",
"/statusbar room room|jid",
"/statusbar up",
@ -1368,16 +1369,18 @@ static struct cmd_t command_defs[] =
CMD_DESC(
"Manage statusbar display preferences.")
CMD_ARGS(
{ "maxtabs <value>", "Set the maximum number of tabs to display, <value> must be between 0 and 10" },
{ "show|hide name", "Show or hide names in tabs." },
{ "show|hide number", "Show or hide numbers in tabs." },
{ "chat user|jid", "Show only the users name, or the full jid if no nick is present for chat tabs." },
{ "room room|jid", "Show only the rooms name, or the full jid for room tabs." },
{ "up", "Move the status bar up the screen." },
{ "down", "Move the status bar down the screen." })
{ "maxtabs <value>", "Set the maximum number of tabs to display, <value> must be between 0 and 10" },
{ "show|hide name", "Show or hide names 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 off", "Disable showing self as status bar title." },
{ "chat user|jid", "Show users name, or the fulljid if no nick is present for chat tabs." },
{ "room room|jid", "Show room name, or the fulljid for room tabs." },
{ "up", "Move the status bar up the screen." },
{ "down", "Move the status bar down the screen." })
CMD_EXAMPLES(
"/statusbar maxtabs 5",
"/statusbar hide name",
"/statusbar self user",
"/statusbar chat jid",
"/statusbar hide name")
},

View File

@ -5846,6 +5846,35 @@ cmd_statusbar(ProfWin *window, const char *const command, gchar **args)
}
}
if (g_strcmp0(args[0], "self") == 0) {
if (g_strcmp0(args[1], "barejid") == 0) {
prefs_set_string(PREF_STATUSBAR_SELF, "barejid");
cons_show("Using barejid for statusbar title.");
ui_resize();
return TRUE;
}
if (g_strcmp0(args[1], "fulljid") == 0) {
prefs_set_string(PREF_STATUSBAR_SELF, "fulljid");
cons_show("Using fulljid for statusbar title.");
ui_resize();
return TRUE;
}
if (g_strcmp0(args[1], "user") == 0) {
prefs_set_string(PREF_STATUSBAR_SELF, "user");
cons_show("Using user for statusbar title.");
ui_resize();
return TRUE;
}
if (g_strcmp0(args[1], "off") == 0) {
prefs_set_string(PREF_STATUSBAR_SELF, "off");
cons_show("Disabling statusbar title.");
ui_resize();
return TRUE;
}
cons_bad_cmd_usage(command);
return TRUE;
}
if (g_strcmp0(args[0], "chat") == 0) {
if (g_strcmp0(args[1], "jid") == 0) {
prefs_set_string(PREF_STATUSBAR_CHAT, "jid");

View File

@ -1588,6 +1588,7 @@ _get_group(preference_t pref)
case PREF_CONSOLE_CHAT:
case PREF_STATUSBAR_SHOW_NAME:
case PREF_STATUSBAR_SHOW_NUMBER:
case PREF_STATUSBAR_SELF:
case PREF_STATUSBAR_CHAT:
case PREF_STATUSBAR_ROOM:
return PREF_GROUP_UI;
@ -1847,6 +1848,8 @@ _get_key(preference_t pref)
return "statusbar.show.name";
case PREF_STATUSBAR_SHOW_NUMBER:
return "statusbar.show.number";
case PREF_STATUSBAR_SELF:
return "statusbar.self";
case PREF_STATUSBAR_CHAT:
return "statusbar.chat";
case PREF_STATUSBAR_ROOM:
@ -1964,6 +1967,8 @@ _get_default_string(preference_t pref)
case PREF_CONSOLE_PRIVATE:
case PREF_CONSOLE_CHAT:
return "all";
case PREF_STATUSBAR_SELF:
return "fulljid";
case PREF_STATUSBAR_CHAT:
return "user";
case PREF_STATUSBAR_ROOM:

View File

@ -145,6 +145,7 @@ typedef enum {
PREF_ROOM_LIST_CACHE,
PREF_STATUSBAR_SHOW_NAME,
PREF_STATUSBAR_SHOW_NUMBER,
PREF_STATUSBAR_SELF,
PREF_STATUSBAR_CHAT,
PREF_STATUSBAR_ROOM,
} preference_t;

View File

@ -1754,6 +1754,14 @@ cons_statusbar_setting(void)
cons_show("Max tabs (/statusbar) : %d", prefs_get_statusbartabs());
char *pref_self = prefs_get_string(PREF_STATUSBAR_SELF);
if (g_strcmp0(pref_self, "off") == 0) {
cons_show("Self statusbar display (/statusbar) : OFF");
} else {
cons_show("Self statusbar display (/statusbar) : %s", pref_self);
}
prefs_free_string(pref_self);
char *pref_chat = prefs_get_string(PREF_STATUSBAR_CHAT);
cons_show("Chat tab display (/statusbar) : %s", pref_chat);
prefs_free_string(pref_chat);

View File

@ -137,7 +137,7 @@ ui_update(void)
_ui_draw_term_title();
}
title_bar_update_virtual();
status_bar_update_virtual();
status_bar_draw();
inp_put_back();
doupdate();
@ -388,8 +388,7 @@ ui_handle_login_account_success(ProfAccount *account, gboolean secured)
title_bar_set_connected(TRUE);
title_bar_set_tls(secured);
status_bar_print_message(connection_get_fulljid());
status_bar_update_virtual();
status_bar_set_prompt(connection_get_fulljid());
}
void
@ -482,8 +481,7 @@ ui_disconnected(void)
title_bar_set_connected(FALSE);
title_bar_set_tls(FALSE);
title_bar_set_presence(CONTACT_OFFLINE);
status_bar_clear_message();
status_bar_update_virtual();
status_bar_clear_prompt();
ui_hide_roster();
}
@ -975,15 +973,14 @@ ui_win_unread(int index)
char*
ui_ask_password(void)
{
status_bar_get_password();
status_bar_update_virtual();
status_bar_set_prompt("Enter password:");
return inp_get_password();
}
char*
ui_get_line(void)
{
status_bar_update_virtual();
status_bar_draw();
return inp_get_line();
}
@ -1006,8 +1003,7 @@ ui_ask_pgp_passphrase(const char *hint, int prev_fail)
ui_update();
status_bar_get_password();
status_bar_update_virtual();
status_bar_set_prompt("Enter password:");
return inp_get_password();
}

View File

@ -251,7 +251,7 @@ inp_get_line(void)
line = inp_readline();
ui_update();
}
status_bar_clear();
status_bar_clear_prompt();
return line;
}
@ -269,7 +269,7 @@ inp_get_password(void)
ui_update();
}
get_password = FALSE;
status_bar_clear();
status_bar_clear_prompt();
return password;
}

View File

@ -61,7 +61,7 @@ typedef struct _status_bar_tab_t {
typedef struct _status_bar_t {
gchar *time;
char *message;
char *prompt;
GHashTable *tabs;
int current_tab;
} StatusBar;
@ -70,9 +70,8 @@ static GTimeZone *tz;
static StatusBar *statusbar;
static WINDOW *statusbar_win;
static void _status_bar_draw(void);
static int _status_bar_draw_time(int pos);
static void _status_bar_draw_message(int pos);
static void _status_bar_draw_prompt(int pos);
static int _status_bar_draw_bracket(gboolean current, int pos, char* ch);
static int _status_bar_draw_extended_tabs(int pos);
static int _status_bar_draw_tab(StatusBarTab *tab, int pos, int num);
@ -88,7 +87,7 @@ status_bar_init(void)
statusbar = malloc(sizeof(StatusBar));
statusbar->time = NULL;
statusbar->message = NULL;
statusbar->prompt = NULL;
statusbar->tabs = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)_destroy_tab);
StatusBarTab *console = malloc(sizeof(StatusBarTab));
console->window_type = WIN_CONSOLE;
@ -100,7 +99,7 @@ status_bar_init(void)
int cols = getmaxx(stdscr);
statusbar_win = newwin(1, cols, row, 0);
_status_bar_draw();
status_bar_draw();
}
void
@ -113,19 +112,13 @@ status_bar_close(void)
if (statusbar->time) {
g_free(statusbar->time);
}
if (statusbar->message) {
free(statusbar->message);
if (statusbar->prompt) {
free(statusbar->prompt);
}
free(statusbar);
}
}
void
status_bar_update_virtual(void)
{
_status_bar_draw();
}
void
status_bar_resize(void)
{
@ -135,7 +128,7 @@ status_bar_resize(void)
mvwin(statusbar_win, row, 0);
wresize(statusbar_win, 1, cols);
_status_bar_draw();
status_bar_draw();
}
void
@ -153,7 +146,7 @@ status_bar_current(int i)
statusbar->current_tab = i;
}
_status_bar_draw();
status_bar_draw();
}
void
@ -166,7 +159,7 @@ status_bar_inactive(const int win)
g_hash_table_remove(statusbar->tabs, GINT_TO_POINTER(true_win));
_status_bar_draw();
status_bar_draw();
}
void
@ -183,7 +176,7 @@ status_bar_active(const int win, win_type_t wintype, char *identifier)
tab->window_type = wintype;
g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab);
_status_bar_draw();
status_bar_draw();
}
void
@ -200,51 +193,34 @@ status_bar_new(const int win, win_type_t wintype, char* identifier)
tab->window_type = wintype;
g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab);
_status_bar_draw();
status_bar_draw();
}
void
status_bar_get_password(void)
status_bar_set_prompt(const char *const prompt)
{
status_bar_print_message("Enter password:");
}
void
status_bar_print_message(const char *const msg)
{
if (statusbar->message) {
free(statusbar->message);
statusbar->message = NULL;
if (statusbar->prompt) {
free(statusbar->prompt);
statusbar->prompt = NULL;
}
statusbar->message = strdup(msg);
statusbar->prompt = strdup(prompt);
_status_bar_draw();
status_bar_draw();
}
void
status_bar_clear(void)
status_bar_clear_prompt(void)
{
if (statusbar->message) {
free(statusbar->message);
statusbar->message = NULL;
if (statusbar->prompt) {
free(statusbar->prompt);
statusbar->prompt = NULL;
}
_status_bar_draw();
status_bar_draw();
}
void
status_bar_clear_message(void)
{
if (statusbar->message) {
free(statusbar->message);
statusbar->message = NULL;
}
_status_bar_draw();
}
static void
_status_bar_draw(void)
status_bar_draw(void)
{
werase(statusbar_win);
wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT));
@ -253,7 +229,7 @@ _status_bar_draw(void)
pos = _status_bar_draw_time(pos);
_status_bar_draw_message(pos);
_status_bar_draw_prompt(pos);
pos = getmaxx(stdscr) - _tabs_width();
gint max_tabs = prefs_get_statusbartabs();
@ -413,10 +389,10 @@ _status_bar_draw_time(int pos)
}
static void
_status_bar_draw_message(int pos)
_status_bar_draw_prompt(int pos)
{
if (statusbar->message) {
mvwprintw(statusbar_win, 0, pos, statusbar->message);
if (statusbar->prompt) {
mvwprintw(statusbar_win, 0, pos, statusbar->prompt);
}
}

View File

@ -36,13 +36,11 @@
#define UI_STATUSBAR_H
void status_bar_init(void);
void status_bar_draw(void);
void status_bar_close(void);
void status_bar_update_virtual(void);
void status_bar_resize(void);
void status_bar_clear(void);
void status_bar_clear_message(void);
void status_bar_get_password(void);
void status_bar_print_message(const char *const msg);
void status_bar_clear_prompt(void);
void status_bar_set_prompt(const char *const prompt);
void status_bar_current(int i);
#endif