]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
webui: the upper info area is configurable now, fixes #2986
authorJaroslav Kysela <perex@perex.cz>
Mon, 21 Sep 2015 10:45:12 +0000 (12:45 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 21 Sep 2015 10:45:12 +0000 (12:45 +0200)
src/config.c
src/config.h
src/webui/comet.c
src/webui/static/app/tvheadend.js

index 082dc69b0ba97f3f7e04348427f1265a2eb814c4..fed51511d0ce2ddaaa5bd7fe28f8cc657bd9fdac 100644 (file)
@@ -1544,6 +1544,7 @@ config_boot ( const char *path, gid_t gid, uid_t uid )
 
   memset(&config, 0, sizeof(config));
   config.idnode.in_class = &config_class;
+  config.info_area = strdup("login,storage,time");
 
   /* Generate default */
   if (!path) {
@@ -1645,6 +1646,7 @@ void config_done ( void )
   free(config.full_version);
   free(config.server_name);
   free(config.language);
+  free(config.info_area);
   free(config.muxconf_path);
   free(config.chicon_path);
   free(config.picon_path);
@@ -1733,6 +1735,45 @@ config_class_language_list ( void *o, const char *lang )
   return m;
 }
 
+static const void *
+config_class_info_area_get ( void *o )
+{
+  return htsmsg_csv_2_list(config.info_area, ',');
+}
+
+static int
+config_class_info_area_set ( void *o, const void *v )
+{
+  char *s = htsmsg_list_2_csv((htsmsg_t *)v, ',', 0);
+  if (strcmp(s ?: "", config.info_area ?: "")) {
+    free(config.info_area);
+    config.info_area = s;
+    return 1;
+  }
+  if (s)
+    free(s);
+  return 0;
+}
+
+static void
+config_class_info_area_list1 ( htsmsg_t *m, const char *key, const char *val )
+{
+  htsmsg_t *e = htsmsg_create_map();
+  htsmsg_add_str(e, "key", key);
+  htsmsg_add_str(e, "val", val);
+  htsmsg_add_msg(m, NULL, e);
+}
+
+static htsmsg_t *
+config_class_info_area_list ( void *o, const char *lang )
+{
+  htsmsg_t *m = htsmsg_create_list();
+  config_class_info_area_list1(m, "login", N_("Login/Logout"));
+  config_class_info_area_list1(m, "storage", N_("Storage space"));
+  config_class_info_area_list1(m, "time", N_("Time"));
+  return m;
+}
+
 const idclass_t config_class = {
   .ic_snode      = &config.idnode,
   .ic_class      = "config",
@@ -1750,17 +1791,21 @@ const idclass_t config_class = {
          .number = 2,
       },
       {
-         .name   = N_("DVB Scan Files"),
+         .name   = N_("Web User Interface"),
          .number = 3,
       },
       {
-         .name   = N_("Time Update"),
+         .name   = N_("DVB Scan Files"),
          .number = 4,
       },
       {
-         .name   = N_("Picon"),
+         .name   = N_("Time Update"),
          .number = 5,
       },
+      {
+         .name   = N_("Picon"),
+         .number = 6,
+      },
       {}
   },
   .ic_properties = (const property_t[]){
@@ -1806,54 +1851,65 @@ const idclass_t config_class = {
       .opts   = PO_LORDER,
       .group  = 2
     },
+    {
+      .type   = PT_STR,
+      .islist = 1,
+      .id     = "info_area",
+      .name   = N_("Information Area"),
+      .set    = config_class_info_area_set,
+      .get    = config_class_info_area_get,
+      .list   = config_class_info_area_list,
+      .opts   = PO_LORDER,
+      .group  = 3
+    },
     {
       .type   = PT_STR,
       .id     = "muxconfpath",
       .name   = N_("DVB scan files path"),
       .off    = offsetof(config_t, muxconf_path),
-      .group  = 3
+      .group  = 4
     },
     {
       .type   = PT_BOOL,
       .id     = "tvhtime_update_enabled",
       .name   = N_("Update time"),
       .off    = offsetof(config_t, tvhtime_update_enabled),
-      .group  = 4,
+      .group  = 5,
     },
     {
       .type   = PT_BOOL,
       .id     = "tvhtime_ntp_enabled",
       .name   = N_("Enable NTP driver"),
       .off    = offsetof(config_t, tvhtime_update_enabled),
-      .group  = 4,
+      .group  = 5,
     },
     {
       .type   = PT_U32,
       .id     = "tvhtime_tolerance",
       .name   = N_("Update tolerance (ms)"),
       .off    = offsetof(config_t, tvhtime_tolerance),
-      .group  = 4,
+      .group  = 5,
     },
     {
       .type   = PT_BOOL,
       .id     = "prefer_picon",
       .name   = N_("Prefer picons over channel name"),
       .off    = offsetof(config_t, prefer_picon),
-      .group  = 5,
+      .group  = 6,
     },
     {
       .type   = PT_STR,
       .id     = "chiconpath",
       .name   = N_("Channel icon path (see Help)"),
       .off    = offsetof(config_t, chicon_path),
-      .group  = 5,
+      .group  = 6,
     },
     {
       .type   = PT_STR,
       .id     = "piconpath",
       .name   = N_("Picon path (see Help)"),
       .off    = offsetof(config_t, picon_path),
-      .group  = 5,
+      .group  = 6,
     },
     {}
   }
index ab15c3703a0ccc88ad341f7b18245550279e29ad..5f355a68293bbfb52f06355fe56f64c2f3e23a49 100644 (file)
@@ -33,6 +33,7 @@ typedef struct config {
   char *full_version;
   char *server_name;
   char *language;
+  char *info_area;
   char *muxconf_path;
   int prefer_picon;
   char *chicon_path;
index d52bade912685d3753585698b6bac35b71806204..3df47db2f69ec51edfe12113c72365f055267a97 100644 (file)
@@ -30,6 +30,7 @@
 #include "htsmsg_json.h"
 
 #include "tvheadend.h"
+#include "config.h"
 #include "http.h"
 #include "dvr/dvr.h"
 #include "webui/webui.h"
@@ -155,6 +156,11 @@ comet_access_update(http_connection_t *hc, comet_mailbox_t *cmb)
   htsmsg_add_u32(m, "dvr",      dvr);
   htsmsg_add_u32(m, "admin",    !http_access_verify(hc, ACCESS_ADMIN));
 
+  htsmsg_add_s64(m, "time",     time(NULL));
+
+  if (config.info_area && config.info_area[0])
+    htsmsg_add_str(m, "info_area", config.info_area);
+
   if (dvr && !dvr_get_disk_space(&bfree, &btotal)) {
     htsmsg_add_s64(m, "freediskspace", bfree);
     htsmsg_add_s64(m, "totaldiskspace", btotal);
index 20e3f0bf9ec2cac3c7e8bcb7c8ad575ad92e9142..0913577ae52907d252bbf84b16665b86d86a0118 100644 (file)
@@ -1,4 +1,3 @@
-
 tvheadend.dynamic = true;
 tvheadend.accessupdate = null;
 tvheadend.capabilities = null;
@@ -350,6 +349,8 @@ function accessUpdate(o) {
     if (!tvheadend.capabilities)
         return;
 
+    if ('info_area' in o)
+      tvheadend.rootTabPanel.setInfoArea(o.info_area);
     if ('username' in o)
       tvheadend.rootTabPanel.setLogin(o.username);
     if ('address' in o)
@@ -554,46 +555,47 @@ tvheadend.RootTabExtraClickComponent = Ext.extend(Ext.Component, {
 
 tvheadend.RootTabPanel = Ext.extend(Ext.TabPanel, {
 
-    extra: {},
-
-    onRender: function(ct, position) {
-        tvheadend.RootTabPanel.superclass.onRender.call(this, ct, position);
-
-        var before = this.strip.dom.childNodes[this.strip.dom.childNodes.length-1];
+    extra: [],
+    info_area: [],
 
-        /* Create login components */
-        if (!this.extra.login) {
-          this.extra.login = new tvheadend.RootTabExtraComponent();
-          this.extra.login.onRender1(this, before);
-        }
-        if (!this.extra.loginCmd) {
-          this.extra.loginCmd = new tvheadend.RootTabExtraClickComponent();
-          this.extra.loginCmd.onRender1(this, before, this.onLoginCmdClicked);
-        }
-        if (!this.extra.storage) {
-          this.extra.storage = new tvheadend.RootTabExtraComponent();
-          this.extra.storage.onRender1(this, before);
+    getComponent: function(comp) {
+        for (var k in this.extra) {
+            var comp2 = this.extra[k];
+            if (comp === comp2.id || comp == comp2)
+                return comp2;
         }
+        return tvheadend.RootTabPanel.superclass.getComponent.call(this, comp);
+    },
 
+    setInfoArea: function(info_area) {
+        this.info_area = info_area.split(',');
         this.on('beforetabchange', function(tp, p) {
             for (var k in this.extra)
                 if (p == this.extra[k])
                     return false;
         });
-    },
 
-    getComponent: function(comp) {
-        for (var k in this.extra) {
-            var comp2 = this.extra[k];
-            if (comp === comp2.id || comp == comp2)
-                return comp2;
+        var before = this.strip.dom.childNodes[this.strip.dom.childNodes.length-1];
+
+        /* Create extra components */
+        for (var itm in this.info_area) {
+            var nm = this.info_area[itm];
+            if (!(nm in this.extra)) {
+                this.extra[nm] = new tvheadend.RootTabExtraComponent();
+                this.extra[nm].onRender1(this, before);
+                if (nm == 'login') {
+                    this.extra.loginCmd = new tvheadend.RootTabExtraClickComponent();
+                    this.extra.loginCmd.onRender1(this, before, this.onLoginCmdClicked);
+                }
+            }
         }
-        return tvheadend.RootTabPanel.superclass.getComponent.call(this, comp);
+        
+        if (this.extra.time)
+            window.setInterval(this.setTime, 1000);
     },
 
     setLogin: function(login) {
-        if (!'login' in this.extra)
-            return;
+        if (!('login' in this.extra)) return;
         this.login = login;
         if (login) {
             text = _('Logged in as') + ' <b>' + login + '</b>';
@@ -612,7 +614,7 @@ tvheadend.RootTabPanel = Ext.extend(Ext.TabPanel, {
     },
 
     setDiskSpace: function(bfree, btotal) {
-        if (!'storage' in this.extra) return;
+        if (!('storage' in this.extra)) return;
         human = function(val) {
           if (val > 1000000000)
             val = parseInt(val / 1000000000) + _('GB');
@@ -628,6 +630,15 @@ tvheadend.RootTabPanel = Ext.extend(Ext.TabPanel, {
         el.qtip = _('Free') + ': ' + human(bfree) + ' ' + _('Total') + ': ' + human(btotal);
     },
 
+    setTime: function(stime) {
+        var panel = tvheadend.rootTabPanel;
+        if (!('time' in panel.extra)) return;
+        var d = stime ? new Date(stime) : new Date();
+        var el = Ext.get(panel.extra.time.tabEl).child('span.x-tab-strip-extra-comp', true);
+        el.innerHTML = '<b>' + d.toLocaleTimeString() + '</b>';
+        el.qtip = d.toLocaleString();
+    },
+
     onLoginCmdClicked: function(e) {
         window.location.href = this.login ? 'logout' : 'login';
     }