Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
wizard: initial (demo) work
  • Loading branch information
perexg committed Dec 3, 2015
1 parent 31cf473 commit ec6abbb
Show file tree
Hide file tree
Showing 16 changed files with 542 additions and 29 deletions.
6 changes: 4 additions & 2 deletions Makefile
Expand Up @@ -207,7 +207,8 @@ SRCS-1 = \
src/intlconv.c \
src/profile.c \
src/bouquet.c \
src/lock.c
src/lock.c \
src/wizard.c
SRCS = $(SRCS-1)
I18N-C = $(SRCS-1)

Expand Down Expand Up @@ -249,7 +250,8 @@ SRCS-2 = \
src/api/api_bouquet.c \
src/api/api_language.c \
src/api/api_satip.c \
src/api/api_timeshift.c
src/api/api_timeshift.c \
src/api/api_wizard.c

SRCS-2 += \
src/parsers/parsers.c \
Expand Down
1 change: 1 addition & 0 deletions Makefile.webui
Expand Up @@ -125,6 +125,7 @@ JAVASCRIPT += $(ROOTPATH)/app/epggrab.js
JAVASCRIPT += $(ROOTPATH)/app/config.js
JAVASCRIPT += $(ROOTPATH)/app/tvhlog.js
JAVASCRIPT += $(ROOTPATH)/app/status.js
JAVASCRIPT += $(ROOTPATH)/app/wizard.js
JAVASCRIPT += $(ROOTPATH)/tv.js
JAVASCRIPT += $(ROOTPATH)/app/servicemapper.js

Expand Down
1 change: 1 addition & 0 deletions src/api.c
Expand Up @@ -140,6 +140,7 @@ void api_init ( void )
api_language_init();
api_satip_server_init();
api_timeshift_init();
api_wizard_init();
}

void api_done ( void )
Expand Down
1 change: 1 addition & 0 deletions src/api.h
Expand Up @@ -80,6 +80,7 @@ void api_profile_init ( void );
void api_language_init ( void );
void api_satip_server_init ( void );
void api_timeshift_init ( void );
void api_wizard_init ( void );

/*
* IDnode
Expand Down
82 changes: 82 additions & 0 deletions src/api/api_wizard.c
@@ -0,0 +1,82 @@
/*
* API - Wizard interface
*
* Copyright (C) 2015 Jaroslav Kysela
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; withm even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "tvheadend.h"
#include "channels.h"
#include "access.h"
#include "api.h"
#include "config.h"
#include "wizard.h"

static int
wizard_idnode_load_simple
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
int r;
wizard_build_fcn_t fcn = opaque;
wizard_page_t *page = fcn();
r = api_idnode_load_simple(perm, &page->idnode, op, args, resp);
page->free(page);
return r;
}

static int
wizard_idnode_save_simple
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
int r;
wizard_build_fcn_t fcn = opaque;
wizard_page_t *page = fcn();
r = api_idnode_save_simple(perm, &page->idnode, op, args, resp);
page->free(page);
return r;
}

static int
wizard_cancel
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
pthread_mutex_lock(&global_lock);
free(config.wizard);
config.wizard = strdup("");
config_save();
pthread_mutex_unlock(&global_lock);
return 0;
}

void
api_wizard_init ( void )
{
static api_hook_t ah[] = {
{ "wizard/hello/load", ACCESS_ADMIN, wizard_idnode_load_simple, wizard_hello },
{ "wizard/hello/save", ACCESS_ADMIN, wizard_idnode_save_simple, wizard_hello },
{ "wizard/network/load", ACCESS_ADMIN, wizard_idnode_load_simple, wizard_network },
{ "wizard/network/save", ACCESS_ADMIN, wizard_idnode_save_simple, wizard_network },
{ "wizard/input/load", ACCESS_ADMIN, wizard_idnode_load_simple, wizard_input },
{ "wizard/input/save", ACCESS_ADMIN, wizard_idnode_save_simple, wizard_input },
{ "wizard/status/load", ACCESS_ADMIN, wizard_idnode_load_simple, wizard_status },
{ "wizard/status/save", ACCESS_ADMIN, wizard_idnode_save_simple, wizard_status },
{ "wizard/mapping/load", ACCESS_ADMIN, wizard_idnode_load_simple, wizard_mapping },
{ "wizard/mapping/save", ACCESS_ADMIN, wizard_idnode_save_simple, wizard_mapping },
{ "wizard/cancel", ACCESS_ADMIN, wizard_cancel, NULL },
{ NULL },
};

api_register_all(ah);
}
9 changes: 9 additions & 0 deletions src/config.c
Expand Up @@ -1626,6 +1626,7 @@ config_boot ( const char *path, gid_t gid, uid_t uid )

memset(&config, 0, sizeof(config));
config.idnode.in_class = &config_class;
config.wizard = strdup("hello");
config.info_area = strdup("login,storage,time");
config.cookie_expires = 7;
config.dscp = -1;
Expand Down Expand Up @@ -1732,6 +1733,7 @@ config_init ( int backup )
void config_done ( void )
{
/* note: tvhlog is inactive !!! */
free(config.wizard);
free(config.full_version);
free(config.server_name);
free(config.language);
Expand Down Expand Up @@ -2110,6 +2112,13 @@ const idclass_t config_class = {
.opts = PO_ADVANCED,
.group = 6,
},
{
.type = PT_STR,
.id = "wizard",
.name = "Wizard level", /* untranslated */
.off = offsetof(config_t, wizard),
.opts = PO_NOUI,
},
{}
}
};
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Expand Up @@ -32,6 +32,7 @@ typedef struct config {
uint32_t version;
int uilevel;
int uilevel_nochange;
char *wizard;
char *full_version;
char *server_name;
char *language;
Expand Down
6 changes: 5 additions & 1 deletion src/webui/comet.c
Expand Up @@ -150,6 +150,7 @@ comet_access_update(http_connection_t *hc, comet_mailbox_t *cmb)
const char *username = hc->hc_access ? (hc->hc_access->aa_username ?: "") : "";
int64_t bfree, btotal;
int dvr = !http_access_verify(hc, ACCESS_RECORDER);
int admin = !http_access_verify(hc, ACCESS_ADMIN);
const char *s;

htsmsg_add_str(m, "notificationClass", "accessUpdate");
Expand All @@ -170,7 +171,7 @@ comet_access_update(http_connection_t *hc, comet_mailbox_t *cmb)
if (hc->hc_peer_ipstr)
htsmsg_add_str(m, "address", hc->hc_peer_ipstr);
htsmsg_add_u32(m, "dvr", dvr);
htsmsg_add_u32(m, "admin", !http_access_verify(hc, ACCESS_ADMIN));
htsmsg_add_u32(m, "admin", admin);

htsmsg_add_s64(m, "time", time(NULL));

Expand All @@ -185,6 +186,9 @@ comet_access_update(http_connection_t *hc, comet_mailbox_t *cmb)
htsmsg_add_s64(m, "totaldiskspace", btotal);
}

if (admin && config.wizard)
htsmsg_add_str(m, "wizard", config.wizard);

if(cmb->cmb_messages == NULL)
cmb->cmb_messages = htsmsg_create_list();
htsmsg_add_msg(cmb->cmb_messages, NULL, m);
Expand Down
13 changes: 13 additions & 0 deletions src/webui/static/app/ext.css
Expand Up @@ -168,6 +168,10 @@
background-image: url(../icons/find.png) !important;
}

.wizard {
background-image: url(../icons/wand.png) !important;
}

.uilevel {
background-image: url(../icons/application_form.png) !important;
}
Expand Down Expand Up @@ -584,6 +588,15 @@
background-image: url(../icons/fetch_images.png) !important;
}

.previous {
background-image: url(../icons/arrow_left.png) !important;
}

.next {
background-image: url(../icons/arrow_right.png) !important;
}


.x-linked {
display: inline-block;
background-image: url(../icons/linked.gif) !important;
Expand Down
70 changes: 44 additions & 26 deletions src/webui/static/app/idnode.js
Expand Up @@ -831,7 +831,7 @@ tvheadend.idnode_editor_form = function(uilevel, d, meta, panel, conf)
var p = d[i];
if (conf.uuids && p.rdonly)
continue;
if (conf.noui)
if (p.noui)
continue;
var f = tvheadend.idnode_editor_field(p, conf);
if (!f)
Expand Down Expand Up @@ -1025,20 +1025,22 @@ tvheadend.idnode_editor = function(_uilevel, item, conf)
var cancelBtn = new Ext.Button({
text: _('Cancel'),
iconCls: 'cancel',
handler: conf.cancel
handler: function() {
conf.cancel(conf);
}
});
buttons.push(cancelBtn);
}

var saveBtn = new Ext.Button({
text: _('Save'),
iconCls: 'save',
text: conf.saveText || _('Save'),
iconCls: conf.saveIconCls || 'save',
handler: function() {
if (panel.getForm().isDirty()) {
var node = panel.getForm().getFieldValues();
node.uuid = conf.uuids ? conf.uuids : item.uuid;
tvheadend.Ajax({
url: 'api/idnode/save',
url: conf.saveURL || 'api/idnode/save',
params: {
node: Ext.encode(node)
},
Expand All @@ -1051,6 +1053,8 @@ tvheadend.idnode_editor = function(_uilevel, item, conf)
if (conf.win)
conf.win.close();
}
if (conf.postsave)
conf.postsave(conf);
}
});
buttons.push(saveBtn);
Expand All @@ -1064,7 +1068,7 @@ tvheadend.idnode_editor = function(_uilevel, item, conf)
var node = panel.getForm().getFieldValues();
node.uuid = conf.uuids ? conf.uuids : item.uuid;
tvheadend.Ajax({
url: 'api/idnode/save',
url: conf.saveURL || 'api/idnode/save',
params: {
node: Ext.encode(node)
},
Expand All @@ -1078,8 +1082,11 @@ tvheadend.idnode_editor = function(_uilevel, item, conf)
buttons.push(applyBtn);
}


var uilevelBtn = null;
if (!tvheadend.uilevel_nochange && (!conf.uilevel || conf.uilevel !== 'expert')) {
if (!tvheadend.uilevel_nochange &&
(!conf.uilevel || conf.uilevel !== 'expert') &&
!conf.noUIlevel) {
uilevelBtn = tvheadend.idnode_uilevel_menu(uilevel, function(l) {
uilevel = l;
var values = panel.getForm().getFieldValues();
Expand All @@ -1100,6 +1107,9 @@ tvheadend.idnode_editor = function(_uilevel, item, conf)
buttons.push(uilevelBtn ? '-' : '->');
buttons.push(helpBtn);
}

if (conf.buildbtn)
conf.buildbtn(conf, buttons);
}

panel = new Ext.form.FormPanel({
Expand All @@ -1122,6 +1132,29 @@ tvheadend.idnode_editor = function(_uilevel, item, conf)
return panel;
};

/*
*
*/
tvheadend.idnode_editor_win = function(_uilevel, item, conf)
{
var p = tvheadend.idnode_editor(_uilevel, item, conf);
var width = p.fixedWidth;
var w = new Ext.ux.Window({
title: conf.winTitle,
iconCls: 'edit',
layout: 'fit',
autoWidth: width ? false : true,
autoHeight: true,
autoScroll: true,
plain: true,
items: p
});
conf.win = w;
if (width)
w.setWidth(width);
w.show();
return w;
}

/*
* IDnode creation dialog
Expand Down Expand Up @@ -1669,28 +1702,13 @@ tvheadend.idnode_grid = function(panel, conf)
}
};
if (uuids.length > 1) {
var title = String.format(_('Edit {0} ({1} entries)'),
conf.titleS, uuids.length);
c.winTitle = String.format(_('Edit {0} ({1} entries)'),
conf.titleS, uuids.length);
c.uuids = uuids;
} else {
var title = String.format(_('Edit {0}'), conf.titleS);
c.winTitle = String.format(_('Edit {0}'), conf.titleS);
}
var p = tvheadend.idnode_editor(uilevel, d[0], c);
var width = p.fixedWidth;
w = new Ext.ux.Window({
title: title,
iconCls: 'edit',
layout: 'fit',
autoWidth: width ? false : true,
autoHeight: true,
autoScroll: true,
plain: true,
items: p
});
if (width)
w.setWidth(width);
c.win = w;
w.show();
tvheadend.idnode_editor_win(uilevel, d[0], c);
}
});
}
Expand Down
4 changes: 4 additions & 0 deletions src/webui/static/app/tvheadend.js
Expand Up @@ -5,6 +5,7 @@ tvheadend.admin = false;
tvheadend.dialog = null;
tvheadend.uilevel = 'expert';
tvheadend.uilevel_nochange = false;
tvheadend.wizard = null;

tvheadend.cookieProvider = new Ext.state.CookieProvider({
// 7 days from now
Expand Down Expand Up @@ -586,6 +587,9 @@ function accessUpdate(o) {
}

tvheadend.rootTabPanel.doLayout();

if (o.wizard)
tvheadend.wizard_start(o.wizard);
}

/**
Expand Down

2 comments on commit ec6abbb

@perexg
Copy link
Contributor Author

@perexg perexg commented on ec6abbb Dec 4, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only for initial setup for a "joe" user... I added 'Start wizard' to the global config in the latest commits.

@CvH
Copy link
Contributor

@CvH CvH commented on ec6abbb Dec 4, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.