]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
timeshift: move to the simple node system
authorJaroslav Kysela <perex@perex.cz>
Tue, 15 Sep 2015 16:12:28 +0000 (18:12 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 15 Sep 2015 16:12:28 +0000 (18:12 +0200)
14 files changed:
Makefile
src/api.c
src/api.h
src/api/api_config.c
src/api/api_timeshift.c [new file with mode: 0644]
src/htsp_server.c
src/main.c
src/timeshift.c
src/timeshift.h
src/timeshift/timeshift_filemgr.c
src/timeshift/timeshift_writer.c
src/webui/extjs.c
src/webui/static/app/idnode.js
src/webui/static/app/timeshift.js

index 7430dec94012855175187cd23d86509f969af2e8..3cb1a9495a5f40db4a6c5b699cae6a5cd2f43f48 100644 (file)
--- 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 \
index a1f71fda6f8c3dbde6e6de53334a1581688eb2f8..6db216a2448f0bc997505bfaa94d766cd3ff66fe 100644 (file)
--- 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 )
index 73fbdc7b17e980f01ebf9226b3f872d459aa850d..8557879c4b2f9e948ddfa716417b3f6c34d1c28a 100644 (file)
--- 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
index c50720c9da70524e90e7e56a742f6b0b8e2a9875..225efedb1580bc63660160ebcd77583a4a616e48 100644 (file)
@@ -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 (file)
index 0000000..2dc0100
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+#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, &timeshift_conf },
+    { "timeshift/config/save", ACCESS_ADMIN, api_idnode_save_simple, &timeshift_conf },
+    { NULL },
+  };
+
+  api_register_all(ah);
+}
index f4d9c052538b28e15307c58139ac1e042e00b1ee..27cd7c22013b7d8fb0122e9e35ee2bede32cce79 100644 (file)
@@ -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
 
index bec5097735c5b4c2ade481b05919fe3142e93117..c2ce9570189db51e2575d679815c45e93cdae17b 100644 (file)
@@ -154,7 +154,7 @@ const tvh_caps_t tvheadend_capabilities[] = {
   { "imagecache", (uint32_t*)&imagecache_conf.enabled },
 #endif
 #if ENABLE_TIMESHIFT
-  { "timeshift", &timeshift_enabled },
+  { "timeshift", (uint32_t *)&timeshift_conf.enabled },
 #endif
 #if ENABLE_TRACE
   { "trace",     NULL },
index 21ede7c26f7d3ab4a5f79640431ea264280e47f2..448d4b9f7820836fd1bae52733f0ca3cc7c95abd 100644 (file)
@@ -23,6 +23,7 @@
 #include "config.h"
 #include "settings.h"
 #include "atomic.h"
+#include "access.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
 
 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(&timeshift_conf, 0, sizeof(timeshift_conf));
+  timeshift_conf.idnode.in_class = &timeshift_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", &timeshift_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(&timeshift_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(&timeshift_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      = &timeshift_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;
index f8f98d5ca9c1fd83af315cb835b49cdad0e043db..d91c62ca469cccb82d051664313a4965fe3e78f1 100644 (file)
 #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);
index 776a25bee4c65a12897d985934385575316c83d4..0da28b120a158a0312a0f28fb94a88a8e2d6a4d7 100644 (file)
@@ -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(&timeshift_total_size, 0) >= timeshift_max_size) {
+    if (!timeshift_conf.unlimited_size &&
+        atomic_pre_add_u64(&timeshift_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(&timeshift_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(&timeshift_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;
index 267c3f9781210d1e2cc86318434cffde97caee1d..61d3989af1cb9c87731a31730a54e06912977d02 100644 (file)
@@ -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(&timeshift_total_size, err);
+    atomic_add_u64(&timeshift_conf.total_size, err);
     if (tsf->ram)
-      atomic_add_u64(&timeshift_total_ram_size, err);
+      atomic_add_u64(&timeshift_conf.total_ram_size, err);
   }
   return err;
 }
index f81cf2a6480fcff5c934246ad9fe41aabf9c3ded..3c741af012fff439cf0be56d51c06acae0466016 100644 (file)
@@ -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);
 }
index 2f09b83e6c38fd5affd2c431f49b1df0916ae8e2..7745c20dbb26f4f5946f9abfbf8632072527535a 100644 (file)
@@ -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',
index eb737046e03d3e75d40a703ebf73b475df5a7f3f..8bb064da344529ec3ba6178da78b9e0651bbc39c 100644 (file)
 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);
 };