From 53aa23d5867ef008cfcf82dccf81146630be27f8 Mon Sep 17 00:00:00 2001 From: Marius Halden Date: Tue, 2 Aug 2016 13:29:42 +0200 Subject: Add autosave after 30 sec --- storage.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'storage.c') diff --git a/storage.c b/storage.c index 7b684ac7..c60cd224 100644 --- a/storage.c +++ b/storage.c @@ -60,6 +60,40 @@ static storage_t *storage_init_single(const char *name) return st; } +static gboolean storage_auto_save(gpointer data, gint fd, b_input_condition cond) +{ + irc_t *irc = data; + if (!(irc->status & USTATUS_IDENTIFIED) || irc->save_source_id == -1) { + return FALSE; + } + + //imcb_log(irc->b->accounts->ic, "Saving config"); /* XXX: debug */ + + /*if (getenv("BITLBEE_DEBUG")) { + fprintf(stderr, "Autosave\n"); + }*/ + + if (storage_save(irc, NULL, 1) != STORAGE_OK) { + imcb_error(irc->b->accounts->ic, "Could not autosave."); + } + + b_event_remove(irc->save_source_id); + irc->save_source_id = -1; + + return FALSE; +} + +void storage_setup_auto_save(irc_t *irc) +{ + if (!set_getbool(&irc->b->set, "auto_save")) { + return; + } + + if ((irc->status & USTATUS_IDENTIFIED) && irc->save_source_id == -1) { + irc->save_source_id = b_timeout_add(30000, storage_auto_save, irc); + } +} + GList *storage_init(const char *primary, char **migrate) { GList *ret = NULL; -- cgit v1.2.3