Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
wizard: scan status page is working now
  • Loading branch information
perexg committed Jan 20, 2016
1 parent c6734e5 commit 565f564
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 12 deletions.
28 changes: 28 additions & 0 deletions src/api/api_wizard.c
Expand Up @@ -22,6 +22,7 @@
#include "access.h"
#include "api.h"
#include "config.h"
#include "input.h"
#include "wizard.h"

static int
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion src/input/mpegts/mpegts_network.c
Expand Up @@ -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;

Expand Down
39 changes: 33 additions & 6 deletions src/webui/static/app/wizard.js
Expand Up @@ -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',
Expand Down Expand Up @@ -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 + '"/>';
Expand All @@ -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) {
Expand Down Expand Up @@ -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',
Expand Down
33 changes: 28 additions & 5 deletions src/wizard.c
Expand Up @@ -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) \
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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), \
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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),
Expand All @@ -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;
}

Expand Down

0 comments on commit 565f564

Please sign in to comment.