From badbc3003f1a6e2d6eecb166a36fef8bc66f9b17 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Nov 2015 21:33:48 +0000 Subject: [PATCH 01/15] Show presence in roster WIP --- src/command/command.c | 10 ++++++-- src/command/commands.c | 28 ++++++++++++++++++++++ src/config/preferences.c | 8 +++++++ src/config/preferences.h | 2 ++ src/ui/rosterwin.c | 50 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 2b8b4d8b..4241acb4 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -274,8 +274,8 @@ static struct cmd_t command_defs[] = CMD_SYN( "/roster", "/roster online", - "/roster show [offline|resource|empty]", - "/roster hide [offline|resource|empty]", + "/roster show [offline|resource|presence|status|empty]", + "/roster hide [offline|resource|presence|status|empty]", "/roster by group|presence|none", "/roster size ", "/roster add []", @@ -291,10 +291,14 @@ static struct cmd_t command_defs[] = { "show", "Show the roster panel." }, { "show offline", "Show offline contacts in the roster panel." }, { "show resource", "Show contact's connected resources in the roster panel." }, + { "show presence", "Show contact's presence in the roster panel." }, + { "show status", "Show contact's status message in the roster panel." }, { "show empty", "When grouping by presence, show empty presence groups." }, { "hide", "Hide the roster panel." }, { "hide offline", "Hide offline contacts in the roster panel." }, { "hide resource", "Hide contact's connected resources in the roster panel." }, + { "hide presence", "Hide contact's presence in the roster panel." }, + { "hide status", "Hide contact's status message in the roster panel." }, { "hide empty", "When grouping by presence, hide empty presence groups." }, { "by group", "Group contacts in the roster panel by roster group." }, { "by presence", "Group contacts in the roster panel by presence." }, @@ -2015,6 +2019,8 @@ cmd_init(void) roster_option_ac = autocomplete_new(); autocomplete_add(roster_option_ac, "offline"); autocomplete_add(roster_option_ac, "resource"); + autocomplete_add(roster_option_ac, "presence"); + autocomplete_add(roster_option_ac, "status"); autocomplete_add(roster_option_ac, "empty"); roster_by_ac = autocomplete_new(); diff --git a/src/command/commands.c b/src/command/commands.c index fe3c7045..40a041c9 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1773,6 +1773,20 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) rosterwin_roster(); } return TRUE; + } else if (g_strcmp0(args[1], "presence") == 0) { + cons_show("Roster presence enabled"); + prefs_set_boolean(PREF_ROSTER_PRESENCE, TRUE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else if (g_strcmp0(args[1], "status") == 0) { + cons_show("Roster status enabled"); + prefs_set_boolean(PREF_ROSTER_STATUS, TRUE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; } else if (g_strcmp0(args[1], "empty") == 0) { cons_show("Roster empty enabled"); prefs_set_boolean(PREF_ROSTER_EMPTY, TRUE); @@ -1806,6 +1820,20 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) rosterwin_roster(); } return TRUE; + } else if (g_strcmp0(args[1], "presence") == 0) { + cons_show("Roster presence disabled"); + prefs_set_boolean(PREF_ROSTER_PRESENCE, FALSE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else if (g_strcmp0(args[1], "status") == 0) { + cons_show("Roster status disabled"); + prefs_set_boolean(PREF_ROSTER_STATUS, FALSE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; } else if (g_strcmp0(args[1], "empty") == 0) { cons_show("Roster empty disabled"); prefs_set_boolean(PREF_ROSTER_EMPTY, FALSE); diff --git a/src/config/preferences.c b/src/config/preferences.c index c7196051..b8f6d607 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -597,6 +597,8 @@ _get_group(preference_t pref) case PREF_ROSTER: case PREF_ROSTER_OFFLINE: case PREF_ROSTER_RESOURCE: + case PREF_ROSTER_PRESENCE: + case PREF_ROSTER_STATUS: case PREF_ROSTER_EMPTY: case PREF_ROSTER_BY: case PREF_RESOURCE_TITLE: @@ -768,6 +770,10 @@ _get_key(preference_t pref) return "roster.offline"; case PREF_ROSTER_RESOURCE: return "roster.resource"; + case PREF_ROSTER_PRESENCE: + return "roster.presence"; + case PREF_ROSTER_STATUS: + return "roster.status"; case PREF_ROSTER_EMPTY: return "roster.empty"; case PREF_ROSTER_BY: @@ -823,6 +829,8 @@ _get_default_boolean(preference_t pref) case PREF_ROSTER: case PREF_ROSTER_OFFLINE: case PREF_ROSTER_RESOURCE: + case PREF_ROSTER_PRESENCE: + case PREF_ROSTER_STATUS: case PREF_ROSTER_EMPTY: case PREF_TLS_SHOW: case PREF_LASTACTIVITY: diff --git a/src/config/preferences.h b/src/config/preferences.h index 9aa6ff72..ff830cce 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -64,6 +64,8 @@ typedef enum { PREF_ROSTER_SIZE, PREF_ROSTER_OFFLINE, PREF_ROSTER_RESOURCE, + PREF_ROSTER_PRESENCE, + PREF_ROSTER_STATUS, PREF_ROSTER_EMPTY, PREF_ROSTER_BY, PREF_MUC_PRIVILEGES, diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index d7d4012d..6201394d 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -47,6 +47,7 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) { const char *name = p_contact_name_or_jid(contact); const char *presence = p_contact_presence(contact); + char *by = prefs_get_string(PREF_ROSTER_BY); if ((g_strcmp0(presence, "offline") != 0) || ((g_strcmp0(presence, "offline") == 0) && (prefs_get_boolean(PREF_ROSTER_OFFLINE)))) { @@ -74,9 +75,58 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(resource_presence_colour)); + if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + gboolean by_presence = g_strcmp0(by, "presence") == 0; + gboolean has_status = resource->status != NULL; + gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); + if (!by_presence || (has_status && show_status)) { + wattron(layout->subwin, theme_attrs(resource_presence_colour)); + GString *msg = g_string_new(" "); + if (!by_presence) { + g_string_append(msg, resource_presence); + } + if (has_status && show_status) { + if (!by_presence) { + g_string_append(msg, ", \""); + } else { + g_string_append(msg, "\""); + } + g_string_append(msg, resource->status); + g_string_append(msg, "\""); + } + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(resource_presence_colour)); + } + } + curr_resource = g_list_next(curr_resource); } g_list_free(resources); + } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + gboolean by_presence = g_strcmp0(by, "presence") == 0; + gboolean has_status = p_contact_status(contact) != NULL; + gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); + if (!by_presence || (has_status && show_status)) { + wattron(layout->subwin, theme_attrs(presence_colour)); + GString *msg = g_string_new(" "); + if (!by_presence) { + g_string_append(msg, presence); + } + if (has_status && show_status) { + if (!by_presence) { + g_string_append(msg, ", \""); + } else { + g_string_append(msg, "\""); + } + const char *status = p_contact_status(contact); + g_string_append(msg, status); + g_string_append(msg, "\""); + } + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(presence_colour)); + } } } } From 98a395e933672320c773a6653f79106373d8b1e3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Nov 2015 22:17:36 +0000 Subject: [PATCH 02/15] Show presence when resource hidden --- src/ui/console.c | 10 ++++++ src/ui/rosterwin.c | 86 ++++++++++++++++++++++++++++++---------------- 2 files changed, 66 insertions(+), 30 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 01f05bca..8825cf69 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1207,6 +1207,16 @@ cons_roster_setting(void) else cons_show("Roster resource (/roster) : hide"); + if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) + cons_show("Roster presence (/roster) : show"); + else + cons_show("Roster presence (/roster) : hide"); + + if (prefs_get_boolean(PREF_ROSTER_STATUS)) + cons_show("Roster status (/roster) : show"); + else + cons_show("Roster status (/roster) : hide"); + if (prefs_get_boolean(PREF_ROSTER_EMPTY)) cons_show("Roster empty (/roster) : show"); else diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 6201394d..e3cff25e 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -62,45 +62,71 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { GList *resources = p_contact_get_available_resources(contact); - GList *curr_resource = resources; - while (curr_resource) { - Resource *resource = curr_resource->data; - const char *resource_presence = string_from_resource_presence(resource->presence); - theme_item_t resource_presence_colour = theme_main_presence_attrs(resource_presence); + if (resources) { + GList *curr_resource = resources; + while (curr_resource) { + Resource *resource = curr_resource->data; + const char *resource_presence = string_from_resource_presence(resource->presence); + theme_item_t resource_presence_colour = theme_main_presence_attrs(resource_presence); - wattron(layout->subwin, theme_attrs(resource_presence_colour)); - GString *msg = g_string_new(" "); - g_string_append(msg, resource->name); - win_printline_nowrap(layout->subwin, msg->str); - g_string_free(msg, TRUE); - wattroff(layout->subwin, theme_attrs(resource_presence_colour)); + wattron(layout->subwin, theme_attrs(resource_presence_colour)); + GString *msg = g_string_new(" "); + g_string_append(msg, resource->name); + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(resource_presence_colour)); - if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { - gboolean by_presence = g_strcmp0(by, "presence") == 0; - gboolean has_status = resource->status != NULL; - gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); - if (!by_presence || (has_status && show_status)) { - wattron(layout->subwin, theme_attrs(resource_presence_colour)); - GString *msg = g_string_new(" "); - if (!by_presence) { - g_string_append(msg, resource_presence); - } - if (has_status && show_status) { + if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + gboolean by_presence = g_strcmp0(by, "presence") == 0; + gboolean has_status = resource->status != NULL; + gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); + if (!by_presence || (has_status && show_status)) { + wattron(layout->subwin, theme_attrs(resource_presence_colour)); + GString *msg = g_string_new(" "); if (!by_presence) { - g_string_append(msg, ", \""); - } else { + g_string_append(msg, resource_presence); + } + if (has_status && show_status) { + if (!by_presence) { + g_string_append(msg, ", \""); + } else { + g_string_append(msg, "\""); + } + g_string_append(msg, resource->status); g_string_append(msg, "\""); } - g_string_append(msg, resource->status); + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(resource_presence_colour)); + } + } + + curr_resource = g_list_next(curr_resource); + } + } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + gboolean by_presence = g_strcmp0(by, "presence") == 0; + gboolean has_status = p_contact_status(contact) != NULL; + gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); + if (!by_presence || (has_status && show_status)) { + wattron(layout->subwin, theme_attrs(presence_colour)); + GString *msg = g_string_new(" "); + if (!by_presence) { + g_string_append(msg, presence); + } + if (has_status && show_status) { + if (!by_presence) { + g_string_append(msg, ", \""); + } else { g_string_append(msg, "\""); } - win_printline_nowrap(layout->subwin, msg->str); - g_string_free(msg, TRUE); - wattroff(layout->subwin, theme_attrs(resource_presence_colour)); + const char *status = p_contact_status(contact); + g_string_append(msg, status); + g_string_append(msg, "\""); } + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(presence_colour)); } - - curr_resource = g_list_next(curr_resource); } g_list_free(resources); } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { From b44ea030224c11233b378e0fde36c3daf2979a05 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Nov 2015 22:54:09 +0000 Subject: [PATCH 03/15] Added _rosterwin_resource() --- src/ui/rosterwin.c | 149 ++++++++++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 69 deletions(-) diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index e3cff25e..b7e77372 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -42,12 +42,89 @@ #include "config/preferences.h" #include "roster_list.h" +static void +_rosterwin_resource(ProfLayoutSplit *layout, PContact contact) +{ + GList *resources = p_contact_get_available_resources(contact); + if (resources) { + GList *curr_resource = resources; + while (curr_resource) { + Resource *resource = curr_resource->data; + const char *resource_presence = string_from_resource_presence(resource->presence); + theme_item_t resource_presence_colour = theme_main_presence_attrs(resource_presence); + + wattron(layout->subwin, theme_attrs(resource_presence_colour)); + GString *msg = g_string_new(" "); + g_string_append(msg, resource->name); + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(resource_presence_colour)); + + if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + char *by = prefs_get_string(PREF_ROSTER_BY); + gboolean by_presence = g_strcmp0(by, "presence") == 0; + gboolean has_status = resource->status != NULL; + gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); + if (!by_presence || (has_status && show_status)) { + wattron(layout->subwin, theme_attrs(resource_presence_colour)); + GString *msg = g_string_new(" "); + if (!by_presence) { + g_string_append(msg, resource_presence); + } + if (has_status && show_status) { + if (!by_presence) { + g_string_append(msg, ", \""); + } else { + g_string_append(msg, "\""); + } + g_string_append(msg, resource->status); + g_string_append(msg, "\""); + } + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(resource_presence_colour)); + } + } + + curr_resource = g_list_next(curr_resource); + } + } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + const char *presence = p_contact_presence(contact); + theme_item_t presence_colour = theme_main_presence_attrs(presence); + char *by = prefs_get_string(PREF_ROSTER_BY); + gboolean by_presence = g_strcmp0(by, "presence") == 0; + gboolean has_status = p_contact_status(contact) != NULL; + gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); + if (!by_presence || (has_status && show_status)) { + wattron(layout->subwin, theme_attrs(presence_colour)); + GString *msg = g_string_new(" "); + if (!by_presence) { + g_string_append(msg, presence); + } + if (has_status && show_status) { + if (!by_presence) { + g_string_append(msg, ", \""); + } else { + g_string_append(msg, "\""); + } + const char *status = p_contact_status(contact); + g_string_append(msg, status); + g_string_append(msg, "\""); + } + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(presence_colour)); + } + } + g_list_free(resources); + +} + static void _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) { const char *name = p_contact_name_or_jid(contact); const char *presence = p_contact_presence(contact); - char *by = prefs_get_string(PREF_ROSTER_BY); if ((g_strcmp0(presence, "offline") != 0) || ((g_strcmp0(presence, "offline") == 0) && (prefs_get_boolean(PREF_ROSTER_OFFLINE)))) { @@ -61,75 +138,9 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) wattroff(layout->subwin, theme_attrs(presence_colour)); if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { - GList *resources = p_contact_get_available_resources(contact); - if (resources) { - GList *curr_resource = resources; - while (curr_resource) { - Resource *resource = curr_resource->data; - const char *resource_presence = string_from_resource_presence(resource->presence); - theme_item_t resource_presence_colour = theme_main_presence_attrs(resource_presence); - - wattron(layout->subwin, theme_attrs(resource_presence_colour)); - GString *msg = g_string_new(" "); - g_string_append(msg, resource->name); - win_printline_nowrap(layout->subwin, msg->str); - g_string_free(msg, TRUE); - wattroff(layout->subwin, theme_attrs(resource_presence_colour)); - - if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { - gboolean by_presence = g_strcmp0(by, "presence") == 0; - gboolean has_status = resource->status != NULL; - gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); - if (!by_presence || (has_status && show_status)) { - wattron(layout->subwin, theme_attrs(resource_presence_colour)); - GString *msg = g_string_new(" "); - if (!by_presence) { - g_string_append(msg, resource_presence); - } - if (has_status && show_status) { - if (!by_presence) { - g_string_append(msg, ", \""); - } else { - g_string_append(msg, "\""); - } - g_string_append(msg, resource->status); - g_string_append(msg, "\""); - } - win_printline_nowrap(layout->subwin, msg->str); - g_string_free(msg, TRUE); - wattroff(layout->subwin, theme_attrs(resource_presence_colour)); - } - } - - curr_resource = g_list_next(curr_resource); - } - } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { - gboolean by_presence = g_strcmp0(by, "presence") == 0; - gboolean has_status = p_contact_status(contact) != NULL; - gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); - if (!by_presence || (has_status && show_status)) { - wattron(layout->subwin, theme_attrs(presence_colour)); - GString *msg = g_string_new(" "); - if (!by_presence) { - g_string_append(msg, presence); - } - if (has_status && show_status) { - if (!by_presence) { - g_string_append(msg, ", \""); - } else { - g_string_append(msg, "\""); - } - const char *status = p_contact_status(contact); - g_string_append(msg, status); - g_string_append(msg, "\""); - } - win_printline_nowrap(layout->subwin, msg->str); - g_string_free(msg, TRUE); - wattroff(layout->subwin, theme_attrs(presence_colour)); - } - } - g_list_free(resources); + _rosterwin_resource(layout, contact); } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + char *by = prefs_get_string(PREF_ROSTER_BY); gboolean by_presence = g_strcmp0(by, "presence") == 0; gboolean has_status = p_contact_status(contact) != NULL; gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); From c31ba8c06613ca9d68e306ebb8686bfaa766537b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Nov 2015 23:13:53 +0000 Subject: [PATCH 04/15] Added _rosterwin_presence() --- src/ui/rosterwin.c | 58 +++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index b7e77372..b19f9858 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -42,6 +42,38 @@ #include "config/preferences.h" #include "roster_list.h" +static void +_rosterwin_presence(ProfLayoutSplit *layout, int indent, theme_item_t colour, const char *presence, const char *status) +{ + char *by = prefs_get_string(PREF_ROSTER_BY); + gboolean by_presence = g_strcmp0(by, "presence") == 0; + gboolean has_status = status != NULL; + gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); + if (!by_presence || (has_status && show_status)) { + wattron(layout->subwin, theme_attrs(colour)); + GString *msg = g_string_new(" "); + while (indent > 0) { + g_string_append(msg, " "); + indent--; + } + if (!by_presence) { + g_string_append(msg, presence); + } + if (has_status && show_status) { + if (!by_presence) { + g_string_append(msg, ", \""); + } else { + g_string_append(msg, "\""); + } + g_string_append(msg, status); + g_string_append(msg, "\""); + } + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(colour)); + } +} + static void _rosterwin_resource(ProfLayoutSplit *layout, PContact contact) { @@ -125,6 +157,7 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) { const char *name = p_contact_name_or_jid(contact); const char *presence = p_contact_presence(contact); + const char *status = p_contact_status(contact); if ((g_strcmp0(presence, "offline") != 0) || ((g_strcmp0(presence, "offline") == 0) && (prefs_get_boolean(PREF_ROSTER_OFFLINE)))) { @@ -140,30 +173,7 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { _rosterwin_resource(layout, contact); } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { - char *by = prefs_get_string(PREF_ROSTER_BY); - gboolean by_presence = g_strcmp0(by, "presence") == 0; - gboolean has_status = p_contact_status(contact) != NULL; - gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); - if (!by_presence || (has_status && show_status)) { - wattron(layout->subwin, theme_attrs(presence_colour)); - GString *msg = g_string_new(" "); - if (!by_presence) { - g_string_append(msg, presence); - } - if (has_status && show_status) { - if (!by_presence) { - g_string_append(msg, ", \""); - } else { - g_string_append(msg, "\""); - } - const char *status = p_contact_status(contact); - g_string_append(msg, status); - g_string_append(msg, "\""); - } - win_printline_nowrap(layout->subwin, msg->str); - g_string_free(msg, TRUE); - wattroff(layout->subwin, theme_attrs(presence_colour)); - } + _rosterwin_presence(layout, 4, presence_colour, presence, status); } } } From 1d9d893ec0b58b33df1b2039622abac37fbec70c Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Nov 2015 23:18:23 +0000 Subject: [PATCH 05/15] Tidy rosterwin --- src/ui/rosterwin.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index b19f9858..3073c85b 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -122,31 +122,9 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact) } } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { const char *presence = p_contact_presence(contact); + const char *status = p_contact_status(contact); theme_item_t presence_colour = theme_main_presence_attrs(presence); - char *by = prefs_get_string(PREF_ROSTER_BY); - gboolean by_presence = g_strcmp0(by, "presence") == 0; - gboolean has_status = p_contact_status(contact) != NULL; - gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); - if (!by_presence || (has_status && show_status)) { - wattron(layout->subwin, theme_attrs(presence_colour)); - GString *msg = g_string_new(" "); - if (!by_presence) { - g_string_append(msg, presence); - } - if (has_status && show_status) { - if (!by_presence) { - g_string_append(msg, ", \""); - } else { - g_string_append(msg, "\""); - } - const char *status = p_contact_status(contact); - g_string_append(msg, status); - g_string_append(msg, "\""); - } - win_printline_nowrap(layout->subwin, msg->str); - g_string_free(msg, TRUE); - wattroff(layout->subwin, theme_attrs(presence_colour)); - } + _rosterwin_presence(layout, 4, presence_colour, presence, status); } g_list_free(resources); From 230a14219cdc12d3548464b5bdd2746b68b8e96a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Nov 2015 23:28:24 +0000 Subject: [PATCH 06/15] Tidy rosterwin.c --- src/ui/rosterwin.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 3073c85b..b721dbfe 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -93,29 +93,7 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact) wattroff(layout->subwin, theme_attrs(resource_presence_colour)); if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { - char *by = prefs_get_string(PREF_ROSTER_BY); - gboolean by_presence = g_strcmp0(by, "presence") == 0; - gboolean has_status = resource->status != NULL; - gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); - if (!by_presence || (has_status && show_status)) { - wattron(layout->subwin, theme_attrs(resource_presence_colour)); - GString *msg = g_string_new(" "); - if (!by_presence) { - g_string_append(msg, resource_presence); - } - if (has_status && show_status) { - if (!by_presence) { - g_string_append(msg, ", \""); - } else { - g_string_append(msg, "\""); - } - g_string_append(msg, resource->status); - g_string_append(msg, "\""); - } - win_printline_nowrap(layout->subwin, msg->str); - g_string_free(msg, TRUE); - wattroff(layout->subwin, theme_attrs(resource_presence_colour)); - } + _rosterwin_presence(layout, 6, resource_presence_colour, resource_presence, resource->status); } curr_resource = g_list_next(curr_resource); From 8e8852fa9f0171bb2c0826303b97655a32e481ca Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 17 Nov 2015 23:37:33 +0000 Subject: [PATCH 07/15] Added /roster order name|presence --- src/command/command.c | 15 +++++ src/command/commands.c | 20 +++++++ src/config/preferences.c | 5 ++ src/config/preferences.h | 1 + src/roster_list.c | 116 ++++++++++++++++++++++++++++++++++++--- src/roster_list.h | 3 + src/ui/console.c | 4 ++ src/ui/rosterwin.c | 30 +++++++++- 8 files changed, 184 insertions(+), 10 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 4241acb4..2a98ba75 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -277,6 +277,7 @@ static struct cmd_t command_defs[] = "/roster show [offline|resource|presence|status|empty]", "/roster hide [offline|resource|presence|status|empty]", "/roster by group|presence|none", + "/roster order name|presence" "/roster size ", "/roster add []", "/roster remove ", @@ -303,6 +304,8 @@ static struct cmd_t command_defs[] = { "by group", "Group contacts in the roster panel by roster group." }, { "by presence", "Group contacts in the roster panel by presence." }, { "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." }, { "size ", "Percentage of the screen taken up by the roster (1-99)." }, { "add []", "Add a new item to the roster." }, { "remove ", "Removes an item from the roster." }, @@ -1771,6 +1774,7 @@ static Autocomplete wins_ac; static Autocomplete roster_ac; static Autocomplete roster_option_ac; static Autocomplete roster_by_ac; +static Autocomplete roster_order_ac; static Autocomplete roster_remove_all_ac; static Autocomplete group_ac; static Autocomplete bookmark_ac; @@ -2014,6 +2018,7 @@ cmd_init(void) autocomplete_add(roster_ac, "show"); autocomplete_add(roster_ac, "hide"); autocomplete_add(roster_ac, "by"); + autocomplete_add(roster_ac, "order"); autocomplete_add(roster_ac, "size"); roster_option_ac = autocomplete_new(); @@ -2028,6 +2033,10 @@ cmd_init(void) autocomplete_add(roster_by_ac, "presence"); autocomplete_add(roster_by_ac, "none"); + roster_order_ac = autocomplete_new(); + autocomplete_add(roster_order_ac, "name"); + autocomplete_add(roster_order_ac, "presence"); + roster_remove_all_ac = autocomplete_new(); autocomplete_add(roster_remove_all_ac, "contacts"); @@ -2282,6 +2291,7 @@ cmd_uninit(void) autocomplete_free(roster_ac); autocomplete_free(roster_option_ac); autocomplete_free(roster_by_ac); + autocomplete_free(roster_order_ac); autocomplete_free(roster_remove_all_ac); autocomplete_free(group_ac); autocomplete_free(bookmark_ac); @@ -2468,6 +2478,7 @@ cmd_reset_autocomplete(ProfWin *window) autocomplete_reset(roster_ac); autocomplete_reset(roster_option_ac); autocomplete_reset(roster_by_ac); + autocomplete_reset(roster_order_ac); autocomplete_reset(roster_remove_all_ac); autocomplete_reset(group_ac); autocomplete_reset(titlebar_ac); @@ -2881,6 +2892,10 @@ _roster_autocomplete(ProfWin *window, const char *const input) if (result) { return result; } + result = autocomplete_param_with_ac(input, "/roster order", roster_order_ac, TRUE); + 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 40a041c9..67f8ae98 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1872,6 +1872,26 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) cons_bad_cmd_usage(command); return TRUE; } + // roster item order + } else if (g_strcmp0(args[0], "order") == 0) { + if (g_strcmp0(args[1], "name") == 0) { + cons_show("Ordering roster by name"); + prefs_set_string(PREF_ROSTER_ORDER, "name"); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else if (g_strcmp0(args[1], "presence") == 0) { + cons_show("Ordering roster by presence"); + prefs_set_string(PREF_ROSTER_ORDER, "presence"); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } // add contact } else if (strcmp(args[0], "add") == 0) { if (conn_status != JABBER_CONNECTED) { diff --git a/src/config/preferences.c b/src/config/preferences.c index b8f6d607..8348edb7 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -601,6 +601,7 @@ _get_group(preference_t pref) case PREF_ROSTER_STATUS: case PREF_ROSTER_EMPTY: case PREF_ROSTER_BY: + case PREF_ROSTER_ORDER: case PREF_RESOURCE_TITLE: case PREF_RESOURCE_MESSAGE: case PREF_ENC_WARN: @@ -778,6 +779,8 @@ _get_key(preference_t pref) return "roster.empty"; case PREF_ROSTER_BY: return "roster.by"; + case PREF_ROSTER_ORDER: + return "roster.order"; case PREF_RESOURCE_TITLE: return "resource.title"; case PREF_RESOURCE_MESSAGE: @@ -861,6 +864,8 @@ _get_default_string(preference_t pref) return "all"; case PREF_ROSTER_BY: return "presence"; + case PREF_ROSTER_ORDER: + return "name"; 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 ff830cce..55b46b07 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -68,6 +68,7 @@ typedef enum { PREF_ROSTER_STATUS, PREF_ROSTER_EMPTY, PREF_ROSTER_BY, + PREF_ROSTER_ORDER, PREF_MUC_PRIVILEGES, PREF_PRESENCE, PREF_WRAP, diff --git a/src/roster_list.c b/src/roster_list.c index 0ba20107..fe3063dd 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -67,7 +67,8 @@ static gboolean _key_equals(void *key1, void *key2); static gboolean _datetimes_equal(GDateTime *dt1, GDateTime *dt2); static void _replace_name(const char *const current_name, const char *const new_name, const char *const barejid); static void _add_name_and_barejid(const char *const name, const char *const barejid); -static gint _compare_contacts(PContact a, PContact b); +static gint _compare_name(PContact a, PContact b); +static gint _compare_presence(PContact a, PContact b); void roster_clear(void) @@ -373,7 +374,7 @@ roster_get_contacts_by_presence(const char *const presence) while (g_hash_table_iter_next(&iter, &key, &value)) { PContact contact = (PContact)value; if (g_strcmp0(p_contact_presence(contact), presence) == 0) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); + result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name); } } @@ -381,6 +382,23 @@ roster_get_contacts_by_presence(const char *const presence) return result; } +GSList* +roster_get_contacts_ord_presence(void) +{ + GSList *result = NULL; + GHashTableIter iter; + gpointer key; + gpointer value; + + g_hash_table_iter_init(&iter, contacts); + while (g_hash_table_iter_next(&iter, &key, &value)) { + result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_presence); + } + + // return all contact structs + return result; +} + GSList* roster_get_contacts(void) { @@ -391,7 +409,7 @@ roster_get_contacts(void) g_hash_table_iter_init(&iter, contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); + result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name); } // return all contact structs @@ -409,7 +427,7 @@ roster_get_contacts_online(void) g_hash_table_iter_init(&iter, contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { if(strcmp(p_contact_presence(value), "offline")) - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); + result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name); } // return all contact structs @@ -446,6 +464,26 @@ roster_fulljid_autocomplete(const char *const search_str) return autocomplete_complete(fulljid_ac, search_str, TRUE); } +GSList* +roster_get_nogroup_ord_presence(void) +{ + GSList *result = NULL; + GHashTableIter iter; + gpointer key; + gpointer value; + + g_hash_table_iter_init(&iter, contacts); + while (g_hash_table_iter_next(&iter, &key, &value)) { + GSList *groups = p_contact_groups(value); + if (groups == NULL) { + result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_presence); + } + } + + // return all contact structs + return result; +} + GSList* roster_get_nogroup(void) { @@ -458,7 +496,31 @@ roster_get_nogroup(void) while (g_hash_table_iter_next(&iter, &key, &value)) { GSList *groups = p_contact_groups(value); if (groups == NULL) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); + result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name); + } + } + + // return all contact structs + return result; +} + +GSList* +roster_get_group_ord_presence(const char *const group) +{ + GSList *result = NULL; + GHashTableIter iter; + gpointer key; + gpointer value; + + g_hash_table_iter_init(&iter, contacts); + while (g_hash_table_iter_next(&iter, &key, &value)) { + GSList *groups = p_contact_groups(value); + while (groups) { + if (strcmp(groups->data, group) == 0) { + result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_presence); + break; + } + groups = g_slist_next(groups); } } @@ -479,7 +541,7 @@ roster_get_group(const char *const group) GSList *groups = p_contact_groups(value); while (groups) { if (strcmp(groups->data, group) == 0) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_contacts); + result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name); break; } groups = g_slist_next(groups); @@ -560,7 +622,7 @@ _add_name_and_barejid(const char *const name, const char *const barejid) } static gint -_compare_contacts(PContact a, PContact b) +_compare_name(PContact a, PContact b) { const char * utf8_str_a = NULL; const char * utf8_str_b = NULL; @@ -580,3 +642,43 @@ _compare_contacts(PContact a, PContact b) return result; } + +static gint +_get_presence_weight(const char *presence) +{ + if (g_strcmp0(presence, "chat") == 0) { + return 0; + } else if (g_strcmp0(presence, "online") == 0) { + return 1; + } else if (g_strcmp0(presence, "away") == 0) { + return 2; + } else if (g_strcmp0(presence, "xa") == 0) { + return 3; + } else if (g_strcmp0(presence, "dnd") == 0) { + return 4; + } else { // offline + return 5; + } +} + +static gint +_compare_presence(PContact a, PContact b) +{ + const char *presence_a = p_contact_presence(a); + const char *presence_b = p_contact_presence(b); + + // if presence different, order by presence + if (g_strcmp0(presence_a, presence_b) != 0) { + int weight_a = _get_presence_weight(presence_a); + int weight_b = _get_presence_weight(presence_b); + if (weight_a < weight_b) { + return -1; + } else { + return 1; + } + + // otherwise order by name + } else { + return _compare_name(a, b); + } +} diff --git a/src/roster_list.h b/src/roster_list.h index 01def408..da4bbbcd 100644 --- a/src/roster_list.h +++ b/src/roster_list.h @@ -55,16 +55,19 @@ gboolean roster_add(const char *const barejid, const char *const name, GSList *g gboolean pending_out); char* roster_barejid_from_name(const char *const name); GSList* roster_get_contacts(void); +GSList* roster_get_contacts_ord_presence(void); GSList* roster_get_contacts_online(void); gboolean roster_has_pending_subscriptions(void); char* roster_contact_autocomplete(const char *const search_str); char* roster_fulljid_autocomplete(const char *const search_str); GSList* roster_get_group(const char *const group); +GSList* roster_get_group_ord_presence(const char *const group); GSList* roster_get_groups(void); char* roster_group_autocomplete(const char *const search_str); char* roster_barejid_autocomplete(const char *const search_str); GSList* roster_get_contacts_by_presence(const char *const presence); GSList* roster_get_nogroup(void); +GSList* roster_get_nogroup_ord_presence(void); char* roster_get_msg_display_name(const char *const barejid, const char *const resource); #endif diff --git a/src/ui/console.c b/src/ui/console.c index 8825cf69..882a9b54 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1226,6 +1226,10 @@ cons_roster_setting(void) cons_show("Roster by (/roster) : %s", by); prefs_free_string(by); + char *order = prefs_get_string(PREF_ROSTER_ORDER); + cons_show("Roster order (/roster) : %s", order); + prefs_free_string(order); + 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 b721dbfe..95d374bd 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -167,7 +167,15 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); - GSList *contacts = roster_get_group(group); + GSList *contacts = NULL; + + char *order = prefs_get_string(PREF_ROSTER_ORDER); + if (g_strcmp0(order, "presence") == 0) { + contacts = roster_get_group_ord_presence(group); + } else { + contacts = roster_get_group(group); + } + if (contacts) { GSList *curr_contact = contacts; while (curr_contact) { @@ -182,7 +190,15 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) static void _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout) { - GSList *contacts = roster_get_nogroup(); + GSList *contacts = NULL; + + char *order = prefs_get_string(PREF_ROSTER_ORDER); + if (g_strcmp0(order, "presence") == 0) { + contacts = roster_get_nogroup_ord_presence(); + } else { + contacts = roster_get_nogroup(); + } + if (contacts) { wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); win_printline_nowrap(layout->subwin, " -no group"); @@ -228,7 +244,15 @@ rosterwin_roster(void) g_slist_free_full(groups, free); _rosterwin_contacts_by_no_group(layout); } else { - GSList *contacts = roster_get_contacts(); + GSList *contacts = NULL; + + char *order = prefs_get_string(PREF_ROSTER_ORDER); + if (g_strcmp0(order, "presence") == 0) { + contacts = roster_get_contacts_ord_presence(); + } else { + contacts = roster_get_contacts(); + } + if (contacts) { werase(layout->subwin); From 2260e3bd6f7e99fd16f05372c7545b8e2379ff6e Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 18 Nov 2015 00:06:00 +0000 Subject: [PATCH 08/15] Pass ordering to roster list functions --- src/command/commands.c | 10 ++-- src/roster_list.c | 86 ++++++++---------------------- src/roster_list.h | 14 ++--- src/ui/console.c | 2 +- src/ui/rosterwin.c | 12 ++--- tests/unittests/test_cmd_roster.c | 2 +- tests/unittests/test_roster_list.c | 20 +++---- 7 files changed, 54 insertions(+), 92 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 67f8ae98..c1edfdb2 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1320,13 +1320,13 @@ _who_roster(ProfWin *window, const char *const command, gchar **args) cons_show(""); GSList *list = NULL; if (group) { - list = roster_get_group(group); + list = roster_get_group(group, ROSTER_ORD_NAME); if (list == NULL) { cons_show("No such group: %s.", group); return; } } else { - list = roster_get_contacts(); + list = roster_get_contacts(ROSTER_ORD_NAME); if (list == NULL) { cons_show("No contacts in roster."); return; @@ -1628,7 +1628,7 @@ cmd_group(ProfWin *window, const char *const command, gchar **args) return TRUE; } - GSList *list = roster_get_group(group); + GSList *list = roster_get_group(group, ROSTER_ORD_NAME); cons_show_roster_group(group, list); return TRUE; } @@ -1711,7 +1711,7 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) return TRUE; } - GSList *list = roster_get_contacts(); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME); cons_show_roster(list); g_slist_free(list); return TRUE; @@ -1931,7 +1931,7 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) return TRUE; } - GSList *all = roster_get_contacts(); + GSList *all = roster_get_contacts(ROSTER_ORD_NAME); GSList *curr = all; while (curr) { PContact contact = curr->data; diff --git a/src/roster_list.c b/src/roster_list.c index fe3063dd..2f1a0b55 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -383,33 +383,23 @@ roster_get_contacts_by_presence(const char *const presence) } GSList* -roster_get_contacts_ord_presence(void) +roster_get_contacts(roster_ord_t order) { GSList *result = NULL; GHashTableIter iter; gpointer key; gpointer value; - g_hash_table_iter_init(&iter, contacts); - while (g_hash_table_iter_next(&iter, &key, &value)) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_presence); + GCompareFunc cmp_func; + if (order == ROSTER_ORD_PRESENCE) { + cmp_func = (GCompareFunc) _compare_presence; + } else { + cmp_func = (GCompareFunc) _compare_name; } - // return all contact structs - return result; -} - -GSList* -roster_get_contacts(void) -{ - GSList *result = NULL; - GHashTableIter iter; - gpointer key; - gpointer value; - g_hash_table_iter_init(&iter, contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name); + result = g_slist_insert_sorted(result, value, cmp_func); } // return all contact structs @@ -465,18 +455,25 @@ roster_fulljid_autocomplete(const char *const search_str) } GSList* -roster_get_nogroup_ord_presence(void) +roster_get_nogroup(roster_ord_t order) { GSList *result = NULL; GHashTableIter iter; gpointer key; gpointer value; + GCompareFunc cmp_func; + if (order == ROSTER_ORD_PRESENCE) { + cmp_func = (GCompareFunc) _compare_presence; + } else { + cmp_func = (GCompareFunc) _compare_name; + } + g_hash_table_iter_init(&iter, contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { GSList *groups = p_contact_groups(value); if (groups == NULL) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_presence); + result = g_slist_insert_sorted(result, value, cmp_func); } } @@ -485,63 +482,26 @@ roster_get_nogroup_ord_presence(void) } GSList* -roster_get_nogroup(void) +roster_get_group(const char *const group, roster_ord_t order) { GSList *result = NULL; GHashTableIter iter; gpointer key; gpointer value; - g_hash_table_iter_init(&iter, contacts); - while (g_hash_table_iter_next(&iter, &key, &value)) { - GSList *groups = p_contact_groups(value); - if (groups == NULL) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name); - } + GCompareFunc cmp_func; + if (order == ROSTER_ORD_PRESENCE) { + cmp_func = (GCompareFunc) _compare_presence; + } else { + cmp_func = (GCompareFunc) _compare_name; } - // return all contact structs - return result; -} - -GSList* -roster_get_group_ord_presence(const char *const group) -{ - GSList *result = NULL; - GHashTableIter iter; - gpointer key; - gpointer value; - g_hash_table_iter_init(&iter, contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { GSList *groups = p_contact_groups(value); while (groups) { if (strcmp(groups->data, group) == 0) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_presence); - break; - } - groups = g_slist_next(groups); - } - } - - // return all contact structs - return result; -} - -GSList* -roster_get_group(const char *const group) -{ - GSList *result = NULL; - GHashTableIter iter; - gpointer key; - gpointer value; - - g_hash_table_iter_init(&iter, contacts); - while (g_hash_table_iter_next(&iter, &key, &value)) { - GSList *groups = p_contact_groups(value); - while (groups) { - if (strcmp(groups->data, group) == 0) { - result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name); + result = g_slist_insert_sorted(result, value, cmp_func); break; } groups = g_slist_next(groups); diff --git a/src/roster_list.h b/src/roster_list.h index da4bbbcd..15cdacef 100644 --- a/src/roster_list.h +++ b/src/roster_list.h @@ -40,6 +40,11 @@ #include "resource.h" #include "contact.h" +typedef enum { + ROSTER_ORD_NAME, + ROSTER_ORD_PRESENCE +} roster_ord_t; + void roster_clear(void); gboolean roster_update_presence(const char *const barejid, Resource *resource, GDateTime *last_activity); PContact roster_get_contact(const char *const barejid); @@ -54,20 +59,17 @@ void roster_update(const char *const barejid, const char *const name, GSList *gr gboolean roster_add(const char *const barejid, const char *const name, GSList *groups, const char *const subscription, gboolean pending_out); char* roster_barejid_from_name(const char *const name); -GSList* roster_get_contacts(void); -GSList* roster_get_contacts_ord_presence(void); +GSList* roster_get_contacts(roster_ord_t order); GSList* roster_get_contacts_online(void); gboolean roster_has_pending_subscriptions(void); char* roster_contact_autocomplete(const char *const search_str); char* roster_fulljid_autocomplete(const char *const search_str); -GSList* roster_get_group(const char *const group); -GSList* roster_get_group_ord_presence(const char *const group); +GSList* roster_get_group(const char *const group, roster_ord_t order); GSList* roster_get_groups(void); char* roster_group_autocomplete(const char *const search_str); char* roster_barejid_autocomplete(const char *const search_str); GSList* roster_get_contacts_by_presence(const char *const presence); -GSList* roster_get_nogroup(void); -GSList* roster_get_nogroup_ord_presence(void); +GSList* roster_get_nogroup(roster_ord_t order); char* roster_get_msg_display_name(const char *const barejid, const char *const resource); #endif diff --git a/src/ui/console.c b/src/ui/console.c index 882a9b54..0c6733c4 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -527,7 +527,7 @@ void cons_show_sent_subs(void) { if (roster_has_pending_subscriptions()) { - GSList *contacts = roster_get_contacts(); + GSList *contacts = roster_get_contacts(ROSTER_ORD_NAME); PContact contact = NULL; cons_show("Awaiting subscription responses from:"); GSList *curr = contacts; diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 95d374bd..a689f033 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -171,9 +171,9 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) char *order = prefs_get_string(PREF_ROSTER_ORDER); if (g_strcmp0(order, "presence") == 0) { - contacts = roster_get_group_ord_presence(group); + contacts = roster_get_group(group, ROSTER_ORD_PRESENCE); } else { - contacts = roster_get_group(group); + contacts = roster_get_group(group, ROSTER_ORD_NAME); } if (contacts) { @@ -194,9 +194,9 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout) char *order = prefs_get_string(PREF_ROSTER_ORDER); if (g_strcmp0(order, "presence") == 0) { - contacts = roster_get_nogroup_ord_presence(); + contacts = roster_get_nogroup(ROSTER_ORD_PRESENCE); } else { - contacts = roster_get_nogroup(); + contacts = roster_get_nogroup(ROSTER_ORD_NAME); } if (contacts) { @@ -248,9 +248,9 @@ rosterwin_roster(void) char *order = prefs_get_string(PREF_ROSTER_ORDER); if (g_strcmp0(order, "presence") == 0) { - contacts = roster_get_contacts_ord_presence(); + contacts = roster_get_contacts(ROSTER_ORD_PRESENCE); } else { - contacts = roster_get_contacts(); + contacts = roster_get_contacts(ROSTER_ORD_NAME); } if (contacts) { diff --git a/tests/unittests/test_cmd_roster.c b/tests/unittests/test_cmd_roster.c index bcc2193a..0ba49237 100644 --- a/tests/unittests/test_cmd_roster.c +++ b/tests/unittests/test_cmd_roster.c @@ -55,7 +55,7 @@ void cmd_roster_shows_roster_when_no_args(void **state) roster_init(); roster_add("bob@server.org", "bob", NULL, "both", FALSE); - GSList *roster = roster_get_contacts(); + GSList *roster = roster_get_contacts(ROSTER_ORD_NAME); expect_memory(cons_show_roster, list, roster, sizeof(roster)); diff --git a/tests/unittests/test_roster_list.c b/tests/unittests/test_roster_list.c index f12361e4..e2644d41 100644 --- a/tests/unittests/test_roster_list.c +++ b/tests/unittests/test_roster_list.c @@ -12,7 +12,7 @@ void empty_list_when_none_added(void **state) { roster_init(); - GSList *list = roster_get_contacts(); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME); assert_null(list); roster_clear(); roster_free(); @@ -22,7 +22,7 @@ void contains_one_element(void **state) { roster_init(); roster_add("James", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME); assert_int_equal(1, g_slist_length(list)); roster_clear(); roster_free(); @@ -32,7 +32,7 @@ void first_element_correct(void **state) { roster_init(); roster_add("James", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME); PContact james = list->data; assert_string_equal("James", p_contact_barejid(james)); @@ -45,7 +45,7 @@ void contains_two_elements(void **state) roster_init(); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME); assert_int_equal(2, g_slist_length(list)); roster_clear(); @@ -57,7 +57,7 @@ void first_and_second_elements_correct(void **state) roster_init(); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME); PContact first = list->data; PContact second = (g_slist_next(list))->data; @@ -74,7 +74,7 @@ void contains_three_elements(void **state) roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Bob", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME); assert_int_equal(3, g_slist_length(list)); roster_clear(); @@ -87,7 +87,7 @@ void first_three_elements_correct(void **state) roster_add("Bob", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); roster_add("James", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME); PContact bob = list->data; PContact dave = (g_slist_next(list))->data; PContact james = (g_slist_next(g_slist_next(list)))->data; @@ -106,7 +106,7 @@ void add_twice_at_beginning_adds_once(void **state) roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); roster_add("Bob", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME); PContact first = list->data; PContact second = (g_slist_next(list))->data; PContact third = (g_slist_next(g_slist_next(list)))->data; @@ -126,7 +126,7 @@ void add_twice_in_middle_adds_once(void **state) roster_add("Dave", NULL, NULL, NULL, FALSE); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Bob", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME); PContact first = list->data; PContact second = (g_slist_next(list))->data; PContact third = (g_slist_next(g_slist_next(list)))->data; @@ -146,7 +146,7 @@ void add_twice_at_end_adds_once(void **state) roster_add("Dave", NULL, NULL, NULL, FALSE); roster_add("Bob", NULL, NULL, NULL, FALSE); roster_add("James", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME); PContact first = list->data; PContact second = (g_slist_next(list))->data; PContact third = (g_slist_next(g_slist_next(list)))->data; From b373cbcfc0688c80314b40024a8a9d596bcc9856 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 18 Nov 2015 00:25:35 +0000 Subject: [PATCH 09/15] Pass offline filter to roster list functions --- src/command/commands.c | 4 ++-- src/roster_list.c | 16 ++++++++++++++-- src/roster_list.h | 4 ++-- src/ui/rosterwin.c | 24 +++++++++++++----------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index c1edfdb2..3a2f5292 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1320,7 +1320,7 @@ _who_roster(ProfWin *window, const char *const command, gchar **args) cons_show(""); GSList *list = NULL; if (group) { - list = roster_get_group(group, ROSTER_ORD_NAME); + list = roster_get_group(group, ROSTER_ORD_NAME, TRUE); if (list == NULL) { cons_show("No such group: %s.", group); return; @@ -1628,7 +1628,7 @@ cmd_group(ProfWin *window, const char *const command, gchar **args) return TRUE; } - GSList *list = roster_get_group(group, ROSTER_ORD_NAME); + GSList *list = roster_get_group(group, ROSTER_ORD_NAME, TRUE); cons_show_roster_group(group, list); return TRUE; } diff --git a/src/roster_list.c b/src/roster_list.c index 2f1a0b55..4b2662ad 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -455,7 +455,7 @@ roster_fulljid_autocomplete(const char *const search_str) } GSList* -roster_get_nogroup(roster_ord_t order) +roster_get_nogroup(roster_ord_t order, gboolean include_offline) { GSList *result = NULL; GHashTableIter iter; @@ -471,6 +471,12 @@ roster_get_nogroup(roster_ord_t order) g_hash_table_iter_init(&iter, contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { + PContact contact = value; + const char *presence = p_contact_presence(contact); + if (!include_offline && (g_strcmp0(presence, "offline") == 0)) { + continue; + } + GSList *groups = p_contact_groups(value); if (groups == NULL) { result = g_slist_insert_sorted(result, value, cmp_func); @@ -482,7 +488,7 @@ roster_get_nogroup(roster_ord_t order) } GSList* -roster_get_group(const char *const group, roster_ord_t order) +roster_get_group(const char *const group, roster_ord_t order, gboolean include_offline) { GSList *result = NULL; GHashTableIter iter; @@ -498,6 +504,12 @@ roster_get_group(const char *const group, roster_ord_t order) g_hash_table_iter_init(&iter, contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { + PContact contact = value; + const char *presence = p_contact_presence(contact); + if (!include_offline && (g_strcmp0(presence, "offline") == 0)) { + continue; + } + GSList *groups = p_contact_groups(value); while (groups) { if (strcmp(groups->data, group) == 0) { diff --git a/src/roster_list.h b/src/roster_list.h index 15cdacef..0f0fbc5b 100644 --- a/src/roster_list.h +++ b/src/roster_list.h @@ -64,12 +64,12 @@ GSList* roster_get_contacts_online(void); gboolean roster_has_pending_subscriptions(void); char* roster_contact_autocomplete(const char *const search_str); char* roster_fulljid_autocomplete(const char *const search_str); -GSList* roster_get_group(const char *const group, roster_ord_t order); +GSList* roster_get_group(const char *const group, roster_ord_t order, gboolean include_offline); GSList* roster_get_groups(void); char* roster_group_autocomplete(const char *const search_str); char* roster_barejid_autocomplete(const char *const search_str); GSList* roster_get_contacts_by_presence(const char *const presence); -GSList* roster_get_nogroup(roster_ord_t order); +GSList* roster_get_nogroup(roster_ord_t order, gboolean include_offline); char* roster_get_msg_display_name(const char *const barejid, const char *const resource); #endif diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index a689f033..8c84a9b2 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -160,23 +160,24 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese static void _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) { - wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); - GString *title = g_string_new(" -"); - g_string_append(title, group); - win_printline_nowrap(layout->subwin, title->str); - g_string_free(title, TRUE); - wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); - GSList *contacts = NULL; char *order = prefs_get_string(PREF_ROSTER_ORDER); + gboolean offline = prefs_get_boolean(PREF_ROSTER_OFFLINE); if (g_strcmp0(order, "presence") == 0) { - contacts = roster_get_group(group, ROSTER_ORD_PRESENCE); + contacts = roster_get_group(group, ROSTER_ORD_PRESENCE, offline); } else { - contacts = roster_get_group(group, ROSTER_ORD_NAME); + contacts = roster_get_group(group, ROSTER_ORD_NAME, offline); } if (contacts) { + wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); + GString *title = g_string_new(" -"); + g_string_append(title, group); + win_printline_nowrap(layout->subwin, title->str); + g_string_free(title, TRUE); + wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); + GSList *curr_contact = contacts; while (curr_contact) { PContact contact = curr_contact->data; @@ -193,10 +194,11 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout) GSList *contacts = NULL; char *order = prefs_get_string(PREF_ROSTER_ORDER); + gboolean offline = prefs_get_boolean(PREF_ROSTER_OFFLINE); if (g_strcmp0(order, "presence") == 0) { - contacts = roster_get_nogroup(ROSTER_ORD_PRESENCE); + contacts = roster_get_nogroup(ROSTER_ORD_PRESENCE, offline); } else { - contacts = roster_get_nogroup(ROSTER_ORD_NAME); + contacts = roster_get_nogroup(ROSTER_ORD_NAME, offline); } if (contacts) { From 4efe456e7446baf125cf55a3c9e4a73c978809ac Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 18 Nov 2015 01:03:35 +0000 Subject: [PATCH 10/15] Pass offline filter to roster_get_contacts --- src/command/commands.c | 6 ++-- src/config/preferences.c | 2 +- src/roster_list.c | 8 +++++- src/roster_list.h | 2 +- src/ui/console.c | 2 +- src/ui/rosterwin.c | 46 ++++++++++++++---------------- tests/unittests/test_cmd_roster.c | 2 +- tests/unittests/test_roster_list.c | 20 ++++++------- 8 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 3a2f5292..10143565 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1326,7 +1326,7 @@ _who_roster(ProfWin *window, const char *const command, gchar **args) return; } } else { - list = roster_get_contacts(ROSTER_ORD_NAME); + list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); if (list == NULL) { cons_show("No contacts in roster."); return; @@ -1711,7 +1711,7 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) return TRUE; } - GSList *list = roster_get_contacts(ROSTER_ORD_NAME); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); cons_show_roster(list); g_slist_free(list); return TRUE; @@ -1931,7 +1931,7 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) return TRUE; } - GSList *all = roster_get_contacts(ROSTER_ORD_NAME); + GSList *all = roster_get_contacts(ROSTER_ORD_NAME, TRUE); GSList *curr = all; while (curr) { PContact contact = curr->data; diff --git a/src/config/preferences.c b/src/config/preferences.c index 8348edb7..163df444 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -865,7 +865,7 @@ _get_default_string(preference_t pref) case PREF_ROSTER_BY: return "presence"; case PREF_ROSTER_ORDER: - return "name"; + return "presence"; case PREF_TIME_CONSOLE: return "%H:%M:%S"; case PREF_TIME_CHAT: diff --git a/src/roster_list.c b/src/roster_list.c index 4b2662ad..ec0ab0c6 100644 --- a/src/roster_list.c +++ b/src/roster_list.c @@ -383,7 +383,7 @@ roster_get_contacts_by_presence(const char *const presence) } GSList* -roster_get_contacts(roster_ord_t order) +roster_get_contacts(roster_ord_t order, gboolean include_offline) { GSList *result = NULL; GHashTableIter iter; @@ -399,6 +399,12 @@ roster_get_contacts(roster_ord_t order) g_hash_table_iter_init(&iter, contacts); while (g_hash_table_iter_next(&iter, &key, &value)) { + PContact contact = value; + const char *presence = p_contact_presence(contact); + if (!include_offline && (g_strcmp0(presence, "offline") == 0)) { + continue; + } + result = g_slist_insert_sorted(result, value, cmp_func); } diff --git a/src/roster_list.h b/src/roster_list.h index 0f0fbc5b..3787447a 100644 --- a/src/roster_list.h +++ b/src/roster_list.h @@ -59,7 +59,7 @@ void roster_update(const char *const barejid, const char *const name, GSList *gr gboolean roster_add(const char *const barejid, const char *const name, GSList *groups, const char *const subscription, gboolean pending_out); char* roster_barejid_from_name(const char *const name); -GSList* roster_get_contacts(roster_ord_t order); +GSList* roster_get_contacts(roster_ord_t order, gboolean include_offline); GSList* roster_get_contacts_online(void); gboolean roster_has_pending_subscriptions(void); char* roster_contact_autocomplete(const char *const search_str); diff --git a/src/ui/console.c b/src/ui/console.c index 0c6733c4..03e944d0 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -527,7 +527,7 @@ void cons_show_sent_subs(void) { if (roster_has_pending_subscriptions()) { - GSList *contacts = roster_get_contacts(ROSTER_ORD_NAME); + GSList *contacts = roster_get_contacts(ROSTER_ORD_NAME, TRUE); PContact contact = NULL; cons_show("Awaiting subscription responses from:"); GSList *curr = contacts; diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 8c84a9b2..74c95996 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -115,22 +115,19 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) const char *presence = p_contact_presence(contact); const char *status = p_contact_status(contact); - if ((g_strcmp0(presence, "offline") != 0) || ((g_strcmp0(presence, "offline") == 0) && - (prefs_get_boolean(PREF_ROSTER_OFFLINE)))) { - theme_item_t presence_colour = theme_main_presence_attrs(presence); + theme_item_t presence_colour = theme_main_presence_attrs(presence); - wattron(layout->subwin, theme_attrs(presence_colour)); - GString *msg = g_string_new(" "); - g_string_append(msg, name); - win_printline_nowrap(layout->subwin, msg->str); - g_string_free(msg, TRUE); - wattroff(layout->subwin, theme_attrs(presence_colour)); + wattron(layout->subwin, theme_attrs(presence_colour)); + GString *msg = g_string_new(" "); + g_string_append(msg, name); + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(presence_colour)); - if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { - _rosterwin_resource(layout, contact); - } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { - _rosterwin_presence(layout, 4, presence_colour, presence, status); - } + if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { + _rosterwin_resource(layout, contact); + } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + _rosterwin_presence(layout, 4, presence_colour, presence, status); } } @@ -170,7 +167,7 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) contacts = roster_get_group(group, ROSTER_ORD_NAME, offline); } - if (contacts) { + if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GString *title = g_string_new(" -"); g_string_append(title, group); @@ -201,7 +198,7 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout) contacts = roster_get_nogroup(ROSTER_ORD_NAME, offline); } - if (contacts) { + if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); win_printline_nowrap(layout->subwin, " -no group"); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -249,19 +246,20 @@ rosterwin_roster(void) GSList *contacts = NULL; char *order = prefs_get_string(PREF_ROSTER_ORDER); + gboolean offline = prefs_get_boolean(PREF_ROSTER_OFFLINE); if (g_strcmp0(order, "presence") == 0) { - contacts = roster_get_contacts(ROSTER_ORD_PRESENCE); + contacts = roster_get_contacts(ROSTER_ORD_PRESENCE, offline); } else { - contacts = roster_get_contacts(ROSTER_ORD_NAME); + contacts = roster_get_contacts(ROSTER_ORD_NAME, offline); } + werase(layout->subwin); + + wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); + win_printline_nowrap(layout->subwin, " -Roster"); + wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); + if (contacts) { - werase(layout->subwin); - - wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); - win_printline_nowrap(layout->subwin, " -Roster"); - wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); - GSList *curr_contact = contacts; while (curr_contact) { PContact contact = curr_contact->data; diff --git a/tests/unittests/test_cmd_roster.c b/tests/unittests/test_cmd_roster.c index 0ba49237..edd6a864 100644 --- a/tests/unittests/test_cmd_roster.c +++ b/tests/unittests/test_cmd_roster.c @@ -55,7 +55,7 @@ void cmd_roster_shows_roster_when_no_args(void **state) roster_init(); roster_add("bob@server.org", "bob", NULL, "both", FALSE); - GSList *roster = roster_get_contacts(ROSTER_ORD_NAME); + GSList *roster = roster_get_contacts(ROSTER_ORD_NAME, TRUE); expect_memory(cons_show_roster, list, roster, sizeof(roster)); diff --git a/tests/unittests/test_roster_list.c b/tests/unittests/test_roster_list.c index e2644d41..26f23672 100644 --- a/tests/unittests/test_roster_list.c +++ b/tests/unittests/test_roster_list.c @@ -12,7 +12,7 @@ void empty_list_when_none_added(void **state) { roster_init(); - GSList *list = roster_get_contacts(ROSTER_ORD_NAME); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); assert_null(list); roster_clear(); roster_free(); @@ -22,7 +22,7 @@ void contains_one_element(void **state) { roster_init(); roster_add("James", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(ROSTER_ORD_NAME); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); assert_int_equal(1, g_slist_length(list)); roster_clear(); roster_free(); @@ -32,7 +32,7 @@ void first_element_correct(void **state) { roster_init(); roster_add("James", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(ROSTER_ORD_NAME); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); PContact james = list->data; assert_string_equal("James", p_contact_barejid(james)); @@ -45,7 +45,7 @@ void contains_two_elements(void **state) roster_init(); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(ROSTER_ORD_NAME); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); assert_int_equal(2, g_slist_length(list)); roster_clear(); @@ -57,7 +57,7 @@ void first_and_second_elements_correct(void **state) roster_init(); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(ROSTER_ORD_NAME); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); PContact first = list->data; PContact second = (g_slist_next(list))->data; @@ -74,7 +74,7 @@ void contains_three_elements(void **state) roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Bob", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(ROSTER_ORD_NAME); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); assert_int_equal(3, g_slist_length(list)); roster_clear(); @@ -87,7 +87,7 @@ void first_three_elements_correct(void **state) roster_add("Bob", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); roster_add("James", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(ROSTER_ORD_NAME); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); PContact bob = list->data; PContact dave = (g_slist_next(list))->data; PContact james = (g_slist_next(g_slist_next(list)))->data; @@ -106,7 +106,7 @@ void add_twice_at_beginning_adds_once(void **state) roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); roster_add("Bob", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(ROSTER_ORD_NAME); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); PContact first = list->data; PContact second = (g_slist_next(list))->data; PContact third = (g_slist_next(g_slist_next(list)))->data; @@ -126,7 +126,7 @@ void add_twice_in_middle_adds_once(void **state) roster_add("Dave", NULL, NULL, NULL, FALSE); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Bob", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(ROSTER_ORD_NAME); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); PContact first = list->data; PContact second = (g_slist_next(list))->data; PContact third = (g_slist_next(g_slist_next(list)))->data; @@ -146,7 +146,7 @@ void add_twice_at_end_adds_once(void **state) roster_add("Dave", NULL, NULL, NULL, FALSE); roster_add("Bob", NULL, NULL, NULL, FALSE); roster_add("James", NULL, NULL, NULL, FALSE); - GSList *list = roster_get_contacts(ROSTER_ORD_NAME); + GSList *list = roster_get_contacts(ROSTER_ORD_NAME, TRUE); PContact first = list->data; PContact second = (g_slist_next(list))->data; PContact third = (g_slist_next(g_slist_next(list)))->data; From edbd2d5843fe7cefd730899aace631416715bb8f Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 18 Nov 2015 01:10:03 +0000 Subject: [PATCH 11/15] Don't show offline below contact --- src/ui/rosterwin.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 74c95996..a8f24e0e 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -49,7 +49,8 @@ _rosterwin_presence(ProfLayoutSplit *layout, int indent, theme_item_t colour, co gboolean by_presence = g_strcmp0(by, "presence") == 0; gboolean has_status = status != NULL; gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); - if (!by_presence || (has_status && show_status)) { + gboolean is_offline = g_strcmp0(presence, "offline") == 0; + if (!is_offline && (!by_presence || (has_status && show_status))) { wattron(layout->subwin, theme_attrs(colour)); GString *msg = g_string_new(" "); while (indent > 0) { From 4505102fa83e00c70d1ee15967b977957dcf3aa5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 18 Nov 2015 02:02:49 +0000 Subject: [PATCH 12/15] Added roster count option --- src/command/command.c | 7 +++++-- src/command/commands.c | 14 ++++++++++++++ src/config/preferences.c | 4 ++++ src/config/preferences.h | 1 + src/ui/console.c | 5 +++++ src/ui/rosterwin.c | 24 +++++++++++++++++++++--- 6 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 2a98ba75..1057084c 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -274,8 +274,8 @@ static struct cmd_t command_defs[] = CMD_SYN( "/roster", "/roster online", - "/roster show [offline|resource|presence|status|empty]", - "/roster hide [offline|resource|presence|status|empty]", + "/roster show [offline|resource|presence|status|empty|count]", + "/roster hide [offline|resource|presence|status|empty|count]", "/roster by group|presence|none", "/roster order name|presence" "/roster size ", @@ -295,12 +295,14 @@ static struct cmd_t command_defs[] = { "show presence", "Show contact's presence in the roster panel." }, { "show status", "Show contact's status message in the roster panel." }, { "show empty", "When grouping by presence, show empty presence groups." }, + { "show count", "Show number of contacts in group/presence." }, { "hide", "Hide the roster panel." }, { "hide offline", "Hide offline contacts in the roster panel." }, { "hide resource", "Hide contact's connected resources in the roster panel." }, { "hide presence", "Hide contact's presence in the roster panel." }, { "hide status", "Hide contact's status message in the roster panel." }, { "hide empty", "When grouping by presence, hide empty presence groups." }, + { "hide count", "Hide number of contacts in group/presence." }, { "by group", "Group contacts in the roster panel by roster group." }, { "by presence", "Group contacts in the roster panel by presence." }, { "by none", "No grouping in the roster panel." }, @@ -2027,6 +2029,7 @@ cmd_init(void) autocomplete_add(roster_option_ac, "presence"); autocomplete_add(roster_option_ac, "status"); autocomplete_add(roster_option_ac, "empty"); + autocomplete_add(roster_option_ac, "count"); roster_by_ac = autocomplete_new(); autocomplete_add(roster_by_ac, "group"); diff --git a/src/command/commands.c b/src/command/commands.c index 10143565..4d8933bd 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1794,6 +1794,13 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) rosterwin_roster(); } return TRUE; + } else if (g_strcmp0(args[1], "count") == 0) { + cons_show("Roster count enabled"); + prefs_set_boolean(PREF_ROSTER_COUNT, TRUE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; } else { cons_bad_cmd_usage(command); return TRUE; @@ -1841,6 +1848,13 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) rosterwin_roster(); } return TRUE; + } else if (g_strcmp0(args[1], "count") == 0) { + cons_show("Roster count disabled"); + prefs_set_boolean(PREF_ROSTER_COUNT, FALSE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; } else { cons_bad_cmd_usage(command); return TRUE; diff --git a/src/config/preferences.c b/src/config/preferences.c index 163df444..46cd3169 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -602,6 +602,7 @@ _get_group(preference_t pref) case PREF_ROSTER_EMPTY: case PREF_ROSTER_BY: case PREF_ROSTER_ORDER: + case PREF_ROSTER_COUNT: case PREF_RESOURCE_TITLE: case PREF_RESOURCE_MESSAGE: case PREF_ENC_WARN: @@ -781,6 +782,8 @@ _get_key(preference_t pref) return "roster.by"; case PREF_ROSTER_ORDER: return "roster.order"; + case PREF_ROSTER_COUNT: + return "roster.count"; case PREF_RESOURCE_TITLE: return "resource.title"; case PREF_RESOURCE_MESSAGE: @@ -835,6 +838,7 @@ _get_default_boolean(preference_t pref) case PREF_ROSTER_PRESENCE: case PREF_ROSTER_STATUS: case PREF_ROSTER_EMPTY: + case PREF_ROSTER_COUNT: case PREF_TLS_SHOW: case PREF_LASTACTIVITY: return TRUE; diff --git a/src/config/preferences.h b/src/config/preferences.h index 55b46b07..dcc0f441 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_COUNT, PREF_MUC_PRIVILEGES, PREF_PRESENCE, PREF_WRAP, diff --git a/src/ui/console.c b/src/ui/console.c index 03e944d0..b145aa6d 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1222,6 +1222,11 @@ cons_roster_setting(void) else cons_show("Roster empty (/roster) : hide"); + if (prefs_get_boolean(PREF_ROSTER_COUNT)) + cons_show("Roster count (/roster) : show"); + else + cons_show("Roster count (/roster) : hide"); + char *by = prefs_get_string(PREF_ROSTER_BY); cons_show("Roster by (/roster) : %s", by); prefs_free_string(by); diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index a8f24e0e..28ac25ce 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -140,7 +140,12 @@ _rosterwin_contacts_by_presence(ProfLayoutSplit *layout, const char *const prese // if this group has contacts, or if we want to show empty groups if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); - win_printline_nowrap(layout->subwin, title); + GString *title_str = g_string_new(title); + if (prefs_get_boolean(PREF_ROSTER_COUNT)) { + g_string_append_printf(title_str, " (%d)", g_slist_length(contacts)); + } + win_printline_nowrap(layout->subwin, title_str->str); + g_string_free(title_str, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); } @@ -172,6 +177,9 @@ _rosterwin_contacts_by_group(ProfLayoutSplit *layout, char *group) wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GString *title = g_string_new(" -"); g_string_append(title, group); + if (prefs_get_boolean(PREF_ROSTER_COUNT)) { + g_string_append_printf(title, " (%d)", g_slist_length(contacts)); + } win_printline_nowrap(layout->subwin, title->str); g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); @@ -201,7 +209,12 @@ _rosterwin_contacts_by_no_group(ProfLayoutSplit *layout) if (contacts || prefs_get_boolean(PREF_ROSTER_EMPTY)) { wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); - win_printline_nowrap(layout->subwin, " -no group"); + GString *title = g_string_new(" -no group"); + if (prefs_get_boolean(PREF_ROSTER_COUNT)) { + g_string_append_printf(title, " (%d)", g_slist_length(contacts)); + } + win_printline_nowrap(layout->subwin, title->str); + g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); GSList *curr_contact = contacts; @@ -257,7 +270,12 @@ rosterwin_roster(void) werase(layout->subwin); wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); - win_printline_nowrap(layout->subwin, " -Roster"); + GString *title = g_string_new(" -Roster"); + if (prefs_get_boolean(PREF_ROSTER_COUNT)) { + g_string_append_printf(title, " (%d)", g_slist_length(contacts)); + } + win_printline_nowrap(layout->subwin, title->str); + g_string_free(title, TRUE); wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); if (contacts) { From 8e84d160e6a7eded077be3e32012e9725961a0cd Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 18 Nov 2015 02:14:11 +0000 Subject: [PATCH 13/15] Added option to show resource priority in roster --- src/command/command.c | 7 +++++-- src/command/commands.c | 14 ++++++++++++++ src/config/preferences.c | 4 ++++ src/config/preferences.h | 1 + src/ui/console.c | 5 +++++ src/ui/rosterwin.c | 3 +++ 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 1057084c..a7f0d718 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -274,8 +274,8 @@ static struct cmd_t command_defs[] = CMD_SYN( "/roster", "/roster online", - "/roster show [offline|resource|presence|status|empty|count]", - "/roster hide [offline|resource|presence|status|empty|count]", + "/roster show [offline|resource|presence|status|empty|count|priority]", + "/roster hide [offline|resource|presence|status|empty|count|priority]", "/roster by group|presence|none", "/roster order name|presence" "/roster size ", @@ -296,6 +296,7 @@ static struct cmd_t command_defs[] = { "show status", "Show contact's status message in the roster panel." }, { "show empty", "When grouping by presence, show empty presence groups." }, { "show count", "Show number of contacts in group/presence." }, + { "show priority", "Show resource priority." }, { "hide", "Hide the roster panel." }, { "hide offline", "Hide offline contacts in the roster panel." }, { "hide resource", "Hide contact's connected resources in the roster panel." }, @@ -303,6 +304,7 @@ static struct cmd_t command_defs[] = { "hide status", "Hide contact's status message in the roster panel." }, { "hide empty", "When grouping by presence, hide empty presence groups." }, { "hide count", "Hide number of contacts in group/presence." }, + { "hide priority", "Hide resource priority." }, { "by group", "Group contacts in the roster panel by roster group." }, { "by presence", "Group contacts in the roster panel by presence." }, { "by none", "No grouping in the roster panel." }, @@ -2030,6 +2032,7 @@ cmd_init(void) autocomplete_add(roster_option_ac, "status"); autocomplete_add(roster_option_ac, "empty"); autocomplete_add(roster_option_ac, "count"); + autocomplete_add(roster_option_ac, "priority"); roster_by_ac = autocomplete_new(); autocomplete_add(roster_by_ac, "group"); diff --git a/src/command/commands.c b/src/command/commands.c index 4d8933bd..92ca5daf 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1801,6 +1801,13 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) rosterwin_roster(); } return TRUE; + } else if (g_strcmp0(args[1], "priority") == 0) { + cons_show("Roster priority enabled"); + prefs_set_boolean(PREF_ROSTER_PRIORITY, TRUE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; } else { cons_bad_cmd_usage(command); return TRUE; @@ -1855,6 +1862,13 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) rosterwin_roster(); } return TRUE; + } else if (g_strcmp0(args[1], "priority") == 0) { + cons_show("Roster priority disabled"); + prefs_set_boolean(PREF_ROSTER_PRIORITY, FALSE); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; } else { cons_bad_cmd_usage(command); return TRUE; diff --git a/src/config/preferences.c b/src/config/preferences.c index 46cd3169..f55895e2 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -603,6 +603,7 @@ _get_group(preference_t pref) case PREF_ROSTER_BY: case PREF_ROSTER_ORDER: case PREF_ROSTER_COUNT: + case PREF_ROSTER_PRIORITY: case PREF_RESOURCE_TITLE: case PREF_RESOURCE_MESSAGE: case PREF_ENC_WARN: @@ -784,6 +785,8 @@ _get_key(preference_t pref) return "roster.order"; case PREF_ROSTER_COUNT: return "roster.count"; + case PREF_ROSTER_PRIORITY: + return "roster.priority"; case PREF_RESOURCE_TITLE: return "resource.title"; case PREF_RESOURCE_MESSAGE: @@ -839,6 +842,7 @@ _get_default_boolean(preference_t pref) case PREF_ROSTER_STATUS: case PREF_ROSTER_EMPTY: case PREF_ROSTER_COUNT: + case PREF_ROSTER_PRIORITY: case PREF_TLS_SHOW: case PREF_LASTACTIVITY: return TRUE; diff --git a/src/config/preferences.h b/src/config/preferences.h index dcc0f441..c5f60469 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -70,6 +70,7 @@ typedef enum { PREF_ROSTER_BY, PREF_ROSTER_ORDER, PREF_ROSTER_COUNT, + PREF_ROSTER_PRIORITY, PREF_MUC_PRIVILEGES, PREF_PRESENCE, PREF_WRAP, diff --git a/src/ui/console.c b/src/ui/console.c index b145aa6d..64eff932 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1227,6 +1227,11 @@ cons_roster_setting(void) else cons_show("Roster count (/roster) : hide"); + if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) + cons_show("Roster priority (/roster) : show"); + else + cons_show("Roster priority (/roster) : hide"); + char *by = prefs_get_string(PREF_ROSTER_BY); cons_show("Roster by (/roster) : %s", by); prefs_free_string(by); diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 28ac25ce..6d51adf9 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -89,6 +89,9 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact) wattron(layout->subwin, theme_attrs(resource_presence_colour)); GString *msg = g_string_new(" "); g_string_append(msg, resource->name); + if (prefs_get_boolean(PREF_ROSTER_PRIORITY)) { + g_string_append_printf(msg, " [%d]", resource->priority); + } win_printline_nowrap(layout->subwin, msg->str); g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(resource_presence_colour)); From 522b9ab6beb8c4e73bc488c6092ac54c361b7b27 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 18 Nov 2015 23:00:06 +0000 Subject: [PATCH 14/15] Show status when show presence disabled --- src/ui/rosterwin.c | 48 ++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 6d51adf9..32d64543 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -45,29 +45,45 @@ static void _rosterwin_presence(ProfLayoutSplit *layout, int indent, theme_item_t colour, const char *presence, const char *status) { + // don't show presence for offline contacts + gboolean is_offline = g_strcmp0(presence, "offline") == 0; + if (is_offline) { + return; + } + char *by = prefs_get_string(PREF_ROSTER_BY); gboolean by_presence = g_strcmp0(by, "presence") == 0; - gboolean has_status = status != NULL; - gboolean show_status = prefs_get_boolean(PREF_ROSTER_STATUS); - gboolean is_offline = g_strcmp0(presence, "offline") == 0; - if (!is_offline && (!by_presence || (has_status && show_status))) { + + // show only status when grouped by presence + if (by_presence) { + if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { + wattron(layout->subwin, theme_attrs(colour)); + GString *msg = g_string_new(" "); + while (indent > 0) { + g_string_append(msg, " "); + indent--; + } + g_string_append_printf(msg, "\"%s\"", status); + win_printline_nowrap(layout->subwin, msg->str); + g_string_free(msg, TRUE); + wattroff(layout->subwin, theme_attrs(colour)); + } + + // show both presence and status when not grouped by presence + } else { wattron(layout->subwin, theme_attrs(colour)); GString *msg = g_string_new(" "); while (indent > 0) { g_string_append(msg, " "); indent--; } - if (!by_presence) { + if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { g_string_append(msg, presence); - } - if (has_status && show_status) { - if (!by_presence) { - g_string_append(msg, ", \""); - } else { - g_string_append(msg, "\""); + if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { + g_string_append_printf(msg, " \"%s\"", status); } - g_string_append(msg, status); - g_string_append(msg, "\""); + } else if (status && prefs_get_boolean(PREF_ROSTER_STATUS)) { + g_string_append_printf(msg, "\"%s\"", status); } win_printline_nowrap(layout->subwin, msg->str); g_string_free(msg, TRUE); @@ -96,13 +112,13 @@ _rosterwin_resource(ProfLayoutSplit *layout, PContact contact) g_string_free(msg, TRUE); wattroff(layout->subwin, theme_attrs(resource_presence_colour)); - if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) { _rosterwin_presence(layout, 6, resource_presence_colour, resource_presence, resource->status); } curr_resource = g_list_next(curr_resource); } - } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + } 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); @@ -130,7 +146,7 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { _rosterwin_resource(layout, contact); - } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE)) { + } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) { _rosterwin_presence(layout, 4, presence_colour, presence, status); } } From 4eb0f14a3de378571b3fb644f230f60b892af29c Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 19 Nov 2015 00:45:03 +0000 Subject: [PATCH 15/15] Changed roster defaults, updated themes --- src/config/preferences.c | 3 --- src/config/theme.c | 5 +++++ themes/boothj5 | 11 ++++++++--- themes/complex | 9 +++++++-- themes/simple | 9 +++++++-- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index f55895e2..0f5041bf 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -837,9 +837,6 @@ _get_default_boolean(preference_t pref) case PREF_RESOURCE_MESSAGE: case PREF_ROSTER: case PREF_ROSTER_OFFLINE: - case PREF_ROSTER_RESOURCE: - case PREF_ROSTER_PRESENCE: - case PREF_ROSTER_STATUS: case PREF_ROSTER_EMPTY: case PREF_ROSTER_COUNT: case PREF_ROSTER_PRIORITY: diff --git a/src/config/theme.c b/src/config/theme.c index 09d0fa1e..a6649e88 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -458,8 +458,13 @@ _load_preferences(void) _set_boolean_preference("roster", PREF_ROSTER); _set_boolean_preference("roster.offline", PREF_ROSTER_OFFLINE); _set_boolean_preference("roster.resource", PREF_ROSTER_RESOURCE); + _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_string_preference("roster.by", PREF_ROSTER_BY); + _set_string_preference("roster.order", PREF_ROSTER_ORDER); + _set_boolean_preference("roster.count", PREF_ROSTER_COUNT); + _set_boolean_preference("roster.priority", PREF_ROSTER_PRIORITY); 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/themes/boothj5 b/themes/boothj5 index b6dbe5b9..0b40fab5 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -73,10 +73,15 @@ statuses.chat=all statuses.muc=all roster=true roster.offline=true -roster.resource=false -roster.by=presence -roster.size=25 +roster.resource=true +roster.presence=true +roster.status=true roster.empty=true +roster.by=group +roster.order=presence +roster.count=true +roster.priority=true +roster.size=25 occupants=true occupants.size=15 occupants.jid=false diff --git a/themes/complex b/themes/complex index 61af29b1..c1abfc81 100644 --- a/themes/complex +++ b/themes/complex @@ -21,9 +21,14 @@ occupants.jid=true roster=true roster.offline=true roster.resource=true -roster.by=presence -roster.size=25 +roster.presence=true +roster.status=true roster.empty=true +roster.by=presence +roster.order=presence +roster.count=true +roster.priority=true +roster.size=25 privileges=true presence=true intype=true diff --git a/themes/simple b/themes/simple index 32a4b20f..a31c9c01 100644 --- a/themes/simple +++ b/themes/simple @@ -20,9 +20,14 @@ occupants.size=15 roster=true roster.offline=false roster.resource=false -roster.by=presence -roster.size=25 +roster.presence=false +roster.status=false roster.empty=false +roster.by=none +roster.order=presence +roster.count=false +roster.priority=false +roster.size=25 privileges=false presence=false intype=false