aboutsummaryrefslogtreecommitdiffstats
path: root/storage.c
diff options
context:
space:
mode:
Diffstat (limited to 'storage.c')
-rw-r--r--storage.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/storage.c b/storage.c
index 9e0f8345..9e16c9e2 100644
--- a/storage.c
+++ b/storage.c
@@ -64,6 +64,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;