Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
epggrab channels: fix data sync and add channel update options
  • Loading branch information
perexg committed May 11, 2016
1 parent 14b81bb commit 02ac9c9
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/epggrab.h
Expand Up @@ -99,6 +99,10 @@ typedef struct epggrab_channel

int only_one; ///< Map to only one channel (auto)
idnode_list_head_t channels; ///< Mapped channels (1 = epggrab channel, 2 = channel)

int update_chicon; ///< Update channel icon
int update_chnum; ///< Update channel number
int update_chname; ///< Update channel name
} epggrab_channel_t;

/*
Expand Down
104 changes: 94 additions & 10 deletions src/epggrab/channel.c
Expand Up @@ -139,20 +139,37 @@ static void epggrab_channel_links_delete( epggrab_channel_t *ec, int delconf )
_epgggrab_channel_link_delete(ilm, delconf);
}

/* Do update */
static void
epggrab_channel_sync( epggrab_channel_t *ec, channel_t *ch )
{
int save = 0;

if (ec->update_chname && ec->name && epggrab_conf.channel_rename)
save |= channel_set_name(ch, ec->name);
if (ec->update_chnum && ec->lcn > 0 && epggrab_conf.channel_renumber)
save |= channel_set_number(ch, ec->lcn / CHANNEL_SPLIT, ec->lcn % CHANNEL_SPLIT);
if (ec->update_chicon && ec->icon && epggrab_conf.channel_reicon)
save |= channel_set_icon(ch, ec->icon);
if (save)
idnode_changed(&ch->ch_id);
}

/* Link epggrab channel to real channel */
int
epggrab_channel_link ( epggrab_channel_t *ec, channel_t *ch, void *origin )
{
int save = 0;
idnode_list_mapping_t *ilm;

/* No change */
if (!ch || !ch->ch_enabled) return 0;

/* Already linked */
LIST_FOREACH(ilm, &ec->channels, ilm_in1_link)
if (ilm->ilm_in2 == &ch->ch_id)
if (ilm->ilm_in2 == &ch->ch_id) {
epggrab_channel_sync(ec, ch);
return 0;
}

/* New link */
tvhdebug(ec->mod->id, "linking %s to %s",
Expand All @@ -164,14 +181,7 @@ epggrab_channel_link ( epggrab_channel_t *ec, channel_t *ch, void *origin )
if (ilm == NULL)
return 0;

if (ec->name && epggrab_conf.channel_rename)
save |= channel_set_name(ch, ec->name);
if (ec->lcn > 0 && epggrab_conf.channel_renumber)
save |= channel_set_number(ch, ec->lcn / CHANNEL_SPLIT, ec->lcn % CHANNEL_SPLIT);
if (ec->icon && epggrab_conf.channel_reicon)
save |= channel_set_icon(ch, ec->icon);
if (save)
idnode_changed(&ch->ch_id);
epggrab_channel_sync(ec, ch);

if (origin == NULL)
idnode_changed(&ec->idnode);
Expand Down Expand Up @@ -332,6 +342,9 @@ epggrab_channel_t *epggrab_channel_create

ec->mod = owner;
ec->enabled = 1;
ec->update_chicon = 1;
ec->update_chnum = 1;
ec->update_chname = 1;

if (conf)
idnode_load(&ec->idnode, conf);
Expand Down Expand Up @@ -628,6 +641,64 @@ epggrab_channel_class_channels_rend ( void *obj, const char *lang )
return idnode_list_get_csv1(&ec->channels, lang);
}

static idnode_slist_t epggrab_channel_class_update_slist[] = {
{
.id = "update_icon",
.name = N_("Icon"),
.off = offsetof(epggrab_channel_t, update_chicon),
},
{
.id = "update_chnum",
.name = N_("Number"),
.off = offsetof(epggrab_channel_t, update_chnum),
},
{
.id = "update_chname",
.name = N_("Name"),
.off = offsetof(epggrab_channel_t, update_chname),
},
{}
};

static htsmsg_t *
epggrab_channel_class_update_enum ( void *obj, const char *lang )
{
return idnode_slist_enum(obj, epggrab_channel_class_update_slist, lang);
}

static const void *
epggrab_channel_class_update_get ( void *obj )
{
return idnode_slist_get(obj, epggrab_channel_class_update_slist);
}

static char *
epggrab_channel_class_update_rend ( void *obj, const char *lang )
{
return idnode_slist_rend(obj, epggrab_channel_class_update_slist, lang);
}

static int
epggrab_channel_class_update_set ( void *obj, const void *p )
{
return idnode_slist_set(obj, epggrab_channel_class_update_slist, p);
}

static void
epggrab_channel_class_update_notify ( void *obj, const char *lang )
{
epggrab_channel_t *ec = obj;
channel_t *ch;
idnode_list_mapping_t *ilm;

if (!ec->update_chicon && !ec->update_chnum && !ec->update_chname)
return;
LIST_FOREACH(ilm, &ec->channels, ilm_in1_link) {
ch = (channel_t *)ilm->ilm_in2;
epggrab_channel_sync(ec, ch);
}
}

static void
epggrab_channel_class_only_one_notify ( void *obj, const char *lang )
{
Expand Down Expand Up @@ -774,6 +845,19 @@ const idclass_t epggrab_channel_class = {
.notify = epggrab_channel_class_only_one_notify,
.group = 1
},
{
.type = PT_INT,
.islist = 1,
.id = "update",
.name = N_("Channel update options"),
.desc = N_("Options used when updating channels."),
.notify = epggrab_channel_class_update_notify,
.list = epggrab_channel_class_update_enum,
.get = epggrab_channel_class_update_get,
.set = epggrab_channel_class_update_set,
.rend = epggrab_channel_class_update_rend,
.opts = PO_ADVANCED
},
{
.type = PT_STR,
.id = "comment",
Expand Down

0 comments on commit 02ac9c9

Please sign in to comment.