diff options
author | James Booth <boothj5@gmail.com> | 2015-11-15 22:54:09 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-11-15 22:54:09 +0000 |
commit | b44ea030224c11233b378e0fde36c3daf2979a05 (patch) | |
tree | e9ae9266400ec9928f143eb4df1a034a6af30762 /src/ui | |
parent | 98a395e933672320c773a6653f79106373d8b1e3 (diff) | |
download | profani-tty-b44ea030224c11233b378e0fde36c3daf2979a05.tar.gz |
Added _rosterwin_resource()
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/rosterwin.c | 143 |
1 files changed, 77 insertions, 66 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 @@ -43,75 +43,33 @@ #include "roster_list.h" static void -_rosterwin_contact(ProfLayoutSplit *layout, PContact contact) +_rosterwin_resource(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)))) { - theme_item_t presence_colour = theme_main_presence_attrs(presence); + 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(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)) { - 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)); - 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)) { + 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 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(presence_colour)); - GString *msg = g_string_new(" "); + wattron(layout->subwin, theme_attrs(resource_presence_colour)); + GString *msg = g_string_new(" "); if (!by_presence) { - g_string_append(msg, presence); + g_string_append(msg, resource_presence); } if (has_status && show_status) { if (!by_presence) { @@ -119,17 +77,70 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) } else { g_string_append(msg, "\""); } - const char *status = p_contact_status(contact); - g_string_append(msg, status); + 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(presence_colour)); + wattroff(layout->subwin, theme_attrs(resource_presence_colour)); } } - g_list_free(resources); + + 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); + + 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); + + 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)) { + 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); |