From 3bc9275079ce76689ad7f08538cf6ba76b034df7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 22 Nov 2015 01:39:20 +0000 Subject: [PATCH] Added word wrap to roster panel --- src/command/command.c | 7 +++++++ src/command/commands.c | 11 +++++++++++ src/config/preferences.c | 3 +++ src/config/preferences.h | 1 + src/config/theme.c | 1 + src/ui/console.c | 5 +++++ src/ui/occupantswin.c | 12 ++++++------ src/ui/rosterwin.c | 28 ++++++++++++++++++---------- src/ui/window.c | 8 ++++++-- src/ui/window.h | 2 +- theme_template | 1 + 11 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 37e963c9..313898c1 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -284,6 +284,7 @@ static struct cmd_t command_defs[] = "/roster indent resource ", "/roster indent presence ", "/roster size ", + "/roster wrap on|off", "/roster add []", "/roster remove ", "/roster remove_all contacts", @@ -323,6 +324,7 @@ static struct cmd_t command_defs[] = { "indent resource ", "Indent resource line by spaces." }, { "indent presence ", "Indent presence line by spaces." }, { "size ", "Percentage of the screen taken up by the roster (1-99)." }, + { "wrap on|off", "Enabled or disanle line wrapping in roster panel." }, { "add []", "Add a new item to the roster." }, { "remove ", "Removes an item from the roster." }, { "remove_all contacts", "Remove all items from roster." }, @@ -2041,6 +2043,7 @@ cmd_init(void) autocomplete_add(roster_ac, "size"); autocomplete_add(roster_ac, "char"); autocomplete_add(roster_ac, "indent"); + autocomplete_add(roster_ac, "wrap"); roster_char_ac = autocomplete_new(); autocomplete_add(roster_char_ac, "header"); @@ -2953,6 +2956,10 @@ _roster_autocomplete(ProfWin *window, const char *const input) if (result) { return result; } + result = autocomplete_param_with_func(input, "/roster wrap", prefs_autocomplete_boolean_choice); + if (result) { + return result; + } result = autocomplete_param_with_ac(input, "/roster", roster_ac, TRUE); if (result) { return result; diff --git a/src/command/commands.c b/src/command/commands.c index 3aa05950..e1710ae1 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1750,6 +1750,17 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) return TRUE; } + // set line wrapping + } else if (g_strcmp0(args[0], "wrap") == 0) { + if (!args[1]) { + cons_bad_cmd_usage(command); + return TRUE; + } else { + int res = _cmd_set_boolean_preference(args[1], command, "Roster panel line wrap", PREF_ROSTER_WRAP); + rosterwin_roster(); + return res; + } + // set header character } else if (g_strcmp0(args[0], "char") == 0) { if (g_strcmp0(args[1], "header") == 0) { diff --git a/src/config/preferences.c b/src/config/preferences.c index 26405989..958ed97c 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -732,6 +732,7 @@ _get_group(preference_t pref) case PREF_ROSTER_ORDER: case PREF_ROSTER_COUNT: case PREF_ROSTER_PRIORITY: + case PREF_ROSTER_WRAP: case PREF_RESOURCE_TITLE: case PREF_RESOURCE_MESSAGE: case PREF_ENC_WARN: @@ -915,6 +916,8 @@ _get_key(preference_t pref) return "roster.count"; case PREF_ROSTER_PRIORITY: return "roster.priority"; + case PREF_ROSTER_WRAP: + return "roster.wrap"; case PREF_RESOURCE_TITLE: return "resource.title"; case PREF_RESOURCE_MESSAGE: diff --git a/src/config/preferences.h b/src/config/preferences.h index 02ea8505..b187cb0b 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -71,6 +71,7 @@ typedef enum { PREF_ROSTER_ORDER, PREF_ROSTER_COUNT, PREF_ROSTER_PRIORITY, + PREF_ROSTER_WRAP, PREF_MUC_PRIVILEGES, PREF_PRESENCE, PREF_WRAP, diff --git a/src/config/theme.c b/src/config/theme.c index 271a48c8..6175bd7a 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -461,6 +461,7 @@ _load_preferences(void) _set_boolean_preference("roster.presence", PREF_ROSTER_PRESENCE); _set_boolean_preference("roster.status", PREF_ROSTER_STATUS); _set_boolean_preference("roster.empty", PREF_ROSTER_EMPTY); + _set_boolean_preference("roster.wrap", PREF_ROSTER_WRAP); _set_string_preference("roster.by", PREF_ROSTER_BY); _set_string_preference("roster.order", PREF_ROSTER_ORDER); _set_boolean_preference("roster.count", PREF_ROSTER_COUNT); diff --git a/src/ui/console.c b/src/ui/console.c index 5f1b5ec4..bcf2de7e 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1263,6 +1263,11 @@ cons_roster_setting(void) gint presence_indent = prefs_get_roster_presence_indent(); cons_show("Roster presence indent (/roster) : %d", presence_indent); + + if (prefs_get_boolean(PREF_ROSTER_WRAP)) + cons_show("Roster wrap (/roster) : ON"); + else + cons_show("Roster wrap (/roster) : OFF"); } void diff --git a/src/ui/occupantswin.c b/src/ui/occupantswin.c index 7e22ab0b..a5cee950 100644 --- a/src/ui/occupantswin.c +++ b/src/ui/occupantswin.c @@ -48,13 +48,13 @@ _occuptantswin_occupant(ProfLayoutSplit *layout, Occupant *occupant, gboolean sh GString *msg = g_string_new(" "); g_string_append(msg, occupant->nick); - win_sub_print(layout->subwin, msg->str, TRUE, FALSE); + win_sub_print(layout->subwin, msg->str, TRUE, FALSE, 0); g_string_free(msg, TRUE); if (showjid && occupant->jid) { GString *msg = g_string_new(" "); g_string_append(msg, occupant->jid); - win_sub_print(layout->subwin, msg->str, TRUE, FALSE); + win_sub_print(layout->subwin, msg->str, TRUE, FALSE, 0); g_string_free(msg, TRUE); } @@ -75,7 +75,7 @@ occupantswin_occupants(const char *const roomjid) if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) { wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_sub_print(layout->subwin, " -Moderators", TRUE, FALSE); + win_sub_print(layout->subwin, " -Moderators", TRUE, FALSE, 0); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); GList *roster_curr = occupants; while (roster_curr) { @@ -87,7 +87,7 @@ occupantswin_occupants(const char *const roomjid) } wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_sub_print(layout->subwin, " -Participants", TRUE, FALSE); + win_sub_print(layout->subwin, " -Participants", TRUE, FALSE, 0); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); roster_curr = occupants; while (roster_curr) { @@ -99,7 +99,7 @@ occupantswin_occupants(const char *const roomjid) } wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_sub_print(layout->subwin, " -Visitors", TRUE, FALSE); + win_sub_print(layout->subwin, " -Visitors", TRUE, FALSE, 0); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); roster_curr = occupants; while (roster_curr) { @@ -111,7 +111,7 @@ occupantswin_occupants(const char *const roomjid) } } else { wattron(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); - win_sub_print(layout->subwin, " -Occupants\n", TRUE, FALSE); + win_sub_print(layout->subwin, " -Occupants\n", TRUE, FALSE, 0); wattroff(layout->subwin, theme_attrs(THEME_OCCUPANTS_HEADER)); GList *roster_curr = occupants; while (roster_curr) { diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 4df9516b..1e43ed8d 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -61,6 +61,8 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr current_indent += presence_indent; } + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); + // show only status when grouped by presence if (by_presence) { if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { @@ -68,7 +70,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr if (presence_indent == -1) { GString *msg = g_string_new(""); g_string_append_printf(msg, ": \"%s\"", status); - win_sub_print(layout->subwin, msg->str, FALSE, FALSE); + win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } else { @@ -79,7 +81,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr } g_string_append_printf(msg, "\"%s\"", status); win_sub_newline_lazy(layout->subwin); - win_sub_print(layout->subwin, msg->str, FALSE, FALSE); + win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } @@ -98,7 +100,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { g_string_append_printf(msg, ": \"%s\"", status); } - win_sub_print(layout->subwin, msg->str, FALSE, FALSE); + win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } else { @@ -116,7 +118,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr g_string_append_printf(msg, "\"%s\"", status); } win_sub_newline_lazy(layout->subwin); - win_sub_print(layout->subwin, msg->str, FALSE, FALSE); + win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(colour)); } @@ -151,7 +153,8 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde g_string_append_printf(msg, " %d", resource->priority); } win_sub_newline_lazy(layout->subwin); - win_sub_print(layout->subwin, msg->str, FALSE, FALSE); + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); + win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(resource_presence_colour)); @@ -197,7 +200,8 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) } g_string_append(msg, name); win_sub_newline_lazy(layout->subwin); - win_sub_print(layout->subwin, msg->str, FALSE, FALSE); + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); + win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(presence_colour)); @@ -228,7 +232,8 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title_str, " (%d)", g_slist_length(contacts)); } - win_sub_print(layout->subwin, title_str->str, FALSE, FALSE); + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); + win_sub_print(layout->subwin, title_str->str, FALSE, wrap, 1); g_string_free(title_str, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); } @@ -272,7 +277,8 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group, gboolean newl if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_sub_print(layout->subwin, title->str, FALSE, FALSE); + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); + win_sub_print(layout->subwin, title->str, FALSE, wrap, 1); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -315,7 +321,8 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout, gboolean newline) if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_sub_print(layout->subwin, title->str, FALSE, FALSE); + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); + win_sub_print(layout->subwin, title->str, FALSE, wrap, 1); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -387,7 +394,8 @@ rosterwin_roster(void) if (prefs_get_boolean(PREF_ROSTER_COUNT)) { g_string_append_printf(title, " (%d)", g_slist_length(contacts)); } - win_sub_print(layout->subwin, title->str, FALSE, FALSE); + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); + win_sub_print(layout->subwin, title->str, FALSE, wrap, 1); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); diff --git a/src/ui/window.c b/src/ui/window.c index b8e2a59d..9317f3b8 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1266,13 +1266,17 @@ win_unread(ProfWin *window) } void -win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap) +win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap, int indent) { int maxx = getmaxx(win); int curx = getcurx(win); int cury = getcury(win); - waddnstr(win, msg, maxx - curx); + if (wrap) { + _win_print_wrapped(win, msg, 1, indent); + } else { + waddnstr(win, msg, maxx - curx); + } if (newline) { wmove(win, cury+1, 0); diff --git a/src/ui/window.h b/src/ui/window.h index 41765276..f5c6aada 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -67,7 +67,7 @@ void win_newline(ProfWin *window); void win_redraw(ProfWin *window); int win_roster_cols(void); int win_occpuants_cols(void); -void win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap); +void win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap, int indent); void win_sub_newline_lazy(WINDOW *win); void win_mark_received(ProfWin *window, const char *const id); diff --git a/theme_template b/theme_template index 14645ce0..ddd41c81 100644 --- a/theme_template +++ b/theme_template @@ -87,6 +87,7 @@ roster.contact.char= roster.contact.indent= roster.resource.indent= roster.presence.indent= +roster.wrap= occupants= occupants.size= occupants.jid=