diff options
author | Marius Halden <marius.h@lden.org> | 2016-08-02 13:29:42 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2016-08-02 13:29:42 +0200 |
commit | 53aa23d5867ef008cfcf82dccf81146630be27f8 (patch) | |
tree | 1ee116a7c76ed2bd7f8b7b5f0573dd0bbb9660ad /storage.c | |
parent | a18f767c1f71f9884ff7f23752db025748713d9e (diff) |
Add autosave after 30 sec
Diffstat (limited to 'storage.c')
-rw-r--r-- | storage.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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; |