degesch: add some trivial "on_change" callbacks

This commit is contained in:
Přemysl Eric Janouch 2015-07-05 16:28:27 +02:00
parent 6de7ae9583
commit 8c2c0472cb

View File

@ -1288,14 +1288,15 @@ server_destroy (void *self)
struct app_context
{
bool no_colors; ///< Disable attribute printing
char *attrs_defaults[ATTR_COUNT]; ///< Default terminal attributes
// Configuration:
struct config config; ///< Program configuration
char *attrs[ATTR_COUNT]; ///< Terminal attributes
bool no_colors; ///< Colour output mode
bool isolate_buffers; ///< Isolate global/server buffers
bool beep_on_highlight; ///< Beep on highlight
struct str_map servers; ///< Our servers
@ -1416,9 +1417,19 @@ static bool irc_is_this_us (struct server *s, const char *prefix);
// --- Configuration -----------------------------------------------------------
// TODO: "on_change" callbacks for everything
static void on_config_attribute_change (struct config_item_ *item);
#define TRIVIAL_BOOLEAN_ON_CHANGE(name) \
static void \
on_config_ ## name ## _change (struct config_item_ *item) \
{ \
struct app_context *ctx = item->user_data; \
ctx->name = item->value.boolean; \
}
TRIVIAL_BOOLEAN_ON_CHANGE (isolate_buffers)
TRIVIAL_BOOLEAN_ON_CHANGE (beep_on_highlight)
static bool
config_validate_nonjunk_string
(const struct config_item_ *item, struct error **e)
@ -1557,11 +1568,13 @@ static struct config_schema g_config_behaviour[] =
{ .name = "isolate_buffers",
.comment = "Don't leak messages from the server and global buffers",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "off" },
.default_ = "off",
.on_change = on_config_isolate_buffers_change },
{ .name = "beep_on_highlight",
.comment = "Beep when highlighted or on a new invisible PM",
.type = CONFIG_ITEM_BOOLEAN,
.default_ = "on" },
.default_ = "on",
.on_change = on_config_beep_on_highlight_change },
{ .name = "logging",
.comment = "Log buffer contents to file",
.type = CONFIG_ITEM_BOOLEAN,
@ -2593,7 +2606,7 @@ log_formatter (struct app_context *ctx,
if (buffer->log_file)
buffer_line_write_to_log (ctx, line, buffer->log_file);
if (get_config_boolean (ctx->config.root, "behaviour.beep_on_highlight"))
if (ctx->beep_on_highlight)
if ((flags & BUFFER_LINE_HIGHLIGHT)
|| (buffer->type == BUFFER_PM && buffer != ctx->current_buffer))
input_ding (&ctx->input);
@ -8748,10 +8761,6 @@ main (int argc, char *argv[])
init_poller_events (&ctx);
load_configuration (&ctx);
// TODO: this won't be needed after adding an "on_change" callback
ctx.isolate_buffers =
get_config_boolean (ctx.config.root, "behaviour.isolate_buffers");
// At this moment we can safely call any "on_change" callbacks
config_schema_call_changed (ctx.config.root);