mirror of
https://github.com/profanity-im/profanity.git
synced 2024-10-13 20:13:38 -04:00
Coloured contact and subscription in /roster and /group output
This commit is contained in:
parent
817857e4c0
commit
581c1e8b95
@ -72,6 +72,8 @@ static struct colours_t {
|
||||
NCURSES_COLOR_T inputtext;
|
||||
NCURSES_COLOR_T timetext;
|
||||
NCURSES_COLOR_T splashtext;
|
||||
NCURSES_COLOR_T subscribed;
|
||||
NCURSES_COLOR_T unsubscribed;
|
||||
NCURSES_COLOR_T online;
|
||||
NCURSES_COLOR_T away;
|
||||
NCURSES_COLOR_T xa;
|
||||
@ -220,6 +222,10 @@ theme_init_colours(void)
|
||||
// states
|
||||
init_pair(60, colour_prefs.typing, colour_prefs.bkgnd);
|
||||
init_pair(61, colour_prefs.gone, colour_prefs.bkgnd);
|
||||
|
||||
// subscription status
|
||||
init_pair(70, colour_prefs.subscribed, colour_prefs.bkgnd);
|
||||
init_pair(71, colour_prefs.unsubscribed, colour_prefs.bkgnd);
|
||||
}
|
||||
|
||||
static NCURSES_COLOR_T
|
||||
@ -306,6 +312,14 @@ _load_colours(void)
|
||||
_set_colour(timetext_val, &colour_prefs.timetext, COLOR_WHITE);
|
||||
g_free(timetext_val);
|
||||
|
||||
gchar *subscribed_val = g_key_file_get_string(theme, "colours", "subscribed", NULL);
|
||||
_set_colour(subscribed_val, &colour_prefs.subscribed, COLOR_GREEN);
|
||||
g_free(subscribed_val);
|
||||
|
||||
gchar *unsubscribed_val = g_key_file_get_string(theme, "colours", "unsubscribed", NULL);
|
||||
_set_colour(unsubscribed_val, &colour_prefs.unsubscribed, COLOR_RED);
|
||||
g_free(unsubscribed_val);
|
||||
|
||||
gchar *online_val = g_key_file_get_string(theme, "colours", "online", NULL);
|
||||
_set_colour(online_val, &colour_prefs.online, COLOR_GREEN);
|
||||
g_free(online_val);
|
||||
|
@ -55,6 +55,8 @@
|
||||
#define COLOUR_XA COLOR_PAIR(55)
|
||||
#define COLOUR_TYPING COLOR_PAIR(60)
|
||||
#define COLOUR_GONE COLOR_PAIR(61)
|
||||
#define COLOUR_SUBSCRIBED COLOR_PAIR(70)
|
||||
#define COLOUR_UNSUBSCRIBED COLOR_PAIR(71)
|
||||
|
||||
void theme_init(const char * const theme_name);
|
||||
void theme_init_colours(void);
|
||||
|
@ -252,6 +252,20 @@ p_contact_subscription(const PContact contact)
|
||||
return contact->subscription;
|
||||
}
|
||||
|
||||
gboolean
|
||||
p_contact_subscribed(const PContact contact)
|
||||
{
|
||||
if (contact->subscription == NULL) {
|
||||
return FALSE;
|
||||
} else if (strcmp(contact->subscription, "to") == 0) {
|
||||
return TRUE;
|
||||
} else if (strcmp(contact->subscription, "both") == 0) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
Resource *
|
||||
p_contact_get_resource(const PContact contact, const char * const resource)
|
||||
{
|
||||
|
@ -53,5 +53,6 @@ Resource * p_contact_get_resource(const PContact contact, const char * const res
|
||||
void p_contact_set_groups(const PContact contact, GSList *groups);
|
||||
GSList * p_contact_groups(const PContact contact);
|
||||
gboolean p_contact_in_group(const PContact contact, const char * const group);
|
||||
gboolean p_contact_subscribed(const PContact contact);
|
||||
|
||||
#endif
|
||||
|
117
src/ui/console.c
117
src/ui/console.c
@ -43,6 +43,7 @@
|
||||
static ProfWin* console;
|
||||
|
||||
static void _cons_splash_logo(void);
|
||||
void _show_roster_contacts(GSList *list, gboolean show_groups);
|
||||
|
||||
ProfWin *
|
||||
cons_create(void)
|
||||
@ -1307,17 +1308,9 @@ cons_navigation_help(void)
|
||||
}
|
||||
|
||||
void
|
||||
cons_show_roster_group(const char * const group, GSList *list)
|
||||
_show_roster_contacts(GSList *list, gboolean show_groups)
|
||||
{
|
||||
GSList *curr = list;
|
||||
cons_show("");
|
||||
|
||||
if (curr != NULL) {
|
||||
cons_show("%s:", group);
|
||||
} else {
|
||||
cons_show("No group named %s exists.", group);
|
||||
}
|
||||
|
||||
while(curr) {
|
||||
|
||||
PContact contact = curr->data;
|
||||
@ -1328,10 +1321,24 @@ cons_show_roster_group(const char * const group, GSList *list)
|
||||
title = g_string_append(title, strdup(p_contact_name(contact)));
|
||||
title = g_string_append(title, ")");
|
||||
}
|
||||
cons_show(title->str);
|
||||
|
||||
const char *presence = p_contact_presence(contact);
|
||||
win_print_time(console, '-');
|
||||
if (p_contact_subscribed(contact)) {
|
||||
win_presence_colour_on(console, presence);
|
||||
wprintw(console->win, "%s\n", title->str);
|
||||
win_presence_colour_off(console, presence);
|
||||
} else {
|
||||
win_presence_colour_on(console, "offline");
|
||||
wprintw(console->win, "%s\n", title->str);
|
||||
win_presence_colour_off(console, "offline");
|
||||
}
|
||||
|
||||
g_string_free(title, TRUE);
|
||||
|
||||
GString *sub = g_string_new(" Subscription : ");
|
||||
win_print_time(console, '-');
|
||||
wprintw(console->win, " Subscription : ");
|
||||
GString *sub = g_string_new("");
|
||||
sub = g_string_append(sub, p_contact_subscription(contact));
|
||||
if (p_contact_pending_out(contact)) {
|
||||
sub = g_string_append(sub, ", request sent");
|
||||
@ -1339,12 +1346,54 @@ cons_show_roster_group(const char * const group, GSList *list)
|
||||
if (presence_sub_request_exists(p_contact_barejid(contact))) {
|
||||
sub = g_string_append(sub, ", request received");
|
||||
}
|
||||
cons_show(sub->str);
|
||||
if (p_contact_subscribed(contact)) {
|
||||
wattron(console->win, COLOUR_SUBSCRIBED);
|
||||
} else {
|
||||
wattron(console->win, COLOUR_UNSUBSCRIBED);
|
||||
}
|
||||
wprintw(console->win, "%s\n", sub->str);
|
||||
if (p_contact_subscribed(contact)) {
|
||||
wattroff(console->win, COLOUR_SUBSCRIBED);
|
||||
} else {
|
||||
wattroff(console->win, COLOUR_UNSUBSCRIBED);
|
||||
}
|
||||
|
||||
g_string_free(sub, TRUE);
|
||||
|
||||
if (show_groups) {
|
||||
GSList *groups = p_contact_groups(contact);
|
||||
if (groups != NULL) {
|
||||
GString *groups_str = g_string_new(" Groups : ");
|
||||
while (groups != NULL) {
|
||||
g_string_append(groups_str, strdup(groups->data));
|
||||
if (g_slist_next(groups) != NULL) {
|
||||
g_string_append(groups_str, ", ");
|
||||
}
|
||||
groups = g_slist_next(groups);
|
||||
}
|
||||
|
||||
cons_show(groups_str->str);
|
||||
g_string_free(groups_str, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
cons_show_roster_group(const char * const group, GSList *list)
|
||||
{
|
||||
cons_show("");
|
||||
|
||||
if (list != NULL) {
|
||||
cons_show("%s:", group);
|
||||
} else {
|
||||
cons_show("No group named %s exists.", group);
|
||||
}
|
||||
|
||||
_show_roster_contacts(list, FALSE);
|
||||
ui_console_dirty();
|
||||
cons_alert();
|
||||
}
|
||||
@ -1352,52 +1401,10 @@ cons_show_roster_group(const char * const group, GSList *list)
|
||||
void
|
||||
cons_show_roster(GSList *list)
|
||||
{
|
||||
GSList *curr = list;
|
||||
cons_show("");
|
||||
cons_show("Roster:");
|
||||
|
||||
while(curr) {
|
||||
|
||||
PContact contact = curr->data;
|
||||
GString *title = g_string_new(" ");
|
||||
title = g_string_append(title, p_contact_barejid(contact));
|
||||
if (p_contact_name(contact) != NULL) {
|
||||
title = g_string_append(title, " (");
|
||||
title = g_string_append(title, strdup(p_contact_name(contact)));
|
||||
title = g_string_append(title, ")");
|
||||
}
|
||||
cons_show(title->str);
|
||||
g_string_free(title, TRUE);
|
||||
|
||||
GString *sub = g_string_new(" Subscription : ");
|
||||
sub = g_string_append(sub, p_contact_subscription(contact));
|
||||
if (p_contact_pending_out(contact)) {
|
||||
sub = g_string_append(sub, ", request sent");
|
||||
}
|
||||
if (presence_sub_request_exists(p_contact_barejid(contact))) {
|
||||
sub = g_string_append(sub, ", request received");
|
||||
}
|
||||
cons_show(sub->str);
|
||||
g_string_free(sub, TRUE);
|
||||
|
||||
GSList *groups = p_contact_groups(contact);
|
||||
if (groups != NULL) {
|
||||
GString *groups_str = g_string_new(" Groups : ");
|
||||
while (groups != NULL) {
|
||||
g_string_append(groups_str, strdup(groups->data));
|
||||
if (g_slist_next(groups) != NULL) {
|
||||
g_string_append(groups_str, ", ");
|
||||
}
|
||||
groups = g_slist_next(groups);
|
||||
}
|
||||
|
||||
cons_show(groups_str->str);
|
||||
g_string_free(groups_str, TRUE);
|
||||
}
|
||||
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
_show_roster_contacts(list, TRUE);
|
||||
ui_console_dirty();
|
||||
cons_alert();
|
||||
}
|
||||
|
@ -562,14 +562,16 @@ _roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
|
||||
// remove each fulljid
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
GList *resources = p_contact_get_available_resources(contact);
|
||||
while (resources != NULL) {
|
||||
GString *fulljid = g_string_new(strdup(barejid));
|
||||
g_string_append(fulljid, "/");
|
||||
g_string_append(fulljid, strdup(resources->data));
|
||||
autocomplete_remove(fulljid_ac, fulljid->str);
|
||||
g_string_free(fulljid, TRUE);
|
||||
resources = g_list_next(resources);
|
||||
if (contact != NULL) {
|
||||
GList *resources = p_contact_get_available_resources(contact);
|
||||
while (resources != NULL) {
|
||||
GString *fulljid = g_string_new(strdup(barejid));
|
||||
g_string_append(fulljid, "/");
|
||||
g_string_append(fulljid, strdup(resources->data));
|
||||
autocomplete_remove(fulljid_ac, fulljid->str);
|
||||
g_string_free(fulljid, TRUE);
|
||||
resources = g_list_next(resources);
|
||||
}
|
||||
}
|
||||
|
||||
// remove the contact
|
||||
|
Loading…
Reference in New Issue
Block a user