From 73aaa44d128cd6c0a7973bed51d1f84b79c97ce7 Mon Sep 17 00:00:00 2001 From: jfreegman Date: Sun, 28 Oct 2018 16:18:17 -0400 Subject: [PATCH] Add config option to set data file auto-save frequency --- cfg/targets/doc.mk | 4 ++-- doc/toxic.conf.5 | 11 ++++++++--- doc/toxic.conf.5.asc | 5 ++++- misc/toxic.conf.example | 3 +++ src/execute.c | 2 +- src/settings.c | 4 ++++ src/settings.h | 1 + src/toxic.c | 3 +-- 8 files changed, 24 insertions(+), 9 deletions(-) diff --git a/cfg/targets/doc.mk b/cfg/targets/doc.mk index 53efb92..34afe57 100644 --- a/cfg/targets/doc.mk +++ b/cfg/targets/doc.mk @@ -1,10 +1,10 @@ # Doc target doc: $(MANFILES:%=$(DOC_DIR)/%) - + $(DOC_DIR)/%: $(DOC_DIR)/%.asc @echo " MAN $(@F)" @a2x -f manpage -a revdate=$(shell git log -1 --date=short --format="%ad" $<) \ -a manmanual="Toxic Manual" -a mansource=toxic \ -a manversion=__VERSION__ -a datadir=__DATADIR__ $< - + .PHONY: doc diff --git a/doc/toxic.conf.5 b/doc/toxic.conf.5 index 85f338c..565d139 100644 --- a/doc/toxic.conf.5 +++ b/doc/toxic.conf.5 @@ -2,12 +2,12 @@ .\" Title: toxic.conf .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.79.1 -.\" Date: 2016-09-20 +.\" Date: 2018-10-27 .\" Manual: Toxic Manual .\" Source: toxic __VERSION__ .\" Language: English .\" -.TH "TOXIC\&.CONF" "5" "2016\-09\-20" "toxic __VERSION__" "Toxic Manual" +.TH "TOXIC\&.CONF" "5" "2018\-10\-27" "toxic __VERSION__" "Toxic Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -120,7 +120,12 @@ Enable friend connection change notifications\&. true or false .PP \fBnodelist_update_freq\fR .RS 4 -How often in days to update the DHT nodes list\&. (0 to disable updates) +How often in days to update the DHT nodes list\&. (integer; 0 to disable) +.RE +.PP +\fBautosave_freq\fR +.RS 4 +How often in seconds to auto\-save the Tox data file\&. (integer; 0 to disable) .RE .PP \fBhistory_size\fR diff --git a/doc/toxic.conf.5.asc b/doc/toxic.conf.5.asc index f11e705..47fc6c5 100644 --- a/doc/toxic.conf.5.asc +++ b/doc/toxic.conf.5.asc @@ -76,7 +76,10 @@ OPTIONS Enable friend connection change notifications. true or false *nodelist_update_freq*;; - How often in days to update the DHT nodes list. (0 to disable updates) + How often in days to update the DHT nodes list. (integer; 0 to disable) + + *autosave_freq*;; + How often in seconds to auto-save the Tox data file. (integer; 0 to disable) *history_size*;; Maximum lines for chat window history. Integer value. (for example: 700) diff --git a/misc/toxic.conf.example b/misc/toxic.conf.example index cffe2c0..b45ee3a 100644 --- a/misc/toxic.conf.example +++ b/misc/toxic.conf.example @@ -47,6 +47,9 @@ ui = { // How often in days to update the DHT nodes list. (0 to disable updates) nodeslist_update_freq=7; + // How often in seconds to auto-save the Tox data file. (0 to disable periodic auto-saves) + autosave_freq=600; + // maximum lines for chat window history history_size=700; diff --git a/src/execute.c b/src/execute.c index f70d328..63989d3 100644 --- a/src/execute.c +++ b/src/execute.c @@ -122,8 +122,8 @@ static const char special_commands[SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = { #ifdef PYTHON "/run", #endif /* PYTHON */ - "/title", "/sendfile", + "/title", }; /* Returns true if input command is in the special_commands array. */ diff --git a/src/settings.c b/src/settings.c index b2e7336..494a8b7 100644 --- a/src/settings.c +++ b/src/settings.c @@ -63,6 +63,7 @@ static struct ui_strings { const char *show_welcome_msg; const char *show_connection_msg; const char *nodeslist_update_freq; + const char *autosave_freq; const char *line_join; const char *line_quit; @@ -90,6 +91,7 @@ static struct ui_strings { "show_welcome_msg", "show_connection_msg", "nodeslist_update_freq", + "autosave_freq", "line_join", "line_quit", "line_alert", @@ -117,6 +119,7 @@ static void ui_defaults(struct user_settings *settings) settings->show_welcome_msg = SHOW_WELCOME_MSG_ON; settings->show_connection_msg = SHOW_CONNECTION_MSG_ON; settings->nodeslist_update_freq = 7; + settings->autosave_freq = 600; snprintf(settings->line_join, LINE_HINT_MAX + 1, "%s", LINE_JOIN); snprintf(settings->line_quit, LINE_HINT_MAX + 1, "%s", LINE_QUIT); @@ -370,6 +373,7 @@ int settings_load(struct user_settings *s, const char *patharg) config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size); config_setting_lookup_int(setting, ui_strings.nodeslist_update_freq, &s->nodeslist_update_freq); + config_setting_lookup_int(setting, ui_strings.autosave_freq, &s->autosave_freq); if (config_setting_lookup_string(setting, ui_strings.line_join, &str)) { snprintf(s->line_join, sizeof(s->line_join), "%s", str); diff --git a/src/settings.h b/src/settings.h index 4d65e4d..364bb05 100644 --- a/src/settings.h +++ b/src/settings.h @@ -54,6 +54,7 @@ struct user_settings { int show_welcome_msg; /* boolean */ int show_connection_msg; /* boolean */ int nodeslist_update_freq; /* int (<= 0 to disable updates) */ + int autosave_freq; /* int (<= 0 to disable autosave) */ char line_join[LINE_HINT_MAX + 1]; char line_quit[LINE_HINT_MAX + 1]; diff --git a/src/toxic.c b/src/toxic.c index 7fa68b1..e68d94b 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -94,7 +94,6 @@ ToxWindow *prompt = NULL; #define DATANAME "toxic_profile.tox" #define BLOCKNAME "toxic_blocklist" -#define AUTOSAVE_FREQ 600 #define MIN_PASSWORD_LEN 6 #define MAX_PASSWORD_LEN 64 @@ -1364,7 +1363,7 @@ int main(int argc, char **argv) time_t cur_time = get_unix_time(); - if (timed_out(last_save, AUTOSAVE_FREQ)) { + if (user_settings->autosave_freq > 0 && timed_out(last_save, user_settings->autosave_freq)) { pthread_mutex_lock(&Winthread.lock); if (store_data(m, DATA_FILE) != 0) {