diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-07-26 22:21:08 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-07-26 22:44:34 +0200 |
commit | 74c975993247c37ff6e2a576bf63c996a9eb625a (patch) | |
tree | f6b117b32203b81aaa9dfa0a812eb4ddadbb0b7e | |
parent | e631803387ca3a442284a627af6640a0248352ec (diff) | |
download | xK-74c975993247c37ff6e2a576bf63c996a9eb625a.tar.gz xK-74c975993247c37ff6e2a576bf63c996a9eb625a.tar.xz xK-74c975993247c37ff6e2a576bf63c996a9eb625a.zip |
degesch: make showing all prefixes optional
-rw-r--r-- | degesch.c | 89 |
1 files changed, 66 insertions, 23 deletions
@@ -1323,6 +1323,7 @@ struct app_context bool isolate_buffers; ///< Isolate global/server buffers bool beep_on_highlight; ///< Beep on highlight bool logging; ///< Logging to file enabled + bool show_all_prefixes; ///< Show all prefixes before nicks struct str_map servers; ///< Our servers @@ -1444,6 +1445,14 @@ on_config_debug_mode_change (struct config_item_ *item) g_debug_mode = item->value.boolean; } +static void +on_config_show_all_prefixes_change (struct config_item_ *item) +{ + struct app_context *ctx = item->user_data; + ctx->show_all_prefixes = item->value.boolean; + refresh_prompt (ctx); +} + static void on_config_attribute_change (struct config_item_ *item); static void on_config_logging_change (struct config_item_ *item); @@ -1621,6 +1630,11 @@ static struct config_schema g_config_behaviour[] = .type = CONFIG_ITEM_BOOLEAN, .default_ = "on", .on_change = on_config_beep_on_highlight_change }, + { .name = "show_all_prefixes", + .comment = "Show all prefixes in front of nicknames", + .type = CONFIG_ITEM_BOOLEAN, + .default_ = "off", + .on_change = on_config_show_all_prefixes_change }, { .name = "logging", .comment = "Log buffer contents to file", .type = CONFIG_ITEM_BOOLEAN, @@ -3257,6 +3271,16 @@ irc_get_or_make_user_buffer (struct server *s, const char *nickname) return buffer; } +static void +irc_get_channel_user_prefix (struct server *s, + struct channel_user *channel_user, struct str *output) +{ + if (s->ctx->show_all_prefixes) + str_append (output, channel_user->prefixes.str); + else if (channel_user->prefixes.len) + str_append_c (output, channel_user->prefixes.str[0]); +} + // Note that this eats the user reference static void irc_channel_link_user (struct channel *channel, struct user *user, @@ -4572,6 +4596,23 @@ make_chanmode_postfix (struct channel *channel, struct str *modes) } static void +make_server_postfix_registered (struct buffer *buffer, struct str *output) +{ + struct server *s = buffer->server; + if (buffer->type == BUFFER_CHANNEL) + { + struct server *s = buffer->server; + struct channel_user *channel_user = + irc_channel_get_user (buffer->channel, s->irc_user); + if (channel_user) + irc_get_channel_user_prefix (s, channel_user, output); + } + str_append (output, s->irc_user->nickname); + if (s->irc_user_mode.len) + str_append_printf (output, "(%s)", s->irc_user_mode.str); +} + +static void make_server_postfix (struct buffer *buffer, struct str *output) { struct server *s = buffer->server; @@ -4581,18 +4622,7 @@ make_server_postfix (struct buffer *buffer, struct str *output) else if (s->state != IRC_REGISTERED) str_append (output, "(unregistered)"); else - { - if (buffer->type == BUFFER_CHANNEL) - { - struct channel_user *channel_user = - irc_channel_get_user (buffer->channel, s->irc_user); - if (channel_user) - str_append (output, channel_user->prefixes.str); - } - str_append (output, s->irc_user->nickname); - if (s->irc_user_mode.len) - str_append_printf (output, "(%s)", s->irc_user_mode.str); - } + make_server_postfix_registered (buffer, output); } static void make_prompt (struct app_context *ctx, struct str *output) @@ -4724,18 +4754,20 @@ irc_is_highlight (struct server *s, const char *message) return result; } -static const char * +static char * irc_get_privmsg_prefix (struct server *s, struct user *user, const char *target) { + struct str prefix; + str_init (&prefix); if (user && irc_is_channel (s, target)) { struct channel *channel; struct channel_user *channel_user; if ((channel = str_map_find (&s->irc_channels, target)) && (channel_user = irc_channel_get_user (channel, user))) - return channel_user->prefixes.str; + irc_get_channel_user_prefix (s, channel_user, &prefix); } - return ""; + return str_steal (&prefix); } // --- Mode processor ---------------------------------------------------------- @@ -5770,6 +5802,24 @@ irc_sync_channel_user (struct server *s, struct channel *channel, } } +static char * +make_channel_users_list (struct server *s, struct channel *channel) +{ + struct str_vector v; + str_vector_init (&v); + LIST_FOR_EACH (struct channel_user, iter, channel->users) + { + struct str item; + str_init (&item); + irc_get_channel_user_prefix (s, iter, &item); + str_append (&item, iter->user->nickname); + str_vector_add_owned (&v, str_steal (&item)); + } + char *result = join_str_vector (&v, ' '); + str_vector_free (&v); + return result; +} + static void irc_process_names (struct server *s, struct channel *channel) { @@ -5800,14 +5850,7 @@ irc_process_names (struct server *s, struct channel *channel) str_map_free (&present); str_vector_reset (&channel->names_buf); - struct str_vector v; - str_vector_init (&v); - LIST_FOR_EACH (struct channel_user, iter, channel->users) - str_vector_add_owned (&v, - xstrdup_printf ("%s%s", iter->prefixes.str, iter->user->nickname)); - char *all_users = join_str_vector (&v, ' '); - str_vector_free (&v); - + char *all_users = make_channel_users_list (s, channel); struct buffer *buffer = str_map_find (&s->irc_buffer_map, channel->name); if (buffer) { |