From aca5c6b9761e041255611c1e4085b59f969ba28b Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 19 Jan 2015 21:19:17 +0100 Subject: [PATCH] timeshift: add 'use only RAM' option --- src/timeshift.c | 16 +++++++++++++ src/timeshift.h | 1 + src/timeshift/timeshift_filemgr.c | 2 +- src/webui/extjs.c | 2 ++ src/webui/static/app/timeshift.js | 40 +++++++++++++++++++------------ 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/timeshift.c b/src/timeshift.c index 70de729e..b4acf3a1 100644 --- a/src/timeshift.c +++ b/src/timeshift.c @@ -43,6 +43,16 @@ int timeshift_unlimited_size; uint64_t timeshift_max_size; uint64_t timeshift_ram_size; uint64_t timeshift_ram_segment_size; +int timeshift_ram_only; + +/* + * Safe values for RAM configuration + */ +static void timeshift_fixup ( void ) +{ + if (timeshift_ram_only) + timeshift_max_size = timeshift_ram_size; +} /* * Intialise global file manager @@ -85,7 +95,10 @@ void timeshift_init ( void ) timeshift_ram_size = 1048576LL * u32; timeshift_ram_segment_size = timeshift_ram_size / 10; } + if (!htsmsg_get_u32(m, "ram_only", &u32)) + timeshift_ram_only = u32 ? 1 : 0; htsmsg_destroy(m); + timeshift_fixup(); } } @@ -106,6 +119,8 @@ void timeshift_save ( void ) { htsmsg_t *m; + timeshift_fixup(); + m = htsmsg_create_map(); htsmsg_add_u32(m, "enabled", timeshift_enabled); htsmsg_add_u32(m, "ondemand", timeshift_ondemand); @@ -116,6 +131,7 @@ void timeshift_save ( void ) htsmsg_add_u32(m, "unlimited_size", timeshift_unlimited_size); htsmsg_add_u32(m, "max_size", timeshift_max_size / 1048576); htsmsg_add_u32(m, "ram_size", timeshift_ram_size / 1048576); + htsmsg_add_u32(m, "ram_only", timeshift_ram_only); hts_settings_save(m, "timeshift/config"); } diff --git a/src/timeshift.h b/src/timeshift.h index 908fceae..f8f98d5c 100644 --- a/src/timeshift.h +++ b/src/timeshift.h @@ -30,6 +30,7 @@ extern uint64_t timeshift_total_size; extern uint64_t timeshift_ram_size; extern uint64_t timeshift_ram_segment_size; extern uint64_t timeshift_total_ram_size; +extern int timeshift_ram_only; typedef struct timeshift_status { diff --git a/src/timeshift/timeshift_filemgr.c b/src/timeshift/timeshift_filemgr.c index 33cf39b6..46d83d5c 100644 --- a/src/timeshift/timeshift_filemgr.c +++ b/src/timeshift/timeshift_filemgr.c @@ -302,7 +302,7 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create ) } } - if (!tsf_tmp) { + if (!tsf_tmp && !timeshift_ram_only) { /* Create directories */ if (!ts->path) { if (timeshift_filemgr_makedirs(ts->id, path, sizeof(path))) diff --git a/src/webui/extjs.c b/src/webui/extjs.c index 0053eaae..736cd386 100755 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -678,6 +678,7 @@ extjs_timeshift(http_connection_t *hc, const char *remain, void *opaque) htsmsg_add_u32(m, "timeshift_unlimited_size", timeshift_unlimited_size); htsmsg_add_u32(m, "timeshift_max_size", timeshift_max_size / 1048576); htsmsg_add_u32(m, "timeshift_ram_size", timeshift_ram_size / 1048576); + htsmsg_add_u32(m, "timeshift_ram_only", timeshift_ram_only); pthread_mutex_unlock(&global_lock); out = json_single_record(m, "config"); @@ -701,6 +702,7 @@ extjs_timeshift(http_connection_t *hc, const char *remain, void *opaque) timeshift_ram_size = atol(str) * 1048576LL; timeshift_ram_segment_size = timeshift_ram_size / 10; } + timeshift_ram_only = http_arg_get(&hc->hc_req_args, "timeshift_ram_only") ? 1 : 0; timeshift_save(); pthread_mutex_unlock(&global_lock); diff --git a/src/webui/static/app/timeshift.js b/src/webui/static/app/timeshift.js index ee7ada92..fd821ee3 100644 --- a/src/webui/static/app/timeshift.js +++ b/src/webui/static/app/timeshift.js @@ -5,17 +5,17 @@ tvheadend.timeshift = function(panel, index) { * ***************************************************************/ var confreader = new Ext.data.JsonReader( - { + { root: 'config' - }, - [ - 'timeshift_enabled', 'timeshift_ondemand', - 'timeshift_path', - 'timeshift_unlimited_period', 'timeshift_max_period', - 'timeshift_unlimited_size', 'timeshift_max_size', - 'timeshift_ram_size' - ] - ); + }, + [ + 'timeshift_enabled', 'timeshift_ondemand', + 'timeshift_path', + 'timeshift_unlimited_period', 'timeshift_max_period', + 'timeshift_unlimited_size', 'timeshift_max_size', + 'timeshift_ram_size', 'timeshift_ram_only' + ] + ); /* **************************************************************** * Fields @@ -64,7 +64,7 @@ tvheadend.timeshift = function(panel, index) { fieldLabel: 'Max. RAM Size (MB)', name: 'timeshift_ram_size', allowBlank: false, - width: 300 + width: 250 }); var timeshiftUnlSize = new Ext.form.Checkbox({ @@ -73,6 +73,12 @@ tvheadend.timeshift = function(panel, index) { width: 300 }); + var timeshiftRamOnly = new Ext.form.Checkbox({ + fieldLabel: 'Use only RAM', + name: 'timeshift_ram_only', + width: 300 + }); + /* **************************************************************** * Events * ***************************************************************/ @@ -82,7 +88,11 @@ tvheadend.timeshift = function(panel, index) { }); timeshiftUnlSize.on('check', function(e, c){ - timeshiftMaxSize.setDisabled(c); + timeshiftMaxSize.setDisabled(c || timeshiftMaxSize.getValue()); + }); + + timeshiftRamOnly.on('check', function(e, c){ + timeshiftMaxSize.setDisabled(c || timeshiftUnlSize.getValue()); }); /* **************************************************************** @@ -108,14 +118,14 @@ tvheadend.timeshift = function(panel, index) { width: 500, autoHeight: true, border: false, - items : [timeshiftMaxPeriod, timeshiftMaxSize, timeshiftRamSize] + items : [timeshiftMaxPeriod, timeshiftMaxSize, timeshiftRamSize] }); var timeshiftPanelB = new Ext.form.FieldSet({ width: 200, autoHeight: true, border: false, - items : [timeshiftUnlPeriod,timeshiftUnlSize] + items : [timeshiftUnlPeriod, timeshiftUnlSize, timeshiftRamOnly] }); var timeshiftPanel = new Ext.form.FieldSet({ @@ -166,7 +176,7 @@ tvheadend.timeshift = function(panel, index) { success: function() { confpanel.enable(); timeshiftMaxPeriod.setDisabled(timeshiftUnlPeriod.getValue()); - timeshiftMaxSize.setDisabled(timeshiftUnlSize.getValue()); + timeshiftMaxSize.setDisabled(timeshiftUnlSize.getValue() || timeshiftRamOnly.getValue()); } }); });