From: Jaroslav Kysela Date: Wed, 20 Jan 2016 10:54:13 +0000 (+0100) Subject: wizard: scan status page is working now X-Git-Tag: v4.2.1~1152 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=565f564231a1d94a18c582ba697e8be95610e5e8;p=thirdparty%2Ftvheadend.git wizard: scan status page is working now --- diff --git a/src/api/api_wizard.c b/src/api/api_wizard.c index e68fbfebd..9cc1e8780 100644 --- a/src/api/api_wizard.c +++ b/src/api/api_wizard.c @@ -22,6 +22,7 @@ #include "access.h" #include "api.h" #include "config.h" +#include "input.h" #include "wizard.h" static int @@ -76,6 +77,32 @@ wizard_start return wizard_page("hello"); } +static int +wizard_status_progress + ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp ) +{ + int64_t active = 0, total = 0, services = 0; + mpegts_service_t *s; + mpegts_mux_t *mm; + mpegts_network_t *mn; + + LIST_FOREACH(mn, &mpegts_network_all, mn_global_link) { + if (!mn->mn_wizard) continue; + LIST_FOREACH(mm, &mn->mn_muxes, mm_network_link) { + total++; + if (mm->mm_scan_state != MM_SCAN_STATE_IDLE) + active++; + LIST_FOREACH(s, &mm->mm_services, s_dvb_mux_link) + services++; + } + } + *resp = htsmsg_create_map(); + htsmsg_add_dbl(*resp, "progress", total ? ((double)1.0 - ((double)active / (double)total)) : 1); + htsmsg_add_s64(*resp, "muxes", total); + htsmsg_add_s64(*resp, "services", services); + return 0; +} + void api_wizard_init ( void ) { @@ -90,6 +117,7 @@ api_wizard_init ( void ) { "wizard/muxes/save", ACCESS_ADMIN, wizard_idnode_save_simple, wizard_muxes }, { "wizard/status/load", ACCESS_ADMIN, wizard_idnode_load_simple, wizard_status }, { "wizard/status/save", ACCESS_ADMIN, wizard_idnode_save_simple, wizard_status }, + { "wizard/status/progress", ACCESS_ADMIN, wizard_status_progress, NULL }, { "wizard/mapping/load", ACCESS_ADMIN, wizard_idnode_load_simple, wizard_mapping }, { "wizard/mapping/save", ACCESS_ADMIN, wizard_idnode_save_simple, wizard_mapping }, { "wizard/start", ACCESS_ADMIN, wizard_start, NULL }, diff --git a/src/input/mpegts/mpegts_network.c b/src/input/mpegts/mpegts_network.c index 0f10cbf69..97ec1b6bc 100644 --- a/src/input/mpegts/mpegts_network.c +++ b/src/input/mpegts/mpegts_network.c @@ -99,7 +99,7 @@ mpegts_network_class_get_num_chn ( void *ptr ) static const void * mpegts_network_class_get_scanq_length ( void *ptr ) { - static __thread int n; + static int n; mpegts_mux_t *mm; mpegts_network_t *mn = ptr; diff --git a/src/webui/static/app/wizard.js b/src/webui/static/app/wizard.js index 49077e0b9..84d5d6cb9 100644 --- a/src/webui/static/app/wizard.js +++ b/src/webui/static/app/wizard.js @@ -6,7 +6,6 @@ tvheadend.wizard_delayed_activation = null; tvheadend.wizard_start = function(page) { - var w = null; var tabMapping = { hello: 'base_config', login: 'access_entry', @@ -70,10 +69,32 @@ tvheadend.wizard_start = function(page) { buttons.splice(0, 0, prevBtn); } + function progressupdate() { + var conf = this; + Ext.Ajax.request({ + url: 'api/wizard/' + page + '/progress', + success: function(d) { + d = json_decode(d); + var t = conf.progress.initialConfig.text; + var i = d['progress']; + conf.progress.updateProgress(i, t + ' ' + Math.round(100*i) + '%'); + conf.progress_task.delay(1000, progressupdate, conf); + for (var key in d) + if (key !== 'progress') { + var f = conf.form.findField(key); + if (f) + f.setValue(d[key]); + } + }, + }); + } + function pbuild(conf, panel) { var data = conf.fullData; var icon = getvalue(data, 'icon'); var text = getvalue(data, 'description'); + var progress = getvalue(data, 'progress'); + conf.form = panel.getForm(); var c = ''; if (icon) c += ''; @@ -89,6 +110,15 @@ tvheadend.wizard_start = function(page) { html: c }); panel.insert(0, p); + if (progress) { + conf.progress = new Ext.ProgressBar({ + text: progress, + style: 'margin: 5px 0 15px;' + }); + panel.insert(1, conf.progress); + conf.progress_task = new Ext.util.DelayedTask(progressupdate, conf); + conf.progress_task.delay(1000); + } } function build(d) { @@ -135,12 +165,9 @@ tvheadend.wizard_start = function(page) { tvheadend.wizard = page; - var delay = 1000; if (tvheadend.wizard_delayed_activation == null) { - tvheadend.wizard_delayed_activation = new Ext.util.DelayedTask(); - delay = 1; - } - tvheadend.wizard_delayed_activation.delay(1000, activate_tab); + tvheadend.wizard_delayed_activation = new Ext.util.DelayedTask(activate_tab); + tvheadend.wizard_delayed_activation.delay(1000); tvheadend.Ajax({ url: 'api/wizard/' + page + '/load', diff --git a/src/wizard.c b/src/wizard.c index 2767aef97..b45f975b4 100644 --- a/src/wizard.c +++ b/src/wizard.c @@ -53,6 +53,7 @@ static const void *icon_get(void *o) #define LAST_BUTTON() SPECIAL_PROP("page_last", empty_get) #define ICON() SPECIAL_PROP("icon", icon_get) #define DESCRIPTION(page) SPECIAL_PROP("description", wizard_description_##page) +#define PROGRESS(fcn) SPECIAL_PROP("progress", fcn) #define DESCRIPTION_FCN(page, desc) \ static const void *wizard_description_##page(void *o) \ @@ -700,6 +701,7 @@ wizard_page_t *wizard_network(const char *lang) */ typedef struct wizard_muxes { + char lang [64]; property_t props [WIZARD_NETWORKS * 3 + 10]; char network [WIZARD_NETWORKS][64]; char networkid [WIZARD_NETWORKS][UUID_HEX_SIZE]; @@ -738,6 +740,14 @@ static void muxes_save(idnode_t *in) } } +static const void *muxes_progress_get(void *o) +{ + wizard_page_t *p = o; + wizard_muxes_t *w = p->aux; + snprintf(prop_sbuf, PROP_SBUF_LEN, "%s", tvh_gettext_lang(w->lang, N_("Scan progress"))); + return &prop_sbuf_ptr; +} + #define MUXES(num) { \ .type = PT_STR, \ .id = "network" STRINGIFY(num), \ @@ -900,6 +910,7 @@ wizard_page_t *wizard_muxes(const char *lang) ic->ic_properties = w->props; ic->ic_save = muxes_save; page->free = muxes_free; + snprintf(w->lang, sizeof(w->lang), "%s", lang ?: ""); for (idx = 0; idx < ARRAY_SIZE(props); idx++) w->props[idx] = props[idx]; @@ -932,29 +943,40 @@ wizard_page_t *wizard_muxes(const char *lang) */ DESCRIPTION_FCN(status, N_("\ -Show the scan status.\ +Show the scan status.\n\ +Please, wait until the scan finishes.\ ")) wizard_page_t *wizard_status(const char *lang) { + static const property_group_t groups[] = { + { + .name = "", + .number = 1, + }, + {} + }; static const property_t props[] = { { .type = PT_STR, .id = "muxes", .name = N_("Found muxes"), .desc = N_("Number of muxes found."), - .get = hello_get_network, - .set = hello_set_network, + .get = empty_get, + .opts = PO_RDONLY, + .group = 1, }, { .type = PT_STR, .id = "services", .name = N_("Found services"), .desc = N_("Total number of services found."), - .get = hello_get_network, - .set = hello_set_network, + .get = empty_get, + .opts = PO_RDONLY, + .group = 1, }, + PROGRESS(muxes_progress_get), ICON(), DESCRIPTION(status), PREV_BUTTON(muxes), @@ -964,6 +986,7 @@ wizard_page_t *wizard_status(const char *lang) wizard_page_t *page = page_init("status", "wizard_status", N_("Scan status")); idclass_t *ic = (idclass_t *)page->idnode.in_class; ic->ic_properties = props; + ic->ic_groups = groups; return page; }