diff options
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/cmd_ac.c | 96 | ||||
-rw-r--r-- | src/command/cmd_defs.c | 39 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 207 | ||||
-rw-r--r-- | src/command/cmd_funcs.h | 2 |
4 files changed, 273 insertions, 71 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index bb6e9cd6..c996d814 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -99,6 +99,7 @@ static char* _blocked_autocomplete(ProfWin *window, const char *const input, gbo static char* _tray_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _presence_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _rooms_autocomplete(ProfWin *window, const char *const input, gboolean previous); +static char* _statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _script_autocomplete_func(const char *const prefix, gboolean previous); @@ -199,6 +200,11 @@ static Autocomplete tray_ac; 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; void cmd_ac_init(void) @@ -386,8 +392,6 @@ cmd_ac_init(void) wins_ac = autocomplete_new(); autocomplete_add(wins_ac, "unread"); autocomplete_add(wins_ac, "prune"); - autocomplete_add(wins_ac, "tidy"); - autocomplete_add(wins_ac, "autotidy"); autocomplete_add(wins_ac, "swap"); roster_ac = autocomplete_new(); @@ -774,6 +778,34 @@ cmd_ac_init(void) winpos_ac = autocomplete_new(); autocomplete_add(winpos_ac, "up"); autocomplete_add(winpos_ac, "down"); + + statusbar_ac = autocomplete_new(); + autocomplete_add(statusbar_ac, "up"); + autocomplete_add(statusbar_ac, "down"); + 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"); + + statusbar_room_ac = autocomplete_new(); + autocomplete_add(statusbar_room_ac, "room"); + autocomplete_add(statusbar_room_ac, "jid"); + + statusbar_show_ac = autocomplete_new(); + autocomplete_add(statusbar_show_ac, "name"); + autocomplete_add(statusbar_show_ac, "number"); } void @@ -1055,6 +1087,11 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(presence_ac); 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); autocomplete_reset(script_ac); if (script_show_ac) { @@ -1182,6 +1219,11 @@ cmd_ac_uninit(void) autocomplete_free(presence_ac); 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); } char* @@ -1301,7 +1343,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ // autocomplete boolean settings gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", "/chlog", "/grlog", - "/history", "/vercheck", "/privileges", "/wrap", "/winstidy", "/carbons", "/encwarn", + "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/encwarn", "/lastactivity" }; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { @@ -1369,8 +1411,8 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ } } - gchar *cmds[] = { "/prefs", "/disco", "/room", "/autoping", "/titlebar", "/mainwin", "/statusbar", "/inputwin" }; - Autocomplete completers[] = { prefs_ac, disco_ac, room_ac, autoping_ac, winpos_ac, winpos_ac, winpos_ac, winpos_ac }; + gchar *cmds[] = { "/prefs", "/disco", "/room", "/autoping", "/titlebar", "/mainwin", "/inputwin" }; + Autocomplete completers[] = { prefs_ac, disco_ac, room_ac, autoping_ac, winpos_ac, winpos_ac, winpos_ac }; for (i = 0; i < ARRAY_SIZE(cmds); i++) { result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE, previous); @@ -1421,6 +1463,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ g_hash_table_insert(ac_funcs, "/tray", _tray_autocomplete); g_hash_table_insert(ac_funcs, "/presence", _presence_autocomplete); g_hash_table_insert(ac_funcs, "/rooms", _rooms_autocomplete); + g_hash_table_insert(ac_funcs, "/statusbar", _statusbar_autocomplete); int len = strlen(input); char parsed[len+1]; @@ -2632,11 +2675,6 @@ _wins_autocomplete(ProfWin *window, const char *const input, gboolean previous) { char *result = NULL; - result = autocomplete_param_with_func(input, "/wins autotidy", prefs_autocomplete_boolean_choice, previous); - if (result) { - return result; - } - result = autocomplete_param_with_ac(input, "/wins", wins_ac, TRUE, previous); if (result) { return result; @@ -3181,3 +3219,41 @@ _rooms_autocomplete(ProfWin *window, const char *const input, gboolean previous) return NULL; } + +static char* +_statusbar_autocomplete(ProfWin *window, const char *const input, gboolean previous) +{ + char *found = NULL; + + found = autocomplete_param_with_ac(input, "/statusbar", statusbar_ac, TRUE, previous); + if (found) { + return found; + } + + found = autocomplete_param_with_ac(input, "/statusbar show", statusbar_show_ac, TRUE, previous); + if (found) { + return found; + } + + found = autocomplete_param_with_ac(input, "/statusbar hide", statusbar_show_ac, TRUE, previous); + if (found) { + 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; + } + + found = autocomplete_param_with_ac(input, "/statusbar room", statusbar_room_ac, TRUE, previous); + if (found) { + return found; + } + + return NULL; +} diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index cb2aa842..d6ee9be6 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -962,18 +962,14 @@ static struct cmd_t command_defs[] = parse_args, 0, 3, NULL, CMD_SUBFUNCS( { "unread", cmd_wins_unread }, - { "tidy", cmd_wins_tidy }, { "prune", cmd_wins_prune }, - { "swap", cmd_wins_swap }, - { "autotidy", cmd_wins_autotidy }) + { "swap", cmd_wins_swap }) CMD_MAINFUNC(cmd_wins) CMD_TAGS( CMD_TAG_UI) CMD_SYN( "/wins", "/wins unread", - "/wins tidy", - "/wins autotidy on|off", "/wins prune", "/wins swap <source> <target>") CMD_DESC( @@ -981,9 +977,7 @@ static struct cmd_t command_defs[] = "Passing no argument will list all currently active windows and information about their usage.") CMD_ARGS( { "unread", "List windows with unread messages." }, - { "tidy", "Move windows so there are no gaps." }, - { "autotidy on|off", "Automatically remove gaps when closing windows." }, - { "prune", "Close all windows with no unread messages, and then tidy so there are no gaps." }, + { "prune", "Close all windows with no unread messages." }, { "swap <source> <target>", "Swap windows, target may be an empty position." }) CMD_NOEXAMPLES }, @@ -1358,20 +1352,37 @@ static struct cmd_t command_defs[] = }, { "/statusbar", - parse_args, 1, 1, &cons_winpos_setting, + parse_args, 1, 2, &cons_statusbar_setting, CMD_NOSUBFUNCS CMD_MAINFUNC(cmd_statusbar) CMD_TAGS( CMD_TAG_UI) CMD_SYN( + "/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", "/statusbar down") CMD_DESC( - "Move the status bar.") - CMD_ARGS( - { "up", "Move the status bar up the screen." }, - { "down", "Move the status bar down the screen." }) - CMD_NOEXAMPLES + "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." }, + { "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 self user", + "/statusbar chat jid", + "/statusbar hide name") }, { "/inputwin", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 53c8b9ed..11f1f51c 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -1253,17 +1253,6 @@ cmd_wins_unread(ProfWin *window, const char *const command, gchar **args) } gboolean -cmd_wins_tidy(ProfWin *window, const char *const command, gchar **args) -{ - if (wins_tidy()) { - cons_show("Windows tidied."); - } else { - cons_show("No tidy needed."); - } - return TRUE; -} - -gboolean cmd_wins_prune(ProfWin *window, const char *const command, gchar **args) { ui_prune_wins(); @@ -1280,38 +1269,34 @@ cmd_wins_swap(ProfWin *window, const char *const command, gchar **args) int source_win = atoi(args[1]); int target_win = atoi(args[2]); + if ((source_win == 1) || (target_win == 1)) { cons_show("Cannot move console window."); - } else if (source_win == 10 || target_win == 10) { + return TRUE; + } + + if (source_win == 10 || target_win == 10) { cons_show("Window 10 does not exist"); - } else if (source_win != target_win) { - gboolean swapped = wins_swap(source_win, target_win); - if (swapped) { - cons_show("Swapped windows %d <-> %d", source_win, target_win); - } else { - cons_show("Window %d does not exist", source_win); - } - } else { + return TRUE; + } + + if (source_win == target_win) { cons_show("Same source and target window supplied."); + return TRUE; } - return TRUE; -} + if (wins_get_by_num(source_win) == NULL) { + cons_show("Window %d does not exist", source_win); + return TRUE; + } -gboolean -cmd_wins_autotidy(ProfWin *window, const char *const command, gchar **args) -{ - if (g_strcmp0(args[1], "on") == 0) { - cons_show("Window autotidy enabled"); - prefs_set_boolean(PREF_WINS_AUTO_TIDY, TRUE); - wins_tidy(); - } else if (g_strcmp0(args[1], "off") == 0) { - cons_show("Window autotidy disabled"); - prefs_set_boolean(PREF_WINS_AUTO_TIDY, FALSE); - } else { - cons_bad_cmd_usage(command); + if (wins_get_by_num(target_win) == NULL) { + cons_show("Window %d does not exist", target_win); + return TRUE; } + wins_swap(source_win, target_win); + cons_show("Swapped windows %d <-> %d", source_win, target_win); return TRUE; } @@ -1407,11 +1392,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) // close the window ui_close_win(index); cons_show("Closed window %d", index); - - // Tidy up the window list. - if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) { - wins_tidy(); - } + wins_tidy(); rosterwin_roster(); return TRUE; @@ -1442,11 +1423,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) // close the window ui_close_win(index); cons_show("Closed window %s", args[0]); - - // Tidy up the window list. - if (prefs_get_boolean(PREF_WINS_AUTO_TIDY)) { - wins_tidy(); - } + wins_tidy(); rosterwin_roster(); return TRUE; @@ -2095,7 +2072,7 @@ cmd_who(ProfWin *window, const char *const command, gchar **args) } if (window->type != WIN_CONSOLE && window->type != WIN_MUC) { - status_bar_new(1); + status_bar_new(1, WIN_CONSOLE, "console"); } return TRUE; @@ -3942,6 +3919,7 @@ cmd_form(ProfWin *window, const char *const command, gchar **args) } ui_focus_win(new_current); wins_close_by_num(num); + wins_tidy(); } return TRUE; @@ -5792,6 +5770,145 @@ cmd_mainwin(ProfWin *window, const char *const command, gchar **args) gboolean cmd_statusbar(ProfWin *window, const char *const command, gchar **args) { + if (g_strcmp0(args[0], "show") == 0) { + if (g_strcmp0(args[1], "name") == 0) { + prefs_set_boolean(PREF_STATUSBAR_SHOW_NAME, TRUE); + cons_show("Enabled showing tab names."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "number") == 0) { + prefs_set_boolean(PREF_STATUSBAR_SHOW_NUMBER, TRUE); + cons_show("Enabled showing tab numbers."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + + if (g_strcmp0(args[0], "hide") == 0) { + if (g_strcmp0(args[1], "name") == 0) { + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NUMBER) == FALSE) { + cons_show("Cannot disable both names and numbers in statusbar."); + cons_show("Use '/statusbar maxtabs 0' to hide tabs."); + return TRUE; + } + prefs_set_boolean(PREF_STATUSBAR_SHOW_NAME, FALSE); + cons_show("Disabled showing tab names."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "number") == 0) { + if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME) == FALSE) { + cons_show("Cannot disable both names and numbers in statusbar."); + cons_show("Use '/statusbar maxtabs 0' to hide tabs."); + return TRUE; + } + prefs_set_boolean(PREF_STATUSBAR_SHOW_NUMBER, FALSE); + cons_show("Disabled showing tab numbers."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + + 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); + } + 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[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"); + cons_show("Using jid for chat tabs."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "user") == 0) { + prefs_set_string(PREF_STATUSBAR_CHAT, "user"); + cons_show("Using user for chat tabs."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + + if (g_strcmp0(args[0], "room") == 0) { + if (g_strcmp0(args[1], "jid") == 0) { + prefs_set_string(PREF_STATUSBAR_ROOM, "jid"); + cons_show("Using jid for room tabs."); + ui_resize(); + return TRUE; + } + if (g_strcmp0(args[1], "room") == 0) { + prefs_set_string(PREF_STATUSBAR_ROOM, "room"); + cons_show("Using room name for room tabs."); + ui_resize(); + return TRUE; + } + cons_bad_cmd_usage(command); + return TRUE; + } + if (g_strcmp0(args[0], "up") == 0) { gboolean result = prefs_statusbar_pos_up(); if (result) { diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index aa703f6d..0bbf338e 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -205,10 +205,8 @@ gboolean cmd_otr_answer(ProfWin *window, const char *const command, gchar **args gboolean cmd_wins(ProfWin *window, const char *const command, gchar **args); gboolean cmd_wins_unread(ProfWin *window, const char *const command, gchar **args); -gboolean cmd_wins_tidy(ProfWin *window, const char *const command, gchar **args); gboolean cmd_wins_prune(ProfWin *window, const char *const command, gchar **args); gboolean cmd_wins_swap(ProfWin *window, const char *const command, gchar **args); -gboolean cmd_wins_autotidy(ProfWin *window, const char *const command, gchar **args); gboolean cmd_form_field(ProfWin *window, char *tag, gchar **args); |