diff options
author | James Booth <boothj5@gmail.com> | 2016-01-14 22:54:50 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-01-14 22:54:50 +0000 |
commit | fbc302317ad635c095c77170882b4fbb16a4dace (patch) | |
tree | b30ff7fdb83ae4e5b6023ebab3b561c0b8af39bf /src | |
parent | 042ad4758f57f056b18dc14eddafadd23d54f57e (diff) | |
download | profani-tty-fbc302317ad635c095c77170882b4fbb16a4dace.tar.gz |
Added roster contact themes
Diffstat (limited to 'src')
-rw-r--r-- | src/command/commands.c | 4 | ||||
-rw-r--r-- | src/config/theme.c | 72 | ||||
-rw-r--r-- | src/config/theme.h | 22 | ||||
-rw-r--r-- | src/event/server_events.c | 4 | ||||
-rw-r--r-- | src/ui/rosterwin.c | 44 |
5 files changed, 141 insertions, 5 deletions
diff --git a/src/command/commands.c b/src/command/commands.c index 447bd4b4..7b6fef6d 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1071,6 +1071,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) } else { cons_show("Closed %d windows.", count); } + rosterwin_roster(); return TRUE; } @@ -1083,6 +1084,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) } else { cons_show("Closed %d windows.", count); } + rosterwin_roster(); return TRUE; } @@ -1141,6 +1143,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) wins_tidy(); } + rosterwin_roster(); return TRUE; } else { if (g_strcmp0(args[0], "console") == 0) { @@ -1175,6 +1178,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) wins_tidy(); } + rosterwin_roster(); return TRUE; } } diff --git a/src/config/theme.c b/src/config/theme.c index 63c42cea..c0a6b134 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -448,6 +448,60 @@ _theme_find(const char *const theme_name) } theme_item_t +theme_roster_unread_presence_attrs(const char *const presence) +{ + if (g_strcmp0(presence, "online") == 0) { + return THEME_ROSTER_ONLINE_UNREAD; + } else if (g_strcmp0(presence, "away") == 0) { + return THEME_ROSTER_AWAY_UNREAD; + } else if (g_strcmp0(presence, "chat") == 0) { + return THEME_ROSTER_CHAT_UNREAD; + } else if (g_strcmp0(presence, "dnd") == 0) { + return THEME_ROSTER_DND_UNREAD; + } else if (g_strcmp0(presence, "xa") == 0) { + return THEME_ROSTER_XA_UNREAD; + } else { + return THEME_ROSTER_OFFLINE_UNREAD; + } +} + +theme_item_t +theme_roster_active_presence_attrs(const char *const presence) +{ + if (g_strcmp0(presence, "online") == 0) { + return THEME_ROSTER_ONLINE_ACTIVE; + } else if (g_strcmp0(presence, "away") == 0) { + return THEME_ROSTER_AWAY_ACTIVE; + } else if (g_strcmp0(presence, "chat") == 0) { + return THEME_ROSTER_CHAT_ACTIVE; + } else if (g_strcmp0(presence, "dnd") == 0) { + return THEME_ROSTER_DND_ACTIVE; + } else if (g_strcmp0(presence, "xa") == 0) { + return THEME_ROSTER_XA_ACTIVE; + } else { + return THEME_ROSTER_OFFLINE_ACTIVE; + } +} + +theme_item_t +theme_roster_presence_attrs(const char *const presence) +{ + if (g_strcmp0(presence, "online") == 0) { + return THEME_ROSTER_ONLINE; + } else if (g_strcmp0(presence, "away") == 0) { + return THEME_ROSTER_AWAY; + } else if (g_strcmp0(presence, "chat") == 0) { + return THEME_ROSTER_CHAT; + } else if (g_strcmp0(presence, "dnd") == 0) { + return THEME_ROSTER_DND; + } else if (g_strcmp0(presence, "xa") == 0) { + return THEME_ROSTER_XA; + } else { + return THEME_ROSTER_OFFLINE; + } +} + +theme_item_t theme_main_presence_attrs(const char *const presence) { if (g_strcmp0(presence, "online") == 0) { @@ -554,6 +608,24 @@ theme_attrs(theme_item_t attrs) case THEME_OTR_TRUSTED: _theme_prep_fgnd("otr.trusted", "green", lookup_str, &bold); break; case THEME_OTR_UNTRUSTED: _theme_prep_fgnd("otr.untrusted", "yellow", lookup_str, &bold); break; case THEME_ROSTER_HEADER: _theme_prep_fgnd("roster.header", "yellow", lookup_str, &bold); break; + case THEME_ROSTER_ONLINE: _theme_prep_fgnd("roster.online", "green", lookup_str, &bold); break; + case THEME_ROSTER_OFFLINE: _theme_prep_fgnd("roster.offline", "red", lookup_str, &bold); break; + case THEME_ROSTER_CHAT: _theme_prep_fgnd("roster.chat", "green", lookup_str, &bold); break; + case THEME_ROSTER_AWAY: _theme_prep_fgnd("roster.away", "cyan", lookup_str, &bold); break; + case THEME_ROSTER_DND: _theme_prep_fgnd("roster.dnd", "red", lookup_str, &bold); break; + case THEME_ROSTER_XA: _theme_prep_fgnd("roster.xa", "cyan", lookup_str, &bold); break; + case THEME_ROSTER_ONLINE_ACTIVE: _theme_prep_fgnd("roster.online.active", "green", lookup_str, &bold); break; + case THEME_ROSTER_OFFLINE_ACTIVE: _theme_prep_fgnd("roster.offline.active", "red", lookup_str, &bold); break; + case THEME_ROSTER_CHAT_ACTIVE: _theme_prep_fgnd("roster.chat.active", "green", lookup_str, &bold); break; + case THEME_ROSTER_AWAY_ACTIVE: _theme_prep_fgnd("roster.away.active", "cyan", lookup_str, &bold); break; + case THEME_ROSTER_DND_ACTIVE: _theme_prep_fgnd("roster.dnd.active", "red", lookup_str, &bold); break; + case THEME_ROSTER_XA_ACTIVE: _theme_prep_fgnd("roster.xa.active", "cyan", lookup_str, &bold); break; + case THEME_ROSTER_ONLINE_UNREAD: _theme_prep_fgnd("roster.online.unread", "green", lookup_str, &bold); break; + case THEME_ROSTER_OFFLINE_UNREAD: _theme_prep_fgnd("roster.offline.unread", "red", lookup_str, &bold); break; + case THEME_ROSTER_CHAT_UNREAD: _theme_prep_fgnd("roster.chat.unread", "green", lookup_str, &bold); break; + case THEME_ROSTER_AWAY_UNREAD: _theme_prep_fgnd("roster.away.unread", "cyan", lookup_str, &bold); break; + case THEME_ROSTER_DND_UNREAD: _theme_prep_fgnd("roster.dnd.unread", "red", lookup_str, &bold); break; + case THEME_ROSTER_XA_UNREAD: _theme_prep_fgnd("roster.xa.unread", "cyan", lookup_str, &bold); break; case THEME_ROSTER_ROOM: _theme_prep_fgnd("roster.room", "green", lookup_str, &bold); break; case THEME_ROSTER_ROOM_UNREAD: _theme_prep_fgnd("roster.room.unread", "green", lookup_str, &bold); break; case THEME_OCCUPANTS_HEADER: _theme_prep_fgnd("occupants.header", "yellow", lookup_str, &bold); break; diff --git a/src/config/theme.h b/src/config/theme.h index c0380354..7b86d1a7 100644 --- a/src/config/theme.h +++ b/src/config/theme.h @@ -85,6 +85,24 @@ typedef enum { THEME_OTR_UNTRUSTED, THEME_OCCUPANTS_HEADER, THEME_ROSTER_HEADER, + THEME_ROSTER_ONLINE, + THEME_ROSTER_OFFLINE, + THEME_ROSTER_AWAY, + THEME_ROSTER_CHAT, + THEME_ROSTER_DND, + THEME_ROSTER_XA, + THEME_ROSTER_ONLINE_ACTIVE, + THEME_ROSTER_OFFLINE_ACTIVE, + THEME_ROSTER_AWAY_ACTIVE, + THEME_ROSTER_CHAT_ACTIVE, + THEME_ROSTER_DND_ACTIVE, + THEME_ROSTER_XA_ACTIVE, + THEME_ROSTER_ONLINE_UNREAD, + THEME_ROSTER_OFFLINE_UNREAD, + THEME_ROSTER_AWAY_UNREAD, + THEME_ROSTER_CHAT_UNREAD, + THEME_ROSTER_DND_UNREAD, + THEME_ROSTER_XA_UNREAD, THEME_ROSTER_ROOM, THEME_ROSTER_ROOM_UNREAD, THEME_RECEIPT_SENT, @@ -113,6 +131,10 @@ gboolean theme_load(const char *const theme_name); GSList* theme_list(void); void theme_close(void); int theme_attrs(theme_item_t attrs); + theme_item_t theme_main_presence_attrs(const char *const presence); +theme_item_t theme_roster_unread_presence_attrs(const char *const presence); +theme_item_t theme_roster_active_presence_attrs(const char *const presence); +theme_item_t theme_roster_presence_attrs(const char *const presence); #endif diff --git a/src/event/server_events.c b/src/event/server_events.c index 147ea6ce..872dc74b 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -427,6 +427,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m } else { _sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message, timestamp); } + rosterwin_roster(); return; #endif #endif @@ -435,6 +436,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m #ifdef HAVE_LIBOTR #ifndef HAVE_LIBGPGME _sv_ev_incoming_otr(chatwin, new_win, barejid, resource, message, timestamp); + rosterwin_roster(); return; #endif #endif @@ -447,6 +449,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m } else { _sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, timestamp); } + rosterwin_roster(); return; #endif #endif @@ -455,6 +458,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message, char *pgp_m #ifndef HAVE_LIBOTR #ifndef HAVE_LIBGPGME _sv_ev_incoming_plain(chatwin, new_win, barejid, resource, message, timestamp); + rosterwin_roster(); return; #endif #endif diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index afafdd86..b05f7b42 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -42,6 +42,12 @@ #include "config/preferences.h" #include "roster_list.h" +typedef enum { + ROSTER_CONTACT, + ROSTER_CONTACT_ACTIVE, + ROSTER_CONTACT_UNREAD +} roster_contact_theme_t; + static void _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *presence, const char *status, int current_indent) @@ -126,7 +132,7 @@ _rosterwin_presence(ProfLayoutSplit *layout, theme_item_t colour, const char *pr } static void -_rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_indent) +_rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_indent, roster_contact_theme_t theme_type) { gboolean join = prefs_get_boolean(PREF_ROSTER_RESOURCE_JOIN); @@ -135,7 +141,13 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde if (join && (g_list_length(resources) == 1)) { Resource *resource = resources->data; const char *resource_presence = string_from_resource_presence(resource->presence); - theme_item_t resource_presence_colour = theme_main_presence_attrs(resource_presence); + + theme_item_t resource_presence_colour; + switch (theme_type) { + case ROSTER_CONTACT: resource_presence_colour = theme_roster_presence_attrs(resource_presence); break; + case ROSTER_CONTACT_ACTIVE: resource_presence_colour = theme_roster_active_presence_attrs(resource_presence); break; + case ROSTER_CONTACT_UNREAD: resource_presence_colour = theme_roster_unread_presence_attrs(resource_presence); break; + } wattron(layout->subwin, theme_attrs(resource_presence_colour)); GString *msg = g_string_new(""); @@ -167,7 +179,13 @@ _rosterwin_resources(ProfLayoutSplit *layout, PContact contact, int current_inde while (curr_resource) { Resource *resource = curr_resource->data; const char *resource_presence = string_from_resource_presence(resource->presence); - theme_item_t resource_presence_colour = theme_main_presence_attrs(resource_presence); + + theme_item_t resource_presence_colour; + switch (theme_type) { + case ROSTER_CONTACT: resource_presence_colour = theme_roster_presence_attrs(resource_presence); break; + case ROSTER_CONTACT_ACTIVE: resource_presence_colour = theme_roster_active_presence_attrs(resource_presence); break; + case ROSTER_CONTACT_UNREAD: resource_presence_colour = theme_roster_unread_presence_attrs(resource_presence); break; + } wattron(layout->subwin, theme_attrs(resource_presence_colour)); GString *msg = g_string_new(" "); @@ -213,8 +231,24 @@ _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); + const char *barejid = p_contact_barejid(contact); - theme_item_t presence_colour = theme_main_presence_attrs(presence); + roster_contact_theme_t theme_type = ROSTER_CONTACT; + ProfChatWin *chatwin = wins_get_chat(barejid); + if (chatwin) { + if (chatwin->unread > 0) { + theme_type = ROSTER_CONTACT_UNREAD; + } else { + theme_type = ROSTER_CONTACT_ACTIVE; + } + } + + theme_item_t presence_colour; + switch (theme_type) { + case ROSTER_CONTACT: presence_colour = theme_roster_presence_attrs(presence); break; + case ROSTER_CONTACT_ACTIVE: presence_colour = theme_roster_active_presence_attrs(presence); break; + case ROSTER_CONTACT_UNREAD: presence_colour = theme_roster_unread_presence_attrs(presence); break; + } wattron(layout->subwin, theme_attrs(presence_colour)); GString *msg = g_string_new(" "); @@ -239,7 +273,7 @@ _rosterwin_contact(ProfLayoutSplit *layout, PContact contact) wattroff(layout->subwin, theme_attrs(presence_colour)); if (prefs_get_boolean(PREF_ROSTER_RESOURCE)) { - _rosterwin_resources(layout, contact, current_indent); + _rosterwin_resources(layout, contact, current_indent, theme_type); } else if (prefs_get_boolean(PREF_ROSTER_PRESENCE) || prefs_get_boolean(PREF_ROSTER_STATUS)) { _rosterwin_presence(layout, presence_colour, presence, status, current_indent); } |