From e58be44f8185a0fbb43a3ee902acf21c89b158b6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 17 Jan 2016 01:49:16 +0000 Subject: [PATCH 1/2] Added /roster room unread preference closes ##708 --- src/command/command.c | 17 +++++++++++++++++ src/command/commands.c | 26 ++++++++++++++++++++++++++ src/config/preferences.c | 5 +++++ src/config/preferences.h | 1 + src/config/theme.c | 1 + src/ui/console.c | 9 +++++++++ src/ui/rosterwin.c | 7 ++++++- themes/boothj5 | 1 + themes/complex | 1 + themes/simple | 1 + 10 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/command/command.c b/src/command/command.c index 681e4ff7..b6c00803 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -283,6 +283,7 @@ static struct cmd_t command_defs[] = "/roster by group|presence|none", "/roster order name|presence", "/roster room order name|unread", + "/roster room unread before|after|off", "/roster header char |none", "/roster presence indent ", "/roster contact char |none", @@ -327,6 +328,9 @@ static struct cmd_t command_defs[] = { "order presence", "Order roster items by presence, and then by name." }, { "room order name", "Order roster rooms by name." }, { "room order unread", "Order roster rooms by unread messages, and then by name." }, + { "room unread before", "Show unread message count before room in roster." }, + { "room unread after", "Show unread message count after room in roster." }, + { "room unread off", "Do not show unread message count for rooms in rosters." }, { "header char ", "Prefix roster headers with specified character." }, { "header char none", "Remove roster header character prefix." }, { "contact char ", "Prefix roster contacts with specified character." }, @@ -1911,6 +1915,7 @@ static Autocomplete roster_char_ac; static Autocomplete roster_remove_all_ac; static Autocomplete roster_room_ac; static Autocomplete roster_room_order_ac; +static Autocomplete roster_unread_ac; static Autocomplete group_ac; static Autocomplete bookmark_ac; static Autocomplete bookmark_property_ac; @@ -2212,8 +2217,14 @@ cmd_init(void) autocomplete_add(roster_order_ac, "name"); autocomplete_add(roster_order_ac, "presence"); + roster_unread_ac = autocomplete_new(); + autocomplete_add(roster_unread_ac, "before"); + autocomplete_add(roster_unread_ac, "after"); + autocomplete_add(roster_unread_ac, "off"); + roster_room_ac = autocomplete_new(); autocomplete_add(roster_room_ac, "order"); + autocomplete_add(roster_room_ac, "unread"); roster_room_order_ac = autocomplete_new(); autocomplete_add(roster_room_order_ac, "name"); @@ -2492,6 +2503,7 @@ cmd_uninit(void) autocomplete_free(roster_by_ac); autocomplete_free(roster_order_ac); autocomplete_free(roster_room_ac); + autocomplete_free(roster_unread_ac); autocomplete_free(roster_room_order_ac); autocomplete_free(roster_remove_all_ac); autocomplete_free(group_ac); @@ -2702,6 +2714,7 @@ cmd_reset_autocomplete(ProfWin *window) autocomplete_reset(roster_by_ac); autocomplete_reset(roster_order_ac); autocomplete_reset(roster_room_ac); + autocomplete_reset(roster_unread_ac); autocomplete_reset(roster_room_order_ac); autocomplete_reset(roster_remove_all_ac); autocomplete_reset(group_ac); @@ -3115,6 +3128,10 @@ _roster_autocomplete(ProfWin *window, const char *const input) if (result) { return result; } + result = autocomplete_param_with_ac(input, "/roster room unread", roster_unread_ac, TRUE); + if (result) { + return result; + } jabber_conn_status_t conn_status = jabber_get_connection_status(); if (conn_status == JABBER_CONNECTED) { diff --git a/src/command/commands.c b/src/command/commands.c index 7b6fef6d..3ad79778 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2330,6 +2330,32 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) cons_bad_cmd_usage(command); return TRUE; } + } else if (g_strcmp0(args[1], "unread") == 0) { + if (g_strcmp0(args[2], "before") == 0) { + cons_show("Roster rooms unread message count: before"); + prefs_set_string(PREF_ROSTER_ROOMS_UNREAD, "before"); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else if (g_strcmp0(args[2], "after") == 0) { + cons_show("Roster rooms unread message count: after"); + prefs_set_string(PREF_ROSTER_ROOMS_UNREAD, "after"); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else if (g_strcmp0(args[2], "off") == 0) { + cons_show("Roster rooms unread message count: off"); + prefs_set_string(PREF_ROSTER_ROOMS_UNREAD, "off"); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } } else { cons_bad_cmd_usage(command); return TRUE; diff --git a/src/config/preferences.c b/src/config/preferences.c index 7188517a..4b762c04 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1048,6 +1048,7 @@ _get_group(preference_t pref) case PREF_ROSTER_RESOURCE_JOIN: case PREF_ROSTER_ROOMS: case PREF_ROSTER_ROOMS_ORDER: + case PREF_ROSTER_ROOMS_UNREAD: case PREF_RESOURCE_TITLE: case PREF_RESOURCE_MESSAGE: case PREF_ENC_WARN: @@ -1246,6 +1247,8 @@ _get_key(preference_t pref) return "roster.rooms"; case PREF_ROSTER_ROOMS_ORDER: return "roster.rooms.order"; + case PREF_ROSTER_ROOMS_UNREAD: + return "roster.rooms.unread"; case PREF_RESOURCE_TITLE: return "resource.title"; case PREF_RESOURCE_MESSAGE: @@ -1335,6 +1338,8 @@ _get_default_string(preference_t pref) return "presence"; case PREF_ROSTER_ROOMS_ORDER: return "name"; + case PREF_ROSTER_ROOMS_UNREAD: + return "after"; case PREF_TIME_CONSOLE: return "%H:%M:%S"; case PREF_TIME_CHAT: diff --git a/src/config/preferences.h b/src/config/preferences.h index a46acf6a..06c2c67b 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -75,6 +75,7 @@ typedef enum { PREF_ROSTER_RESOURCE_JOIN, PREF_ROSTER_ROOMS, PREF_ROSTER_ROOMS_ORDER, + PREF_ROSTER_ROOMS_UNREAD, PREF_MUC_PRIVILEGES, PREF_PRESENCE, PREF_WRAP, diff --git a/src/config/theme.c b/src/config/theme.c index c0a6b134..6460f65d 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -321,6 +321,7 @@ _load_preferences(void) _set_boolean_preference("roster.priority", PREF_ROSTER_PRIORITY); _set_boolean_preference("roster.rooms", PREF_ROSTER_ROOMS); _set_string_preference("roster.rooms.order", PREF_ROSTER_ROOMS_ORDER); + _set_string_preference("roster.rooms.unread", PREF_ROSTER_ROOMS_ORDER); if (g_key_file_has_key(theme, "ui", "roster.size", NULL)) { gint roster_size = g_key_file_get_integer(theme, "ui", "roster.size", NULL); prefs_set_roster_size(roster_size); diff --git a/src/ui/console.c b/src/ui/console.c index 42001960..4656b4e3 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1341,6 +1341,15 @@ cons_roster_setting(void) cons_show("Roster rooms order (/roster) : %s", rooms_order); prefs_free_string(rooms_order); + char *roomsunread = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD); + if (g_strcmp0(roomsunread, "before") == 0) { + cons_show("Roster rooms unread (/roster) : before"); + } else if (g_strcmp0(roomsunread, "after") == 0) { + cons_show("Roster rooms unread (/roster) : after"); + } else { + cons_show("Roster rooms unread (/roster) : OFF"); + } + int size = prefs_get_roster_size(); cons_show("Roster size (/roster) : %d", size); diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 06ac4673..5b18ec95 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -483,10 +483,15 @@ _rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin) g_string_append_printf(msg, "%c", ch); } + char *unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD); + if ((g_strcmp0(unreadpos, "before") == 0) && mucwin->unread > 0) { + g_string_append_printf(msg, "(%d) ", mucwin->unread); + } g_string_append(msg, mucwin->roomjid); - if (mucwin->unread > 0) { + if ((g_strcmp0(unreadpos, "after") == 0) && mucwin->unread > 0) { g_string_append_printf(msg, " (%d)", mucwin->unread); } + prefs_free_string(unreadpos); win_sub_newline_lazy(layout->subwin); gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); diff --git a/themes/boothj5 b/themes/boothj5 index 83f07fa9..31c3586c 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -111,6 +111,7 @@ roster.presence.indent=-1 roster.status=true roster.rooms=true roster.rooms.order=name +roster.rooms.unread=after occupants=true occupants.size=15 occupants.jid=false diff --git a/themes/complex b/themes/complex index dc98217e..16aa96a7 100644 --- a/themes/complex +++ b/themes/complex @@ -39,6 +39,7 @@ roster.presence.indent=1 roster.status=true roster.rooms=true roster.rooms.order=unread +roster.rooms.unread=after privileges=true presence=true intype=true diff --git a/themes/simple b/themes/simple index 2f9ace50..39423e25 100644 --- a/themes/simple +++ b/themes/simple @@ -31,6 +31,7 @@ roster.resource=false roster.presence=false roster.status=false roster.rooms=false +roster.rooms.unread=off privileges=false presence=false intype=false From cce01f1d75a43b943237a11f9695e8426425210a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 17 Jan 2016 02:17:12 +0000 Subject: [PATCH 2/2] Added /roster unread preferrence closes #712 --- src/command/command.c | 11 ++++++++++- src/command/commands.c | 27 +++++++++++++++++++++++++++ src/config/preferences.c | 5 +++++ src/config/preferences.h | 1 + src/config/theme.c | 1 + src/ui/console.c | 19 ++++++++++++++----- src/ui/rosterwin.c | 35 +++++++++++++++++++++++++---------- theme_template | 2 ++ themes/boothj5 | 3 ++- themes/complex | 1 + themes/simple | 1 + 11 files changed, 89 insertions(+), 17 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index b6c00803..f3c4d3bb 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -282,6 +282,7 @@ static struct cmd_t command_defs[] = "/roster hide [offline|resource|presence|status|empty|count|priority|rooms]", "/roster by group|presence|none", "/roster order name|presence", + "/roster unread before|after|off", "/roster room order name|unread", "/roster room unread before|after|off", "/roster header char |none", @@ -326,11 +327,14 @@ static struct cmd_t command_defs[] = { "by none", "No grouping in the roster panel." }, { "order name", "Order roster items by name only." }, { "order presence", "Order roster items by presence, and then by name." }, + { "unread before", "Show unread message count before contact in roster." }, + { "unread after", "Show unread message count after contact in roster." }, + { "unread off", "Do not show unread message count for contacts in roster." }, { "room order name", "Order roster rooms by name." }, { "room order unread", "Order roster rooms by unread messages, and then by name." }, { "room unread before", "Show unread message count before room in roster." }, { "room unread after", "Show unread message count after room in roster." }, - { "room unread off", "Do not show unread message count for rooms in rosters." }, + { "room unread off", "Do not show unread message count for rooms in roster." }, { "header char ", "Prefix roster headers with specified character." }, { "header char none", "Remove roster header character prefix." }, { "contact char ", "Prefix roster contacts with specified character." }, @@ -2172,6 +2176,7 @@ cmd_init(void) autocomplete_add(roster_ac, "hide"); autocomplete_add(roster_ac, "by"); autocomplete_add(roster_ac, "order"); + autocomplete_add(roster_ac, "unread"); autocomplete_add(roster_ac, "room"); autocomplete_add(roster_ac, "size"); autocomplete_add(roster_ac, "wrap"); @@ -3169,6 +3174,10 @@ _roster_autocomplete(ProfWin *window, const char *const input) if (result) { return result; } + result = autocomplete_param_with_ac(input, "/roster unread", roster_unread_ac, TRUE); + if (result) { + return result; + } result = autocomplete_param_with_ac(input, "/roster room", roster_room_ac, TRUE); if (result) { return result; diff --git a/src/command/commands.c b/src/command/commands.c index 3ad79778..76904ef0 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2310,6 +2310,33 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) return TRUE; } + } else if (g_strcmp0(args[0], "unread") == 0) { + if (g_strcmp0(args[1], "before") == 0) { + cons_show("Roster unread message count: before"); + prefs_set_string(PREF_ROSTER_UNREAD, "before"); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else if (g_strcmp0(args[1], "after") == 0) { + cons_show("Roster unread message count: after"); + prefs_set_string(PREF_ROSTER_UNREAD, "after"); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else if (g_strcmp0(args[1], "off") == 0) { + cons_show("Roster unread message count: off"); + prefs_set_string(PREF_ROSTER_UNREAD, "off"); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } + } else if (g_strcmp0(args[0], "room") == 0) { if (g_strcmp0(args[1], "order") == 0) { if (g_strcmp0(args[2], "name") == 0) { diff --git a/src/config/preferences.c b/src/config/preferences.c index 4b762c04..54bc5516 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1042,6 +1042,7 @@ _get_group(preference_t pref) case PREF_ROSTER_EMPTY: case PREF_ROSTER_BY: case PREF_ROSTER_ORDER: + case PREF_ROSTER_UNREAD: case PREF_ROSTER_COUNT: case PREF_ROSTER_PRIORITY: case PREF_ROSTER_WRAP: @@ -1235,6 +1236,8 @@ _get_key(preference_t pref) return "roster.by"; case PREF_ROSTER_ORDER: return "roster.order"; + case PREF_ROSTER_UNREAD: + return "roster.unread"; case PREF_ROSTER_COUNT: return "roster.count"; case PREF_ROSTER_PRIORITY: @@ -1336,6 +1339,8 @@ _get_default_string(preference_t pref) return "presence"; case PREF_ROSTER_ORDER: return "presence"; + case PREF_ROSTER_UNREAD: + return "after"; case PREF_ROSTER_ROOMS_ORDER: return "name"; case PREF_ROSTER_ROOMS_UNREAD: diff --git a/src/config/preferences.h b/src/config/preferences.h index 06c2c67b..df6cd482 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -69,6 +69,7 @@ typedef enum { PREF_ROSTER_EMPTY, PREF_ROSTER_BY, PREF_ROSTER_ORDER, + PREF_ROSTER_UNREAD, PREF_ROSTER_COUNT, PREF_ROSTER_PRIORITY, PREF_ROSTER_WRAP, diff --git a/src/config/theme.c b/src/config/theme.c index 6460f65d..3dad150a 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -317,6 +317,7 @@ _load_preferences(void) _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_string_preference("roster.unread", PREF_ROSTER_UNREAD); _set_boolean_preference("roster.count", PREF_ROSTER_COUNT); _set_boolean_preference("roster.priority", PREF_ROSTER_PRIORITY); _set_boolean_preference("roster.rooms", PREF_ROSTER_ROOMS); diff --git a/src/ui/console.c b/src/ui/console.c index 4656b4e3..78ab8d2a 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1324,11 +1324,6 @@ cons_roster_setting(void) else cons_show("Roster priority (/roster) : hide"); - if (prefs_get_boolean(PREF_ROSTER_ROOMS)) - cons_show("Roster rooms (/roster) : show"); - else - cons_show("Roster rooms (/roster) : hide"); - char *by = prefs_get_string(PREF_ROSTER_BY); cons_show("Roster by (/roster) : %s", by); prefs_free_string(by); @@ -1337,6 +1332,20 @@ cons_roster_setting(void) cons_show("Roster order (/roster) : %s", order); prefs_free_string(order); + char *unread = prefs_get_string(PREF_ROSTER_UNREAD); + if (g_strcmp0(unread, "before") == 0) { + cons_show("Roster unread (/roster) : before"); + } else if (g_strcmp0(unread, "after") == 0) { + cons_show("Roster unread (/roster) : after"); + } else { + cons_show("Roster unread (/roster) : OFF"); + } + + if (prefs_get_boolean(PREF_ROSTER_ROOMS)) + cons_show("Roster rooms (/roster) : show"); + else + cons_show("Roster rooms (/roster) : hide"); + char *rooms_order = prefs_get_string(PREF_ROSTER_ROOMS_ORDER); cons_show("Roster rooms order (/roster) : %s", rooms_order); prefs_free_string(rooms_order); diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 5b18ec95..7593b9ab 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -167,9 +167,11 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde g_string_append_printf(msg, " %d", resource->priority); } - if (unread > 0) { + char *unreadpos = prefs_get_string(PREF_ROSTER_UNREAD); + if ((g_strcmp0(unreadpos, "after") == 0) && unread > 0) { g_string_append_printf(msg, " (%d)", unread); } + prefs_free_string(unreadpos); gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); win_sub_print(layout->subwin, msg->str, FALSE, wrap, 0); @@ -182,7 +184,8 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde } else { gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); - if (unread > 0) { + char *unreadpos = prefs_get_string(PREF_ROSTER_UNREAD); + if ((g_strcmp0(unreadpos, "after") == 0) && unread > 0) { GString *unreadmsg = g_string_new(""); g_string_append_printf(unreadmsg, " (%d)", unread); @@ -193,6 +196,7 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde win_sub_print(layout->subwin, unreadmsg->str, FALSE, wrap, current_indent); wattroff(layout->subwin, theme_attrs(presence_colour)); } + prefs_free_string(unreadpos); int resource_indent = prefs_get_roster_resource_indent(); if (resource_indent > 0) { @@ -238,7 +242,8 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde theme_item_t presence_colour = _get_roster_theme(theme_type, presence); gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); - if (unread > 0) { + char *unreadpos = prefs_get_string(PREF_ROSTER_UNREAD); + if ((g_strcmp0(unreadpos, "after") == 0) && unread > 0) { GString *unreadmsg = g_string_new(""); g_string_append_printf(unreadmsg, " (%d)", unread); @@ -246,11 +251,13 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde win_sub_print(layout->subwin, unreadmsg->str, FALSE, wrap, current_indent); wattroff(layout->subwin, theme_attrs(presence_colour)); } + prefs_free_string(unreadpos); _rosterwin_presence(layout, presence_colour, presence, status, current_indent); } else { gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); - if (unread > 0) { + char *unreadpos = prefs_get_string(PREF_ROSTER_UNREAD); + if ((g_strcmp0(unreadpos, "after") == 0) && unread > 0) { GString *unreadmsg = g_string_new(""); g_string_append_printf(unreadmsg, " (%d)", unread); const char *presence = p_contact_presence(contact); @@ -260,6 +267,7 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde win_sub_print(layout->subwin, unreadmsg->str, FALSE, wrap, current_indent); wattroff(layout->subwin, theme_attrs(presence_colour)); } + prefs_free_string(unreadpos); } g_list_free(resources); @@ -303,14 +311,21 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) if (ch) { g_string_append_printf(msg, "%c", ch); } - g_string_append(msg, name); - if (!prefs_get_boolean(PREF_ROSTER_RESOURCE)) { - if (unread > 0) { - g_string_append_printf(msg, " (%d)", unread); - } - unread = 0; + char *unreadpos = prefs_get_string(PREF_ROSTER_UNREAD); + if ((g_strcmp0(unreadpos, "before") == 0) && unread > 0) { + g_string_append_printf(msg, "(%d) ", unread); } + g_string_append(msg, name); + if (g_strcmp0(unreadpos, "after") == 0) { + if (!prefs_get_boolean(PREF_ROSTER_RESOURCE)) { + if (unread > 0) { + g_string_append_printf(msg, " (%d)", unread); + } + unread = 0; + } + } + prefs_free_string(unreadpos); win_sub_newline_lazy(layout->subwin); gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); diff --git a/theme_template b/theme_template index a0382029..70d2a765 100644 --- a/theme_template +++ b/theme_template @@ -96,6 +96,7 @@ roster.offline= roster.empty= roster.by= roster.order= +roster.unread= roster.count= roster.priority= roster.size= @@ -112,6 +113,7 @@ roster.presence.indent= roster.status= roster.rooms= roster.rooms.order= +roster.rooms.unread= occupants= occupants.size= occupants.jid= diff --git a/themes/boothj5 b/themes/boothj5 index 31c3586c..c01354fa 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -96,6 +96,7 @@ roster.offline=true roster.empty=false roster.by=group roster.order=presence +roster.unread=before roster.count=true roster.priority=false roster.size=25 @@ -111,7 +112,7 @@ roster.presence.indent=-1 roster.status=true roster.rooms=true roster.rooms.order=name -roster.rooms.unread=after +roster.rooms.unread=before occupants=true occupants.size=15 occupants.jid=false diff --git a/themes/complex b/themes/complex index 16aa96a7..b509e242 100644 --- a/themes/complex +++ b/themes/complex @@ -23,6 +23,7 @@ roster.offline=true roster.empty=true roster.by=presence roster.order=presence +roster.unread=after roster.count=true roster.priority=true roster.size=25 diff --git a/themes/simple b/themes/simple index 39423e25..debfe45a 100644 --- a/themes/simple +++ b/themes/simple @@ -22,6 +22,7 @@ roster.offline=false roster.empty=false roster.by=none roster.order=presence +roster.unread=off roster.count=false roster.priority=false roster.size=25