timeshift: add 'use only RAM' option

This commit is contained in:
Jaroslav Kysela 2015-01-19 21:19:17 +01:00
parent bc9874cc26
commit aca5c6b976
5 changed files with 45 additions and 16 deletions

View file

@ -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");
}

View file

@ -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
{

View file

@ -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)))

View file

@ -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);

View file

@ -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());
}
});
});