From: Jaroslav Kysela Date: Mon, 21 Sep 2015 10:45:12 +0000 (+0200) Subject: webui: the upper info area is configurable now, fixes #2986 X-Git-Tag: v4.2.1~2087 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=984fbdc1721fc2cd657247a8de92142b5dbb2038;p=thirdparty%2Ftvheadend.git webui: the upper info area is configurable now, fixes #2986 --- diff --git a/src/config.c b/src/config.c index 082dc69b0..fed51511d 100644 --- a/src/config.c +++ b/src/config.c @@ -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, }, {} } diff --git a/src/config.h b/src/config.h index ab15c3703..5f355a682 100644 --- a/src/config.h +++ b/src/config.h @@ -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; diff --git a/src/webui/comet.c b/src/webui/comet.c index d52bade91..3df47db2f 100644 --- a/src/webui/comet.c +++ b/src/webui/comet.c @@ -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); diff --git a/src/webui/static/app/tvheadend.js b/src/webui/static/app/tvheadend.js index 20e3f0bf9..0913577ae 100644 --- a/src/webui/static/app/tvheadend.js +++ b/src/webui/static/app/tvheadend.js @@ -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') + ' ' + login + ''; @@ -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 = '' + d.toLocaleTimeString() + ''; + el.qtip = d.toLocaleString(); + }, + onLoginCmdClicked: function(e) { window.location.href = this.login ? 'logout' : 'login'; }