aboutsummaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-07-05 17:02:11 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-07-05 17:02:11 +0200
commit550f8baa1a4f31abdde03a21fd35ce415d959986 (patch)
tree3462747b5c5492b3e464c1e2fe824b8afc1bd6b1 /degesch.c
parent8c2c0472cb0537ba74023db73ca11a541422f409 (diff)
downloadxK-550f8baa1a4f31abdde03a21fd35ce415d959986.tar.gz
xK-550f8baa1a4f31abdde03a21fd35ce415d959986.tar.xz
xK-550f8baa1a4f31abdde03a21fd35ce415d959986.zip
degesch: add "on_change" for behaviour.logging
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/degesch.c b/degesch.c
index 5bdb58d..1e59f50 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1297,6 +1297,7 @@ struct app_context
char *attrs[ATTR_COUNT]; ///< Terminal attributes
bool isolate_buffers; ///< Isolate global/server buffers
bool beep_on_highlight; ///< Beep on highlight
+ bool logging; ///< Logging to file enabled
struct str_map servers; ///< Our servers
@@ -1418,6 +1419,7 @@ static bool irc_is_this_us (struct server *s, const char *prefix);
// --- Configuration -----------------------------------------------------------
static void on_config_attribute_change (struct config_item_ *item);
+static void on_config_logging_change (struct config_item_ *item);
#define TRIVIAL_BOOLEAN_ON_CHANGE(name) \
static void \
@@ -1578,7 +1580,8 @@ static struct config_schema g_config_behaviour[] =
{ .name = "logging",
.comment = "Log buffer contents to file",
.type = CONFIG_ITEM_BOOLEAN,
- .default_ = "off" },
+ .default_ = "off",
+ .on_change = on_config_logging_change },
{}
};
@@ -2707,7 +2710,7 @@ make_log_filename (const char *filename, struct str *output)
static void
buffer_open_log_file (struct app_context *ctx, struct buffer *buffer)
{
- if (!get_config_boolean (ctx->config.root, "behaviour.logging"))
+ if (!ctx->logging || buffer->log_file)
return;
struct str path;
@@ -2728,6 +2731,29 @@ buffer_open_log_file (struct app_context *ctx, struct buffer *buffer)
str_free (&path);
}
+static void
+buffer_close_log_file (struct buffer *buffer)
+{
+ if (buffer->log_file)
+ (void) fclose (buffer->log_file);
+ buffer->log_file = NULL;
+}
+
+static void
+on_config_logging_change (struct config_item_ *item)
+{
+ struct app_context *ctx = item->user_data;
+ ctx->logging = item->value.boolean;
+
+ for (struct buffer *buffer = ctx->buffers; buffer; buffer = buffer->next)
+ if (ctx->logging)
+ buffer_open_log_file (ctx, buffer);
+ else
+ buffer_close_log_file (buffer);
+}
+
+// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
static struct buffer *
buffer_by_name (struct app_context *ctx, const char *name)
{
@@ -2875,11 +2901,7 @@ buffer_rename (struct app_context *ctx,
str_map_set (&ctx->buffers_by_name, buffer->name, NULL);
str_map_set (&ctx->buffers_by_name, new_name, buffer);
- if (buffer->log_file)
- {
- (void) fclose (buffer->log_file);
- buffer->log_file = NULL;
- }
+ buffer_close_log_file (buffer);
buffer_open_log_file (ctx, buffer);
free (buffer->name);