diff --git a/src/command/command.c b/src/command/command.c index bb28b962..eef6a828 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -284,9 +284,12 @@ static struct cmd_t command_defs[] = "/roster by group|presence|none", "/roster order name|presence", "/roster unread before|after|off", + "/roster room char |none", "/roster room position first|last", "/roster room order name|unread", "/roster room unread before|after|off", + "/roster private room|group|off", + "/roster private char |none", "/roster header char |none", "/roster presence indent ", "/roster contact char |none", @@ -334,6 +337,8 @@ static struct cmd_t command_defs[] = { "unread before", "Show unread message count before contact in roster." }, { "unread after", "Show unread message count after contact in roster." }, { "unread off", "Do not show unread message count for contacts in roster." }, + { "room char ", "Prefix roster rooms with specified character." }, + { "room char none", "Remove roster room character prefix." }, { "room position first", "Show rooms first in roster." }, { "room position last", "Show rooms last in roster." }, { "room order name", "Order roster rooms by name." }, @@ -341,6 +346,11 @@ static struct cmd_t command_defs[] = { "room unread before", "Show unread message count before room in roster." }, { "room unread after", "Show unread message count after room in roster." }, { "room unread off", "Do not show unread message count for rooms in roster." }, + { "private room", "Show room private chats below the room in the roster." }, + { "private group", "Show room private chats as a separate roster group." }, + { "private off", "Do not show room private chats in the roster." }, + { "private char ", "Prefix roster private room chats with specified character." }, + { "private char none", "Remove roster private room chat character prefix." }, { "header char ", "Prefix roster headers with specified character." }, { "header char none", "Remove roster header character prefix." }, { "contact char ", "Prefix roster contacts with specified character." }, @@ -1943,6 +1953,7 @@ static Autocomplete roster_room_ac; static Autocomplete roster_room_position_ac; static Autocomplete roster_room_order_ac; static Autocomplete roster_unread_ac; +static Autocomplete roster_private_ac; static Autocomplete group_ac; static Autocomplete bookmark_ac; static Autocomplete bookmark_property_ac; @@ -2210,6 +2221,13 @@ cmd_init(void) autocomplete_add(roster_ac, "contact"); autocomplete_add(roster_ac, "resource"); autocomplete_add(roster_ac, "presence"); + autocomplete_add(roster_ac, "private"); + + roster_private_ac = autocomplete_new(); + autocomplete_add(roster_private_ac, "room"); + autocomplete_add(roster_private_ac, "group"); + autocomplete_add(roster_private_ac, "off"); + autocomplete_add(roster_private_ac, "char"); roster_header_ac = autocomplete_new(); autocomplete_add(roster_header_ac, "char"); @@ -2255,6 +2273,7 @@ cmd_init(void) autocomplete_add(roster_unread_ac, "off"); roster_room_ac = autocomplete_new(); + autocomplete_add(roster_room_ac, "char"); autocomplete_add(roster_room_ac, "position"); autocomplete_add(roster_room_ac, "order"); autocomplete_add(roster_room_ac, "unread"); @@ -2544,6 +2563,7 @@ cmd_uninit(void) autocomplete_free(roster_room_position_ac); autocomplete_free(roster_room_order_ac); autocomplete_free(roster_remove_all_ac); + autocomplete_free(roster_private_ac); autocomplete_free(group_ac); autocomplete_free(bookmark_ac); autocomplete_free(bookmark_property_ac); @@ -2756,6 +2776,7 @@ cmd_reset_autocomplete(ProfWin *window) autocomplete_reset(roster_room_position_ac); autocomplete_reset(roster_room_order_ac); autocomplete_reset(roster_remove_all_ac); + autocomplete_reset(roster_private_ac); autocomplete_reset(group_ac); autocomplete_reset(titlebar_ac); autocomplete_reset(bookmark_ac); @@ -3165,6 +3186,14 @@ _roster_autocomplete(ProfWin *window, const char *const input) if (result) { return result; } + result = autocomplete_param_with_ac(input, "/roster room char", roster_char_ac, TRUE); + if (result) { + return result; + } + result = autocomplete_param_with_ac(input, "/roster private char", roster_char_ac, TRUE); + if (result) { + return result; + } result = autocomplete_param_with_ac(input, "/roster resource char", roster_char_ac, TRUE); if (result) { return result; @@ -3250,6 +3279,10 @@ _roster_autocomplete(ProfWin *window, const char *const input) if (result) { return result; } + result = autocomplete_param_with_ac(input, "/roster private", roster_private_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 4117213f..d22ee511 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2416,8 +2416,61 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args) return TRUE; } + } else if (g_strcmp0(args[0], "private") == 0) { + if (g_strcmp0(args[1], "char") == 0) { + if (!args[2]) { + cons_bad_cmd_usage(command); + } else if (g_strcmp0(args[2], "none") == 0) { + prefs_clear_roster_private_char(); + cons_show("Roster private room chat char removed."); + rosterwin_roster(); + } else { + prefs_set_roster_private_char(args[2][0]); + cons_show("Roster private room chat char set to %c.", args[2][0]); + rosterwin_roster(); + } + return TRUE; + } else if (g_strcmp0(args[1], "room") == 0) { + cons_show("Showing room private chats under room."); + prefs_set_string(PREF_ROSTER_PRIVATE, "room"); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else if (g_strcmp0(args[1], "group") == 0) { + cons_show("Showing room private chats as roster group."); + prefs_set_string(PREF_ROSTER_PRIVATE, "group"); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else if (g_strcmp0(args[1], "off") == 0) { + cons_show("Hiding room private chats in roster."); + prefs_set_string(PREF_ROSTER_PRIVATE, "off"); + if (conn_status == JABBER_CONNECTED) { + rosterwin_roster(); + } + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } + } else if (g_strcmp0(args[0], "room") == 0) { - if (g_strcmp0(args[1], "position") == 0) { + if (g_strcmp0(args[1], "char") == 0) { + if (!args[2]) { + cons_bad_cmd_usage(command); + } else if (g_strcmp0(args[2], "none") == 0) { + prefs_clear_roster_room_char(); + cons_show("Roster room char removed."); + rosterwin_roster(); + } else { + prefs_set_roster_room_char(args[2][0]); + cons_show("Roster room char set to %c.", args[2][0]); + rosterwin_roster(); + } + return TRUE; + } else if (g_strcmp0(args[1], "position") == 0) { if (g_strcmp0(args[2], "first") == 0) { cons_show("Showing rooms first in roster."); prefs_set_string(PREF_ROSTER_ROOMS_POS, "first"); diff --git a/src/config/preferences.c b/src/config/preferences.c index b42c643f..0d3127af 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -768,6 +768,80 @@ prefs_clear_roster_resource_char(void) _save_prefs(); } +char +prefs_get_roster_private_char(void) +{ + char result = 0; + + char *resultstr = g_key_file_get_string(prefs, PREF_GROUP_UI, "roster.private.char", NULL); + if (!resultstr) { + result = 0; + } else { + result = resultstr[0]; + } + free(resultstr); + + return result; +} + +void +prefs_set_roster_private_char(char ch) +{ + char str[2]; + str[0] = ch; + str[1] = '\0'; + + g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.private.char", str); + _save_prefs(); +} + +void +prefs_clear_roster_private_char(void) +{ + g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.private.char", NULL); + _save_prefs(); +} + + + +char +prefs_get_roster_room_char(void) +{ + char result = 0; + + char *resultstr = g_key_file_get_string(prefs, PREF_GROUP_UI, "roster.rooms.char", NULL); + if (!resultstr) { + result = 0; + } else { + result = resultstr[0]; + } + free(resultstr); + + return result; +} + +void +prefs_set_roster_room_char(char ch) +{ + char str[2]; + str[0] = ch; + str[1] = '\0'; + + g_key_file_set_string(prefs, PREF_GROUP_UI, "roster.rooms.char", str); + _save_prefs(); +} + +void +prefs_clear_roster_room_char(void) +{ + g_key_file_remove_key(prefs, PREF_GROUP_UI, "roster.rooms.char", NULL); + _save_prefs(); +} + + + + + gint prefs_get_roster_contact_indent(void) { @@ -1064,6 +1138,7 @@ _get_group(preference_t pref) case PREF_ROSTER_ROOMS_POS: case PREF_ROSTER_ROOMS_ORDER: case PREF_ROSTER_ROOMS_UNREAD: + case PREF_ROSTER_PRIVATE: case PREF_RESOURCE_TITLE: case PREF_RESOURCE_MESSAGE: case PREF_ENC_WARN: @@ -1270,6 +1345,8 @@ _get_key(preference_t pref) return "roster.rooms.order"; case PREF_ROSTER_ROOMS_UNREAD: return "roster.rooms.unread"; + case PREF_ROSTER_PRIVATE: + return "roster.private"; case PREF_RESOURCE_TITLE: return "resource.title"; case PREF_RESOURCE_MESSAGE: @@ -1366,6 +1443,8 @@ _get_default_string(preference_t pref) return "name"; case PREF_ROSTER_ROOMS_UNREAD: return "after"; + case PREF_ROSTER_PRIVATE: + return "room"; 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 2838d550..55b3932f 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -79,6 +79,7 @@ typedef enum { PREF_ROSTER_ROOMS_POS, PREF_ROSTER_ROOMS_ORDER, PREF_ROSTER_ROOMS_UNREAD, + PREF_ROSTER_PRIVATE, PREF_MUC_PRIVILEGES, PREF_PRESENCE, PREF_WRAP, @@ -193,6 +194,12 @@ void prefs_clear_roster_contact_char(void); char prefs_get_roster_resource_char(void); void prefs_set_roster_resource_char(char ch); void prefs_clear_roster_resource_char(void); +char prefs_get_roster_private_char(void); +void prefs_set_roster_private_char(char ch); +void prefs_clear_roster_private_char(void); +char prefs_get_roster_room_char(void); +void prefs_set_roster_room_char(char ch); +void prefs_clear_roster_room_char(void); gint prefs_get_roster_contact_indent(void); void prefs_set_roster_contact_indent(gint value); diff --git a/src/config/theme.c b/src/config/theme.c index 1099fbe8..a83a0d15 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -373,29 +373,10 @@ _load_preferences(void) _set_boolean_preference("splash", PREF_SPLASH); _set_boolean_preference("wrap", PREF_WRAP); _set_boolean_preference("wins.autotidy", PREF_WINS_AUTO_TIDY); - _set_string_preference("time.console", PREF_TIME_CONSOLE); - _set_string_preference("time.chat", PREF_TIME_CHAT); - _set_string_preference("time.muc", PREF_TIME_MUC); - _set_string_preference("time.mucconfig", PREF_TIME_MUCCONFIG); - _set_string_preference("time.private", PREF_TIME_PRIVATE); - _set_string_preference("time.xmlconsole", PREF_TIME_XMLCONSOLE); - _set_string_preference("time.statusbar", PREF_TIME_STATUSBAR); - _set_string_preference("time.lastactivity", PREF_TIME_LASTACTIVITY); - _set_boolean_preference("resource.title", PREF_RESOURCE_TITLE); _set_boolean_preference("resource.message", PREF_RESOURCE_MESSAGE); - - _set_string_preference("statuses.console", PREF_STATUSES_CONSOLE); - _set_string_preference("statuses.chat", PREF_STATUSES_CHAT); - _set_string_preference("statuses.muc", PREF_STATUSES_MUC); - _set_boolean_preference("occupants", PREF_OCCUPANTS); _set_boolean_preference("occupants.jid", PREF_OCCUPANTS_JID); - if (g_key_file_has_key(theme, "ui", "occupants.size", NULL)) { - gint occupants_size = g_key_file_get_integer(theme, "ui", "occupants.size", NULL); - prefs_set_occupants_size(occupants_size); - } - _set_boolean_preference("roster", PREF_ROSTER); _set_boolean_preference("roster.offline", PREF_ROSTER_OFFLINE); _set_boolean_preference("roster.resource", PREF_ROSTER_RESOURCE); @@ -404,20 +385,46 @@ _load_preferences(void) _set_boolean_preference("roster.status", PREF_ROSTER_STATUS); _set_boolean_preference("roster.empty", PREF_ROSTER_EMPTY); _set_boolean_preference("roster.wrap", PREF_ROSTER_WRAP); - _set_string_preference("roster.by", PREF_ROSTER_BY); - _set_string_preference("roster.order", PREF_ROSTER_ORDER); - _set_string_preference("roster.unread", PREF_ROSTER_UNREAD); _set_boolean_preference("roster.count", PREF_ROSTER_COUNT); _set_boolean_preference("roster.priority", PREF_ROSTER_PRIORITY); _set_boolean_preference("roster.contacts", PREF_ROSTER_CONTACTS); _set_boolean_preference("roster.rooms", PREF_ROSTER_ROOMS); + _set_boolean_preference("privileges", PREF_MUC_PRIVILEGES); + _set_boolean_preference("presence", PREF_PRESENCE); + _set_boolean_preference("intype", PREF_INTYPE); + _set_boolean_preference("enc.warn", PREF_ENC_WARN); + _set_boolean_preference("tls.show", PREF_TLS_SHOW); + + _set_string_preference("time.console", PREF_TIME_CONSOLE); + _set_string_preference("time.chat", PREF_TIME_CHAT); + _set_string_preference("time.muc", PREF_TIME_MUC); + _set_string_preference("time.mucconfig", PREF_TIME_MUCCONFIG); + _set_string_preference("time.private", PREF_TIME_PRIVATE); + _set_string_preference("time.xmlconsole", PREF_TIME_XMLCONSOLE); + _set_string_preference("time.statusbar", PREF_TIME_STATUSBAR); + _set_string_preference("time.lastactivity", PREF_TIME_LASTACTIVITY); + _set_string_preference("statuses.console", PREF_STATUSES_CONSOLE); + _set_string_preference("statuses.chat", PREF_STATUSES_CHAT); + _set_string_preference("statuses.muc", PREF_STATUSES_MUC); + _set_string_preference("console.muc", PREF_CONSOLE_MUC); + _set_string_preference("roster.by", PREF_ROSTER_BY); + _set_string_preference("roster.order", PREF_ROSTER_ORDER); + _set_string_preference("roster.unread", PREF_ROSTER_UNREAD); _set_string_preference("roster.rooms.order", PREF_ROSTER_ROOMS_ORDER); _set_string_preference("roster.rooms.unread", PREF_ROSTER_ROOMS_UNREAD); _set_string_preference("roster.rooms.pos", PREF_ROSTER_ROOMS_POS); + _set_string_preference("roster.private", PREF_ROSTER_PRIVATE); + + if (g_key_file_has_key(theme, "ui", "occupants.size", NULL)) { + gint occupants_size = g_key_file_get_integer(theme, "ui", "occupants.size", NULL); + prefs_set_occupants_size(occupants_size); + } + 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); } + if (g_key_file_has_key(theme, "ui", "roster.header.char", NULL)) { gchar *ch = g_key_file_get_string(theme, "ui", "roster.header.char", NULL); if (ch && strlen(ch) > 0) { @@ -427,6 +434,7 @@ _load_preferences(void) } else { prefs_clear_roster_header_char(); } + if (g_key_file_has_key(theme, "ui", "roster.contact.char", NULL)) { gchar *ch = g_key_file_get_string(theme, "ui", "roster.contact.char", NULL); if (ch && strlen(ch) > 0) { @@ -436,6 +444,7 @@ _load_preferences(void) } else { prefs_clear_roster_contact_char(); } + if (g_key_file_has_key(theme, "ui", "roster.resource.char", NULL)) { gchar *ch = g_key_file_get_string(theme, "ui", "roster.resource.char", NULL); if (ch && strlen(ch) > 0) { @@ -445,27 +454,42 @@ _load_preferences(void) } else { prefs_clear_roster_resource_char(); } + + if (g_key_file_has_key(theme, "ui", "roster.rooms.char", NULL)) { + gchar *ch = g_key_file_get_string(theme, "ui", "roster.rooms.char", NULL); + if (ch && strlen(ch) > 0) { + prefs_set_roster_room_char(ch[0]); + g_free(ch); + } + } else { + prefs_clear_roster_room_char(); + } + + if (g_key_file_has_key(theme, "ui", "roster.private.char", NULL)) { + gchar *ch = g_key_file_get_string(theme, "ui", "roster.private.char", NULL); + if (ch && strlen(ch) > 0) { + prefs_set_roster_private_char(ch[0]); + g_free(ch); + } + } else { + prefs_clear_roster_private_char(); + } + if (g_key_file_has_key(theme, "ui", "roster.contact.indent", NULL)) { gint contact_indent = g_key_file_get_integer(theme, "ui", "roster.contact.indent", NULL); prefs_set_roster_contact_indent(contact_indent); } + if (g_key_file_has_key(theme, "ui", "roster.resource.indent", NULL)) { gint resource_indent = g_key_file_get_integer(theme, "ui", "roster.resource.indent", NULL); prefs_set_roster_resource_indent(resource_indent); } + if (g_key_file_has_key(theme, "ui", "roster.presence.indent", NULL)) { gint presence_indent = g_key_file_get_integer(theme, "ui", "roster.presence.indent", NULL); prefs_set_roster_presence_indent(presence_indent); } - _set_boolean_preference("privileges", PREF_MUC_PRIVILEGES); - - _set_boolean_preference("presence", PREF_PRESENCE); - _set_boolean_preference("intype", PREF_INTYPE); - - _set_boolean_preference("enc.warn", PREF_ENC_WARN); - _set_boolean_preference("tls.show", PREF_TLS_SHOW); - if (g_key_file_has_key(theme, "ui", "otr.char", NULL)) { gchar *ch = g_key_file_get_string(theme, "ui", "otr.char", NULL); if (ch && strlen(ch) > 0) { @@ -473,6 +497,7 @@ _load_preferences(void) g_free(ch); } } + if (g_key_file_has_key(theme, "ui", "pgp.char", NULL)) { gchar *ch = g_key_file_get_string(theme, "ui", "pgp.char", NULL); if (ch && strlen(ch) > 0) { @@ -480,8 +505,6 @@ _load_preferences(void) g_free(ch); } } - - _set_string_preference("console.muc", PREF_CONSOLE_MUC); } static gchar* diff --git a/src/event/server_events.c b/src/event/server_events.c index 71ac7f37..3519e983 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -333,6 +333,7 @@ sv_ev_incoming_private_message(const char *const fulljid, char *message) plugins_post_priv_message_display(fulljid, plugin_message); free(plugin_message); + rosterwin_roster(); } void diff --git a/src/ui/console.c b/src/ui/console.c index 677b082e..b291a07f 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1277,6 +1277,24 @@ cons_roster_setting(void) else cons_show("Roster contact char (/roster) : none"); + char resource_ch = prefs_get_roster_resource_char(); + if (resource_ch) + cons_show("Roster resource char (/roster) : %c", resource_ch); + else + cons_show("Roster resource char (/roster) : none"); + + char room_ch = prefs_get_roster_room_char(); + if (room_ch) + cons_show("Roster room char (/roster) : %c", room_ch); + else + cons_show("Roster room char (/roster) : none"); + + char private_ch = prefs_get_roster_private_char(); + if (private_ch) + cons_show("Roster private char (/roster) : %c", private_ch); + else + cons_show("Roster private char (/roster) : none"); + gint contact_indent = prefs_get_roster_contact_indent(); cons_show("Roster contact indent (/roster) : %d", contact_indent); @@ -1285,12 +1303,6 @@ cons_roster_setting(void) else cons_show("Roster resource (/roster) : hide"); - char resource_ch = prefs_get_roster_resource_char(); - if (resource_ch) - cons_show("Roster resource char (/roster) : %c", resource_ch); - else - cons_show("Roster resource char (/roster) : none"); - gint resource_indent = prefs_get_roster_resource_indent(); cons_show("Roster resource indent (/roster) : %d", resource_indent); @@ -1354,6 +1366,15 @@ cons_roster_setting(void) else cons_show("Roster rooms (/roster) : hide"); + char *priv = prefs_get_string(PREF_ROSTER_PRIVATE); + if (g_strcmp0(priv, "room") == 0) { + cons_show("Roster private (/roster) : room"); + } else if (g_strcmp0(priv, "group") == 0) { + cons_show("Roster private (/roster) : group"); + } else { + cons_show("Roster private (/roster) : OFF"); + } + char *rooms_pos = prefs_get_string(PREF_ROSTER_ROOMS_POS); cons_show("Roster rooms position (/roster) : %s", rooms_pos); prefs_free_string(rooms_pos); diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index 86472d48..d7c8875b 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -494,7 +494,7 @@ _rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin) indent--; } } - char ch = prefs_get_roster_contact_char(); + char ch = prefs_get_roster_room_char(); if (ch) { g_string_append_printf(msg, "%c", ch); } @@ -519,6 +519,75 @@ _rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin) } else { wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM)); } + + char *privpref = prefs_get_string(PREF_ROSTER_PRIVATE); + if (g_strcmp0(privpref, "room") == 0) { + GList *privs = wins_get_private_chats(mucwin->roomjid); + GList *curr = privs; + while (curr) { + ProfPrivateWin *privwin = curr->data; + win_sub_newline_lazy(layout->subwin); + + GString *privmsg = g_string_new(" "); + indent = prefs_get_roster_contact_indent(); + current_indent = 0; + if (indent > 0) { + current_indent += indent; + while (indent > 0) { + g_string_append(privmsg, " "); + indent--; + } + } + + // TODO add preference + indent = prefs_get_roster_resource_indent(); + if (indent > 0) { + current_indent += indent; + while (indent > 0) { + g_string_append(privmsg, " "); + indent--; + } + } + + unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD); + if ((g_strcmp0(unreadpos, "before") == 0) && privwin->unread > 0) { + g_string_append_printf(privmsg, "(%d) ", privwin->unread); + } + + ch = prefs_get_roster_private_char(); + if (ch) { + g_string_append_printf(privmsg, "%c", ch); + } + + g_string_append(privmsg, privwin->fulljid + strlen(mucwin->roomjid) + 1); + + if ((g_strcmp0(unreadpos, "after") == 0) && privwin->unread > 0) { + g_string_append_printf(privmsg, " (%d)", privwin->unread); + } + prefs_free_string(unreadpos); + + if (privwin->unread > 0) { + wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD)); + } else { + wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM)); + } + + win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent); + + if (privwin->unread > 0) { + wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD)); + } else { + wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM)); + } + + g_string_free(privmsg, TRUE); + curr = g_list_next(curr); + } + + g_list_free(privs); + } + + prefs_free_string(privpref); } static int @@ -539,6 +608,82 @@ _compare_rooms_unread(ProfMucWin *a, ProfMucWin *b) } } +void +_rosterwin_private_chats(ProfLayoutSplit *layout) +{ + GList *privs = wins_get_private_chats(NULL); + if (privs || prefs_get_boolean(PREF_ROSTER_EMPTY)) { + win_sub_newline_lazy(layout->subwin); + wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); + GString *title_str = g_string_new(" "); + char ch = prefs_get_roster_header_char(); + if (ch) { + g_string_append_printf(title_str, "%c", ch); + } + g_string_append(title_str, "Private chats"); + if (prefs_get_boolean(PREF_ROSTER_COUNT)) { + g_string_append_printf(title_str, " (%d)", g_list_length(privs)); + } + gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP); + win_sub_print(layout->subwin, title_str->str, FALSE, wrap, 1); + g_string_free(title_str, TRUE); + wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER)); + + GList *curr = privs; + while (curr) { + ProfPrivateWin *privwin = curr->data; + win_sub_newline_lazy(layout->subwin); + + GString *privmsg = g_string_new(" "); + int indent = prefs_get_roster_contact_indent(); + int current_indent = 0; + if (indent > 0) { + current_indent += indent; + while (indent > 0) { + g_string_append(privmsg, " "); + indent--; + } + } + + char *unreadpos = prefs_get_string(PREF_ROSTER_ROOMS_UNREAD); + if ((g_strcmp0(unreadpos, "before") == 0) && privwin->unread > 0) { + g_string_append_printf(privmsg, "(%d) ", privwin->unread); + } + + ch = prefs_get_roster_private_char(); + if (ch) { + g_string_append_printf(privmsg, "%c", ch); + } + + g_string_append(privmsg, privwin->fulljid); + + if ((g_strcmp0(unreadpos, "after") == 0) && privwin->unread > 0) { + g_string_append_printf(privmsg, " (%d)", privwin->unread); + } + prefs_free_string(unreadpos); + + if (privwin->unread > 0) { + wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD)); + } else { + wattron(layout->subwin, theme_attrs(THEME_ROSTER_ROOM)); + } + + win_sub_print(layout->subwin, privmsg->str, FALSE, wrap, current_indent); + + if (privwin->unread > 0) { + wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM_UNREAD)); + } else { + wattroff(layout->subwin, theme_attrs(THEME_ROSTER_ROOM)); + } + + g_string_free(privmsg, TRUE); + curr = g_list_next(curr); + } + + g_list_free(privs); + } +} + void _rosterwin_rooms(ProfLayoutSplit *layout, gboolean newline) { @@ -560,7 +705,7 @@ _rosterwin_rooms(ProfLayoutSplit *layout, gboolean newline) } g_list_free(rooms); - // if this group has contacts, or if we want to show empty groups + // if there are active rooms, or if we want to show empty groups if (rooms_sorted || prefs_get_boolean(PREF_ROSTER_EMPTY)) { if (newline) { win_sub_newline_lazy(layout->subwin); @@ -588,6 +733,12 @@ _rosterwin_rooms(ProfLayoutSplit *layout, gboolean newline) } g_list_free(rooms_sorted); + + char *privpref = prefs_get_string(PREF_ROSTER_PRIVATE); + if (g_strcmp0(privpref, "group") == 0) { + _rosterwin_private_chats(layout); + } + prefs_free_string(privpref); } void diff --git a/src/window_list.c b/src/window_list.c index 4f96374d..72a4e817 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -193,6 +193,31 @@ wins_get_plugin(const char *const tag) return NULL; } +GList* +wins_get_private_chats(const char *const roomjid) +{ + GList *result = NULL; + GString *prefix = g_string_new(roomjid); + g_string_append(prefix, "/"); + GList *values = g_hash_table_get_values(windows); + GList *curr = values; + + while (curr) { + ProfWin *window = curr->data; + if (window->type == WIN_PRIVATE) { + ProfPrivateWin *privatewin = (ProfPrivateWin*)window; + if (roomjid == NULL || g_str_has_prefix(privatewin->fulljid, prefix->str)) { + result = g_list_append(result, privatewin); + } + } + curr = g_list_next(curr); + } + + g_list_free(values); + g_string_free(prefix, TRUE); + return result; +} + ProfWin* wins_get_current(void) { diff --git a/src/window_list.h b/src/window_list.h index 4cd574af..10493fd0 100644 --- a/src/window_list.h +++ b/src/window_list.h @@ -47,6 +47,7 @@ ProfWin* wins_new_private(const char *const fulljid); ProfWin* wins_new_plugin(const char *const tag); gboolean wins_chat_exists(const char *const barejid); +GList* wins_get_private_chats(const char *const roomjid); ProfWin* wins_get_console(void); ProfChatWin* wins_get_chat(const char *const barejid); diff --git a/theme_template b/theme_template index 2ae5d9c1..83716865 100644 --- a/theme_template +++ b/theme_template @@ -116,6 +116,9 @@ roster.rooms= roster.rooms.order= roster.rooms.unread= roster.rooms.pos= +roster.rooms.char= +roster.private= +roster.private.char= occupants= occupants.size= occupants.jid= diff --git a/themes/boothj5 b/themes/boothj5 index 618f7a43..2a627787 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -96,7 +96,7 @@ roster.offline=true roster.empty=false roster.by=group roster.order=presence -roster.unread=before +roster.unread=after roster.count=true roster.priority=false roster.size=25 @@ -113,8 +113,10 @@ roster.status=true roster.contacts=true roster.rooms=true roster.rooms.order=name -roster.rooms.unread=before +roster.rooms.unread=after roster.rooms.pos=last +roster.rooms.char=# +roster.private=room occupants=true occupants.size=15 occupants.jid=false diff --git a/themes/complex b/themes/complex index a63ab8ea..2f42bc9e 100644 --- a/themes/complex +++ b/themes/complex @@ -43,6 +43,9 @@ roster.rooms=true roster.rooms.order=unread roster.rooms.unread=after roster.rooms.pos=last +roster.rooms.char=# +roster.private=room +roster.private.char=/ privileges=true presence=true intype=true