]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
wizard: scan status page is working now
authorJaroslav Kysela <perex@perex.cz>
Wed, 20 Jan 2016 10:54:13 +0000 (11:54 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 20 Jan 2016 10:54:13 +0000 (11:54 +0100)
src/api/api_wizard.c
src/input/mpegts/mpegts_network.c
src/webui/static/app/wizard.js
src/wizard.c

index e68fbfebdc6c20f51dc6a5332678a45ff0b62b62..9cc1e87808f1a3e47d2f99c72e86d72d29f1ee27 100644 (file)
@@ -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 },
index 0f10cbf69e49d7ae3c80dc9de64040ecc52d5602..97ec1b6bcef78e83138d933b321fb26cdde47793 100644 (file)
@@ -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;
 
index 49077e0b99845425526451b4873dd3af0e596d5c..84d5d6cb936c2387f5dae2ef20d5d33a6a4763ac 100644 (file)
@@ -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 += '<img class="x-wizard-icon" src="' + icon + '"/>';
@@ -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',
index 2767aef978b332ca87f8618ddf60861e14bacd6e..b45f975b47ff5b93d817999bbe4783f7c549627b 100644 (file)
@@ -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;
 }