From aab6a52eeea0445b823bc579e9d2122349a46923 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 15 Jan 2016 00:44:47 +0000 Subject: [PATCH 1/2] Show unread message count for contacts in roster --- src/ui/rosterwin.c | 103 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 79 insertions(+), 24 deletions(-) diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index b05f7b42..06ac4673 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -131,8 +131,19 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr } } +theme_item_t +_get_roster_theme(roster_contact_theme_t theme_type, const char *presence) +{ + switch (theme_type) { + case ROSTER_CONTACT: return theme_roster_presence_attrs(presence); + case ROSTER_CONTACT_ACTIVE: return theme_roster_active_presence_attrs(presence); + case ROSTER_CONTACT_UNREAD: return theme_roster_unread_presence_attrs(presence); + default: return theme_roster_presence_attrs(presence); + } +} + static void -_rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_indent, roster_contact_theme_t theme_type) +_rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_indent, roster_contact_theme_t theme_type, int unread) { gboolean join = prefs_get_boolean(PREF_ROSTER_RESOURCE_JOIN); @@ -141,13 +152,7 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde if (join && (g_list_length(resources) == 1)) { Resource *resource = resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); - - theme_item_t resource_presence_colour; - switch (theme_type) { - case ROSTER_CONTACT: resource_presence_colour = theme_roster_presence_attrs(resource_presence); break; - case ROSTER_CONTACT_ACTIVE: resource_presence_colour = theme_roster_active_presence_attrs(resource_presence); break; - case ROSTER_CONTACT_UNREAD: resource_presence_colour = theme_roster_unread_presence_attrs(resource_presence); break; - } + theme_item_t resource_presence_colour = _get_roster_theme(theme_type, resource_presence); wattron(layout->subwin, theme_attrs(resource_presence_colour)); GString *msg = g_string_new(""); @@ -161,6 +166,11 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) { g_string_append_printf(msg, " %d", resource->priority); } + + if (unread > 0) { + g_string_append_printf(msg, " (%d)", unread); + } + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); win_sub_print(layout->subwin, msg->str, FALSE, wrap, 0); g_string_free(msg, TRUE); @@ -170,6 +180,20 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde _rosterwin_presence(layout, resource_presence_colour, resource_presence, resource->status, current_indent); } } else { + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); + + if (unread > 0) { + GString *unreadmsg = g_string_new(""); + g_string_append_printf(unreadmsg, " (%d)", unread); + + const char *presence = p_contact_presence(contact); + theme_item_t presence_colour = _get_roster_theme(theme_type, presence); + + wattron(layout->subwin, theme_attrs(presence_colour)); + win_sub_print(layout->subwin, unreadmsg->str, FALSE, wrap, current_indent); + wattroff(layout->subwin, theme_attrs(presence_colour)); + } + int resource_indent = prefs_get_roster_resource_indent(); if (resource_indent > 0) { current_indent += resource_indent; @@ -179,13 +203,7 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde while (curr_resource) { Resource *resource = curr_resource->data; const char *resource_presence = string_from_resource_presence(resource->presence); - - theme_item_t resource_presence_colour; - switch (theme_type) { - case ROSTER_CONTACT: resource_presence_colour = theme_roster_presence_attrs(resource_presence); break; - case ROSTER_CONTACT_ACTIVE: resource_presence_colour = theme_roster_active_presence_attrs(resource_presence); break; - case ROSTER_CONTACT_UNREAD: resource_presence_colour = theme_roster_unread_presence_attrs(resource_presence); break; - } + theme_item_t resource_presence_colour = _get_roster_theme(theme_type, resource_presence); wattron(layout->subwin, theme_attrs(resource_presence_colour)); GString *msg = g_string_new(" "); @@ -203,7 +221,6 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde g_string_append_printf(msg, " %d", resource->priority); } win_sub_newline_lazy(layout->subwin); - 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)); @@ -218,9 +235,33 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) { const char *presence = p_contact_presence(contact); const char *status = p_contact_status(contact); - theme_item_t presence_colour = theme_main_presence_attrs(presence); + theme_item_t presence_colour = _get_roster_theme(theme_type, presence); + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); + + if (unread > 0) { + GString *unreadmsg = g_string_new(""); + g_string_append_printf(unreadmsg, " (%d)", unread); + + wattron(layout->subwin, theme_attrs(presence_colour)); + win_sub_print(layout->subwin, unreadmsg->str, FALSE, wrap, current_indent); + wattroff(layout->subwin, theme_attrs(presence_colour)); + } _rosterwin_presence(layout, presence_colour, presence, status, current_indent); + } else { + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); + + if (unread > 0) { + GString *unreadmsg = g_string_new(""); + g_string_append_printf(unreadmsg, " (%d)", unread); + const char *presence = p_contact_presence(contact); + theme_item_t presence_colour = _get_roster_theme(theme_type, presence); + + wattron(layout->subwin, theme_attrs(presence_colour)); + win_sub_print(layout->subwin, unreadmsg->str, FALSE, wrap, current_indent); + wattroff(layout->subwin, theme_attrs(presence_colour)); + } } + g_list_free(resources); } @@ -232,23 +273,20 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) const char *presence = p_contact_presence(contact); const char *status = p_contact_status(contact); const char *barejid = p_contact_barejid(contact); + int unread = 0; roster_contact_theme_t theme_type = ROSTER_CONTACT; ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { if (chatwin->unread > 0) { theme_type = ROSTER_CONTACT_UNREAD; + unread = chatwin->unread; } else { theme_type = ROSTER_CONTACT_ACTIVE; } } - theme_item_t presence_colour; - switch (theme_type) { - case ROSTER_CONTACT: presence_colour = theme_roster_presence_attrs(presence); break; - case ROSTER_CONTACT_ACTIVE: presence_colour = theme_roster_active_presence_attrs(presence); break; - case ROSTER_CONTACT_UNREAD: presence_colour = theme_roster_unread_presence_attrs(presence); break; - } + theme_item_t presence_colour = _get_roster_theme(theme_type, presence); wattron(layout->subwin, theme_attrs(presence_colour)); GString *msg = g_string_new(" "); @@ -266,6 +304,14 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) 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; + } + win_sub_newline_lazy(layout->subwin); gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); win_sub_print(layout->subwin, msg->str, FALSE, wrap, current_indent); @@ -273,8 +319,17 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) wattroff(layout->subwin, theme_attrs(presence_colour)); if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { - _rosterwin_resources(layout, contact, current_indent, theme_type); + _rosterwin_resources(layout, contact, current_indent, theme_type, unread); } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) { + if (unread > 0) { + GString *unreadmsg = g_string_new(""); + g_string_append_printf(unreadmsg, " (%d)", unread); + wattron(layout->subwin, theme_attrs(presence_colour)); + win_sub_print(layout->subwin, unreadmsg->str, FALSE, wrap, current_indent); + g_string_free(unreadmsg, TRUE); + wattroff(layout->subwin, theme_attrs(presence_colour)); + } + _rosterwin_presence(layout, presence_colour, presence, status, current_indent); } } From 56751e896bf60e1305d99ed9f827279ac9cc25d3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 15 Jan 2016 00:45:37 +0000 Subject: [PATCH 2/2] Updated boothj5 theme --- themes/boothj5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/boothj5 b/themes/boothj5 index 1f356161..83f07fa9 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -97,7 +97,7 @@ roster.empty=false roster.by=group roster.order=presence roster.count=true -roster.priority=true +roster.priority=false roster.size=25 roster.wrap=true roster.header.char=@