From: Jaroslav Kysela Date: Tue, 15 Sep 2015 16:12:28 +0000 (+0200) Subject: timeshift: move to the simple node system X-Git-Tag: v4.2.1~2121 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3bec33b7e5b0a8b3633a04cec553be0076eda1b;p=thirdparty%2Ftvheadend.git timeshift: move to the simple node system --- diff --git a/Makefile b/Makefile index 7430dec94..3cb1a9495 100644 --- a/Makefile +++ b/Makefile @@ -211,7 +211,8 @@ SRCS-2 = \ src/api/api_profile.c \ src/api/api_bouquet.c \ src/api/api_language.c \ - src/api/api_satip.c + src/api/api_satip.c \ + src/api/api_timeshift.c SRCS-2 += \ src/parsers/parsers.c \ diff --git a/src/api.c b/src/api.c index a1f71fda6..6db216a24 100644 --- a/src/api.c +++ b/src/api.c @@ -139,6 +139,7 @@ void api_init ( void ) api_profile_init(); api_language_init(); api_satip_server_init(); + api_timeshift_init(); } void api_done ( void ) diff --git a/src/api.h b/src/api.h index 73fbdc7b1..8557879c4 100644 --- a/src/api.h +++ b/src/api.h @@ -79,6 +79,7 @@ void api_caclient_init ( void ); void api_profile_init ( void ); void api_language_init ( void ); void api_satip_server_init ( void ); +void api_timeshift_init ( void ); /* * IDnode diff --git a/src/api/api_config.c b/src/api/api_config.c index c50720c9d..225efedb1 100644 --- a/src/api/api_config.c +++ b/src/api/api_config.c @@ -1,5 +1,5 @@ /* - * API - SAT>IP Server related calls + * API - General configuration related calls * * Copyright (C) 2015 Jaroslav Kysela * diff --git a/src/api/api_timeshift.c b/src/api/api_timeshift.c new file mode 100644 index 000000000..2dc010032 --- /dev/null +++ b/src/api/api_timeshift.c @@ -0,0 +1,36 @@ +/* + * API - Timeshift related calls + * + * Copyright (C) 2015 Jaroslav Kysela + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; withm even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "tvheadend.h" +#include "channels.h" +#include "access.h" +#include "api.h" +#include "timeshift.h" + +void +api_timeshift_init ( void ) +{ + static api_hook_t ah[] = { + { "timeshift/config/load", ACCESS_ADMIN, api_idnode_load_simple, ×hift_conf }, + { "timeshift/config/save", ACCESS_ADMIN, api_idnode_save_simple, ×hift_conf }, + { NULL }, + }; + + api_register_all(ah); +} diff --git a/src/htsp_server.c b/src/htsp_server.c index f4d9c0525..27cd7c220 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -2045,10 +2045,10 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in) profile_id = htsmsg_get_str(in, "profile"); #if ENABLE_TIMESHIFT - if (timeshift_enabled) { + if (timeshift_conf.enabled) { timeshiftPeriod = htsmsg_get_u32_or_default(in, "timeshiftPeriod", 0); - if (!timeshift_unlimited_period) - timeshiftPeriod = MIN(timeshiftPeriod, timeshift_max_period); + if (!timeshift_conf.unlimited_period) + timeshiftPeriod = MIN(timeshiftPeriod, timeshift_conf.max_period); } #endif diff --git a/src/main.c b/src/main.c index bec509773..c2ce95701 100644 --- a/src/main.c +++ b/src/main.c @@ -154,7 +154,7 @@ const tvh_caps_t tvheadend_capabilities[] = { { "imagecache", (uint32_t*)&imagecache_conf.enabled }, #endif #if ENABLE_TIMESHIFT - { "timeshift", ×hift_enabled }, + { "timeshift", (uint32_t *)×hift_conf.enabled }, #endif #if ENABLE_TRACE { "trace", NULL }, diff --git a/src/timeshift.c b/src/timeshift.c index 21ede7c26..448d4b9f7 100644 --- a/src/timeshift.c +++ b/src/timeshift.c @@ -23,6 +23,7 @@ #include "config.h" #include "settings.h" #include "atomic.h" +#include "access.h" #include #include @@ -34,24 +35,15 @@ static int timeshift_index = 0; -uint32_t timeshift_enabled; -int timeshift_ondemand; -char *timeshift_path; -int timeshift_unlimited_period; -uint32_t timeshift_max_period; -int timeshift_unlimited_size; -uint64_t timeshift_max_size; -uint64_t timeshift_ram_size; -uint64_t timeshift_ram_segment_size; -int timeshift_ram_only; +struct timeshift_conf timeshift_conf; /* * Safe values for RAM configuration */ static void timeshift_fixup ( void ) { - if (timeshift_ram_only) - timeshift_max_size = timeshift_ram_size; + if (timeshift_conf.ram_only) + timeshift_conf.max_size = timeshift_conf.ram_size; } /* @@ -60,43 +52,18 @@ static void timeshift_fixup ( void ) void timeshift_init ( void ) { htsmsg_t *m; - const char *str; - uint32_t u32; timeshift_filemgr_init(); /* Defaults */ - timeshift_enabled = 0; // Disabled - timeshift_ondemand = 0; // Permanent - timeshift_path = NULL; // setting dir - timeshift_unlimited_period = 0; - timeshift_max_period = 3600; // 1Hr - timeshift_unlimited_size = 0; - timeshift_max_size = 10000 * (size_t)1048576; // 10G - timeshift_ram_size = 0; - timeshift_ram_segment_size = 0; + memset(×hift_conf, 0, sizeof(timeshift_conf)); + timeshift_conf.idnode.in_class = ×hift_conf_class; + timeshift_conf.max_period = 3600; // 1Hr + timeshift_conf.max_size = 10000 * (size_t)1048576; // 10G /* Load settings */ if ((m = hts_settings_load("timeshift/config"))) { - if (!htsmsg_get_u32(m, "enabled", &u32)) - timeshift_enabled = u32 ? 1 : 0; - if (!htsmsg_get_u32(m, "ondemand", &u32)) - timeshift_ondemand = u32 ? 1 : 0; - if ((str = htsmsg_get_str(m, "path"))) - timeshift_path = strdup(str); - if (!htsmsg_get_u32(m, "unlimited_period", &u32)) - timeshift_unlimited_period = u32 ? 1 : 0; - htsmsg_get_u32(m, "max_period", ×hift_max_period); - if (!htsmsg_get_u32(m, "unlimited_size", &u32)) - timeshift_unlimited_size = u32 ? 1 : 0; - if (!htsmsg_get_u32(m, "max_size", &u32)) - timeshift_max_size = 1048576LL * u32; - if (!htsmsg_get_u32(m, "ram_size", &u32)) { - 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; + idnode_load(×hift_conf.idnode, m); htsmsg_destroy(m); timeshift_fixup(); } @@ -108,34 +75,135 @@ void timeshift_init ( void ) void timeshift_term ( void ) { timeshift_filemgr_term(); - free(timeshift_path); - timeshift_path = NULL; + free(timeshift_conf.path); + timeshift_conf.path = NULL; } /* * Save settings */ -void timeshift_save ( void ) +static void timeshift_conf_class_save ( idnode_t *self ) { htsmsg_t *m; timeshift_fixup(); m = htsmsg_create_map(); - htsmsg_add_u32(m, "enabled", timeshift_enabled); - htsmsg_add_u32(m, "ondemand", timeshift_ondemand); - if (timeshift_path) - htsmsg_add_str(m, "path", timeshift_path); - htsmsg_add_u32(m, "unlimited_period", timeshift_unlimited_period); - htsmsg_add_u32(m, "max_period", timeshift_max_period); - 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); - + idnode_save(×hift_conf.idnode, m); hts_settings_save(m, "timeshift/config"); + htsmsg_destroy(m); +} + +/* + * Class + */ +static const void * +timeshift_conf_class_max_size_get ( void *o ) +{ + static uint64_t r; + r = timeshift_conf.max_size / 1048576LL; + return &r; +} + +static int +timeshift_conf_class_max_size_set ( void *o, const void *v ) +{ + uint64_t u64 = *(uint64_t *)v * 1048576LL; + if (u64 != timeshift_conf.max_size) { + timeshift_conf.max_size = u64; + return 1; + } + return 0; +} + +static const void * +timeshift_conf_class_ram_size_get ( void *o ) +{ + static uint64_t r; + r = timeshift_conf.ram_size / 1048576LL; + return &r; +} + +static int +timeshift_conf_class_ram_size_set ( void *o, const void *v ) +{ + uint64_t u64 = *(uint64_t *)v * 1048576LL; + timeshift_conf.ram_segment_size = u64 / 10; + if (u64 != timeshift_conf.ram_size) { + timeshift_conf.ram_size = u64; + return 1; + } + return 0; } +const idclass_t timeshift_conf_class = { + .ic_snode = ×hift_conf.idnode, + .ic_class = "timeshift", + .ic_caption = N_("Timeshift"), + .ic_event = "timeshift", + .ic_perm_def = ACCESS_ADMIN, + .ic_save = timeshift_conf_class_save, + .ic_properties = (const property_t[]){ + { + .type = PT_BOOL, + .id = "enabled", + .name = N_("Enabled"), + .off = offsetof(timeshift_conf_t, enabled), + }, + { + .type = PT_BOOL, + .id = "ondemand", + .name = N_("On-Demand"), + .off = offsetof(timeshift_conf_t, ondemand), + }, + { + .type = PT_STR, + .id = "path", + .name = N_("Storage Path"), + .off = offsetof(timeshift_conf_t, path), + }, + { + .type = PT_U32, + .id = "max_period", + .name = N_("Maximum Period (mins)"), + .off = offsetof(timeshift_conf_t, max_period), + }, + { + .type = PT_BOOL, + .id = "unlimited_period", + .name = N_("Unlimited Time"), + .off = offsetof(timeshift_conf_t, unlimited_period), + }, + { + .type = PT_S64, + .id = "max_size", + .name = N_("Maximum Size (MB)"), + .set = timeshift_conf_class_max_size_set, + .get = timeshift_conf_class_max_size_get, + }, + { + .type = PT_S64, + .id = "ram_size", + .name = N_("Maximum RAM Size (MB)"), + .set = timeshift_conf_class_ram_size_set, + .get = timeshift_conf_class_ram_size_get, + }, + { + .type = PT_BOOL, + .id = "unlimited_size", + .name = N_("Unlimited Size"), + .off = offsetof(timeshift_conf_t, unlimited_size), + }, + { + .type = PT_BOOL, + .id = "ram_only", + .name = N_("Use only RAM"), + .off = offsetof(timeshift_conf_t, ram_only), + }, + {} + } +}; + /* * Decode initial time diff * @@ -326,7 +394,7 @@ streaming_target_t *timeshift_create ts->full = 0; ts->vididx = -1; ts->id = timeshift_index; - ts->ondemand = timeshift_ondemand; + ts->ondemand = timeshift_conf.ondemand; ts->pts_delta = PTS_UNSET; for (i = 0; i < ARRAY_SIZE(ts->pts_val); i++) ts->pts_val[i] = PTS_UNSET; diff --git a/src/timeshift.h b/src/timeshift.h index f8f98d5ca..d91c62ca4 100644 --- a/src/timeshift.h +++ b/src/timeshift.h @@ -19,18 +19,26 @@ #ifndef __TVH_TIMESHIFT_H__ #define __TVH_TIMESHIFT_H__ -extern uint32_t timeshift_enabled; -extern int timeshift_ondemand; -extern char *timeshift_path; -extern int timeshift_unlimited_period; -extern uint32_t timeshift_max_period; -extern int timeshift_unlimited_size; -extern uint64_t timeshift_max_size; -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; +#include "idnode.h" + +typedef struct timeshift_conf { + idnode_t idnode; + int enabled; + int ondemand; + char *path; + int unlimited_period; + uint32_t max_period; + int unlimited_size; + uint64_t max_size; + uint64_t total_size; + uint64_t ram_size; + uint64_t ram_segment_size; + uint64_t total_ram_size; + int ram_only; +} timeshift_conf_t; + +extern struct timeshift_conf timeshift_conf; +extern const idclass_t timeshift_conf_class; typedef struct timeshift_status { @@ -42,7 +50,6 @@ typedef struct timeshift_status void timeshift_init ( void ); void timeshift_term ( void ); -void timeshift_save ( void ); streaming_target_t *timeshift_create (streaming_target_t *out, time_t max_period); diff --git a/src/timeshift/timeshift_filemgr.c b/src/timeshift/timeshift_filemgr.c index 776a25bee..0da28b120 100644 --- a/src/timeshift/timeshift_filemgr.c +++ b/src/timeshift/timeshift_filemgr.c @@ -126,7 +126,7 @@ static void timeshift_reaper_remove ( timeshift_file_t *tsf ) static int timeshift_filemgr_get_root ( char *buf, size_t len ) { - const char *path = timeshift_path; + const char *path = timeshift_conf.path; if (!path || !*path) { return hts_settings_buildpath(buf, len, "timeshift/buffer"); } else { @@ -243,7 +243,7 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create ) time = tp.tv_sec / TIMESHIFT_FILE_PERIOD; tsf_tl = TAILQ_LAST(&ts->files, timeshift_file_list); if (!tsf_tl || tsf_tl->time != time || - (tsf_tl->ram && tsf_tl->woff >= timeshift_ram_segment_size)) { + (tsf_tl->ram && tsf_tl->woff >= timeshift_conf.ram_segment_size)) { tsf_hd = TAILQ_FIRST(&ts->files); /* Close existing */ @@ -251,7 +251,7 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create ) timeshift_filemgr_close(tsf_tl); /* Check period */ - if (!timeshift_unlimited_period && + if (!timeshift_conf.unlimited_period && ts->max_time && tsf_hd && tsf_tl) { time_t d = (tsf_tl->time - tsf_hd->time) * TIMESHIFT_FILE_PERIOD; if (d > (ts->max_time+5)) { @@ -266,8 +266,8 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create ) } /* Check size */ - if (!timeshift_unlimited_size && - atomic_pre_add_u64(×hift_total_size, 0) >= timeshift_max_size) { + if (!timeshift_conf.unlimited_size && + atomic_pre_add_u64(×hift_conf.total_size, 0) >= timeshift_conf.max_size) { /* Remove the last file (if we can) */ if (tsf_hd && !tsf_hd->refcount) { @@ -286,12 +286,12 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create ) tvhtrace("timeshift", "ts %d RAM total %"PRId64" requested %"PRId64" segment %"PRId64, ts->id, atomic_pre_add_u64(×hift_total_ram_size, 0), - timeshift_ram_size, timeshift_ram_segment_size); - if (timeshift_ram_size >= 8*1024*1024 && + timeshift_conf.ram_size, timeshift_conf.ram_segment_size); + if (timeshift_conf.ram_size >= 8*1024*1024 && atomic_pre_add_u64(×hift_total_ram_size, 0) < - timeshift_ram_size + (timeshift_ram_segment_size / 2)) { + timeshift_conf.ram_size + (timeshift_conf.ram_segment_size / 2)) { tsf_tmp = timeshift_filemgr_file_init(ts, time); - tsf_tmp->ram_size = MIN(16*1024*1024, timeshift_ram_segment_size); + tsf_tmp->ram_size = MIN(16*1024*1024, timeshift_conf.ram_segment_size); tsf_tmp->ram = malloc(tsf_tmp->ram_size); if (!tsf_tmp->ram) { free(tsf_tmp); @@ -302,7 +302,7 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create ) } } - if (!tsf_tmp && !timeshift_ram_only) { + if (!tsf_tmp && !timeshift_conf.ram_only) { /* Create directories */ if (!ts->path) { if (timeshift_filemgr_makedirs(ts->id, path, sizeof(path))) @@ -402,7 +402,7 @@ void timeshift_filemgr_init ( void ) /* Size processing */ timeshift_total_size = 0; - timeshift_ram_size = 0; + timeshift_conf.ram_size = 0; /* Start the reaper thread */ timeshift_reaper_run = 1; diff --git a/src/timeshift/timeshift_writer.c b/src/timeshift/timeshift_writer.c index 267c3f978..61d3989af 100644 --- a/src/timeshift/timeshift_writer.c +++ b/src/timeshift/timeshift_writer.c @@ -62,7 +62,7 @@ static ssize_t _write if (tsf->ram) { pthread_mutex_lock(&tsf->ram_lock); if (tsf->ram_size < tsf->woff + count) { - if (tsf->ram_size >= timeshift_ram_segment_size) + if (tsf->ram_size >= timeshift_conf.ram_segment_size) alloc = MAX(count, 64*1024); else alloc = MAX(count, 4*1024*1024); @@ -275,9 +275,9 @@ static inline ssize_t _process_msg0 if (err > 0) { tsf->last = sm->sm_time; tsf->size += err; - atomic_add_u64(×hift_total_size, err); + atomic_add_u64(×hift_conf.total_size, err); if (tsf->ram) - atomic_add_u64(×hift_total_ram_size, err); + atomic_add_u64(×hift_conf.total_ram_size, err); } return err; } diff --git a/src/webui/extjs.c b/src/webui/extjs.c index f81cf2a64..3c741af01 100644 --- a/src/webui/extjs.c +++ b/src/webui/extjs.c @@ -489,86 +489,6 @@ extjs_capabilities(http_connection_t *hc, const char *remain, void *opaque) return 0; } -/** - * - */ -#if ENABLE_TIMESHIFT -static int -extjs_timeshift(http_connection_t *hc, const char *remain, void *opaque) -{ - htsbuf_queue_t *hq = &hc->hc_reply; - const char *op = http_arg_get(&hc->hc_req_args, "op"); - htsmsg_t *out, *m; - const char *str; - - if(op == NULL) - return HTTP_STATUS_BAD_REQUEST; - - pthread_mutex_lock(&global_lock); - - if(http_access_verify(hc, ACCESS_ADMIN)) { - pthread_mutex_unlock(&global_lock); - return HTTP_STATUS_UNAUTHORIZED; - } - - pthread_mutex_unlock(&global_lock); - - /* Basic settings (not the advanced schedule) */ - if(!strcmp(op, "loadSettings")) { - pthread_mutex_lock(&global_lock); - m = htsmsg_create_map(); - htsmsg_add_u32(m, "timeshift_enabled", timeshift_enabled); - htsmsg_add_u32(m, "timeshift_ondemand", timeshift_ondemand); - if (timeshift_path) - htsmsg_add_str(m, "timeshift_path", timeshift_path); - htsmsg_add_u32(m, "timeshift_unlimited_period", timeshift_unlimited_period); - htsmsg_add_u32(m, "timeshift_max_period", timeshift_max_period / 60); - 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"); - - /* Save settings */ - } else if (!strcmp(op, "saveSettings") ) { - pthread_mutex_lock(&global_lock); - timeshift_enabled = http_arg_get(&hc->hc_req_args, "timeshift_enabled") ? 1 : 0; - timeshift_ondemand = http_arg_get(&hc->hc_req_args, "timeshift_ondemand") ? 1 : 0; - if ((str = http_arg_get(&hc->hc_req_args, "timeshift_path"))) { - if (timeshift_path) - free(timeshift_path); - timeshift_path = strdup(str); - } - timeshift_unlimited_period = http_arg_get(&hc->hc_req_args, "timeshift_unlimited_period") ? 1 : 0; - if ((str = http_arg_get(&hc->hc_req_args, "timeshift_max_period"))) - timeshift_max_period = (uint32_t)atol(str) * 60; - timeshift_unlimited_size = http_arg_get(&hc->hc_req_args, "timeshift_unlimited_size") ? 1 : 0; - if ((str = http_arg_get(&hc->hc_req_args, "timeshift_max_size"))) - timeshift_max_size = atol(str) * 1048576LL; - if ((str = http_arg_get(&hc->hc_req_args, "timeshift_ram_size"))) { - 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); - - out = htsmsg_create_map(); - htsmsg_add_u32(out, "success", 1); - - } else { - return HTTP_STATUS_BAD_REQUEST; - } - - htsmsg_json_serialize(out, hq, 0); - htsmsg_destroy(out); - http_output_content(hc, "text/x-json; charset=UTF-8"); - - return 0; -} -#endif - /** * WEB user interface */ @@ -580,8 +500,5 @@ extjs_start(void) http_path_add("/tv.html", NULL, extjs_livetv, ACCESS_WEB_INTERFACE); http_path_add("/capabilities", NULL, extjs_capabilities, ACCESS_WEB_INTERFACE); http_path_add("/epggrab", NULL, extjs_epggrab, ACCESS_WEB_INTERFACE); -#if ENABLE_TIMESHIFT - http_path_add("/timeshift", NULL, extjs_timeshift, ACCESS_ADMIN); -#endif http_path_add("/tvhlog", NULL, extjs_tvhlog, ACCESS_ADMIN); } diff --git a/src/webui/static/app/idnode.js b/src/webui/static/app/idnode.js index 2f09b83e6..7745c20db 100644 --- a/src/webui/static/app/idnode.js +++ b/src/webui/static/app/idnode.js @@ -2205,9 +2205,14 @@ tvheadend.idnode_simple = function(panel, conf) }); } + function fonchange(f, o, n) { + if (current) + conf.onchange(current, f, o, n); + } + function form_build(d) { - fpanel = new Ext.form.FormPanel({ + var fpanel = new Ext.form.FormPanel({ //title: conf.title || null, frame: true, border: true, @@ -2225,6 +2230,14 @@ tvheadend.idnode_simple = function(panel, conf) tvheadend.idnode_editor_form(d.props || d.params, d.meta, fpanel, { showpwd: conf.showpwd }); + if (conf.onchange) { + var f = fpanel.getForm().items; + for (var i = 0; i < f.items.length; i++) { + var it = f.items[i]; + it.on('check', fonchange); + it.on('change', fonchange); + } + } return fpanel; } @@ -2239,7 +2252,6 @@ tvheadend.idnode_simple = function(panel, conf) if (!force && current) return; var params = conf.edit ? (conf.edit.params || {}) : {}; - params.uuid = r.id; params.meta = 1; tvheadend.Ajax({ url: conf.url + '/load', diff --git a/src/webui/static/app/timeshift.js b/src/webui/static/app/timeshift.js index eb737046e..8bb064da3 100644 --- a/src/webui/static/app/timeshift.js +++ b/src/webui/static/app/timeshift.js @@ -1,200 +1,28 @@ tvheadend.timeshift = function(panel, index) { - /* **************************************************************** - * Data - * ***************************************************************/ - - 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_ram_only' - ] - ); - - /* **************************************************************** - * Fields - * ***************************************************************/ - - var timeshiftEnabled = new Ext.form.Checkbox({ - fieldLabel: _('Enabled'), - name: 'timeshift_enabled', - width: 300 - }); - - var timeshiftOndemand = new Ext.form.Checkbox({ - fieldLabel: _('On-Demand'), - name: 'timeshift_ondemand', - width: 300 - }); - - var timeshiftPath = new Ext.form.TextField({ - fieldLabel: _('Storage Path'), - name: 'timeshift_path', - allowBlank: true, - width: 300 - }); - - var timeshiftMaxPeriod = new Ext.form.NumberField({ - fieldLabel: _('Maximum Period (mins)'), - name: 'timeshift_max_period', - allowBlank: false, - width: 300 - }); - - var timeshiftUnlPeriod = new Ext.form.Checkbox({ - fieldLabel: _('Unlimited time'), - name: 'timeshift_unlimited_period', - width: 300 - }); - - var timeshiftMaxSize = new Ext.form.NumberField({ - fieldLabel: _('Maximum Size (MB)'), - name: 'timeshift_max_size', - allowBlank: false, - width: 300 - }); - - var timeshiftRamSize = new Ext.form.NumberField({ - fieldLabel: _('Maximum RAM Size (MB)'), - name: 'timeshift_ram_size', - allowBlank: false, - width: 250 - }); - - var timeshiftUnlSize = new Ext.form.Checkbox({ - fieldLabel: _('Unlimited size'), - name: 'timeshift_unlimited_size', - width: 300 - }); - - var timeshiftRamOnly = new Ext.form.Checkbox({ - fieldLabel: _('Use only RAM'), - name: 'timeshift_ram_only', - width: 300 - }); - - /* **************************************************************** - * Events - * ***************************************************************/ - - timeshiftUnlPeriod.on('check', function(e, c){ - timeshiftMaxPeriod.setDisabled(c); - }); - - timeshiftUnlSize.on('check', function(e, c){ - timeshiftMaxSize.setDisabled(c || timeshiftMaxSize.getValue()); - }); - - timeshiftRamOnly.on('check', function(e, c){ - timeshiftMaxSize.setDisabled(c || timeshiftUnlSize.getValue()); - }); - - /* **************************************************************** - * Form - * ***************************************************************/ - - var saveButton = new Ext.Button({ - text: _("Save configuration"), - tooltip: _('Save changes made to configuration below'), - iconCls: 'save', - handler: saveChanges - }); + function onchange(form, field, nval, oval) { + var f = form.getForm(); + var unlperiod = f.findField('unlimited_period'); + var unlsize = f.findField('unlimited_size'); + var ramonly = f.findField('ram_only'); + var maxperiod = f.findField('max_period'); + var maxsize = f.findField('max_size'); + maxperiod.setDisabled(unlperiod.getValue()); + maxsize.setDisabled(unlsize.getValue() || ramonly.getValue()); + } - var helpButton = new Ext.Button({ - text: _('Help'), - iconCls: 'help', - handler: function() { + tvheadend.idnode_simple(panel, { + url: 'api/timeshift/config', + title: _('Timeshift'), + iconCls: 'timeshift', + tabIndex: index, + comet: 'timeshift', + labelWidth: 220, + width: 570, + onchange: onchange, + help: function() { new tvheadend.help(_('Timeshift Configuration'), 'config_timeshift.html'); } }); - var timeshiftPanelA = new Ext.form.FieldSet({ - width: 500, - autoHeight: true, - border: false, - items : [timeshiftMaxPeriod, timeshiftMaxSize, timeshiftRamSize] - }); - - var timeshiftPanelB = new Ext.form.FieldSet({ - width: 200, - autoHeight: true, - border: false, - items : [timeshiftUnlPeriod, timeshiftUnlSize, timeshiftRamOnly] - }); - - var timeshiftPanel = new Ext.form.FieldSet({ - title: _('Timeshift Options'), - width: 700, - autoHeight: true, - collapsible: true, - animCollapse: true, - items : [ - timeshiftEnabled, - timeshiftOndemand, - timeshiftPath, - { - layout: 'column', - border: false, - items: [timeshiftPanelA, timeshiftPanelB] - } - ] - }); - - var confpanel = new Ext.form.FormPanel({ - title : _('Timeshift'), - iconCls : 'timeshift', - border : false, - bodyStyle : 'padding:15px', - labelAlign : 'left', - labelWidth : 150, - waitMsgTarget : true, - reader : confreader, - layout : 'form', - defaultType : 'textfield', - autoHeight : true, - animCollapse : true, - items : [timeshiftPanel], - tbar : [saveButton, '->', helpButton] - }); - - /* **************************************************************** - * Load/Save - * ***************************************************************/ - - confpanel.on('render', function() { - confpanel.getForm().load({ - url: 'timeshift', - params: { - 'op': 'loadSettings' - }, - success: function() { - confpanel.enable(); - timeshiftMaxPeriod.setDisabled(timeshiftUnlPeriod.getValue()); - timeshiftMaxSize.setDisabled(timeshiftUnlSize.getValue() || timeshiftRamOnly.getValue()); - } - }); - }); - - function saveChanges() { - confpanel.getForm().submit({ - url: 'timeshift', - params: { - op: 'saveSettings' - }, - waitMsg: _('Saving Data...'), - success: function(form, action) { - }, - failure: function(form, action) { - Ext.Msg.alert(_('Save failed'), action.result.errormsg); - } - }); - } - - tvheadend.paneladd(panel, confpanel, index); };