about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2018-03-08 22:27:49 +0000
committerJames Booth <boothj5@gmail.com>2018-03-08 22:27:49 +0000
commit720dce866eb759a7b5ecdaff7c7d9ceeb6e2487c (patch)
tree8f9e072c17a0d8ecb8acefd97f304015442fd694
parent119c5650cf1b40d3074faae1a280e8d3dfbedc03 (diff)
downloadprofani-tty-720dce866eb759a7b5ecdaff7c7d9ceeb6e2487c.tar.gz
Add prefs for empty tabs and tab names
-rw-r--r--src/command/cmd_ac.c45
-rw-r--r--src/command/cmd_defs.c19
-rw-r--r--src/command/cmd_funcs.c38
-rw-r--r--src/config/preferences.c6
-rw-r--r--src/config/preferences.h2
-rw-r--r--src/ui/console.c16
-rw-r--r--src/ui/statusbar.c25
-rw-r--r--src/ui/ui.h1
-rw-r--r--src/ui/window.c7
-rw-r--r--tests/unittests/ui/stub_ui.c1
10 files changed, 140 insertions, 20 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index bb6e9cd6..ec572325 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,8 @@ static Autocomplete tray_ac;
 static Autocomplete presence_ac;
 static Autocomplete presence_setting_ac;
 static Autocomplete winpos_ac;
+static Autocomplete statusbar_ac;
+static Autocomplete statusbar_show_ac;
 
 void
 cmd_ac_init(void)
@@ -774,6 +777,16 @@ 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");
+
+    statusbar_show_ac = autocomplete_new();
+    autocomplete_add(statusbar_show_ac, "empty");
+    autocomplete_add(statusbar_show_ac, "name");
 }
 
 void
@@ -1055,6 +1068,8 @@ 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_show_ac);
 
     autocomplete_reset(script_ac);
     if (script_show_ac) {
@@ -1182,6 +1197,8 @@ cmd_ac_uninit(void)
     autocomplete_free(presence_ac);
     autocomplete_free(presence_setting_ac);
     autocomplete_free(winpos_ac);
+    autocomplete_free(statusbar_ac);
+    autocomplete_free(statusbar_show_ac);
 }
 
 char*
@@ -1369,8 +1386,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 +1438,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];
@@ -3181,3 +3199,26 @@ _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;
+    }
+
+    return NULL;
+}
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index cb2aa842..f8c50739 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -1358,20 +1358,29 @@ 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 empty|name",
+            "/statusbar hide empty|name",
+//            "/statusbar maxtabs <value>",
             "/statusbar up",
             "/statusbar down")
         CMD_DESC(
-            "Move the status bar.")
+            "Manage statusbar display preferences.")
         CMD_ARGS(
-            { "up", "Move the status bar up the screen." },
-            { "down", "Move the status bar down the screen." })
-        CMD_NOEXAMPLES
+//            { "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 name",     "Show or hide names in tabs." },
+            { "up",                 "Move the status bar up the screen." },
+            { "down",               "Move the status bar down the screen." })
+        CMD_EXAMPLES(
+//            "/statusbar maxtabs 5",
+            "/statusbar show empty",
+            "/statusbar hide name")
     },
 
     { "/inputwin",
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index b4840afd..1e5b3b55 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -5792,6 +5792,44 @@ 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], "empty") == 0) {
+            prefs_set_boolean(PREF_STATUSBAR_SHOW_EMPTY, TRUE);
+            cons_show("Enabled showing empty tabs.");
+            ui_resize();
+            return TRUE;
+        }
+        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;
+        }
+        cons_bad_cmd_usage(command);
+        return TRUE;
+    }
+
+    if (g_strcmp0(args[0], "hide") == 0) {
+        if (g_strcmp0(args[1], "empty") == 0) {
+            prefs_set_boolean(PREF_STATUSBAR_SHOW_EMPTY, FALSE);
+            cons_show("Disabled showing empty tabs.");
+            ui_resize();
+            return TRUE;
+        }
+        if (g_strcmp0(args[1], "name") == 0) {
+            prefs_set_boolean(PREF_STATUSBAR_SHOW_NAME, FALSE);
+            cons_show("Disabled showing tab names.");
+            ui_resize();
+            return TRUE;
+        }
+        cons_bad_cmd_usage(command);
+        return TRUE;
+    }
+
+    if (g_strcmp0(args[0], "maxtabs") == 0) {
+
+    }
+
     if (g_strcmp0(args[0], "up") == 0) {
         gboolean result = prefs_statusbar_pos_up();
         if (result) {
diff --git a/src/config/preferences.c b/src/config/preferences.c
index d935061c..63089a20 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -1570,6 +1570,8 @@ _get_group(preference_t pref)
         case PREF_CONSOLE_MUC:
         case PREF_CONSOLE_PRIVATE:
         case PREF_CONSOLE_CHAT:
+        case PREF_STATUSBAR_SHOW_EMPTY:
+        case PREF_STATUSBAR_SHOW_NAME:
             return PREF_GROUP_UI;
         case PREF_STATES:
         case PREF_OUTTYPE:
@@ -1825,6 +1827,10 @@ _get_key(preference_t pref)
             return "sourcepath";
         case PREF_ROOM_LIST_CACHE:
             return "rooms.cache";
+        case PREF_STATUSBAR_SHOW_EMPTY:
+            return "statusbar.show.empty";
+        case PREF_STATUSBAR_SHOW_NAME:
+            return "statusbar.show.name";
         default:
             return NULL;
     }
diff --git a/src/config/preferences.h b/src/config/preferences.h
index 6eb2241d..183d033a 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -144,6 +144,8 @@ typedef enum {
     PREF_BOOKMARK_INVITE,
     PREF_PLUGINS_SOURCEPATH,
     PREF_ROOM_LIST_CACHE,
+    PREF_STATUSBAR_SHOW_EMPTY,
+    PREF_STATUSBAR_SHOW_NAME,
 } preference_t;
 
 typedef struct prof_alias_t {
diff --git a/src/ui/console.c b/src/ui/console.c
index 55bba1c5..84e7b59b 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -1748,6 +1748,22 @@ cons_inpblock_setting(void)
 }
 
 void
+cons_statusbar_setting(void)
+{
+    cons_winpos_setting();
+    if (prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY)) {
+        cons_show("Show empty tabs (/statusbar)        : ON");
+    } else {
+        cons_show("Show empty tabs (/statusbar)        : OFF");
+    }
+    if (prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME)) {
+        cons_show("Show tab names (/statusbar)         : ON");
+    } else {
+        cons_show("Show tab names (/statusbar)         : OFF");
+    }
+}
+
+void
 cons_winpos_setting(void)
 {
     ProfWinPlacement *placement = prefs_get_win_placement();
diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c
index ff264202..ca8e8a47 100644
--- a/src/ui/statusbar.c
+++ b/src/ui/statusbar.c
@@ -63,9 +63,7 @@ typedef struct _status_bar_t {
     int current_tab;
 } StatusBar;
 
-#define MAX_TABS 5
-#define SHOW_EMPTY_TABS FALSE
-#define SHOW_NAME TRUE
+#define MAX_TABS 10
 
 static GTimeZone *tz;
 static StatusBar *statusbar;
@@ -229,8 +227,6 @@ status_bar_clear(void)
         statusbar->message = NULL;
     }
 
-    werase(statusbar_win);
-
     _status_bar_draw();
 }
 
@@ -248,8 +244,11 @@ status_bar_clear_message(void)
 static int
 _tabs_width(void)
 {
-    if (SHOW_NAME) {
-        if (SHOW_EMPTY_TABS) {
+    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++) {
@@ -275,7 +274,7 @@ _tabs_width(void)
             return width;
         }
     } else {
-        if (SHOW_EMPTY_TABS) {
+        if (show_empty) {
             return MAX_TABS * 3 + 4;
         } else {
             return g_hash_table_size(statusbar->tabs) * 3 + 4;
@@ -286,6 +285,7 @@ _tabs_width(void)
 static void
 _status_bar_draw(void)
 {
+    werase(statusbar_win);
     wbkgd(statusbar_win, theme_attrs(THEME_STATUS_TEXT));
 
     int pos = 1;
@@ -337,12 +337,15 @@ _status_bar_draw(void)
     pos = cols - _tabs_width();
     int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);
 
+    gboolean show_empty = prefs_get_boolean(PREF_STATUSBAR_SHOW_EMPTY);
+    gboolean show_name = prefs_get_boolean(PREF_STATUSBAR_SHOW_NAME);
+
     int i = 1;
     for (i = 1; i <= MAX_TABS; i++) {
         int display_num = i == 10 ? 0 : i;
 
         StatusBarTab *tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i));
-        if (tab || (tab == NULL && SHOW_EMPTY_TABS)) {
+        if (tab || (tab == NULL && show_empty)) {
             wattron(statusbar_win, bracket_attrs);
             if (i == statusbar->current_tab) {
                 mvwprintw(statusbar_win, 0, pos, "-");
@@ -356,7 +359,7 @@ _status_bar_draw(void)
                     int status_attrs = theme_attrs(THEME_STATUS_NEW);
                     wattron(statusbar_win, status_attrs);
                     mvwprintw(statusbar_win, 0, pos, "%d", display_num);
-                    if (SHOW_NAME) {
+                    if (show_name) {
                         pos++;
                         mvwprintw(statusbar_win, 0, pos, ":");
                         pos++;
@@ -368,7 +371,7 @@ _status_bar_draw(void)
                     int status_attrs = theme_attrs(THEME_STATUS_ACTIVE);
                     wattron(statusbar_win, status_attrs);
                     mvwprintw(statusbar_win, 0, pos, "%d", display_num);
-                    if (SHOW_NAME) {
+                    if (show_name) {
                         pos++;
                         mvwprintw(statusbar_win, 0, pos, ":");
                         pos++;
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 5d779df6..81af4b30 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -318,6 +318,7 @@ void cons_autoping_setting(void);
 void cons_autoconnect_setting(void);
 void cons_room_cache_setting(void);
 void cons_inpblock_setting(void);
+void cons_statusbar_setting(void);
 void cons_winpos_setting(void);
 void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity);
 void cons_show_contact_offline(PContact contact, char *resource, char *status);
diff --git a/src/ui/window.c b/src/ui/window.c
index 83da1219..39d178ee 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -210,7 +210,10 @@ win_create_muc_config(const char *const roomjid, DataForm *form)
 {
     ProfMucConfWin *new_win = malloc(sizeof(ProfMucConfWin));
     new_win->window.type = WIN_MUC_CONFIG;
-    new_win->window.tab_name = strdup(roomjid);
+    GString *tab_str = g_string_new(roomjid);
+    g_string_append(tab_str, " config");
+    new_win->window.tab_name = strdup(tab_str->str);
+    g_string_free(tab_str, TRUE);
     new_win->window.layout = _win_create_simple_layout();
 
     new_win->roomjid = strdup(roomjid);
@@ -257,7 +260,7 @@ win_create_plugin(const char *const plugin_name, const char *const tag)
 {
     ProfPluginWin *new_win = malloc(sizeof(ProfPluginWin));
     new_win->window.type = WIN_PLUGIN;
-    new_win->window.tab_name = strdup(plugin_name);
+    new_win->window.tab_name = strdup(tag);
     new_win->window.layout = _win_create_simple_layout();
 
     new_win->tag = strdup(tag);
diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c
index e31e88f5..da226092 100644
--- a/tests/unittests/ui/stub_ui.c
+++ b/tests/unittests/ui/stub_ui.c
@@ -448,6 +448,7 @@ void cons_autoconnect_setting(void) {}
 void cons_rooms_cache_setting(void) {}
 void cons_inpblock_setting(void) {}
 void cons_winpos_setting(void) {}
+void cons_statusbar_setting(void) {}
 void cons_tray_setting(void) {}
 
 void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity)